From 902a929f6681931b495ed989b7808ab3a4cfeb7e Mon Sep 17 00:00:00 2001 From: Jon P Smith Date: Tue, 5 Jan 2021 17:22:55 +0000 Subject: [PATCH] Updated headers --- Benchmarking/PerfCallMethodToUpdate1.cs | 12 +- Benchmarking/PerfCallMethodUpdate2.cs | 11 +- Benchmarking/PerfListMany.cs | 5 +- DataLayer/Dtos/OrderBooksDto.cs | 4 +- DataLayer/EfClasses/Author.cs | 4 +- DataLayer/EfClasses/Book.cs | 44 +++---- DataLayer/EfClasses/BookAuthor.cs | 5 +- DataLayer/EfClasses/LineItem.cs | 4 +- DataLayer/EfClasses/Order.cs | 4 +- DataLayer/EfClasses/Review.cs | 4 +- DataLayer/EfCode/BookDbContext.cs | 10 +- .../EfCode/Configurations/BookAuthorConfig.cs | 4 +- DataLayer/EfCode/Configurations/BookConfig.cs | 4 +- .../EfCode/Configurations/LineItemConfig.cs | 4 +- .../EfCode/Configurations/OrderConfig.cs | 4 +- DataLayer/EfCode/EfCoreContext.cs | 4 +- DataLayer/EfCode/OrderDbContext.cs | 4 +- DataLayer/QueryObjects/GenericPaging.cs | 4 +- .../Configuration/DefaultNameMatcher.cs | 4 +- .../Configuration/GenericServicesConfig.cs | 5 +- .../Configuration/IGenericServicesConfig.cs | 5 +- .../Configuration/Internal/CrudTypes.cs | 4 +- .../Configuration/PerDtoConfig.Generic.cs | 5 +- GenericServices/Configuration/PerDtoConfig.cs | 8 +- .../Configuration/PropertyMatch.cs | 61 +++++----- GenericServices/CrudValues.cs | 4 +- GenericServices/ICrudServices.Generic.cs | 6 +- GenericServices/ICrudServices.cs | 7 +- GenericServices/ICrudServicesAsync.Generic.cs | 6 +- GenericServices/ICrudServicesAsync.cs | 5 +- GenericServices/ILinkToEntity.cs | 4 +- GenericServices/IncludeThenAttribute.cs | 14 +-- .../Internal/Decoders/BestMethodCtorMatch.cs | 21 ++-- .../Internal/Decoders/BestPropertyMatch.cs | 20 ++-- .../Internal/Decoders/DecodeName.cs | 14 +-- .../Internal/Decoders/DecodedDataCache.cs | 19 ++- .../Internal/Decoders/DecodedDto.cs | 36 +++--- .../Internal/Decoders/DecodedDtoExtensions.cs | 8 +- .../Internal/Decoders/DecodedDtoProperty.cs | 9 +- .../Internal/Decoders/DecodedEntityClass.cs | 38 +++--- .../Internal/Decoders/MethodCtorMatch.cs | 28 ++--- .../Internal/Decoders/MethodCtorMatcher.cs | 4 +- .../Internal/Decoders/ParametersMatch.cs | 24 ++-- .../Internal/ErrorMessageExtensions.cs | 4 +- .../Internal/ExtractDisplayHelpers.cs | 6 +- .../Internal/LinqBuilders/BuildCall.cs | 20 ++-- .../Internal/LinqBuilders/BuildCallAsync.cs | 5 +- .../Internal/LinqBuilders/BuildFilter.cs | 5 +- .../Internal/MappingCode/CreateMapper.cs | 14 +-- .../MappingCode/EntityCreateHandler.cs | 10 +- .../MappingCode/EntityUpdateHandler.cs | 10 +- .../Internal/MappingCode/KeyHandlers.cs | 5 +- GenericServices/Internal/SplitterExtension.cs | 5 +- .../PublicButHidden/CrudServices.cs | 71 ++++++----- .../PublicButHidden/CrudServicesAsync.cs | 71 ++++++----- .../PublicButHidden/WrappedConfigAndMapper.cs | 4 +- GenericServices/SaveChangesExtensions.cs | 4 +- .../Setup/ConfigureGenericServices.cs | 6 +- .../Setup/IGenericServicesSetupPart1.cs | 4 +- .../Setup/IGenericServicesSetupPart2.cs | 5 +- .../Setup/Internal/CreateConfigGenerator.cs | 8 +- .../Internal/GenericServicesSetupPart2.cs | 5 +- .../Setup/Internal/MappingProfile.cs | 5 +- .../Setup/Internal/RegisterOneDtoType.cs | 19 ++- .../Setup/Internal/SetupAllEntities.cs | 10 +- .../Setup/Internal/SetupDtosAndMappings.cs | 10 +- .../Setup/Internal/SetupEntitiesExtensions.cs | 4 +- GenericServices/Setup/SpecificUseData.cs | 27 ++--- GenericServices/Setup/UnitTestSetup.cs | 4 +- .../ValidationDbContextServiceProvider.cs | 4 +- .../Dtos/AuthorWithBookCountDto.cs | 5 +- .../DatabaseCode/Dtos/BookInfoJson.cs | 4 +- .../DatabaseCode/Services/BookJsonLoader.cs | 4 +- .../DatabaseCode/Services/SetupHelpers.cs | 4 +- ServiceLayer/HomeController/DropdownTuple.cs | 5 +- .../Dtos/AddRemovePromotionDto.cs | 4 +- .../HomeController/Dtos/AddReviewDto.cs | 4 +- .../Dtos/BookListCombinedDto.cs | 4 +- .../HomeController/Dtos/BookListDto.cs | 4 +- .../HomeController/Dtos/BookListDtoConfig.cs | 4 +- .../HomeController/Dtos/ChangePubDateDto.cs | 4 +- .../HomeController/Dtos/CreateBookDto.cs | 42 ++++--- .../HomeController/Dtos/DeleteBookDto.cs | 4 +- .../Dtos/DeleteBookDtoConfig.cs | 4 +- .../IAddRemovePromotionService.cs | 5 +- .../HomeController/IAddReviewService.cs | 5 +- .../IBookFilterDropdownService.cs | 4 +- .../HomeController/IChangePubDateService.cs | 5 +- .../HomeController/IListBooksService.cs | 4 +- .../QueryObjects/BookListDtoFilter.cs | 4 +- .../QueryObjects/BookListDtoSelect.cs | 4 +- .../QueryObjects/BookListDtoSort.cs | 4 +- .../Services/AddRemovePromotionService.cs | 5 +- .../Services/AddReviewService.cs | 4 +- .../Services/BookFilterDropdownService.cs | 4 +- .../Services/ChangePubDateService.cs | 5 +- .../Services/GenericAddPromotionService.cs | 11 +- .../Services/ListBooksService.cs | 4 +- .../HomeController/SortFilterPageOptions.cs | 4 +- Tests/Configs/AuthorNestedV2DtoConfig.cs | 4 +- Tests/Configs/BookTitleAndCountConfig.cs | 4 +- Tests/Configs/BookWithAuthorsConfig.cs | 4 +- Tests/Configs/BookWithTagsConfig.cs | 4 +- Tests/Configs/InContactAddressConfig.cs | 4 +- Tests/Configs/UniqueConfig.cs | 4 +- .../AddNewAuthorToBookUsingIncludesDto.cs | 3 +- Tests/Dtos/AddReviewByNameExtendedDto.cs | 4 +- Tests/Dtos/AddReviewDto.cs | 4 +- Tests/Dtos/AddReviewWithIncludeDto.cs | 3 +- Tests/Dtos/AuthorNameDto.cs | 4 +- Tests/Dtos/AuthorNestedV1Dto.cs | 4 +- Tests/Dtos/AuthorNestedV2Dto.cs | 4 +- Tests/Dtos/BookListNestedV1Dto.cs | 5 +- Tests/Dtos/BookListNestedV2Dto.cs | 5 +- Tests/Dtos/BookTitle.cs | 4 +- Tests/Dtos/BookTitleAndCount.cs | 6 +- Tests/Dtos/BookTitleBadType.cs | 4 +- Tests/Dtos/BookWithAuthors.cs | 4 +- Tests/Dtos/BookWithTags.cs | 4 +- Tests/Dtos/ChangePubDateDto.cs | 4 +- Tests/Dtos/ChildDbQueryDto.cs | 2 +- Tests/Dtos/CreatorOfBooksDto.cs | 12 +- Tests/Dtos/DddCompositeIntStringCreateDto.cs | 4 +- Tests/Dtos/DddCtorEntityAbstractBaseDto.cs | 7 +- Tests/Dtos/DddCtorEntityAbstractMainDto.cs | 4 +- Tests/Dtos/DtoLinkedToOwnedType.cs | 2 +- Tests/Dtos/InAddressDto.cs | 6 +- Tests/Dtos/InContactAddressDto.cs | 2 +- Tests/Dtos/MultiMatchTestDto.cs | 2 +- .../Dtos/NormalEntityAllMarkedReadOnlyDto.cs | 5 +- Tests/Dtos/NormalEntityDto.cs | 4 +- Tests/Dtos/NormalEntityKeyAbstractDto.cs | 4 +- Tests/Dtos/NormalEntityKeyPrivateSetDto.cs | 4 +- Tests/Dtos/SoftDelEntity.cs | 2 +- Tests/Dtos/TestAbstractCreate.cs | 2 +- Tests/Dtos/TestAbstractUpdateViaAutoMapper.cs | 2 +- Tests/Dtos/TestAbstractUpdateViaMethod.cs | 2 +- Tests/Dtos/UniqueNoConfigDto.cs | 5 +- Tests/Dtos/UniqueWithConfigDto.cs | 5 +- Tests/Dtos/WriteAuthorAll.cs | 4 +- Tests/Dtos/WriteAuthorReadOnlyDto.cs | 7 +- Tests/EfClasses/Address.cs | 5 +- Tests/EfClasses/AddressNotOwned.cs | 6 +- Tests/EfClasses/Child.cs | 2 +- Tests/EfClasses/ChildReadOnly.cs | 2 +- Tests/EfClasses/ContactAddress.cs | 4 +- Tests/EfClasses/DddCompositeIntString.cs | 17 ++- Tests/EfClasses/DddCtorAndFactEntity.cs | 15 +-- Tests/EfClasses/DddCtorEntity.cs | 5 +- Tests/EfClasses/DddStaticCreateEntity.cs | 13 +- Tests/EfClasses/KeyIsString.cs | 4 +- Tests/EfClasses/NormalEntity.cs | 6 +- Tests/EfClasses/NotUpdatableEntity.cs | 6 +- Tests/EfClasses/Parent.cs | 3 +- Tests/EfClasses/ParentOneToOne.cs | 2 +- Tests/EfClasses/ParentWithChildCountQuery.cs | 2 +- Tests/EfClasses/ReadOnlyEntity.cs | 7 +- Tests/EfClasses/SoftDelEntity.cs | 2 +- Tests/EfClasses/TenantAddress.cs | 13 +- Tests/EfClasses/TestAbstractBase.cs | 2 +- Tests/EfClasses/TestAbstractMain.cs | 3 +- Tests/EfClasses/UniqueEntity.cs | 5 +- Tests/EfCode/TestDbContext.cs | 8 +- Tests/Helpers/AutoMapperHelpers.cs | 5 +- Tests/Helpers/DddEfTestData.cs | 4 +- Tests/Helpers/UnitTestProfile.cs | 5 +- Tests/UnitTests/DataLayer/TestDddBook.cs | 6 +- Tests/UnitTests/DataLayer/TestDddBookLoad.cs | 12 +- Tests/UnitTests/DataLayer/TestDddOrder.cs | 7 +- Tests/UnitTests/DataLayer/TestQueryDb.cs | 12 +- .../TestSaveChangesWithValidation.cs | 5 +- .../TestGenericServicesVersions.cs | 5 +- .../TestHandCodedVersions.cs | 5 +- .../TestBestMethodCtorMatch.cs | 95 ++++++++------- .../GenericServicesInternal/TestBuildCall.cs | 111 +++++++++--------- .../TestBuildCallAsync.cs | 47 +++----- .../TestCreateMapGenerator.cs | 13 +- .../GenericServicesInternal/TestDecodedDto.cs | 62 +++++----- .../TestDecodedDtoKeyIsString.cs | 19 +-- .../TestDecodedEntityClass.cs | 10 +- .../TestExtractDisplayHelpers.cs | 38 +++--- .../TestKeyHandlers.cs | 10 +- .../TestParametersMatch.cs | 28 ++--- .../TestAbstractClassAccess.cs | 5 +- .../GenericServicesPublic/TestCreateViaDto.cs | 63 +++++----- .../GenericServicesPublic/TestDbQueryCrud.cs | 4 +- .../TestDeleteWithQueryFilter.cs | 9 +- .../GenericServicesPublic/TestDirectAccess.cs | 8 +- .../TestGenericServicesConfig.cs | 4 +- .../TestIncludeThenAttribute.cs | 16 +-- .../GenericServicesPublic/TestJsonPatch.cs | 7 +- .../TestMultipleMatch.cs | 5 +- .../GenericServicesPublic/TestNestedDtos.cs | 9 +- .../TestNestedInDtosIssue13.cs | 8 +- .../TestProjectFromEntityToDto.cs | 6 +- .../GenericServicesPublic/TestReadViaDto.cs | 5 +- .../TestSaveChangesWithValidation.cs | 36 +++--- .../GenericServicesPublic/TestUpdateViaDto.cs | 44 +++---- .../TestUpdateWithIncludeThenAttribute.cs | 7 +- .../TestCreateViaDtoAsync.cs | 47 ++++---- .../TestDbQueryCrudAsync.cs | 5 +- .../TestDeleteWithQueryFilter.cs | 8 +- .../TestDirectAccessAsync.cs | 6 +- .../TestJsonPatchAsync.cs | 7 +- .../TestProjectFromEntityToDto.cs | 4 +- .../TestReadViaDtoAsync.cs | 6 +- .../TestSaveChangesWithValidationAsync.cs | 36 +++--- .../TestUpdateViaDtoAsync.cs | 63 +++++----- .../TestBeforeSaveChangesAsync.cs | 6 +- .../TestBeforeSaveChangesSync.cs | 6 +- .../TestReadSingleNull.cs | 6 +- .../TestSetupDtosAndMappings.cs | 7 +- .../TestSqlErrorHandlerAsync.cs | 5 +- .../TestSqlErrorHandlerSync.cs | 7 +- .../GenericServicesSetup/TestUnitTestSetup.cs | 26 ++-- Tests/UnitTests/Libraries/TestAutoMapper.cs | 7 +- .../Performance/CompareAgainstHandCoded.cs | 27 ++--- .../Performance/TestNewCreateMapper.cs | 4 +- Tests/UnitTests/TestIssues/TestIssue30.cs | 10 +- Tests/UnitTests/TestIssues/TestIssue31.cs | 6 +- Tests/UnitTests/TestIssues/TestIssue41.cs | 2 +- Tests/UnitTests/TestIssues/TestIssue43.cs | 3 +- Tests/UnitTests/TestIssues/TestIssue47.cs | 6 +- 223 files changed, 1109 insertions(+), 1248 deletions(-) diff --git a/Benchmarking/PerfCallMethodToUpdate1.cs b/Benchmarking/PerfCallMethodToUpdate1.cs index 07a58f6..6728dfb 100644 --- a/Benchmarking/PerfCallMethodToUpdate1.cs +++ b/Benchmarking/PerfCallMethodToUpdate1.cs @@ -1,6 +1,7 @@ -using System; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + using System.Linq; -using AutoMapper; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Running; using DataLayer.EfClasses; @@ -11,7 +12,6 @@ using Tests.Dtos; using Tests.Helpers; using TestSupport.EfHelpers; -using TestSupport.Helpers; using Xunit; using Xunit.Extensions.AssertExtensions; @@ -19,8 +19,8 @@ namespace Benchmarking { public class PerfCallMethodToUpdate1 { - private SpecificUseData _utData; private DbContextOptions _options; + private SpecificUseData _utData; [Fact] public void AddReviewToBook() @@ -50,7 +50,7 @@ public void RunGenericService() var numReviews = context.Set().Count(); //ATTEMPT - var dto = new Tests.Dtos.AddReviewDto { BookId = 1, Comment = "comment", NumStars = 3, VoterName = "user" }; + var dto = new AddReviewDto { BookId = 1, Comment = "comment", NumStars = 3, VoterName = "user" }; service.UpdateAndSave(dto, nameof(Book.AddReview)); //VERIFY @@ -76,7 +76,5 @@ public void RunHandCoded() context.Set().Count().ShouldEqual(numReviews + 1); } } - - } } diff --git a/Benchmarking/PerfCallMethodUpdate2.cs b/Benchmarking/PerfCallMethodUpdate2.cs index 07efbef..d3059bf 100644 --- a/Benchmarking/PerfCallMethodUpdate2.cs +++ b/Benchmarking/PerfCallMethodUpdate2.cs @@ -1,3 +1,6 @@ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + using System; using System.Linq; using BenchmarkDotNet.Attributes; @@ -17,9 +20,9 @@ namespace Benchmarking { public class PerfCallMethodUpdate2 { - private SpecificUseData _utData; - private DbContextOptions _options; private int _incdDay = 0; + private DbContextOptions _options; + private SpecificUseData _utData; [Fact] public void ChangePublicationDate() @@ -116,9 +119,5 @@ public void RunGenericServiceMethodAccess() entity.PublishedOn.ShouldEqual(newDate); } } - - - - } } diff --git a/Benchmarking/PerfListMany.cs b/Benchmarking/PerfListMany.cs index 77a35e9..392bd2e 100644 --- a/Benchmarking/PerfListMany.cs +++ b/Benchmarking/PerfListMany.cs @@ -1,3 +1,6 @@ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + using System.Linq; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Running; @@ -69,7 +72,5 @@ public void RunGenericService() books.Count.ShouldEqual(100); } } - - } } diff --git a/DataLayer/Dtos/OrderBooksDto.cs b/DataLayer/Dtos/OrderBooksDto.cs index 27d370e..fdca9d8 100644 --- a/DataLayer/Dtos/OrderBooksDto.cs +++ b/DataLayer/Dtos/OrderBooksDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using DataLayer.EfClasses; diff --git a/DataLayer/EfClasses/Author.cs b/DataLayer/EfClasses/Author.cs index 3b6093d..8ee51d2 100644 --- a/DataLayer/EfClasses/Author.cs +++ b/DataLayer/EfClasses/Author.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Collections.Generic; using System.ComponentModel.DataAnnotations; diff --git a/DataLayer/EfClasses/Book.cs b/DataLayer/EfClasses/Book.cs index bbc795d..4fe12f9 100644 --- a/DataLayer/EfClasses/Book.cs +++ b/DataLayer/EfClasses/Book.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; @@ -14,13 +14,13 @@ public class Book { public const int PromotionalTextLength = 200; private HashSet _authorsLink; - private HashSet _tags; //----------------------------------------------- //relationships //Use uninitialised backing fields - this means we can detect if the collection was loaded private HashSet _reviews; + private HashSet _tags; //----------------------------------------------- //ctors @@ -53,6 +53,26 @@ public Book(string title, string description, DateTime publishedOn, _authorsLink = new HashSet(authors.Select(a => new BookAuthor(this, a, order++))); } + public int BookId { get; private set; } + + [Required(AllowEmptyStrings = false)] + public string Title { get; private set; } + + public string Description { get; private set; } + public DateTime PublishedOn { get; set; } + public string Publisher { get; private set; } + public decimal OrgPrice { get; private set; } + public decimal ActualPrice { get; private set; } + + [MaxLength(PromotionalTextLength)] + public string PromotionalText { get; private set; } + + public string ImageUrl { get; private set; } + + public IEnumerable Reviews => _reviews?.ToList(); + public IEnumerable Tags => _tags?.ToList(); + public IEnumerable AuthorsLink => _authorsLink?.ToList(); + public static IStatusGeneric CreateBook(string title, string description, DateTime publishedOn, string publisher, decimal price, string imageUrl, ICollection authors, ICollection tags = null) @@ -87,24 +107,6 @@ public static IStatusGeneric CreateBook(string title, string description, return status.SetResult(book); } - public int BookId { get; private set; } - [Required(AllowEmptyStrings = false)] - public string Title { get; private set; } - public string Description { get; private set; } - public DateTime PublishedOn { get; set; } - public string Publisher { get; private set; } - public decimal OrgPrice { get; private set; } - public decimal ActualPrice { get; private set; } - - [MaxLength(PromotionalTextLength)] - public string PromotionalText { get; private set; } - - public string ImageUrl { get; private set; } - - public IEnumerable Reviews => _reviews?.ToList(); - public IEnumerable Tags => _tags?.ToList(); - public IEnumerable AuthorsLink => _authorsLink?.ToList(); - public void UpdatePublishedOn(DateTime publishedOn) { PublishedOn = publishedOn; diff --git a/DataLayer/EfClasses/BookAuthor.cs b/DataLayer/EfClasses/BookAuthor.cs index ba5caf5..66a6eb5 100644 --- a/DataLayer/EfClasses/BookAuthor.cs +++ b/DataLayer/EfClasses/BookAuthor.cs @@ -1,5 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + namespace DataLayer.EfClasses { public class BookAuthor diff --git a/DataLayer/EfClasses/LineItem.cs b/DataLayer/EfClasses/LineItem.cs index 5f8101c..fcefaf3 100644 --- a/DataLayer/EfClasses/LineItem.cs +++ b/DataLayer/EfClasses/LineItem.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; diff --git a/DataLayer/EfClasses/Order.cs b/DataLayer/EfClasses/Order.cs index 596fb63..9c96435 100644 --- a/DataLayer/EfClasses/Order.cs +++ b/DataLayer/EfClasses/Order.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; diff --git a/DataLayer/EfClasses/Review.cs b/DataLayer/EfClasses/Review.cs index 912a918..221205c 100644 --- a/DataLayer/EfClasses/Review.cs +++ b/DataLayer/EfClasses/Review.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.ComponentModel.DataAnnotations; diff --git a/DataLayer/EfCode/BookDbContext.cs b/DataLayer/EfCode/BookDbContext.cs index c343678..f7955f4 100644 --- a/DataLayer/EfCode/BookDbContext.cs +++ b/DataLayer/EfCode/BookDbContext.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; using DataLayer.EfCode.Configurations; @@ -9,15 +9,15 @@ namespace DataLayer.EfCode { public class BookDbContext : DbContext { - public DbSet Books { get; set; } - public DbSet Authors { get; set; } - public BookDbContext( DbContextOptions options) : base(options) { } + public DbSet Books { get; set; } + public DbSet Authors { get; set; } + protected override void OnModelCreating(ModelBuilder modelBuilder) { diff --git a/DataLayer/EfCode/Configurations/BookAuthorConfig.cs b/DataLayer/EfCode/Configurations/BookAuthorConfig.cs index 66a3f25..4683369 100644 --- a/DataLayer/EfCode/Configurations/BookAuthorConfig.cs +++ b/DataLayer/EfCode/Configurations/BookAuthorConfig.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; using Microsoft.EntityFrameworkCore; diff --git a/DataLayer/EfCode/Configurations/BookConfig.cs b/DataLayer/EfCode/Configurations/BookConfig.cs index a99e42c..daf434a 100644 --- a/DataLayer/EfCode/Configurations/BookConfig.cs +++ b/DataLayer/EfCode/Configurations/BookConfig.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; using Microsoft.EntityFrameworkCore; diff --git a/DataLayer/EfCode/Configurations/LineItemConfig.cs b/DataLayer/EfCode/Configurations/LineItemConfig.cs index 9a7aaa1..27c545c 100644 --- a/DataLayer/EfCode/Configurations/LineItemConfig.cs +++ b/DataLayer/EfCode/Configurations/LineItemConfig.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; using Microsoft.EntityFrameworkCore; diff --git a/DataLayer/EfCode/Configurations/OrderConfig.cs b/DataLayer/EfCode/Configurations/OrderConfig.cs index 85170da..236d82e 100644 --- a/DataLayer/EfCode/Configurations/OrderConfig.cs +++ b/DataLayer/EfCode/Configurations/OrderConfig.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; using Microsoft.EntityFrameworkCore; diff --git a/DataLayer/EfCode/EfCoreContext.cs b/DataLayer/EfCode/EfCoreContext.cs index f08d409..e388708 100644 --- a/DataLayer/EfCode/EfCoreContext.cs +++ b/DataLayer/EfCode/EfCoreContext.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; using DataLayer.EfCode.Configurations; diff --git a/DataLayer/EfCode/OrderDbContext.cs b/DataLayer/EfCode/OrderDbContext.cs index 285071a..8be7252 100644 --- a/DataLayer/EfCode/OrderDbContext.cs +++ b/DataLayer/EfCode/OrderDbContext.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; using DataLayer.EfCode.Configurations; diff --git a/DataLayer/QueryObjects/GenericPaging.cs b/DataLayer/QueryObjects/GenericPaging.cs index 693f726..24d2cf9 100644 --- a/DataLayer/QueryObjects/GenericPaging.cs +++ b/DataLayer/QueryObjects/GenericPaging.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; diff --git a/GenericServices/Configuration/DefaultNameMatcher.cs b/GenericServices/Configuration/DefaultNameMatcher.cs index 435039d..2bfa038 100644 --- a/GenericServices/Configuration/DefaultNameMatcher.cs +++ b/GenericServices/Configuration/DefaultNameMatcher.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; diff --git a/GenericServices/Configuration/GenericServicesConfig.cs b/GenericServices/Configuration/GenericServicesConfig.cs index 16d6903..d56ba3d 100644 --- a/GenericServices/Configuration/GenericServicesConfig.cs +++ b/GenericServices/Configuration/GenericServicesConfig.cs @@ -1,8 +1,7 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; -using System.ComponentModel.DataAnnotations; using System.Reflection; using Microsoft.EntityFrameworkCore; using StatusGeneric; diff --git a/GenericServices/Configuration/IGenericServicesConfig.cs b/GenericServices/Configuration/IGenericServicesConfig.cs index b4f7624..5ea3388 100644 --- a/GenericServices/Configuration/IGenericServicesConfig.cs +++ b/GenericServices/Configuration/IGenericServicesConfig.cs @@ -1,8 +1,7 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; -using System.ComponentModel.DataAnnotations; using Microsoft.EntityFrameworkCore; using StatusGeneric; diff --git a/GenericServices/Configuration/Internal/CrudTypes.cs b/GenericServices/Configuration/Internal/CrudTypes.cs index e7ae926..e3f7e0b 100644 --- a/GenericServices/Configuration/Internal/CrudTypes.cs +++ b/GenericServices/Configuration/Internal/CrudTypes.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; diff --git a/GenericServices/Configuration/PerDtoConfig.Generic.cs b/GenericServices/Configuration/PerDtoConfig.Generic.cs index b9e127c..122f28a 100644 --- a/GenericServices/Configuration/PerDtoConfig.Generic.cs +++ b/GenericServices/Configuration/PerDtoConfig.Generic.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using AutoMapper; @@ -27,6 +27,5 @@ public abstract class PerDtoConfig : PerDtoConfig /// This allows you to alter the AutoMapper create/update mapping, i.e. from DTO/ViewModel to Entity class /// public virtual Action> AlterSaveMapping { get { return null; } } - } } \ No newline at end of file diff --git a/GenericServices/Configuration/PerDtoConfig.cs b/GenericServices/Configuration/PerDtoConfig.cs index 90767e8..6e3811a 100644 --- a/GenericServices/Configuration/PerDtoConfig.cs +++ b/GenericServices/Configuration/PerDtoConfig.cs @@ -1,7 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. - -using System; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. namespace GenericServices.Configuration { @@ -38,7 +36,5 @@ public abstract class PerDtoConfig /// Setting this to true/false will override everything so that you can set validation on/off just the methods in this DTO. /// public virtual bool? UseSaveChangesWithValidation { get; } = null; - - } } \ No newline at end of file diff --git a/GenericServices/Configuration/PropertyMatch.cs b/GenericServices/Configuration/PropertyMatch.cs index 267ca70..f248ee8 100644 --- a/GenericServices/Configuration/PropertyMatch.cs +++ b/GenericServices/Configuration/PropertyMatch.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Reflection; @@ -20,24 +20,46 @@ public enum MatchSources { Property, DbContext } /// public class PropertyMatch { + /// + /// These are the type match values. It is very imporant that they go from zero to 3, as the match maths relise on this + /// + public enum TypeMatchLevels + { +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member + NoMatch = 0, + Match = 3 +#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member + } + /// /// Use "score >= PerfectMatchValue" to check if there is a perfect match /// public const double PerfectMatchValue = 0.99999; + /// /// Use "score lessThanOrEqual NoMatchAtAll" to check if there is a perfect match /// public const double NoMatchAtAll = 0.00001; /// - /// These are the type match values. It is very imporant that they go from zero to 3, as the match maths relise on this + /// This is the ctor to create a PropertyMatch /// - public enum TypeMatchLevels + /// + /// + /// + public PropertyMatch(bool nameMatched, TypeMatchLevels typeMatch, PropertyInfo propertyInfo) + : this(nameMatched, typeMatch, propertyInfo, MatchSources.Property, null) { } + + internal PropertyMatch(bool nameMatched, TypeMatchLevels typeMatch, PropertyInfo propertyInfo, + MatchSources matchSource, Type nonPropertyMatchType) { -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - NoMatch = 0, - Match = 3 -#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member + NameMatched = nameMatched; + TypeMatch = typeMatch; + if ((int)TypeMatch > 3) + throw new InvalidOperationException("The TypeMatchLevels must run from 0 to 3, 3 being a perfect match."); + PropertyInfo = propertyInfo; + MatchSource = matchSource; + NonPropertyMatchType = nonPropertyMatchType; } /// @@ -70,27 +92,6 @@ public enum TypeMatchLevels /// public double Score => (NameMatched ? 0.7 : 0.0) + ((int) TypeMatch / 10.0); - /// - /// This is the ctor to create a PropertyMatch - /// - /// - /// - /// - public PropertyMatch(bool nameMatched, TypeMatchLevels typeMatch, PropertyInfo propertyInfo) - : this(nameMatched, typeMatch, propertyInfo, MatchSources.Property, null) { } - - internal PropertyMatch(bool nameMatched, TypeMatchLevels typeMatch, PropertyInfo propertyInfo, - MatchSources matchSource, Type nonPropertyMatchType) - { - NameMatched = nameMatched; - TypeMatch = typeMatch; - if ((int)TypeMatch > 3) - throw new InvalidOperationException("The TypeMatchLevels must run from 0 to 3, 3 being a perfect match."); - PropertyInfo = propertyInfo; - MatchSource = matchSource; - NonPropertyMatchType = nonPropertyMatchType; - } - /// /// This returns useful information on a match /// @@ -98,7 +99,7 @@ internal PropertyMatch(bool nameMatched, TypeMatchLevels typeMatch, PropertyInfo public override string ToString() { string matchInfo = "wrong name"; - if (Score >= PropertyMatch.PerfectMatchValue) + if (Score >= PerfectMatchValue) matchInfo = $"{PropertyInfo.PropertyType.Name} {PropertyInfo.Name}"; else if (Score <= NoMatchAtAll) matchInfo = "nothing matches"; diff --git a/GenericServices/CrudValues.cs b/GenericServices/CrudValues.cs index d4a92dc..e956ea9 100644 --- a/GenericServices/CrudValues.cs +++ b/GenericServices/CrudValues.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. namespace GenericServices { diff --git a/GenericServices/ICrudServices.Generic.cs b/GenericServices/ICrudServices.Generic.cs index 4182d7b..43fbd0f 100644 --- a/GenericServices/ICrudServices.Generic.cs +++ b/GenericServices/ICrudServices.Generic.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore; @@ -10,5 +10,5 @@ namespace GenericServices /// Useful if you have multiple DbContext (known as database bounded contexts) /// /// - public interface ICrudServices : ICrudServices where TContext : DbContext { } + public interface ICrudServices : ICrudServices where TContext : DbContext {} } \ No newline at end of file diff --git a/GenericServices/ICrudServices.cs b/GenericServices/ICrudServices.cs index 2b0df97..e769ff3 100644 --- a/GenericServices/ICrudServices.cs +++ b/GenericServices/ICrudServices.cs @@ -1,6 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. - +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; @@ -59,7 +58,7 @@ public interface ICrudServices : IStatusGeneric /// IQueryable ProjectFromEntityToDto(Func, IQueryable> query) where TEntity : class; - + /// /// This will create a new entity in the database. If you provide class which is an entity class (i.e. in your EF Core database) then /// the method will add, and then call SaveChanges. If the class you provide is a CrudServices DTO which has a interface diff --git a/GenericServices/ICrudServicesAsync.Generic.cs b/GenericServices/ICrudServicesAsync.Generic.cs index 54868ce..70c00be 100644 --- a/GenericServices/ICrudServicesAsync.Generic.cs +++ b/GenericServices/ICrudServicesAsync.Generic.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore; @@ -9,5 +9,5 @@ namespace GenericServices /// This is the interface for the async form of CrudServices where you define the DbContext to be used in the CrudServices /// Useful if you have multiple DbContext (known as database bounded contexts) /// - public interface ICrudServicesAsync : ICrudServicesAsync where TContext : DbContext { } + public interface ICrudServicesAsync : ICrudServicesAsync where TContext : DbContext {} } \ No newline at end of file diff --git a/GenericServices/ICrudServicesAsync.cs b/GenericServices/ICrudServicesAsync.cs index 48946e5..4655a98 100644 --- a/GenericServices/ICrudServicesAsync.cs +++ b/GenericServices/ICrudServicesAsync.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + +using System; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; diff --git a/GenericServices/ILinkToEntity.cs b/GenericServices/ILinkToEntity.cs index 80dc92b..0e148ae 100644 --- a/GenericServices/ILinkToEntity.cs +++ b/GenericServices/ILinkToEntity.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. namespace GenericServices { diff --git a/GenericServices/IncludeThenAttribute.cs b/GenericServices/IncludeThenAttribute.cs index 655a354..d845484 100644 --- a/GenericServices/IncludeThenAttribute.cs +++ b/GenericServices/IncludeThenAttribute.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2020 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT license. See License file in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; @@ -16,11 +16,6 @@ namespace GenericServices [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public class IncludeThenAttribute : Attribute { - /// - /// This holds the combined includeName and thenIncludeNames from the constructor - /// - public string IncludeNames { get; private set; } - /// /// This will cause a Include to be added to the database query in an UpdateAndSave call /// Useful when updating something in the main entity class where you need a relationships, e.g. adding a new Review. @@ -35,5 +30,10 @@ public IncludeThenAttribute(string includeName, params string[] thenIncludeNames if (thenIncludeNames.Any()) IncludeNames += "." + string.Join(".", thenIncludeNames); } + + /// + /// This holds the combined includeName and thenIncludeNames from the constructor + /// + public string IncludeNames { get; private set; } } } \ No newline at end of file diff --git a/GenericServices/Internal/Decoders/BestMethodCtorMatch.cs b/GenericServices/Internal/Decoders/BestMethodCtorMatch.cs index ad492cc..f8474ac 100644 --- a/GenericServices/Internal/Decoders/BestMethodCtorMatch.cs +++ b/GenericServices/Internal/Decoders/BestMethodCtorMatch.cs @@ -1,7 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; @@ -15,6 +14,14 @@ namespace GenericServices.Internal.Decoders { internal class BestMethodCtorMatch { + private BestMethodCtorMatch(object methodOrCtor, List propertyMatches) + { + Method = methodOrCtor as MethodInfo; + Constructor = methodOrCtor as ConstructorInfo; + DtoPropertiesInOrder = propertyMatches.ToImmutableList(); + Score = propertyMatches.Average(x => x.Score); + } + public MethodInfo Method { get; set; } public ConstructorInfo Constructor { get; } @@ -25,14 +32,6 @@ internal class BestMethodCtorMatch /// public double Score { get; set; } - private BestMethodCtorMatch(object methodOrCtor, List propertyMatches) - { - Method = methodOrCtor as MethodInfo; - Constructor = methodOrCtor as ConstructorInfo; - DtoPropertiesInOrder = propertyMatches.ToImmutableList(); - Score = propertyMatches.Average(x => x.Score); - } - public static BestMethodCtorMatch FindMatch(ImmutableList propertyInfos, dynamic[] whattoConsider) { if (whattoConsider.Length == 0) diff --git a/GenericServices/Internal/Decoders/BestPropertyMatch.cs b/GenericServices/Internal/Decoders/BestPropertyMatch.cs index 31a8390..3c26461 100644 --- a/GenericServices/Internal/Decoders/BestPropertyMatch.cs +++ b/GenericServices/Internal/Decoders/BestPropertyMatch.cs @@ -1,12 +1,10 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; -using AutoMapper; [assembly: InternalsVisibleTo("Tests")] @@ -14,13 +12,6 @@ namespace GenericServices.Internal.Decoders { internal class BestPropertyMatch { - public PropertyInfo PropertyInfo { get; private set; } - - /// - /// A Score of 1 means a perfect match. - /// - public double Score { get; set; } - public BestPropertyMatch(string name, Type type, PropertyInfo propertyInfo) { PropertyInfo = propertyInfo; @@ -31,6 +22,13 @@ public BestPropertyMatch(string name, Type type, PropertyInfo propertyInfo) Score += type == propertyInfo?.PropertyType ? 0.3 : 0; } + public PropertyInfo PropertyInfo { get; private set; } + + /// + /// A Score of 1 means a perfect match. + /// + public double Score { get; set; } + public static BestPropertyMatch FindMatch(PropertyInfo propertyToMatch, IEnumerable propertiesToCheck) { return FindMatch(propertyToMatch.Name, propertyToMatch.PropertyType, propertiesToCheck); diff --git a/GenericServices/Internal/Decoders/DecodeName.cs b/GenericServices/Internal/Decoders/DecodeName.cs index aec52f6..7152aed 100644 --- a/GenericServices/Internal/Decoders/DecodeName.cs +++ b/GenericServices/Internal/Decoders/DecodeName.cs @@ -1,9 +1,7 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.Linq; namespace GenericServices.Internal.Decoders { @@ -11,10 +9,6 @@ internal enum DecodedNameTypes { NoNameGiven, Method, Ctor, AutoMapper} internal class DecodeName { - public string Name { get; } - public DecodedNameTypes NameType { get; } - public int NumParams { get; } = -1; //This means number of parameters was not defined - public DecodeName(string nameToDecode) { if (string.IsNullOrEmpty(nameToDecode)) @@ -50,6 +44,10 @@ public DecodeName(string nameToDecode) NameType = DecodedNameTypes.AutoMapper; } + public string Name { get; } + public DecodedNameTypes NameType { get; } + public int NumParams { get; } = -1; //This means number of parameters was not defined + public override string ToString() { return NameType == DecodedNameTypes.NoNameGiven diff --git a/GenericServices/Internal/Decoders/DecodedDataCache.cs b/GenericServices/Internal/Decoders/DecodedDataCache.cs index c247607..a25471c 100644 --- a/GenericServices/Internal/Decoders/DecodedDataCache.cs +++ b/GenericServices/Internal/Decoders/DecodedDataCache.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Concurrent; @@ -14,6 +14,13 @@ namespace GenericServices.Internal.Decoders { internal static class DecodedDataCache { + //----------------------------------------------------- + //private methods/dicts + + private static readonly ConcurrentDictionary DecodedDtoCache = new ConcurrentDictionary(); + + private static readonly ConcurrentDictionary EntityInfoCache = new ConcurrentDictionary(); + public static DecodedEntityClass GetEntityInfoThrowExceptionIfNotThere(this DbContext context, Type entityOrDto) { //If the entity type is found in the LinkToEntity interface it returns that, otherwise the called type because it must be the entity @@ -54,17 +61,9 @@ public static IStatusGeneric GetOrCreateDtoInfo(this Type classType, return status; } - //----------------------------------------------------- - //private methods/dicts - - private static readonly ConcurrentDictionary DecodedDtoCache = new ConcurrentDictionary(); - - private static readonly ConcurrentDictionary EntityInfoCache = new ConcurrentDictionary(); - private static DecodedEntityClass GetEntityClassInfo(this DbContext context, Type classType) { return EntityInfoCache.GetOrAdd(classType, type => new DecodedEntityClass(classType, context)); } - } } \ No newline at end of file diff --git a/GenericServices/Internal/Decoders/DecodedDto.cs b/GenericServices/Internal/Decoders/DecodedDto.cs index b2565d7..97b2f99 100644 --- a/GenericServices/Internal/Decoders/DecodedDto.cs +++ b/GenericServices/Internal/Decoders/DecodedDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; @@ -12,26 +12,16 @@ namespace GenericServices.Internal.Decoders { internal class DecodedDto { - private readonly List _matchedSetterMethods; + private readonly string[] _endingsToRemove = new[] { "Dto", "VM", "ViewModel" }; private readonly List _matchedCtorsAndStaticMethods; - - private List _allPossibleSetterMatches; - private List _allPossibleCtorsAndStaticMatches; + private readonly List _matchedSetterMethods; private readonly MethodCtorMatcher _matcher; private readonly PerDtoConfig _perDtoConfig; //can be null + private List _allPossibleCtorsAndStaticMatches; - public Type DtoType { get; } - public DecodedEntityClass LinkedEntityInfo { get; } - public ImmutableList PropertyInfos { get; } - + private List _allPossibleSetterMatches; - /// - /// This contains the different way the entity can be created - /// - public ImmutableList MatchedCtorsAndStaticMethods => - _matchedCtorsAndStaticMethods.ToImmutableList(); - public DecodedDto(Type dtoType, DecodedEntityClass entityInfo, IGenericServicesConfig publicConfig, PerDtoConfig perDtoConfig) { @@ -61,6 +51,17 @@ public DecodedDto(Type dtoType, DecodedEntityClass entityInfo, new DecodeName(_perDtoConfig?.UpdateMethod), null); } + public Type DtoType { get; } + public DecodedEntityClass LinkedEntityInfo { get; } + public ImmutableList PropertyInfos { get; } + + + /// + /// This contains the different way the entity can be created + /// + public ImmutableList MatchedCtorsAndStaticMethods => + _matchedCtorsAndStaticMethods.ToImmutableList(); + /// /// This returns true if the SaveChanges should be validated /// Done this way to allow unit tests to have different DtoAccessValidateOnSave settings @@ -94,6 +95,7 @@ public DecodeName GetSpecifiedName(string nameGivenInCommand, CrudTypes createOr throw new ArgumentException("You should only use Create or Update here", nameof(createOrUpdate)); } } + public MethodCtorMatch GetMethodToRun(DecodeName nameInfo, DecodedEntityClass entityInfo) { if (nameInfo.NameType == DecodedNameTypes.NoNameGiven) @@ -223,8 +225,6 @@ private List MatchCtorsAndStaticMethodsToProperties(DecodedEnti return _allPossibleCtorsAndStaticMatches.Where(x => x.PropertiesMatch.Score >= PropertyMatch.PerfectMatchValue).ToList(); } - private readonly string[] _endingsToRemove = new[] { "Dto", "VM", "ViewModel" }; - private string ExtractPossibleMethodNameFromDtoTypeName() { var name = DtoType.Name; diff --git a/GenericServices/Internal/Decoders/DecodedDtoExtensions.cs b/GenericServices/Internal/Decoders/DecodedDtoExtensions.cs index 047d0ab..fd364ce 100644 --- a/GenericServices/Internal/Decoders/DecodedDtoExtensions.cs +++ b/GenericServices/Internal/Decoders/DecodedDtoExtensions.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; @@ -10,9 +10,9 @@ namespace GenericServices.Internal.Decoders { internal static class DecodedDtoExtensions { - private class ClassWithILinkInterface : ILinkToEntity { } //This contains the name of the ILinkToEntity interface public static readonly string InterfaceNameILinkToEntity = typeof(ClassWithILinkInterface).GetInterfaces().Single().Name; + public static readonly string HumanReadableILinkToEntity = InterfaceNameILinkToEntity.Substring(0, InterfaceNameILinkToEntity.Length - 2); @@ -41,5 +41,7 @@ public static Type FormPerDtoConfigType(this Type dtoType, Type entityType) Type[] typeArgs = { dtoType, entityType }; return perDtoConfigBase.MakeGenericType(typeArgs); } + + private class ClassWithILinkInterface : ILinkToEntity {} } } \ No newline at end of file diff --git a/GenericServices/Internal/Decoders/DecodedDtoProperty.cs b/GenericServices/Internal/Decoders/DecodedDtoProperty.cs index 03bbba3..3a211ca 100644 --- a/GenericServices/Internal/Decoders/DecodedDtoProperty.cs +++ b/GenericServices/Internal/Decoders/DecodedDtoProperty.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.ComponentModel; @@ -18,9 +18,6 @@ internal enum DtoPropertyTypes } internal class DecodedDtoProperty { - public PropertyInfo PropertyInfo { get; private set; } - public DtoPropertyTypes PropertyType { get; private set; } - public DecodedDtoProperty(PropertyInfo propertyInfo, bool isKeyProperty) { PropertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo)); @@ -31,5 +28,7 @@ public DecodedDtoProperty(PropertyInfo propertyInfo, bool isKeyProperty) PropertyType |= DtoPropertyTypes.ReadOnly; } + public PropertyInfo PropertyInfo { get; private set; } + public DtoPropertyTypes PropertyType { get; private set; } } } \ No newline at end of file diff --git a/GenericServices/Internal/Decoders/DecodedEntityClass.cs b/GenericServices/Internal/Decoders/DecodedEntityClass.cs index 10284c9..676dff5 100644 --- a/GenericServices/Internal/Decoders/DecodedEntityClass.cs +++ b/GenericServices/Internal/Decoders/DecodedEntityClass.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; @@ -9,8 +9,6 @@ using System.Reflection; using GenericServices.Configuration.Internal; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Metadata.Internal; using StatusGeneric; namespace GenericServices.Internal.Decoders @@ -41,22 +39,6 @@ internal class DecodedEntityClass { private readonly string[] _methodNamesToIgnore; - public Type EntityType { get; } - public EntityStyles EntityStyle { get; } - - public ImmutableList PrimaryKeyProperties { get; private set; } - - public ConstructorInfo[] PublicCtors { get; } - public MethodInfo[] PublicStaticCreatorMethods { get; } = new MethodInfo[0]; - public MethodInfo[] PublicSetterMethods { get; } - public PropertyInfo[] PropertiesWithPublicSetter { get; } - - public bool CanBeCreatedViaAutoMapper => HasPublicParameterlessCtor && CanBeUpdatedViaProperties; - public bool CanBeUpdatedViaProperties => PropertiesWithPublicSetter.Any(); - public bool HasPublicParameterlessCtor => PublicCtors.Any(x => !x.GetParameters().Any()); - public bool CanBeUpdatedViaMethods => PublicSetterMethods.Any(); - public bool CanBeCreatedByCtorOrStaticMethod => PublicCtors.Any(x => x.GetParameters().Length > 0) || PublicStaticCreatorMethods.Any(); - public DecodedEntityClass(Type entityType, DbContext context) { EntityType = entityType ?? throw new ArgumentNullException(nameof(entityType)); @@ -133,6 +115,22 @@ public DecodedEntityClass(Type entityType, DbContext context) } + public Type EntityType { get; } + public EntityStyles EntityStyle { get; } + + public ImmutableList PrimaryKeyProperties { get; private set; } + + public ConstructorInfo[] PublicCtors { get; } + public MethodInfo[] PublicStaticCreatorMethods { get; } = new MethodInfo[0]; + public MethodInfo[] PublicSetterMethods { get; } + public PropertyInfo[] PropertiesWithPublicSetter { get; } + + public bool CanBeCreatedViaAutoMapper => HasPublicParameterlessCtor && CanBeUpdatedViaProperties; + public bool CanBeUpdatedViaProperties => PropertiesWithPublicSetter.Any(); + public bool HasPublicParameterlessCtor => PublicCtors.Any(x => !x.GetParameters().Any()); + public bool CanBeUpdatedViaMethods => PublicSetterMethods.Any(); + public bool CanBeCreatedByCtorOrStaticMethod => PublicCtors.Any(x => x.GetParameters().Length > 0) || PublicStaticCreatorMethods.Any(); + private MethodInfo[] GetMethodsThatGenericServicesCanCall(Type entityType) { var methodsToInspect = FindAllMethodsInType(entityType); diff --git a/GenericServices/Internal/Decoders/MethodCtorMatch.cs b/GenericServices/Internal/Decoders/MethodCtorMatch.cs index 4db1465..a11ea93 100644 --- a/GenericServices/Internal/Decoders/MethodCtorMatch.cs +++ b/GenericServices/Internal/Decoders/MethodCtorMatch.cs @@ -1,13 +1,11 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using GenericServices.Configuration; -using Microsoft.EntityFrameworkCore; [assembly: InternalsVisibleTo("Tests")] @@ -21,16 +19,6 @@ internal enum HowTheyWereAskedFor { Unset, DefaultMatchToProperties, NamedMethod /// internal class MethodCtorMatch { - public string Name { get; set; } - public MethodInfo Method { get;} - public ConstructorInfo Constructor { get; } - - public ParametersMatch PropertiesMatch { get; } - - public HowTheyWereAskedFor HowDefined { get; } - - public bool IsParameterlessMethod => !PropertiesMatch.MatchedPropertiesInOrder.Any(); - public MethodCtorMatch(dynamic methodOrCtor, ParametersMatch propertiesMatch, HowTheyWereAskedFor howDefined) { Method = methodOrCtor as MethodInfo; @@ -43,6 +31,16 @@ public MethodCtorMatch(dynamic methodOrCtor, ParametersMatch propertiesMatch, Ho HowDefined = howDefined; } + public string Name { get; set; } + public MethodInfo Method { get;} + public ConstructorInfo Constructor { get; } + + public ParametersMatch PropertiesMatch { get; } + + public HowTheyWereAskedFor HowDefined { get; } + + public bool IsParameterlessMethod => !PropertiesMatch.MatchedPropertiesInOrder.Any(); + public override string ToString() { var start = PropertiesMatch.Score >= PropertyMatch.PerfectMatchValue @@ -57,7 +55,5 @@ public string ToStringShort() { return $"{Name}({PropertiesMatch.MatchedPropertiesInOrder.Count} params)"; } - - } } \ No newline at end of file diff --git a/GenericServices/Internal/Decoders/MethodCtorMatcher.cs b/GenericServices/Internal/Decoders/MethodCtorMatcher.cs index 886586d..6caeeb9 100644 --- a/GenericServices/Internal/Decoders/MethodCtorMatcher.cs +++ b/GenericServices/Internal/Decoders/MethodCtorMatcher.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; diff --git a/GenericServices/Internal/Decoders/ParametersMatch.cs b/GenericServices/Internal/Decoders/ParametersMatch.cs index a9b161d..d19f438 100644 --- a/GenericServices/Internal/Decoders/ParametersMatch.cs +++ b/GenericServices/Internal/Decoders/ParametersMatch.cs @@ -1,7 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; @@ -19,15 +18,6 @@ namespace GenericServices.Internal.Decoders /// internal class ParametersMatch { - /// - /// This holds the matching properties to the method/ctor in order. If there is no match the entry will be null - /// - public ImmutableList MatchedPropertiesInOrder { get; } - - public double Score => MatchedPropertiesInOrder.Any() - ? MatchedPropertiesInOrder.Average(x => x?.Score ?? 0) - : 1; //if there are no parameters then it is a perfect fit! - public ParametersMatch(IEnumerable parameters, List propertiesToMatch, MatchNameAndType propMatcher) { var matchedProps = new List(); @@ -39,6 +29,15 @@ public ParametersMatch(IEnumerable parameters, List MatchedPropertiesInOrder = matchedProps.ToImmutableList(); } + /// + /// This holds the matching properties to the method/ctor in order. If there is no match the entry will be null + /// + public ImmutableList MatchedPropertiesInOrder { get; } + + public double Score => MatchedPropertiesInOrder.Any() + ? MatchedPropertiesInOrder.Average(x => x?.Score ?? 0) + : 1; //if there are no parameters then it is a perfect fit! + private static PropertyMatch FindMatch(ParameterInfo parameter, IEnumerable propertiesToCheck, MatchNameAndType propMatcher) { PropertyMatch bestMatch = null; @@ -50,6 +49,5 @@ private static PropertyMatch FindMatch(ParameterInfo parameter, IEnumerable CallMethodReturnVoidCache = new ConcurrentDictionary(); + + private static readonly ConcurrentDictionary CallMethodReturnStatusCache = new ConcurrentDictionary(); + + private static readonly ConcurrentDictionary CallStaticCreatorCache = new ConcurrentDictionary(); + + private static readonly ConcurrentDictionary CallConstructorCache = new ConcurrentDictionary(); //BE WARNED: extension methods don't work with dynamics - got some strange error messages //Also the dto, entity and DbContext parameters cannot be object, but dynamic works @@ -79,8 +85,6 @@ public static IStatusGeneric RunMethodOrCtorViaLinq(MethodCtorMatch ctor : staticFunc(dto); } - private static readonly ConcurrentDictionary CallMethodReturnVoidCache = new ConcurrentDictionary(); - public static dynamic CallMethodReturnVoid(MethodInfo methodInfo, Type tDto, Type tEntity, List propertyMatches) { return CallMethodReturnVoidCache.GetOrAdd(methodInfo.GenerateKey(tDto), @@ -114,8 +118,6 @@ private static dynamic PrivateCallMethodReturnVoid(MethodInfo methodInfo, Type t return built.Compile(); } - private static readonly ConcurrentDictionary CallMethodReturnStatusCache = new ConcurrentDictionary(); - public static dynamic CallMethodReturnStatus(MethodInfo methodInfo, Type tDto, Type tEntity, List propertyMatches) { return CallMethodReturnStatusCache.GetOrAdd(methodInfo.GenerateKey(tDto), @@ -149,8 +151,6 @@ private static dynamic PrivateCallMethodReturnStatus(MethodInfo methodInfo, Type return built.Compile(); } - private static readonly ConcurrentDictionary CallStaticCreatorCache = new ConcurrentDictionary(); - public static dynamic CallStaticCreator(MethodInfo methodInfo, Type tDto, List propertyMatches) { return CallStaticCreatorCache.GetOrAdd(methodInfo.GenerateKey(tDto), @@ -182,8 +182,6 @@ private static dynamic PrivateCallStaticCreator(MethodInfo methodInfo, Type tDto return built.Compile(); } - private static readonly ConcurrentDictionary CallConstructorCache = new ConcurrentDictionary(); - public static dynamic CallConstructor(ConstructorInfo ctor, Type tDto, List propertyMatches) { return CallConstructorCache.GetOrAdd(ctor.GenerateKey(tDto), diff --git a/GenericServices/Internal/LinqBuilders/BuildCallAsync.cs b/GenericServices/Internal/LinqBuilders/BuildCallAsync.cs index 192bb6f..e25d2ca 100644 --- a/GenericServices/Internal/LinqBuilders/BuildCallAsync.cs +++ b/GenericServices/Internal/LinqBuilders/BuildCallAsync.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; @@ -7,7 +7,6 @@ using System.Linq.Expressions; using System.Reflection; using System.Runtime.CompilerServices; -using System.Threading.Tasks; using GenericServices.Configuration; [assembly: InternalsVisibleTo("Tests")] diff --git a/GenericServices/Internal/LinqBuilders/BuildFilter.cs b/GenericServices/Internal/LinqBuilders/BuildFilter.cs index fe66691..ba8a87c 100644 --- a/GenericServices/Internal/LinqBuilders/BuildFilter.cs +++ b/GenericServices/Internal/LinqBuilders/BuildFilter.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; @@ -12,7 +12,6 @@ namespace GenericServices.Internal.LinqBuilders { internal static class BuildFilter { - public static Expression> CreateFilter(this ImmutableList keyProperties, object[] keyValues) { if (keyProperties.Count != keyValues.Length) diff --git a/GenericServices/Internal/MappingCode/CreateMapper.cs b/GenericServices/Internal/MappingCode/CreateMapper.cs index e376ab2..0aea45d 100644 --- a/GenericServices/Internal/MappingCode/CreateMapper.cs +++ b/GenericServices/Internal/MappingCode/CreateMapper.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Concurrent; @@ -17,7 +17,7 @@ namespace GenericServices.Internal.MappingCode { internal class CreateMapper { - public dynamic Accessor { get; } + private static readonly ConcurrentDictionary NewGenericMapperCache = new ConcurrentDictionary(); public CreateMapper(DbContext context, IWrappedConfigAndMapper configAndMapper, Type tDto, DecodedEntityClass entityInfo) { @@ -29,7 +29,7 @@ public CreateMapper(DbContext context, IWrappedConfigAndMapper configAndMapper, //Accessor = Activator.CreateInstance(genericType, context, configAndMapper, entityInfo); } - private static readonly ConcurrentDictionary NewGenericMapperCache = new ConcurrentDictionary(); + public dynamic Accessor { get; } //This is only public for performance tests public static Func GetNewGenericMapper(Type genericType, ConstructorInfo ctor) @@ -54,10 +54,8 @@ public class GenericMapper where TEntity : class { private readonly DbContext _context; - private readonly IWrappedConfigAndMapper _wrappedMapper; private readonly DecodedEntityClass _entityInfo; - - public string EntityName => _entityInfo.EntityType.Name; + private readonly IWrappedConfigAndMapper _wrappedMapper; public GenericMapper(DbContext context, IWrappedConfigAndMapper wrappedMapper, DecodedEntityClass entityInfo) { @@ -66,6 +64,8 @@ public GenericMapper(DbContext context, IWrappedConfigAndMapper wrappedMapper, D _entityInfo = entityInfo ?? throw new ArgumentNullException(nameof(entityInfo)); } + public string EntityName => _entityInfo.EntityType.Name; + public void MapDtoToEntity(TDto dto, object entity) { _wrappedMapper.MapperSaveConfig.CreateMapper().Map(dto, entity); diff --git a/GenericServices/Internal/MappingCode/EntityCreateHandler.cs b/GenericServices/Internal/MappingCode/EntityCreateHandler.cs index 72b444d..c908d6b 100644 --- a/GenericServices/Internal/MappingCode/EntityCreateHandler.cs +++ b/GenericServices/Internal/MappingCode/EntityCreateHandler.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; @@ -15,10 +15,10 @@ namespace GenericServices.Internal.MappingCode internal class EntityCreateHandler : StatusGenericHandler where TDto : class { - private readonly DecodedDto _dtoInfo; - private readonly DecodedEntityClass _entityInfo; private readonly IWrappedConfigAndMapper _configAndMapper; private readonly DbContext _context; + private readonly DecodedDto _dtoInfo; + private readonly DecodedEntityClass _entityInfo; public EntityCreateHandler(DecodedDto dtoInfo, DecodedEntityClass entityInfo, IWrappedConfigAndMapper configAndMapper, DbContext context) { @@ -61,7 +61,5 @@ public object CreateEntityAndFillFromDto(TDto dto, string methodCtorName) $"There was no way to create the entity class {_entityInfo.EntityType.Name} using {decodedName.ToString() ?? "any approach"}."); } - - } } \ No newline at end of file diff --git a/GenericServices/Internal/MappingCode/EntityUpdateHandler.cs b/GenericServices/Internal/MappingCode/EntityUpdateHandler.cs index eed54a6..a6116b3 100644 --- a/GenericServices/Internal/MappingCode/EntityUpdateHandler.cs +++ b/GenericServices/Internal/MappingCode/EntityUpdateHandler.cs @@ -1,13 +1,13 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; using System.Threading.Tasks; using GenericServices.Configuration.Internal; using GenericServices.Internal.Decoders; -using GenericServices.PublicButHidden; using GenericServices.Internal.LinqBuilders; +using GenericServices.PublicButHidden; using Microsoft.EntityFrameworkCore; using StatusGeneric; @@ -16,10 +16,10 @@ namespace GenericServices.Internal.MappingCode internal class EntityUpdateHandler : StatusGenericHandler where TDto : class { - private readonly DecodedDto _dtoInfo; - private readonly DecodedEntityClass _entityInfo; private readonly IWrappedConfigAndMapper _configAndMapper; private readonly DbContext _context; + private readonly DecodedDto _dtoInfo; + private readonly DecodedEntityClass _entityInfo; public EntityUpdateHandler(DecodedDto dtoInfo, DecodedEntityClass entityInfo, IWrappedConfigAndMapper configAndMapper, DbContext context) { diff --git a/GenericServices/Internal/MappingCode/KeyHandlers.cs b/GenericServices/Internal/MappingCode/KeyHandlers.cs index 5cb76ec..d5f1549 100644 --- a/GenericServices/Internal/MappingCode/KeyHandlers.cs +++ b/GenericServices/Internal/MappingCode/KeyHandlers.cs @@ -1,9 +1,8 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; diff --git a/GenericServices/Internal/SplitterExtension.cs b/GenericServices/Internal/SplitterExtension.cs index 57c5b88..1f3f3e7 100644 --- a/GenericServices/Internal/SplitterExtension.cs +++ b/GenericServices/Internal/SplitterExtension.cs @@ -1,4 +1,6 @@ - +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + using System.Text.RegularExpressions; @@ -18,6 +20,5 @@ public static string SplitPascalCase(this string str) { return Reg.Replace(str, "$1 "); } - } } diff --git a/GenericServices/PublicButHidden/CrudServices.cs b/GenericServices/PublicButHidden/CrudServices.cs index 7572ab5..de3a904 100644 --- a/GenericServices/PublicButHidden/CrudServices.cs +++ b/GenericServices/PublicButHidden/CrudServices.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; @@ -44,11 +44,8 @@ public class CrudServices : StatusGenericHandler, ICrudServices where TContext : DbContext { - private readonly TContext _context; private readonly IWrappedConfigAndMapper _configAndMapper; - - /// - public DbContext Context => _context; + private readonly TContext _context; /// /// CrudServices needs the correct DbContext and the AutoMapper config @@ -61,6 +58,9 @@ public CrudServices(TContext context, IWrappedConfigAndMapper configAndMapper) _configAndMapper = configAndMapper ?? throw new ArgumentException(nameof(configAndMapper)); } + /// + public DbContext Context => _context; + /// public T ReadSingle(params object[] keys) where T : class { @@ -205,36 +205,6 @@ public TEntity UpdateAndSave(JsonPatchDocument patch, Expressi return LocalUpdateAndSave(patch, () => _context.Set().SingleOrDefault(whereExpression)); } - /// - /// Local version of UpdateAndSave with JsonPatch - contains the common code - /// - /// - /// - /// - /// - private TEntity LocalUpdateAndSave(JsonPatchDocument patch, Func getEntity) - where TEntity : class - { - var entityInfo = _context.GetEntityInfoThrowExceptionIfNotThere(typeof(TEntity)); - entityInfo.CheckCanDoOperation(CrudTypes.Update); - Message = $"Successfully updated the {entityInfo.EntityType.GetNameForClass()}"; - if (entityInfo.EntityType != typeof(TEntity)) - throw new NotImplementedException( - $"I could not find the entity class {typeof(TEntity).Name}. JsonPatch only works on entity classes."); - - var entity = getEntity(); - if (entity != null) - patch.ApplyTo(entity, error => AddError(error.ErrorMessage)); - else - AddError( - $"Sorry, I could not find the {entityInfo.EntityType.GetNameForClass()} you were trying to update."); - if (IsValid) - CombineStatuses(_context.SaveChangesWithOptionalValidation( - _configAndMapper.Config.DirectAccessValidateOnSave, _configAndMapper.Config)); - - return entity; - } - /// public void DeleteAndSave(params object[] keys) where TEntity : class { @@ -285,5 +255,34 @@ public void DeleteWithActionAndSave(Func + /// Local version of UpdateAndSave with JsonPatch - contains the common code + /// + /// + /// + /// + /// + private TEntity LocalUpdateAndSave(JsonPatchDocument patch, Func getEntity) + where TEntity : class + { + var entityInfo = _context.GetEntityInfoThrowExceptionIfNotThere(typeof(TEntity)); + entityInfo.CheckCanDoOperation(CrudTypes.Update); + Message = $"Successfully updated the {entityInfo.EntityType.GetNameForClass()}"; + if (entityInfo.EntityType != typeof(TEntity)) + throw new NotImplementedException( + $"I could not find the entity class {typeof(TEntity).Name}. JsonPatch only works on entity classes."); + + var entity = getEntity(); + if (entity != null) + patch.ApplyTo(entity, error => AddError(error.ErrorMessage)); + else + AddError( + $"Sorry, I could not find the {entityInfo.EntityType.GetNameForClass()} you were trying to update."); + if (IsValid) + CombineStatuses(_context.SaveChangesWithOptionalValidation( + _configAndMapper.Config.DirectAccessValidateOnSave, _configAndMapper.Config)); + + return entity; + } } } \ No newline at end of file diff --git a/GenericServices/PublicButHidden/CrudServicesAsync.cs b/GenericServices/PublicButHidden/CrudServicesAsync.cs index 328d0c1..2f775e3 100644 --- a/GenericServices/PublicButHidden/CrudServicesAsync.cs +++ b/GenericServices/PublicButHidden/CrudServicesAsync.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; @@ -45,11 +45,8 @@ public class CrudServicesAsync : StatusGenericHandler, ICrudServicesAsync where TContext : DbContext { - private readonly TContext _context; private readonly IWrappedConfigAndMapper _configAndMapper; - - /// - public DbContext Context => _context; + private readonly TContext _context; /// /// This allows you to access the current DbContext that this instance of the CrudServices is using. @@ -62,6 +59,9 @@ public CrudServicesAsync(TContext context, IWrappedConfigAndMapper configAndMapp _configAndMapper = configAndMapper ?? throw new ArgumentException(nameof(configAndMapper)); } + /// + public DbContext Context => _context; + /// public async Task ReadSingleAsync(params object[] keys) where T : class { @@ -208,36 +208,6 @@ public async Task UpdateAndSaveAsync(JsonPatchDocument _context.Set().SingleOrDefaultAsync(whereExpression)).ConfigureAwait(false); } - /// - /// Local version of UpdateAndSave with JsonPatch - contains the common code - /// - /// - /// - /// - /// - private async Task LocalUpdateAndSaveAsync(JsonPatchDocument patch, Func> getEntity) - where TEntity : class - { - var entityInfo = _context.GetEntityInfoThrowExceptionIfNotThere(typeof(TEntity)); - entityInfo.CheckCanDoOperation(CrudTypes.Update); - Message = $"Successfully updated the {entityInfo.EntityType.GetNameForClass()}"; - if (entityInfo.EntityType != typeof(TEntity)) - throw new NotImplementedException( - $"I could not find the entity class {typeof(TEntity).Name}. JsonPatch only works on entity classes."); - - var entity = await getEntity().ConfigureAwait(false); - if (entity != null) - patch.ApplyTo(entity, error => AddError(error.ErrorMessage)); - else - AddError( - $"Sorry, I could not find the {entityInfo.EntityType.GetNameForClass()} you were trying to update."); - if (IsValid) - CombineStatuses(await _context.SaveChangesWithOptionalValidationAsync( - _configAndMapper.Config.DirectAccessValidateOnSave, _configAndMapper.Config).ConfigureAwait(false)); - - return entity; - } - /// public async Task DeleteAndSaveAsync(params object[] keys) where TEntity : class { @@ -281,5 +251,34 @@ public async Task DeleteWithActionAndSaveAsync(Func + /// Local version of UpdateAndSave with JsonPatch - contains the common code + /// + /// + /// + /// + /// + private async Task LocalUpdateAndSaveAsync(JsonPatchDocument patch, Func> getEntity) + where TEntity : class + { + var entityInfo = _context.GetEntityInfoThrowExceptionIfNotThere(typeof(TEntity)); + entityInfo.CheckCanDoOperation(CrudTypes.Update); + Message = $"Successfully updated the {entityInfo.EntityType.GetNameForClass()}"; + if (entityInfo.EntityType != typeof(TEntity)) + throw new NotImplementedException( + $"I could not find the entity class {typeof(TEntity).Name}. JsonPatch only works on entity classes."); + + var entity = await getEntity().ConfigureAwait(false); + if (entity != null) + patch.ApplyTo(entity, error => AddError(error.ErrorMessage)); + else + AddError( + $"Sorry, I could not find the {entityInfo.EntityType.GetNameForClass()} you were trying to update."); + if (IsValid) + CombineStatuses(await _context.SaveChangesWithOptionalValidationAsync( + _configAndMapper.Config.DirectAccessValidateOnSave, _configAndMapper.Config).ConfigureAwait(false)); + + return entity; + } } } \ No newline at end of file diff --git a/GenericServices/PublicButHidden/WrappedConfigAndMapper.cs b/GenericServices/PublicButHidden/WrappedConfigAndMapper.cs index 819b609..5c870bb 100644 --- a/GenericServices/PublicButHidden/WrappedConfigAndMapper.cs +++ b/GenericServices/PublicButHidden/WrappedConfigAndMapper.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using AutoMapper; diff --git a/GenericServices/SaveChangesExtensions.cs b/GenericServices/SaveChangesExtensions.cs index 94ed945..bbf88d9 100644 --- a/GenericServices/SaveChangesExtensions.cs +++ b/GenericServices/SaveChangesExtensions.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; diff --git a/GenericServices/Setup/ConfigureGenericServices.cs b/GenericServices/Setup/ConfigureGenericServices.cs index 797d7a4..9484d44 100644 --- a/GenericServices/Setup/ConfigureGenericServices.cs +++ b/GenericServices/Setup/ConfigureGenericServices.cs @@ -1,11 +1,11 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Reflection; using GenericServices.Configuration; -using GenericServices.Setup.Internal; using GenericServices.PublicButHidden; +using GenericServices.Setup.Internal; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; diff --git a/GenericServices/Setup/IGenericServicesSetupPart1.cs b/GenericServices/Setup/IGenericServicesSetupPart1.cs index 62ebe2c..d5cc0e1 100644 --- a/GenericServices/Setup/IGenericServicesSetupPart1.cs +++ b/GenericServices/Setup/IGenericServicesSetupPart1.cs @@ -1,4 +1,6 @@ -using System; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + using GenericServices.Configuration; using Microsoft.Extensions.DependencyInjection; diff --git a/GenericServices/Setup/IGenericServicesSetupPart2.cs b/GenericServices/Setup/IGenericServicesSetupPart2.cs index e5ee84f..30559b4 100644 --- a/GenericServices/Setup/IGenericServicesSetupPart2.cs +++ b/GenericServices/Setup/IGenericServicesSetupPart2.cs @@ -1,4 +1,7 @@ -using GenericServices.Configuration; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + +using GenericServices.Configuration; using GenericServices.PublicButHidden; using Microsoft.Extensions.DependencyInjection; diff --git a/GenericServices/Setup/Internal/CreateConfigGenerator.cs b/GenericServices/Setup/Internal/CreateConfigGenerator.cs index f0cb964..d5c9e3c 100644 --- a/GenericServices/Setup/Internal/CreateConfigGenerator.cs +++ b/GenericServices/Setup/Internal/CreateConfigGenerator.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using AutoMapper; @@ -10,8 +10,6 @@ namespace GenericServices.Setup.Internal { internal class CreateConfigGenerator { - public dynamic Accessor { get; } - public CreateConfigGenerator(Type dtoType, DecodedEntityClass entityInfo, object configInfo) { var myGeneric = typeof(ConfigGenerator<,>); @@ -19,6 +17,8 @@ public CreateConfigGenerator(Type dtoType, DecodedEntityClass entityInfo, object Accessor = Activator.CreateInstance(copierType, new object[]{ configInfo}); } + public dynamic Accessor { get; } + public class ConfigGenerator where TDto : class where TEntity : class diff --git a/GenericServices/Setup/Internal/GenericServicesSetupPart2.cs b/GenericServices/Setup/Internal/GenericServicesSetupPart2.cs index d3add75..c006499 100644 --- a/GenericServices/Setup/Internal/GenericServicesSetupPart2.cs +++ b/GenericServices/Setup/Internal/GenericServicesSetupPart2.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using GenericServices.Configuration; @@ -13,7 +13,6 @@ namespace GenericServices.Setup.Internal /// public class GenericServicesSetupPart2 : IGenericServicesSetupPart2 { - internal GenericServicesSetupPart2(IServiceCollection services, IGenericServicesConfig publicConfig, IWrappedConfigAndMapper configAndMapper) { Services = services ?? throw new ArgumentNullException(nameof(services)); diff --git a/GenericServices/Setup/Internal/MappingProfile.cs b/GenericServices/Setup/Internal/MappingProfile.cs index eb61938..b32b204 100644 --- a/GenericServices/Setup/Internal/MappingProfile.cs +++ b/GenericServices/Setup/Internal/MappingProfile.cs @@ -1,7 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using System; using System.ComponentModel; using System.Reflection; using System.Runtime.CompilerServices; diff --git a/GenericServices/Setup/Internal/RegisterOneDtoType.cs b/GenericServices/Setup/Internal/RegisterOneDtoType.cs index 33b2836..8addeec 100644 --- a/GenericServices/Setup/Internal/RegisterOneDtoType.cs +++ b/GenericServices/Setup/Internal/RegisterOneDtoType.cs @@ -1,24 +1,16 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; using GenericServices.Configuration; using GenericServices.Internal.Decoders; -using GenericServices.Setup.Internal; using StatusGeneric; namespace GenericServices.Setup.Internal { internal class RegisterOneDtoType : StatusGenericHandler { - public DecodedEntityClass EntityInfo { get; } - public DecodedDto DtoInfo { get; } - - public PerDtoConfig PerDtoConfig { get; } - - public CreateConfigGenerator ConfigGenerator { get; } - public RegisterOneDtoType(Type dtoType, Type[] typesInAssembly, IGenericServicesConfig configuration) { @@ -51,6 +43,13 @@ public RegisterOneDtoType(Type dtoType, Type[] typesInAssembly, IGenericServices DtoInfo = decodeStatus.Result; } + public DecodedEntityClass EntityInfo { get; } + public DecodedDto DtoInfo { get; } + + public PerDtoConfig PerDtoConfig { get; } + + public CreateConfigGenerator ConfigGenerator { get; } + private object FindConfigInfoIfPresent(Type dtoType, Type entityType, Type[] typesToScan) { var perDtoConfigType = dtoType.FormPerDtoConfigType(entityType); diff --git a/GenericServices/Setup/Internal/SetupAllEntities.cs b/GenericServices/Setup/Internal/SetupAllEntities.cs index 71d4cd7..24819d6 100644 --- a/GenericServices/Setup/Internal/SetupAllEntities.cs +++ b/GenericServices/Setup/Internal/SetupAllEntities.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using GenericServices.Configuration; @@ -10,9 +10,6 @@ namespace GenericServices.Setup.Internal { internal class SetupAllEntities : IGenericServicesSetupPart1 { - public IGenericServicesConfig PublicConfig { get; } - public IServiceCollection Services { get; } - public SetupAllEntities(IServiceCollection services, IGenericServicesConfig publicConfig, Type[] contextTypes) { Services = services ?? throw new ArgumentNullException(nameof(services)); @@ -36,6 +33,7 @@ public SetupAllEntities(IServiceCollection services, IGenericServicesConfig publ } } - + public IGenericServicesConfig PublicConfig { get; } + public IServiceCollection Services { get; } } } \ No newline at end of file diff --git a/GenericServices/Setup/Internal/SetupDtosAndMappings.cs b/GenericServices/Setup/Internal/SetupDtosAndMappings.cs index 02ebeb5..2b9968e 100644 --- a/GenericServices/Setup/Internal/SetupDtosAndMappings.cs +++ b/GenericServices/Setup/Internal/SetupDtosAndMappings.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; @@ -17,13 +17,13 @@ internal class SetupDtosAndMappings : StatusGenericHandler readonly MappingProfile _readProfile = new MappingProfile(false); readonly MappingProfile _saveProfile = new MappingProfile(true); - public IGenericServicesConfig PublicConfig { get; } - public SetupDtosAndMappings(IGenericServicesConfig publicConfig) { PublicConfig = publicConfig ?? throw new ArgumentNullException(nameof(publicConfig)); } + public IGenericServicesConfig PublicConfig { get; } + public IWrappedConfigAndMapper ScanAllAssemblies(Assembly[] assembliesToScan, IGenericServicesConfig config) { if (assembliesToScan == null || assembliesToScan.Length == 0) @@ -86,7 +86,5 @@ private void RegisterDtosInAssemblyAndBuildMaps(Assembly assemblyToScan) SetupMappingForDto(dtoRegister, _readProfile, _saveProfile); } } - - } } \ No newline at end of file diff --git a/GenericServices/Setup/Internal/SetupEntitiesExtensions.cs b/GenericServices/Setup/Internal/SetupEntitiesExtensions.cs index ed6ed67..b8222ab 100644 --- a/GenericServices/Setup/Internal/SetupEntitiesExtensions.cs +++ b/GenericServices/Setup/Internal/SetupEntitiesExtensions.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; using GenericServices.Internal.Decoders; diff --git a/GenericServices/Setup/SpecificUseData.cs b/GenericServices/Setup/SpecificUseData.cs index 19224e3..a25474c 100644 --- a/GenericServices/Setup/SpecificUseData.cs +++ b/GenericServices/Setup/SpecificUseData.cs @@ -1,7 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using System; using GenericServices.Configuration; using GenericServices.PublicButHidden; using GenericServices.Setup.Internal; @@ -19,6 +18,17 @@ public class SpecificUseData /// private IWrappedConfigAndMapper _configAndMapper; + /// + /// ctor + /// + /// + public SpecificUseData(IGenericServicesConfig publicConfig) + { + PublicConfig = publicConfig ?? new GenericServicesConfig(); + ReadProfile = new MappingProfile(false); + SaveProfile = new MappingProfile(true); + } + internal MappingProfile ReadProfile { get; } internal MappingProfile SaveProfile { get; } @@ -33,16 +43,5 @@ public class SpecificUseData /// This is the global config /// public IGenericServicesConfig PublicConfig { get; } - - /// - /// ctor - /// - /// - public SpecificUseData(IGenericServicesConfig publicConfig) - { - PublicConfig = publicConfig ?? new GenericServicesConfig(); - ReadProfile = new MappingProfile(false); - SaveProfile = new MappingProfile(true); - } } } \ No newline at end of file diff --git a/GenericServices/Setup/UnitTestSetup.cs b/GenericServices/Setup/UnitTestSetup.cs index eb10718..b634324 100644 --- a/GenericServices/Setup/UnitTestSetup.cs +++ b/GenericServices/Setup/UnitTestSetup.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using GenericServices.Configuration; diff --git a/GenericServices/ValidationDbContextServiceProvider.cs b/GenericServices/ValidationDbContextServiceProvider.cs index d9154c0..fea1e9d 100644 --- a/GenericServices/ValidationDbContextServiceProvider.cs +++ b/GenericServices/ValidationDbContextServiceProvider.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using Microsoft.EntityFrameworkCore; diff --git a/ServiceLayer/AuthorController/Dtos/AuthorWithBookCountDto.cs b/ServiceLayer/AuthorController/Dtos/AuthorWithBookCountDto.cs index 0c5d9fd..474fc50 100644 --- a/ServiceLayer/AuthorController/Dtos/AuthorWithBookCountDto.cs +++ b/ServiceLayer/AuthorController/Dtos/AuthorWithBookCountDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.ComponentModel.DataAnnotations; using DataLayer.EfClasses; @@ -14,6 +14,7 @@ public class AuthorWithBookCountDto : ILinkToEntity [Required] [MaxLength(Author.NameLength)] public string Name { get; set; } + public int BooksLinkCount { get; set; } } } \ No newline at end of file diff --git a/ServiceLayer/DatabaseCode/Dtos/BookInfoJson.cs b/ServiceLayer/DatabaseCode/Dtos/BookInfoJson.cs index 75f02bc..a2b9f92 100644 --- a/ServiceLayer/DatabaseCode/Dtos/BookInfoJson.cs +++ b/ServiceLayer/DatabaseCode/Dtos/BookInfoJson.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/ServiceLayer/DatabaseCode/Services/BookJsonLoader.cs b/ServiceLayer/DatabaseCode/Services/BookJsonLoader.cs index e196786..6f0a788 100644 --- a/ServiceLayer/DatabaseCode/Services/BookJsonLoader.cs +++ b/ServiceLayer/DatabaseCode/Services/BookJsonLoader.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; diff --git a/ServiceLayer/DatabaseCode/Services/SetupHelpers.cs b/ServiceLayer/DatabaseCode/Services/SetupHelpers.cs index 8bcabb3..56ad4d6 100644 --- a/ServiceLayer/DatabaseCode/Services/SetupHelpers.cs +++ b/ServiceLayer/DatabaseCode/Services/SetupHelpers.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; diff --git a/ServiceLayer/HomeController/DropdownTuple.cs b/ServiceLayer/HomeController/DropdownTuple.cs index 9a28325..5f37075 100644 --- a/ServiceLayer/HomeController/DropdownTuple.cs +++ b/ServiceLayer/HomeController/DropdownTuple.cs @@ -1,5 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + namespace ServiceLayer.HomeController { public class DropdownTuple diff --git a/ServiceLayer/HomeController/Dtos/AddRemovePromotionDto.cs b/ServiceLayer/HomeController/Dtos/AddRemovePromotionDto.cs index cfbb781..20ad831 100644 --- a/ServiceLayer/HomeController/Dtos/AddRemovePromotionDto.cs +++ b/ServiceLayer/HomeController/Dtos/AddRemovePromotionDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.ComponentModel; using DataLayer.EfClasses; diff --git a/ServiceLayer/HomeController/Dtos/AddReviewDto.cs b/ServiceLayer/HomeController/Dtos/AddReviewDto.cs index 4f4b841..b4406c9 100644 --- a/ServiceLayer/HomeController/Dtos/AddReviewDto.cs +++ b/ServiceLayer/HomeController/Dtos/AddReviewDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.ComponentModel; using System.ComponentModel.DataAnnotations; diff --git a/ServiceLayer/HomeController/Dtos/BookListCombinedDto.cs b/ServiceLayer/HomeController/Dtos/BookListCombinedDto.cs index 4a715fb..d1e34b6 100644 --- a/ServiceLayer/HomeController/Dtos/BookListCombinedDto.cs +++ b/ServiceLayer/HomeController/Dtos/BookListCombinedDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/ServiceLayer/HomeController/Dtos/BookListDto.cs b/ServiceLayer/HomeController/Dtos/BookListDto.cs index 2ba27af..b906cb2 100644 --- a/ServiceLayer/HomeController/Dtos/BookListDto.cs +++ b/ServiceLayer/HomeController/Dtos/BookListDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using DataLayer.EfClasses; diff --git a/ServiceLayer/HomeController/Dtos/BookListDtoConfig.cs b/ServiceLayer/HomeController/Dtos/BookListDtoConfig.cs index 9e52da5..c56276a 100644 --- a/ServiceLayer/HomeController/Dtos/BookListDtoConfig.cs +++ b/ServiceLayer/HomeController/Dtos/BookListDtoConfig.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; diff --git a/ServiceLayer/HomeController/Dtos/ChangePubDateDto.cs b/ServiceLayer/HomeController/Dtos/ChangePubDateDto.cs index 531fdbb..af3a409 100644 --- a/ServiceLayer/HomeController/Dtos/ChangePubDateDto.cs +++ b/ServiceLayer/HomeController/Dtos/ChangePubDateDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.ComponentModel; diff --git a/ServiceLayer/HomeController/Dtos/CreateBookDto.cs b/ServiceLayer/HomeController/Dtos/CreateBookDto.cs index 9622d7a..d69239b 100644 --- a/ServiceLayer/HomeController/Dtos/CreateBookDto.cs +++ b/ServiceLayer/HomeController/Dtos/CreateBookDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; @@ -13,6 +13,11 @@ namespace ServiceLayer.HomeController.Dtos { public class CreateBookDto : ILinkToEntity { + public CreateBookDto() + { + PublishedOn = DateTime.Today; + } + //This will be populated with the primary key of the created book public int BookId { get; set; } @@ -21,20 +26,34 @@ public class CreateBookDto : ILinkToEntity //[Required(AllowEmptyStrings = false)] public string Title { get; set; } public string Description { get; set; } + [DataType(DataType.Date)] public DateTime PublishedOn { get; set; } + public string Publisher { get; set; } + [Range(0,1000)] public decimal Price { get; set; } + public string ImageUrl { get; set; } public ICollection Authors { get; set; } public ICollection Tags { get; set; } - public CreateBookDto() + public List AllPossibleAuthors { get; private set; } + + public List BookAuthorIds { get; set; } = new List(); + + public void BeforeDisplay(DbContext context) { - PublishedOn = DateTime.Today; + AllPossibleAuthors = context.Set().Select(x => new KeyName(x.AuthorId, x.Name)) + .OrderBy(x => x.Name).ToList(); + } + + public void BeforeSave(DbContext context) + { + Authors = BookAuthorIds.Select(x => context.Find(x)).Where(x => x != null).ToList(); } //--------------------------------------------------------- @@ -51,20 +70,5 @@ public KeyName(int authorId, string name) public int AuthorId { get; } public string Name { get; } } - - public List AllPossibleAuthors { get; private set; } - - public void BeforeDisplay(DbContext context) - { - AllPossibleAuthors = context.Set().Select(x => new KeyName(x.AuthorId, x.Name)) - .OrderBy(x => x.Name).ToList(); - } - - public List BookAuthorIds { get; set; } = new List(); - - public void BeforeSave(DbContext context) - { - Authors = BookAuthorIds.Select(x => context.Find(x)).Where(x => x != null).ToList(); - } } } \ No newline at end of file diff --git a/ServiceLayer/HomeController/Dtos/DeleteBookDto.cs b/ServiceLayer/HomeController/Dtos/DeleteBookDto.cs index d56d68b..de61a54 100644 --- a/ServiceLayer/HomeController/Dtos/DeleteBookDto.cs +++ b/ServiceLayer/HomeController/Dtos/DeleteBookDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; using GenericServices; diff --git a/ServiceLayer/HomeController/Dtos/DeleteBookDtoConfig.cs b/ServiceLayer/HomeController/Dtos/DeleteBookDtoConfig.cs index 6490e87..a0225ee 100644 --- a/ServiceLayer/HomeController/Dtos/DeleteBookDtoConfig.cs +++ b/ServiceLayer/HomeController/Dtos/DeleteBookDtoConfig.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; diff --git a/ServiceLayer/HomeController/IAddRemovePromotionService.cs b/ServiceLayer/HomeController/IAddRemovePromotionService.cs index df91473..fab72b4 100644 --- a/ServiceLayer/HomeController/IAddRemovePromotionService.cs +++ b/ServiceLayer/HomeController/IAddRemovePromotionService.cs @@ -1,8 +1,7 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; -using GenericServices; using ServiceLayer.HomeController.Dtos; using StatusGeneric; diff --git a/ServiceLayer/HomeController/IAddReviewService.cs b/ServiceLayer/HomeController/IAddReviewService.cs index c52c732..81b305c 100644 --- a/ServiceLayer/HomeController/IAddReviewService.cs +++ b/ServiceLayer/HomeController/IAddReviewService.cs @@ -1,8 +1,7 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; -using GenericServices; using ServiceLayer.HomeController.Dtos; using StatusGeneric; diff --git a/ServiceLayer/HomeController/IBookFilterDropdownService.cs b/ServiceLayer/HomeController/IBookFilterDropdownService.cs index 8d83b5e..077fab0 100644 --- a/ServiceLayer/HomeController/IBookFilterDropdownService.cs +++ b/ServiceLayer/HomeController/IBookFilterDropdownService.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Collections.Generic; using ServiceLayer.HomeController.QueryObjects; diff --git a/ServiceLayer/HomeController/IChangePubDateService.cs b/ServiceLayer/HomeController/IChangePubDateService.cs index cd94e9c..0b6d551 100644 --- a/ServiceLayer/HomeController/IChangePubDateService.cs +++ b/ServiceLayer/HomeController/IChangePubDateService.cs @@ -1,8 +1,7 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; -using GenericServices; using ServiceLayer.HomeController.Dtos; using StatusGeneric; diff --git a/ServiceLayer/HomeController/IListBooksService.cs b/ServiceLayer/HomeController/IListBooksService.cs index ca45530..0e28ef0 100644 --- a/ServiceLayer/HomeController/IListBooksService.cs +++ b/ServiceLayer/HomeController/IListBooksService.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; using System.Threading.Tasks; diff --git a/ServiceLayer/HomeController/QueryObjects/BookListDtoFilter.cs b/ServiceLayer/HomeController/QueryObjects/BookListDtoFilter.cs index 92e0e80..dccc417 100644 --- a/ServiceLayer/HomeController/QueryObjects/BookListDtoFilter.cs +++ b/ServiceLayer/HomeController/QueryObjects/BookListDtoFilter.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.ComponentModel.DataAnnotations; diff --git a/ServiceLayer/HomeController/QueryObjects/BookListDtoSelect.cs b/ServiceLayer/HomeController/QueryObjects/BookListDtoSelect.cs index 652d738..92bceca 100644 --- a/ServiceLayer/HomeController/QueryObjects/BookListDtoSelect.cs +++ b/ServiceLayer/HomeController/QueryObjects/BookListDtoSelect.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; using DataLayer.EfClasses; diff --git a/ServiceLayer/HomeController/QueryObjects/BookListDtoSort.cs b/ServiceLayer/HomeController/QueryObjects/BookListDtoSort.cs index 8091055..76aa340 100644 --- a/ServiceLayer/HomeController/QueryObjects/BookListDtoSort.cs +++ b/ServiceLayer/HomeController/QueryObjects/BookListDtoSort.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.ComponentModel.DataAnnotations; diff --git a/ServiceLayer/HomeController/Services/AddRemovePromotionService.cs b/ServiceLayer/HomeController/Services/AddRemovePromotionService.cs index c8266ff..a09bfbd 100644 --- a/ServiceLayer/HomeController/Services/AddRemovePromotionService.cs +++ b/ServiceLayer/HomeController/Services/AddRemovePromotionService.cs @@ -1,10 +1,9 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; using DataLayer.EfClasses; using DataLayer.EfCode; -using GenericServices; using ServiceLayer.HomeController.Dtos; using StatusGeneric; diff --git a/ServiceLayer/HomeController/Services/AddReviewService.cs b/ServiceLayer/HomeController/Services/AddReviewService.cs index 46f78fd..c1b58c3 100644 --- a/ServiceLayer/HomeController/Services/AddReviewService.cs +++ b/ServiceLayer/HomeController/Services/AddReviewService.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; using DataLayer.EfClasses; diff --git a/ServiceLayer/HomeController/Services/BookFilterDropdownService.cs b/ServiceLayer/HomeController/Services/BookFilterDropdownService.cs index c180103..d78a533 100644 --- a/ServiceLayer/HomeController/Services/BookFilterDropdownService.cs +++ b/ServiceLayer/HomeController/Services/BookFilterDropdownService.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; diff --git a/ServiceLayer/HomeController/Services/ChangePubDateService.cs b/ServiceLayer/HomeController/Services/ChangePubDateService.cs index 8ed87e6..0fb1ebb 100644 --- a/ServiceLayer/HomeController/Services/ChangePubDateService.cs +++ b/ServiceLayer/HomeController/Services/ChangePubDateService.cs @@ -1,10 +1,9 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; using DataLayer.EfClasses; using DataLayer.EfCode; -using GenericServices; using ServiceLayer.HomeController.Dtos; using StatusGeneric; diff --git a/ServiceLayer/HomeController/Services/GenericAddPromotionService.cs b/ServiceLayer/HomeController/Services/GenericAddPromotionService.cs index 9209b1a..f20f9ae 100644 --- a/ServiceLayer/HomeController/Services/GenericAddPromotionService.cs +++ b/ServiceLayer/HomeController/Services/GenericAddPromotionService.cs @@ -1,9 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using System.Linq; -using DataLayer.EfClasses; -using DataLayer.EfCode; using GenericServices; using ServiceLayer.HomeController.Dtos; using StatusGeneric; @@ -14,13 +11,13 @@ public class GenericAddPromotionService { private readonly ICrudServices _service; - public IStatusGeneric Status => _service; - public GenericAddPromotionService(ICrudServices service) { _service = service; } + public IStatusGeneric Status => _service; + public AddRemovePromotionDto GetOriginal(int id) { return _service.ReadSingle(id); diff --git a/ServiceLayer/HomeController/Services/ListBooksService.cs b/ServiceLayer/HomeController/Services/ListBooksService.cs index 3cf54a5..6189d00 100644 --- a/ServiceLayer/HomeController/Services/ListBooksService.cs +++ b/ServiceLayer/HomeController/Services/ListBooksService.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; using System.Threading.Tasks; diff --git a/ServiceLayer/HomeController/SortFilterPageOptions.cs b/ServiceLayer/HomeController/SortFilterPageOptions.cs index 3f40160..82585e7 100644 --- a/ServiceLayer/HomeController/SortFilterPageOptions.cs +++ b/ServiceLayer/HomeController/SortFilterPageOptions.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; diff --git a/Tests/Configs/AuthorNestedV2DtoConfig.cs b/Tests/Configs/AuthorNestedV2DtoConfig.cs index c92f2a1..e6f4c71 100644 --- a/Tests/Configs/AuthorNestedV2DtoConfig.cs +++ b/Tests/Configs/AuthorNestedV2DtoConfig.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using AutoMapper; diff --git a/Tests/Configs/BookTitleAndCountConfig.cs b/Tests/Configs/BookTitleAndCountConfig.cs index ec52b43..24bd4ac 100644 --- a/Tests/Configs/BookTitleAndCountConfig.cs +++ b/Tests/Configs/BookTitleAndCountConfig.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; diff --git a/Tests/Configs/BookWithAuthorsConfig.cs b/Tests/Configs/BookWithAuthorsConfig.cs index 54bc2a3..81498f5 100644 --- a/Tests/Configs/BookWithAuthorsConfig.cs +++ b/Tests/Configs/BookWithAuthorsConfig.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; diff --git a/Tests/Configs/BookWithTagsConfig.cs b/Tests/Configs/BookWithTagsConfig.cs index 4d54f3c..a74c5fa 100644 --- a/Tests/Configs/BookWithTagsConfig.cs +++ b/Tests/Configs/BookWithTagsConfig.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; diff --git a/Tests/Configs/InContactAddressConfig.cs b/Tests/Configs/InContactAddressConfig.cs index 7e4ac5d..a399746 100644 --- a/Tests/Configs/InContactAddressConfig.cs +++ b/Tests/Configs/InContactAddressConfig.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using AutoMapper; diff --git a/Tests/Configs/UniqueConfig.cs b/Tests/Configs/UniqueConfig.cs index 58772e4..3692188 100644 --- a/Tests/Configs/UniqueConfig.cs +++ b/Tests/Configs/UniqueConfig.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using GenericServices.Configuration; using Tests.Dtos; diff --git a/Tests/Dtos/AddNewAuthorToBookUsingIncludesDto.cs b/Tests/Dtos/AddNewAuthorToBookUsingIncludesDto.cs index 6539cae..3a5afe7 100644 --- a/Tests/Dtos/AddNewAuthorToBookUsingIncludesDto.cs +++ b/Tests/Dtos/AddNewAuthorToBookUsingIncludesDto.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; @@ -12,6 +12,7 @@ public class AddNewAuthorToBookUsingIncludesDto : ILinkToEntity { [HiddenInput] public int BookId { get; set; } + public Author AddThisAuthor { get; set; } public byte Order { get; set; } } diff --git a/Tests/Dtos/AddReviewByNameExtendedDto.cs b/Tests/Dtos/AddReviewByNameExtendedDto.cs index c99ee9d..6d422d7 100644 --- a/Tests/Dtos/AddReviewByNameExtendedDto.cs +++ b/Tests/Dtos/AddReviewByNameExtendedDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.ComponentModel; using System.ComponentModel.DataAnnotations; diff --git a/Tests/Dtos/AddReviewDto.cs b/Tests/Dtos/AddReviewDto.cs index 70b0082..0ccfb74 100644 --- a/Tests/Dtos/AddReviewDto.cs +++ b/Tests/Dtos/AddReviewDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.ComponentModel; using System.ComponentModel.DataAnnotations; diff --git a/Tests/Dtos/AddReviewWithIncludeDto.cs b/Tests/Dtos/AddReviewWithIncludeDto.cs index 814bdaf..bfbdea4 100644 --- a/Tests/Dtos/AddReviewWithIncludeDto.cs +++ b/Tests/Dtos/AddReviewWithIncludeDto.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using System.ComponentModel; @@ -20,6 +20,7 @@ public class AddReviewWithIncludeDto : ILinkToEntity [MaxLength(Review.NameLength)] public string VoterName { get; set; } + public int NumStars { get; set; } public string Comment { get; set; } } diff --git a/Tests/Dtos/AuthorNameDto.cs b/Tests/Dtos/AuthorNameDto.cs index 151358c..48b3d8b 100644 --- a/Tests/Dtos/AuthorNameDto.cs +++ b/Tests/Dtos/AuthorNameDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; using GenericServices; diff --git a/Tests/Dtos/AuthorNestedV1Dto.cs b/Tests/Dtos/AuthorNestedV1Dto.cs index a73e9ca..e33e6bd 100644 --- a/Tests/Dtos/AuthorNestedV1Dto.cs +++ b/Tests/Dtos/AuthorNestedV1Dto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; using GenericServices; diff --git a/Tests/Dtos/AuthorNestedV2Dto.cs b/Tests/Dtos/AuthorNestedV2Dto.cs index b1d36d8..5288c18 100644 --- a/Tests/Dtos/AuthorNestedV2Dto.cs +++ b/Tests/Dtos/AuthorNestedV2Dto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; using GenericServices; diff --git a/Tests/Dtos/BookListNestedV1Dto.cs b/Tests/Dtos/BookListNestedV1Dto.cs index 02e7fe5..bb01dac 100644 --- a/Tests/Dtos/BookListNestedV1Dto.cs +++ b/Tests/Dtos/BookListNestedV1Dto.cs @@ -1,7 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using DataLayer.EfClasses; using GenericServices; diff --git a/Tests/Dtos/BookListNestedV2Dto.cs b/Tests/Dtos/BookListNestedV2Dto.cs index 515d140..a4801ee 100644 --- a/Tests/Dtos/BookListNestedV2Dto.cs +++ b/Tests/Dtos/BookListNestedV2Dto.cs @@ -1,7 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using DataLayer.EfClasses; using GenericServices; diff --git a/Tests/Dtos/BookTitle.cs b/Tests/Dtos/BookTitle.cs index 0b50f58..c443530 100644 --- a/Tests/Dtos/BookTitle.cs +++ b/Tests/Dtos/BookTitle.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfClasses; using GenericServices; diff --git a/Tests/Dtos/BookTitleAndCount.cs b/Tests/Dtos/BookTitleAndCount.cs index 10f2e8a..cb30599 100644 --- a/Tests/Dtos/BookTitleAndCount.cs +++ b/Tests/Dtos/BookTitleAndCount.cs @@ -1,8 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using System.Linq; -using AutoMapper; using DataLayer.EfClasses; using GenericServices; diff --git a/Tests/Dtos/BookTitleBadType.cs b/Tests/Dtos/BookTitleBadType.cs index 8a94695..e76e48e 100644 --- a/Tests/Dtos/BookTitleBadType.cs +++ b/Tests/Dtos/BookTitleBadType.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using DataLayer.EfClasses; diff --git a/Tests/Dtos/BookWithAuthors.cs b/Tests/Dtos/BookWithAuthors.cs index 6e246d2..a2110c6 100644 --- a/Tests/Dtos/BookWithAuthors.cs +++ b/Tests/Dtos/BookWithAuthors.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Collections.Generic; using DataLayer.EfClasses; diff --git a/Tests/Dtos/BookWithTags.cs b/Tests/Dtos/BookWithTags.cs index dd708d8..1b32b7f 100644 --- a/Tests/Dtos/BookWithTags.cs +++ b/Tests/Dtos/BookWithTags.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Collections.Generic; using DataLayer.EfClasses; diff --git a/Tests/Dtos/ChangePubDateDto.cs b/Tests/Dtos/ChangePubDateDto.cs index 3557c14..9ca3966 100644 --- a/Tests/Dtos/ChangePubDateDto.cs +++ b/Tests/Dtos/ChangePubDateDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.ComponentModel; diff --git a/Tests/Dtos/ChildDbQueryDto.cs b/Tests/Dtos/ChildDbQueryDto.cs index 1533908..dde0b58 100644 --- a/Tests/Dtos/ChildDbQueryDto.cs +++ b/Tests/Dtos/ChildDbQueryDto.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using GenericServices; diff --git a/Tests/Dtos/CreatorOfBooksDto.cs b/Tests/Dtos/CreatorOfBooksDto.cs index 8094a3c..de89cee 100644 --- a/Tests/Dtos/CreatorOfBooksDto.cs +++ b/Tests/Dtos/CreatorOfBooksDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; @@ -13,15 +13,19 @@ public class CreatorOfBooksDto : ILinkToEntity { public string Title { get; set; } public string Description { get; set; } + [DataType(DataType.Date)] public DateTime PublishedOn { get; set; } + public string Publisher { get; set; } + [Range(0, 1000)] public decimal Price { get; set; } + public string ImageUrl { get; set; } - public ICollection Authors { get; set; } - + public ICollection Authors { get; set; } + public ICollection Tags { get; set; } } } \ No newline at end of file diff --git a/Tests/Dtos/DddCompositeIntStringCreateDto.cs b/Tests/Dtos/DddCompositeIntStringCreateDto.cs index 4ab0681..ed86b37 100644 --- a/Tests/Dtos/DddCompositeIntStringCreateDto.cs +++ b/Tests/Dtos/DddCompositeIntStringCreateDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using GenericServices; using Tests.EfClasses; diff --git a/Tests/Dtos/DddCtorEntityAbstractBaseDto.cs b/Tests/Dtos/DddCtorEntityAbstractBaseDto.cs index 9ad8180..3549472 100644 --- a/Tests/Dtos/DddCtorEntityAbstractBaseDto.cs +++ b/Tests/Dtos/DddCtorEntityAbstractBaseDto.cs @@ -1,8 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. - -using GenericServices; -using Tests.EfClasses; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. namespace Tests.Dtos { diff --git a/Tests/Dtos/DddCtorEntityAbstractMainDto.cs b/Tests/Dtos/DddCtorEntityAbstractMainDto.cs index 832c754..8bbc94e 100644 --- a/Tests/Dtos/DddCtorEntityAbstractMainDto.cs +++ b/Tests/Dtos/DddCtorEntityAbstractMainDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using GenericServices; using Tests.EfClasses; diff --git a/Tests/Dtos/DtoLinkedToOwnedType.cs b/Tests/Dtos/DtoLinkedToOwnedType.cs index b642342..01dc356 100644 --- a/Tests/Dtos/DtoLinkedToOwnedType.cs +++ b/Tests/Dtos/DtoLinkedToOwnedType.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using GenericServices; diff --git a/Tests/Dtos/InAddressDto.cs b/Tests/Dtos/InAddressDto.cs index 741007b..bf9c511 100644 --- a/Tests/Dtos/InAddressDto.cs +++ b/Tests/Dtos/InAddressDto.cs @@ -1,4 +1,7 @@ -using System.ComponentModel.DataAnnotations; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + +using System.ComponentModel.DataAnnotations; using GenericServices; using Tests.EfClasses; @@ -9,6 +12,7 @@ public class InAddressDto : ILinkToEntity { [Required] public string Address1 { get; set; } + public string Address2 { get; set; } public string City { get; set; } public string StateOrProvice { get; set; } diff --git a/Tests/Dtos/InContactAddressDto.cs b/Tests/Dtos/InContactAddressDto.cs index 4d6aaaa..b0e196d 100644 --- a/Tests/Dtos/InContactAddressDto.cs +++ b/Tests/Dtos/InContactAddressDto.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using GenericServices; diff --git a/Tests/Dtos/MultiMatchTestDto.cs b/Tests/Dtos/MultiMatchTestDto.cs index 5089a53..effa5c0 100644 --- a/Tests/Dtos/MultiMatchTestDto.cs +++ b/Tests/Dtos/MultiMatchTestDto.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using GenericServices; diff --git a/Tests/Dtos/NormalEntityAllMarkedReadOnlyDto.cs b/Tests/Dtos/NormalEntityAllMarkedReadOnlyDto.cs index 0a098ca..8074d5f 100644 --- a/Tests/Dtos/NormalEntityAllMarkedReadOnlyDto.cs +++ b/Tests/Dtos/NormalEntityAllMarkedReadOnlyDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.ComponentModel; using GenericServices; @@ -11,6 +11,7 @@ public class NormalEntityAllMarkedReadOnlyDto : ILinkToEntity { [ReadOnly(true)] public int Id { get; set; } + [ReadOnly(true)] public string MyString { get; set; } } diff --git a/Tests/Dtos/NormalEntityDto.cs b/Tests/Dtos/NormalEntityDto.cs index b6251a5..4b3781c 100644 --- a/Tests/Dtos/NormalEntityDto.cs +++ b/Tests/Dtos/NormalEntityDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using GenericServices; using Tests.EfClasses; diff --git a/Tests/Dtos/NormalEntityKeyAbstractDto.cs b/Tests/Dtos/NormalEntityKeyAbstractDto.cs index 49b6557..ec241db 100644 --- a/Tests/Dtos/NormalEntityKeyAbstractDto.cs +++ b/Tests/Dtos/NormalEntityKeyAbstractDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using GenericServices; using Tests.EfClasses; diff --git a/Tests/Dtos/NormalEntityKeyPrivateSetDto.cs b/Tests/Dtos/NormalEntityKeyPrivateSetDto.cs index 922da63..c4dca74 100644 --- a/Tests/Dtos/NormalEntityKeyPrivateSetDto.cs +++ b/Tests/Dtos/NormalEntityKeyPrivateSetDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using GenericServices; using Tests.EfClasses; diff --git a/Tests/Dtos/SoftDelEntity.cs b/Tests/Dtos/SoftDelEntity.cs index 88c8f48..988cf22 100644 --- a/Tests/Dtos/SoftDelEntity.cs +++ b/Tests/Dtos/SoftDelEntity.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using GenericServices; diff --git a/Tests/Dtos/TestAbstractCreate.cs b/Tests/Dtos/TestAbstractCreate.cs index 6e3a358..29711c6 100644 --- a/Tests/Dtos/TestAbstractCreate.cs +++ b/Tests/Dtos/TestAbstractCreate.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using GenericServices; diff --git a/Tests/Dtos/TestAbstractUpdateViaAutoMapper.cs b/Tests/Dtos/TestAbstractUpdateViaAutoMapper.cs index 258a19c..2886384 100644 --- a/Tests/Dtos/TestAbstractUpdateViaAutoMapper.cs +++ b/Tests/Dtos/TestAbstractUpdateViaAutoMapper.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using GenericServices; diff --git a/Tests/Dtos/TestAbstractUpdateViaMethod.cs b/Tests/Dtos/TestAbstractUpdateViaMethod.cs index 367288d..14152c0 100644 --- a/Tests/Dtos/TestAbstractUpdateViaMethod.cs +++ b/Tests/Dtos/TestAbstractUpdateViaMethod.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using GenericServices; diff --git a/Tests/Dtos/UniqueNoConfigDto.cs b/Tests/Dtos/UniqueNoConfigDto.cs index 5504ac4..3d405d8 100644 --- a/Tests/Dtos/UniqueNoConfigDto.cs +++ b/Tests/Dtos/UniqueNoConfigDto.cs @@ -1,7 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using System.ComponentModel.DataAnnotations; using GenericServices; using Tests.EfClasses; diff --git a/Tests/Dtos/UniqueWithConfigDto.cs b/Tests/Dtos/UniqueWithConfigDto.cs index cf86163..303ee72 100644 --- a/Tests/Dtos/UniqueWithConfigDto.cs +++ b/Tests/Dtos/UniqueWithConfigDto.cs @@ -1,7 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using System.ComponentModel.DataAnnotations; using GenericServices; using Tests.EfClasses; diff --git a/Tests/Dtos/WriteAuthorAll.cs b/Tests/Dtos/WriteAuthorAll.cs index 97505e9..7e80ac1 100644 --- a/Tests/Dtos/WriteAuthorAll.cs +++ b/Tests/Dtos/WriteAuthorAll.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.ComponentModel.DataAnnotations; using DataLayer.EfClasses; diff --git a/Tests/Dtos/WriteAuthorReadOnlyDto.cs b/Tests/Dtos/WriteAuthorReadOnlyDto.cs index c1d460b..c773f95 100644 --- a/Tests/Dtos/WriteAuthorReadOnlyDto.cs +++ b/Tests/Dtos/WriteAuthorReadOnlyDto.cs @@ -1,10 +1,7 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using DataLayer.EfClasses; -using Microsoft.AspNetCore.Mvc; namespace Tests.Dtos { diff --git a/Tests/EfClasses/Address.cs b/Tests/EfClasses/Address.cs index 2a597f4..c06c0e0 100644 --- a/Tests/EfClasses/Address.cs +++ b/Tests/EfClasses/Address.cs @@ -1,4 +1,6 @@ - +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + using System.ComponentModel.DataAnnotations; using Microsoft.EntityFrameworkCore; @@ -9,6 +11,7 @@ public class Address { [Required] public string Address1 { get; set; } + public string Address2 { get; set; } public string City { get; set; } public string StateOrProvice { get; set; } diff --git a/Tests/EfClasses/AddressNotOwned.cs b/Tests/EfClasses/AddressNotOwned.cs index 41913e0..dde3b88 100644 --- a/Tests/EfClasses/AddressNotOwned.cs +++ b/Tests/EfClasses/AddressNotOwned.cs @@ -1,6 +1,7 @@ - +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + using System.ComponentModel.DataAnnotations; -using Microsoft.EntityFrameworkCore; namespace Tests.EfClasses { @@ -11,6 +12,7 @@ public class AddressNotOwned [Required] public string Address1 { get; set; } + public string Address2 { get; set; } public string City { get; set; } public string StateOrProvice { get; set; } diff --git a/Tests/EfClasses/Child.cs b/Tests/EfClasses/Child.cs index bda317e..d16e5d0 100644 --- a/Tests/EfClasses/Child.cs +++ b/Tests/EfClasses/Child.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. namespace Tests.EfClasses diff --git a/Tests/EfClasses/ChildReadOnly.cs b/Tests/EfClasses/ChildReadOnly.cs index 6c76987..4e72421 100644 --- a/Tests/EfClasses/ChildReadOnly.cs +++ b/Tests/EfClasses/ChildReadOnly.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. namespace Tests.EfClasses diff --git a/Tests/EfClasses/ContactAddress.cs b/Tests/EfClasses/ContactAddress.cs index 0bca7bb..f40e9eb 100644 --- a/Tests/EfClasses/ContactAddress.cs +++ b/Tests/EfClasses/ContactAddress.cs @@ -1,5 +1,5 @@ - -using System; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. namespace Tests.EfClasses { diff --git a/Tests/EfClasses/DddCompositeIntString.cs b/Tests/EfClasses/DddCompositeIntString.cs index 73f80fc..1574d9b 100644 --- a/Tests/EfClasses/DddCompositeIntString.cs +++ b/Tests/EfClasses/DddCompositeIntString.cs @@ -1,17 +1,10 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. - -using Microsoft.EntityFrameworkCore.Metadata.Internal; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. namespace Tests.EfClasses { public class DddCompositeIntString - { - - public int MyInt { get; private set; } - - public string MyString { get; private set; } - + { private DddCompositeIntString() { } public DddCompositeIntString(string myString, int myInt) @@ -19,5 +12,9 @@ public DddCompositeIntString(string myString, int myInt) MyString = myString; MyInt = myInt; } + + public int MyInt { get; private set; } + + public string MyString { get; private set; } } } \ No newline at end of file diff --git a/Tests/EfClasses/DddCtorAndFactEntity.cs b/Tests/EfClasses/DddCtorAndFactEntity.cs index 55a894c..15e0363 100644 --- a/Tests/EfClasses/DddCtorAndFactEntity.cs +++ b/Tests/EfClasses/DddCtorAndFactEntity.cs @@ -1,7 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using GenericServices; using StatusGeneric; namespace Tests.EfClasses @@ -17,6 +16,10 @@ public DddCtorAndFactEntity(int id, int myInt, string myString) MyString = myString; } + public int Id { get; private set; } + public int MyInt { get; private set; } + public string MyString { get; private set; } + public static IStatusGeneric Create(int id, int myInt, string myString) { var status = new StatusGenericHandler(); @@ -32,10 +35,6 @@ public static IStatusGeneric Create(int id, int myInt, str return status.SetResult(result); //This will return null if there are errors } - public int Id { get; private set; } - public int MyInt { get; private set; } - public string MyString { get; private set; } - public void SetInt(int myInt) { @@ -59,7 +58,5 @@ public IStatusGeneric SetIntAndString(int myInt, string myString) MyInt = myInt; return SetString(myString); } - - } } \ No newline at end of file diff --git a/Tests/EfClasses/DddCtorEntity.cs b/Tests/EfClasses/DddCtorEntity.cs index f8959f9..fae68f4 100644 --- a/Tests/EfClasses/DddCtorEntity.cs +++ b/Tests/EfClasses/DddCtorEntity.cs @@ -1,7 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using GenericServices; using StatusGeneric; namespace Tests.EfClasses diff --git a/Tests/EfClasses/DddStaticCreateEntity.cs b/Tests/EfClasses/DddStaticCreateEntity.cs index 371da3f..e29dffe 100644 --- a/Tests/EfClasses/DddStaticCreateEntity.cs +++ b/Tests/EfClasses/DddStaticCreateEntity.cs @@ -1,7 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using GenericServices; using StatusGeneric; namespace Tests.EfClasses @@ -10,6 +9,10 @@ public class DddStaticCreateEntity { private DddStaticCreateEntity() { } + public int Id { get; private set; } + public int MyInt { get; private set; } + public string MyString { get; private set; } + public static IStatusGeneric Create(int myInt, string myString) { var status = new StatusGenericHandler(); @@ -24,10 +27,6 @@ public static IStatusGeneric Create(int myInt, string myS return status.SetResult(result); //This will return null if there are errors } - public int Id { get; private set; } - public int MyInt { get; private set; } - public string MyString { get; private set; } - public void SetInt(int myInt) { diff --git a/Tests/EfClasses/KeyIsString.cs b/Tests/EfClasses/KeyIsString.cs index f266991..16e7eb5 100644 --- a/Tests/EfClasses/KeyIsString.cs +++ b/Tests/EfClasses/KeyIsString.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.ComponentModel.DataAnnotations; diff --git a/Tests/EfClasses/NormalEntity.cs b/Tests/EfClasses/NormalEntity.cs index c08c5ff..08c528f 100644 --- a/Tests/EfClasses/NormalEntity.cs +++ b/Tests/EfClasses/NormalEntity.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.ComponentModel.DataAnnotations; @@ -8,8 +8,10 @@ namespace Tests.EfClasses public class NormalEntity { public int Id { get; set; } + [Range(0,100)] public int MyInt { get; set; } + public string MyString { get; set; } } } \ No newline at end of file diff --git a/Tests/EfClasses/NotUpdatableEntity.cs b/Tests/EfClasses/NotUpdatableEntity.cs index ba7d061..c4b5770 100644 --- a/Tests/EfClasses/NotUpdatableEntity.cs +++ b/Tests/EfClasses/NotUpdatableEntity.cs @@ -1,7 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. - -using Microsoft.EntityFrameworkCore.Metadata.Internal; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. namespace Tests.EfClasses { diff --git a/Tests/EfClasses/Parent.cs b/Tests/EfClasses/Parent.cs index e690510..5cc6f85 100644 --- a/Tests/EfClasses/Parent.cs +++ b/Tests/EfClasses/Parent.cs @@ -1,7 +1,6 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. -using System.Collections; using System.Collections.Generic; namespace Tests.EfClasses diff --git a/Tests/EfClasses/ParentOneToOne.cs b/Tests/EfClasses/ParentOneToOne.cs index 9823fe0..a14882c 100644 --- a/Tests/EfClasses/ParentOneToOne.cs +++ b/Tests/EfClasses/ParentOneToOne.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/Tests/EfClasses/ParentWithChildCountQuery.cs b/Tests/EfClasses/ParentWithChildCountQuery.cs index 63ff80d..3e20359 100644 --- a/Tests/EfClasses/ParentWithChildCountQuery.cs +++ b/Tests/EfClasses/ParentWithChildCountQuery.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. namespace Tests.EfClasses diff --git a/Tests/EfClasses/ReadOnlyEntity.cs b/Tests/EfClasses/ReadOnlyEntity.cs index eaf0589..0043498 100644 --- a/Tests/EfClasses/ReadOnlyEntity.cs +++ b/Tests/EfClasses/ReadOnlyEntity.cs @@ -1,14 +1,13 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. namespace Tests.EfClasses { public class ReadOnlyEntity { + private ReadOnlyEntity() { } public int Id { get; private set; } public int MyInt { get; private set; } public string MyString { get; private set; } - - private ReadOnlyEntity() { } } } \ No newline at end of file diff --git a/Tests/EfClasses/SoftDelEntity.cs b/Tests/EfClasses/SoftDelEntity.cs index 6b95252..b47d4da 100644 --- a/Tests/EfClasses/SoftDelEntity.cs +++ b/Tests/EfClasses/SoftDelEntity.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. namespace Tests.EfClasses diff --git a/Tests/EfClasses/TenantAddress.cs b/Tests/EfClasses/TenantAddress.cs index daed687..76f8ade 100644 --- a/Tests/EfClasses/TenantAddress.cs +++ b/Tests/EfClasses/TenantAddress.cs @@ -1,18 +1,21 @@ -using System; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + +using System; namespace Tests.EfClasses { public class TenantAddress { - public int TenantAddressId { get; private set; } - - public Address Address { get; private set; } - private TenantAddress() { } public TenantAddress(Address address) { Address = address ?? throw new ArgumentNullException(nameof(address)); } + + public int TenantAddressId { get; private set; } + + public Address Address { get; private set; } } } \ No newline at end of file diff --git a/Tests/EfClasses/TestAbstractBase.cs b/Tests/EfClasses/TestAbstractBase.cs index 45c0710..1bcfac8 100644 --- a/Tests/EfClasses/TestAbstractBase.cs +++ b/Tests/EfClasses/TestAbstractBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. namespace Tests.EfClasses diff --git a/Tests/EfClasses/TestAbstractMain.cs b/Tests/EfClasses/TestAbstractMain.cs index 8e5aaed..4eb3627 100644 --- a/Tests/EfClasses/TestAbstractMain.cs +++ b/Tests/EfClasses/TestAbstractMain.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. namespace Tests.EfClasses @@ -12,6 +12,5 @@ public TestAbstractMain(string abstractPropPrivate, string abstractPropPublic, s } public string NotAbstractPropPublic { get; set; } - } } \ No newline at end of file diff --git a/Tests/EfClasses/UniqueEntity.cs b/Tests/EfClasses/UniqueEntity.cs index ff2df5f..6b598a5 100644 --- a/Tests/EfClasses/UniqueEntity.cs +++ b/Tests/EfClasses/UniqueEntity.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.ComponentModel.DataAnnotations; @@ -8,6 +8,7 @@ namespace Tests.EfClasses public class UniqueEntity { public int Id { get; set; } + [MaxLength(100)] public string UniqueString { get; set; } } diff --git a/Tests/EfCode/TestDbContext.cs b/Tests/EfCode/TestDbContext.cs index 8cc523b..7c2ed06 100644 --- a/Tests/EfCode/TestDbContext.cs +++ b/Tests/EfCode/TestDbContext.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore; using Tests.EfClasses; @@ -8,6 +8,7 @@ namespace Tests.EfCode { public class TestDbContext : DbContext { + public TestDbContext(DbContextOptions options): base(options) { } public DbSet NormalEntities { get; set; } public DbSet DddCtorEntities { get; set; } public DbSet DddStaticFactEntities { get; set; } @@ -29,9 +30,6 @@ public class TestDbContext : DbContext public DbSet ParentOneToOnes { get; set; } - - public TestDbContext(DbContextOptions options): base(options) { } - protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().HasKey(p => new {p.MyInt, p.MyString}); diff --git a/Tests/Helpers/AutoMapperHelpers.cs b/Tests/Helpers/AutoMapperHelpers.cs index f716a47..ff0dc3f 100644 --- a/Tests/Helpers/AutoMapperHelpers.cs +++ b/Tests/Helpers/AutoMapperHelpers.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using AutoMapper; @@ -11,7 +11,6 @@ namespace Tests.Helpers { public static class AutoMapperHelpers { - public static MapperConfiguration CreateReadConfig(Action> alterMapping) { var readProfile = new MappingProfile(false); diff --git a/Tests/Helpers/DddEfTestData.cs b/Tests/Helpers/DddEfTestData.cs index b733524..b174900 100644 --- a/Tests/Helpers/DddEfTestData.cs +++ b/Tests/Helpers/DddEfTestData.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2016 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; diff --git a/Tests/Helpers/UnitTestProfile.cs b/Tests/Helpers/UnitTestProfile.cs index 09c5ea0..1903c31 100644 --- a/Tests/Helpers/UnitTestProfile.cs +++ b/Tests/Helpers/UnitTestProfile.cs @@ -1,9 +1,8 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.ComponentModel; -using System.ComponentModel.DataAnnotations; using System.Reflection; using AutoMapper; diff --git a/Tests/UnitTests/DataLayer/TestDddBook.cs b/Tests/UnitTests/DataLayer/TestDddBook.cs index ca6df6d..39f3e53 100644 --- a/Tests/UnitTests/DataLayer/TestDddBook.cs +++ b/Tests/UnitTests/DataLayer/TestDddBook.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; @@ -15,7 +15,6 @@ namespace Tests.UnitTests.DataLayer { public class TestDddBook { - [Fact] public void TestCreateBookOk() { @@ -292,7 +291,6 @@ public void TestRemovePromotionBookOk() book.ActualPrice.ShouldEqual(book.OrgPrice); } } - } } \ No newline at end of file diff --git a/Tests/UnitTests/DataLayer/TestDddBookLoad.cs b/Tests/UnitTests/DataLayer/TestDddBookLoad.cs index b67f6b2..bfd1327 100644 --- a/Tests/UnitTests/DataLayer/TestDddBookLoad.cs +++ b/Tests/UnitTests/DataLayer/TestDddBookLoad.cs @@ -1,12 +1,7 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using System.IO; -using System.Linq; -using ServiceLayer.DatabaseCode.Services; -using TestSupport.Helpers; using Xunit; -using Xunit.Extensions.AssertExtensions; namespace Tests.UnitTests.DataLayer { @@ -28,9 +23,6 @@ public void TestLoadBooksOk() //books.Count.ShouldEqual(53); //books.All(x => x.ActualPrice != 0).ShouldBeTrue(); } - - - } } \ No newline at end of file diff --git a/Tests/UnitTests/DataLayer/TestDddOrder.cs b/Tests/UnitTests/DataLayer/TestDddOrder.cs index 41eb338..616c8fd 100644 --- a/Tests/UnitTests/DataLayer/TestDddOrder.cs +++ b/Tests/UnitTests/DataLayer/TestDddOrder.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; @@ -105,9 +105,6 @@ public void TestCreateOrderAndAddToDbOk() context.Set().Count().ShouldEqual(1); } } - - - } } \ No newline at end of file diff --git a/Tests/UnitTests/DataLayer/TestQueryDb.cs b/Tests/UnitTests/DataLayer/TestQueryDb.cs index a9a14db..883b52c 100644 --- a/Tests/UnitTests/DataLayer/TestQueryDb.cs +++ b/Tests/UnitTests/DataLayer/TestQueryDb.cs @@ -1,21 +1,15 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using System.Linq; -using DataLayer.Dtos; -using DataLayer.EfClasses; -using DataLayer.EfCode; using Tests.EfClasses; using Tests.EfCode; -using Tests.Helpers; using TestSupport.EfHelpers; using TestSupport.Helpers; using Xunit; using Xunit.Abstractions; using Xunit.Extensions.AssertExtensions; -using Xunit.Sdk; namespace Tests.UnitTests.DataLayer { @@ -52,8 +46,6 @@ public void TestDbQueryChildReadOnlyOk() children.Count.ShouldEqual(2); } } - - } } \ No newline at end of file diff --git a/Tests/UnitTests/DataLayer/TestSaveChangesWithValidation.cs b/Tests/UnitTests/DataLayer/TestSaveChangesWithValidation.cs index 238df12..067bf3e 100644 --- a/Tests/UnitTests/DataLayer/TestSaveChangesWithValidation.cs +++ b/Tests/UnitTests/DataLayer/TestSaveChangesWithValidation.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; using System.Threading.Tasks; @@ -14,7 +14,6 @@ namespace Tests.UnitTests.DataLayer { public class TestSaveChangesWithValidation { - [Fact] public void TestSaveChangesWithValidationNoErrorsOk() { diff --git a/Tests/UnitTests/ExampleRazorPages/TestGenericServicesVersions.cs b/Tests/UnitTests/ExampleRazorPages/TestGenericServicesVersions.cs index df7db0c..a15bd98 100644 --- a/Tests/UnitTests/ExampleRazorPages/TestGenericServicesVersions.cs +++ b/Tests/UnitTests/ExampleRazorPages/TestGenericServicesVersions.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; @@ -265,7 +265,6 @@ public void TestRemovePromotionBookOk() book.ActualPrice.ShouldEqual(40); } } - } } \ No newline at end of file diff --git a/Tests/UnitTests/ExampleRazorPages/TestHandCodedVersions.cs b/Tests/UnitTests/ExampleRazorPages/TestHandCodedVersions.cs index 91fabb7..06955ab 100644 --- a/Tests/UnitTests/ExampleRazorPages/TestHandCodedVersions.cs +++ b/Tests/UnitTests/ExampleRazorPages/TestHandCodedVersions.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; using DataLayer.EfClasses; @@ -124,7 +124,6 @@ public void TestRemovePromotionBookOk() book.ActualPrice.ShouldEqual(dto.OrgPrice); } } - } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesInternal/TestBestMethodCtorMatch.cs b/Tests/UnitTests/GenericServicesInternal/TestBestMethodCtorMatch.cs index 13e9f2e..a226ebb 100644 --- a/Tests/UnitTests/GenericServicesInternal/TestBestMethodCtorMatch.cs +++ b/Tests/UnitTests/GenericServicesInternal/TestBestMethodCtorMatch.cs @@ -1,44 +1,19 @@ -using System; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; using System.Linq; using System.Reflection; -using DataLayer.EfClasses; -using Xunit; -using GenericServices.Internal; using GenericServices.Internal.Decoders; +using Xunit; using Xunit.Extensions.AssertExtensions; namespace Tests.UnitTests.GenericServicesInternal { public class TestBestMethodCtorMatch { - - private class Dto - { - public int MyInt { get; set; } - public string MyString { get; set; } - public IEnumerable MyList { get; set; } - } - - private class InstanceMethods - { - public void MyGoodMethod(IEnumerable myList, int myInt, string myString) - { - } - - public void MyAverageMethod(string myString, int myInt, ICollection myList) - { - } - - public void MyBadMethod(bool myBool, string myString) - { - } - } - - [Theory] [InlineData(1, "MyGoodMethod", "")] [InlineData(0.9, "MyAverageMethod", "MyGoodMethod")] @@ -92,6 +67,47 @@ public void TestToString() bestMethod.ToString().ShouldEqual("Closest match at 50%: MyBadMethod(Int32 MyInt, String MyString)"); } + [Theory] + [InlineData(1, 3, "")] + [InlineData(0.85, 2, "MyInt")] + public void TestGetMatchCtors(double expectedScore, int numParamExpected, string excludeThisProperty) + { + //SETUP + var props = typeof(Dto).GetProperties().Where(x => x.Name != excludeThisProperty).ToImmutableList(); + var ctors = typeof(Ctors).GetConstructors(); + + //ATTEMPT + var bestMethod = BestMethodCtorMatch.FindMatch(props, ctors); + + //VERIFY + bestMethod.ShouldNotBeNull(); + Math.Abs(bestMethod.Score - expectedScore).ShouldBeInRange(0, 0.05); + bestMethod.Constructor.GetParameters().Length.ShouldEqual(numParamExpected); + + } + + private class Dto + { + public int MyInt { get; set; } + public string MyString { get; set; } + public IEnumerable MyList { get; set; } + } + + private class InstanceMethods + { + public void MyGoodMethod(IEnumerable myList, int myInt, string myString) + { + } + + public void MyAverageMethod(string myString, int myInt, ICollection myList) + { + } + + public void MyBadMethod(bool myBool, string myString) + { + } + } + //----------------------------------------------------------- //Ctors @@ -118,24 +134,5 @@ private Ctors(int myInt) { } } - - [Theory] - [InlineData(1, 3, "")] - [InlineData(0.85, 2, "MyInt")] - public void TestGetMatchCtors(double expectedScore, int numParamExpected, string excludeThisProperty) - { - //SETUP - var props = typeof(Dto).GetProperties().Where(x => x.Name != excludeThisProperty).ToImmutableList(); - var ctors = typeof(Ctors).GetConstructors(); - - //ATTEMPT - var bestMethod = BestMethodCtorMatch.FindMatch(props, ctors); - - //VERIFY - bestMethod.ShouldNotBeNull(); - Math.Abs(bestMethod.Score - expectedScore).ShouldBeInRange(0, 0.05); - bestMethod.Constructor.GetParameters().Length.ShouldEqual(numParamExpected); - - } } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesInternal/TestBuildCall.cs b/Tests/UnitTests/GenericServicesInternal/TestBuildCall.cs index 037469c..b698423 100644 --- a/Tests/UnitTests/GenericServicesInternal/TestBuildCall.cs +++ b/Tests/UnitTests/GenericServicesInternal/TestBuildCall.cs @@ -1,8 +1,10 @@ -using System; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + +using System; using System.Collections.Generic; using System.Linq; using DataLayer.EfClasses; -using GenericServices; using GenericServices.Configuration; using GenericServices.Internal.LinqBuilders; using StatusGeneric; @@ -17,56 +19,6 @@ namespace Tests.UnitTests.GenericServicesInternal { public class TestBuildCall { - - private class Dto - { - public int MyInt { get; set; } - public string MyString { get; set; } - public IEnumerable MyList { get; set; } - } - - private class Target1 - { - public Target1() { } - - public Target1(int myInt, string myString) - { - MyInt = myInt; - MyString = myString; - } - - public int MyInt { get; set; } - public string MyString { get; set; } - - public void SetMyInt(int myInt) - { - MyInt = myInt; - } - - public void SetMyIntAndAddEntityToDb(int myInt, TestDbContext context) - { - MyInt = myInt; - context.Add(new NormalEntity {MyInt = myInt}); - } - - public IStatusGeneric SetMyString(string myString) - { - MyString = myString; - return new StatusGenericHandler {Message = "OK"}; - } - - public static IStatusGeneric Create(int myInt, string myString) - { - var status = - new StatusGenericHandler - { - Message = "Static" - }; - return status.SetResult(new Target1(myInt, myString)); - } - - } - [Fact] public void TestBuildCallMethodNoReturn() { @@ -106,13 +58,13 @@ public void TestBuildCallChangePubDateDto() { //SETUP var prop = new PropertyMatch(true, PropertyMatch.TypeMatchLevels.Match, - typeof(Tests.Dtos.ChangePubDateDto).GetProperty(nameof(Tests.Dtos.ChangePubDateDto.PublishedOn))); + typeof(Dtos.ChangePubDateDto).GetProperty(nameof(Dtos.ChangePubDateDto.PublishedOn))); var method = typeof(Book).GetMethod(nameof(Book.UpdatePublishedOn)); - var dto = new Tests.Dtos.ChangePubDateDto { PublishedOn = new DateTime(2000,1,1)}; + var dto = new Dtos.ChangePubDateDto { PublishedOn = new DateTime(2000,1,1)}; var target = DddEfTestData.CreateDummyBooks(1).Single(); //ATTEMPT - var action = BuildCall.CallMethodReturnVoid(method, typeof(Tests.Dtos.ChangePubDateDto), typeof(Book), new List{prop}); + var action = BuildCall.CallMethodReturnVoid(method, typeof(Dtos.ChangePubDateDto), typeof(Book), new List{prop}); action.Invoke(dto, target); //VERIFY @@ -127,7 +79,7 @@ public void TestBuildCallNoParameters() var target = DddEfTestData.CreateFourBooks().Last(); //ATTEMPT - var action = BuildCall.CallMethodReturnVoid(method, typeof(Tests.Dtos.ChangePubDateDto), typeof(Book), new List()); + var action = BuildCall.CallMethodReturnVoid(method, typeof(Dtos.ChangePubDateDto), typeof(Book), new List()); action.Invoke(target); //VERIFY @@ -216,5 +168,52 @@ public void TestBuildCallCtor() ((string)newInstance.MyString).ShouldEqual("Hello"); } + private class Dto + { + public int MyInt { get; set; } + public string MyString { get; set; } + public IEnumerable MyList { get; set; } + } + + private class Target1 + { + public Target1() { } + + public Target1(int myInt, string myString) + { + MyInt = myInt; + MyString = myString; + } + + public int MyInt { get; set; } + public string MyString { get; set; } + + public void SetMyInt(int myInt) + { + MyInt = myInt; + } + + public void SetMyIntAndAddEntityToDb(int myInt, TestDbContext context) + { + MyInt = myInt; + context.Add(new NormalEntity {MyInt = myInt}); + } + + public IStatusGeneric SetMyString(string myString) + { + MyString = myString; + return new StatusGenericHandler {Message = "OK"}; + } + + public static IStatusGeneric Create(int myInt, string myString) + { + var status = + new StatusGenericHandler + { + Message = "Static" + }; + return status.SetResult(new Target1(myInt, myString)); + } + } } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesInternal/TestBuildCallAsync.cs b/Tests/UnitTests/GenericServicesInternal/TestBuildCallAsync.cs index 65efa31..2564c16 100644 --- a/Tests/UnitTests/GenericServicesInternal/TestBuildCallAsync.cs +++ b/Tests/UnitTests/GenericServicesInternal/TestBuildCallAsync.cs @@ -1,15 +1,10 @@ -using System; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; -using DataLayer.EfClasses; -using GenericServices; using GenericServices.Configuration; using GenericServices.Internal.LinqBuilders; -using Tests.EfClasses; -using Tests.EfCode; -using Tests.Helpers; -using TestSupport.EfHelpers; using Xunit; using Xunit.Extensions.AssertExtensions; @@ -17,6 +12,22 @@ namespace Tests.UnitTests.GenericServicesInternal { public class TestBuildCallAsync { + [Fact] + public async Task TestBuildCallTaskMethodNoReturn() + { + //SETUP + var prop = new PropertyMatch(true, PropertyMatch.TypeMatchLevels.Match, typeof(Dto).GetProperty(nameof(Dto.MyInt))); + var method = typeof(Target1).GetMethod(nameof(Target1.MyTask)); + var dto = new Dto {MyInt = 123}; + var target = new Target1(); + + //ATTEMPT + var action = BuildCallAsync.TaskCallMethodReturnVoid(method, typeof(Dto), typeof(Target1), new List{prop}); + await action.Invoke(dto, target); + + //VERIFY + target.MyInt.ShouldEqual(123); + } private class Dto { @@ -43,26 +54,6 @@ public async Task MyTask(int myInt) MyInt = myInt; await Task.Delay(10); } - } - - [Fact] - public async Task TestBuildCallTaskMethodNoReturn() - { - //SETUP - var prop = new PropertyMatch(true, PropertyMatch.TypeMatchLevels.Match, typeof(Dto).GetProperty(nameof(Dto.MyInt))); - var method = typeof(Target1).GetMethod(nameof(Target1.MyTask)); - var dto = new Dto {MyInt = 123}; - var target = new Target1(); - - //ATTEMPT - var action = BuildCallAsync.TaskCallMethodReturnVoid(method, typeof(Dto), typeof(Target1), new List{prop}); - await action.Invoke(dto, target); - - //VERIFY - target.MyInt.ShouldEqual(123); - } - - } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesInternal/TestCreateMapGenerator.cs b/Tests/UnitTests/GenericServicesInternal/TestCreateMapGenerator.cs index 4c79a46..1f0e6ba 100644 --- a/Tests/UnitTests/GenericServicesInternal/TestCreateMapGenerator.cs +++ b/Tests/UnitTests/GenericServicesInternal/TestCreateMapGenerator.cs @@ -1,23 +1,27 @@ -using System.Linq; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + +using System.Linq; using AutoMapper; using AutoMapper.Configuration; using DataLayer.EfClasses; using DataLayer.EfCode; -using Xunit; using GenericServices.Internal.Decoders; using GenericServices.Setup.Internal; using Tests.Configs; using Tests.Dtos; using Tests.Helpers; using TestSupport.EfHelpers; +using Xunit; using Xunit.Extensions.AssertExtensions; namespace Tests.UnitTests.GenericServicesInternal { public class TestCreateMapGenerator { - private readonly DecodedEntityClass _bookInfo; private readonly DecodedEntityClass _authorInfo; + private readonly DecodedEntityClass _bookInfo; + public TestCreateMapGenerator() { var options = SqliteInMemory.CreateOptions(); @@ -62,8 +66,5 @@ public void TestBookReadMappingsWithConfig() dto.Title.ShouldEqual("Quantum Networking"); dto.ReviewsCount.ShouldEqual(2); } - - - } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesInternal/TestDecodedDto.cs b/Tests/UnitTests/GenericServicesInternal/TestDecodedDto.cs index ee80e9b..dae8398 100644 --- a/Tests/UnitTests/GenericServicesInternal/TestDecodedDto.cs +++ b/Tests/UnitTests/GenericServicesInternal/TestDecodedDto.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + +using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; @@ -6,10 +9,10 @@ using DataLayer.EfCode; using GenericServices; using GenericServices.Configuration; -using Xunit; using GenericServices.Internal.Decoders; using Microsoft.AspNetCore.Mvc; using TestSupport.EfHelpers; +using Xunit; using Xunit.Extensions.AssertExtensions; namespace Tests.UnitTests.GenericServicesInternal @@ -17,6 +20,7 @@ namespace Tests.UnitTests.GenericServicesInternal public class TestDecodedDto { private DecodedEntityClass _bookEntityInfo; + public TestDecodedDto() { var options = SqliteInMemory.CreateOptions(); @@ -26,16 +30,6 @@ public TestDecodedDto() } } - public class Dto1 : ILinkToEntity - { - public int BookId { get; set; } - - [ReadOnly(true)] - public string Title { get; set; } - - public string ImageUrl { get; set; } - } - [Fact] public void TestDecodedDto1CheckPropertyTypes() { @@ -59,7 +53,7 @@ public void TestDecodedDto1CheckPropertyTypes() public void TestFindSetterMethod() { //SETUP - var decoded = new DecodedDto(typeof(Tests.Dtos.ChangePubDateDto), _bookEntityInfo, new GenericServicesConfig(), null); + var decoded = new DecodedDto(typeof(Dtos.ChangePubDateDto), _bookEntityInfo, new GenericServicesConfig(), null); //ATTEMPT var method = decoded.GetMethodToRun(new DecodeName("UpdatePublishedOn"), _bookEntityInfo); @@ -72,7 +66,7 @@ public void TestFindSetterMethod() public void TestFindSetterMethodWithGivenNumParams() { //SETUP - var decoded = new DecodedDto(typeof(Tests.Dtos.ChangePubDateDto), _bookEntityInfo, new GenericServicesConfig(), null); + var decoded = new DecodedDto(typeof(Dtos.ChangePubDateDto), _bookEntityInfo, new GenericServicesConfig(), null); //ATTEMPT var method = decoded.GetMethodToRun(new DecodeName("UpdatePublishedOn(1)"), _bookEntityInfo); @@ -85,7 +79,7 @@ public void TestFindSetterMethodWithGivenNumParams() public void TestFindSetterMethodBadName() { //SETUP - var decoded = new DecodedDto(typeof(Tests.Dtos.ChangePubDateDto), _bookEntityInfo, new GenericServicesConfig(), null); + var decoded = new DecodedDto(typeof(Dtos.ChangePubDateDto), _bookEntityInfo, new GenericServicesConfig(), null); //ATTEMPT var ex = Assert.Throws(() => decoded.GetMethodToRun(new DecodeName("badname"), _bookEntityInfo)); @@ -98,7 +92,7 @@ public void TestFindSetterMethodBadName() public void TestFindSetterMethodNumParamsBad() { //SETUP - var decoded = new DecodedDto(typeof(Tests.Dtos.ChangePubDateDto), _bookEntityInfo, new GenericServicesConfig(), null); + var decoded = new DecodedDto(typeof(Dtos.ChangePubDateDto), _bookEntityInfo, new GenericServicesConfig(), null); //ATTEMPT var ex = Assert.Throws(() => decoded.GetMethodToRun(new DecodeName("UpdatePublishedOn(2)"), _bookEntityInfo)); @@ -111,7 +105,7 @@ public void TestFindSetterMethodNumParamsBad() public void TestGetDefaultSetterMethod() { //SETUP - var decoded = new DecodedDto(typeof(Tests.Dtos.ChangePubDateDto), _bookEntityInfo, new GenericServicesConfig(), null); + var decoded = new DecodedDto(typeof(Dtos.ChangePubDateDto), _bookEntityInfo, new GenericServicesConfig(), null); //ATTEMPT var method = decoded.GetMethodToRun(new DecodeName(null), _bookEntityInfo); @@ -120,19 +114,6 @@ public void TestGetDefaultSetterMethod() method.Method.Name.ShouldEqual("UpdatePublishedOn"); } - public class ExtraParamsDto : ILinkToEntity - { - [HiddenInput] - public int BookId { get; set; } - - public string Title { get; set; } - - [DataType(DataType.Date)] - public DateTime PublishedOn { get; set; } - - public DateTime SomeOtherParam { get; set; } - } - [Fact] public void TestCheckExtraParamsOk() { @@ -146,6 +127,27 @@ public void TestCheckExtraParamsOk() method.Method.Name.ShouldEqual("UpdatePublishedOn"); } + public class Dto1 : ILinkToEntity + { + public int BookId { get; set; } + + [ReadOnly(true)] + public string Title { get; set; } + + public string ImageUrl { get; set; } + } + + public class ExtraParamsDto : ILinkToEntity + { + [HiddenInput] + public int BookId { get; set; } + + public string Title { get; set; } + + [DataType(DataType.Date)] + public DateTime PublishedOn { get; set; } + public DateTime SomeOtherParam { get; set; } + } } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesInternal/TestDecodedDtoKeyIsString.cs b/Tests/UnitTests/GenericServicesInternal/TestDecodedDtoKeyIsString.cs index 7301535..e18665b 100644 --- a/Tests/UnitTests/GenericServicesInternal/TestDecodedDtoKeyIsString.cs +++ b/Tests/UnitTests/GenericServicesInternal/TestDecodedDtoKeyIsString.cs @@ -1,19 +1,14 @@ -using System; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + using System.Linq; -using DataLayer.EfClasses; -using DataLayer.EfCode; -using GenericServices; using GenericServices.Configuration; -using Xunit; using GenericServices.Internal.Decoders; -using Microsoft.AspNetCore.Mvc; using Tests.Dtos; using Tests.EfClasses; using Tests.EfCode; -using Tests.UnitTests.GenericServicesPublic; using TestSupport.EfHelpers; +using Xunit; using Xunit.Extensions.AssertExtensions; namespace Tests.UnitTests.GenericServicesInternal @@ -21,6 +16,7 @@ namespace Tests.UnitTests.GenericServicesInternal public class TestDecodedDtoKeyIsString { private DecodedEntityClass _EntityInfo; + public TestDecodedDtoKeyIsString() { var options = SqliteInMemory.CreateOptions(); @@ -62,10 +58,5 @@ public void TestFindSetterMethodWithGivenNumParams() //VERIFY methodOrCtor.Name.ShouldEqual("Ctor"); } - - - - - } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesInternal/TestDecodedEntityClass.cs b/Tests/UnitTests/GenericServicesInternal/TestDecodedEntityClass.cs index 6fcc9ff..bb02323 100644 --- a/Tests/UnitTests/GenericServicesInternal/TestDecodedEntityClass.cs +++ b/Tests/UnitTests/GenericServicesInternal/TestDecodedEntityClass.cs @@ -1,21 +1,20 @@ -using System; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + using System.Linq; -using System.Reflection; using DataLayer.EfClasses; using DataLayer.EfCode; -using Xunit; using GenericServices.Internal.Decoders; using Tests.EfClasses; using Tests.EfCode; using TestSupport.EfHelpers; +using Xunit; using Xunit.Extensions.AssertExtensions; namespace Tests.UnitTests.GenericServicesInternal { public class TestDecodedEntityClass { - - [Fact] public void AuthorDecodedEntityClass() { @@ -266,6 +265,5 @@ public void TestReadOnlyEntityDecoded() decoded.CanBeCreatedByCtorOrStaticMethod.ShouldBeFalse(); } } - } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesInternal/TestExtractDisplayHelpers.cs b/Tests/UnitTests/GenericServicesInternal/TestExtractDisplayHelpers.cs index 17691d7..f017c4a 100644 --- a/Tests/UnitTests/GenericServicesInternal/TestExtractDisplayHelpers.cs +++ b/Tests/UnitTests/GenericServicesInternal/TestExtractDisplayHelpers.cs @@ -1,7 +1,9 @@ -using System.ComponentModel; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + using System.ComponentModel.DataAnnotations; -using Xunit; using GenericServices.Internal; +using Xunit; using Xunit.Extensions.AssertExtensions; namespace Tests.UnitTests.GenericServicesInternal @@ -10,22 +12,6 @@ public class TestExtractDisplayHelpers { private Test _test = new Test(); - [Display(Name="ClassName")] - private class Test - { - [Display(Name = "Display Name")] - public int I { get; set; } - [Display(Name = "OneName")] - public int J { get; set; } - public int PascalName { get; set; } - public int Longwordnotcamel { get; set; } - } - - private class TestWithoutDisplayName - { - - } - [Fact] public void TestGetDisplayName() @@ -51,6 +37,22 @@ public void TestClassName() ExtractDisplayHelpers.GetNameForClass().ShouldEqual("Test Without Display Name"); } + [Display(Name="ClassName")] + private class Test + { + [Display(Name = "Display Name")] + public int I { get; set; } + + [Display(Name = "OneName")] + public int J { get; set; } + + public int PascalName { get; set; } + public int Longwordnotcamel { get; set; } + } + + private class TestWithoutDisplayName + {} + //[Fact] //public void TestGetShortName() //{ diff --git a/Tests/UnitTests/GenericServicesInternal/TestKeyHandlers.cs b/Tests/UnitTests/GenericServicesInternal/TestKeyHandlers.cs index a0c23bc..84931c1 100644 --- a/Tests/UnitTests/GenericServicesInternal/TestKeyHandlers.cs +++ b/Tests/UnitTests/GenericServicesInternal/TestKeyHandlers.cs @@ -1,18 +1,20 @@ -using GenericServices.Configuration; -using Xunit; +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. + +using GenericServices.Configuration; using GenericServices.Internal.Decoders; using GenericServices.Internal.MappingCode; using Tests.Dtos; using Tests.EfClasses; using Tests.EfCode; using TestSupport.EfHelpers; +using Xunit; using Xunit.Extensions.AssertExtensions; namespace Tests.UnitTests.GenericServicesInternal { public class TestKeyHandlers { - [Fact] public void TestNormalKeyExtract() { @@ -109,7 +111,5 @@ public void TestCompositeKeyCopyBack() dto.MyInt.ShouldEqual(999); } } - - } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesInternal/TestParametersMatch.cs b/Tests/UnitTests/GenericServicesInternal/TestParametersMatch.cs index a647883..09a6c11 100644 --- a/Tests/UnitTests/GenericServicesInternal/TestParametersMatch.cs +++ b/Tests/UnitTests/GenericServicesInternal/TestParametersMatch.cs @@ -1,12 +1,11 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Collections.Generic; using System.Linq; using System.Reflection; using DataLayer.EfCode; using GenericServices.Configuration; -using GenericServices.Configuration.Internal; using GenericServices.Internal.Decoders; using Xunit; using Xunit.Extensions.AssertExtensions; @@ -15,18 +14,6 @@ namespace Tests.UnitTests.GenericServicesInternal { public class TestParametersMatch { -#pragma warning disable xUnit1013 // Public method should be marked as test - public void ParemeterlessMethod() { } - public void SetMyInt(int myInt) { } - - public void SetMyString(string myString) { } - - public void NotMatch(string myString, int notMyInt) { } - - public int MyInt { get; set; } - public string MyString { get; set; } -#pragma warning restore xUnit1013 // Public method should be marked as test - private static MethodInfo _paremeterlessMethod = typeof(TestParametersMatch).GetMethod(nameof(ParemeterlessMethod)); private static MethodInfo _setMyInt = typeof(TestParametersMatch).GetMethod(nameof(SetMyInt)); private static MethodInfo _setMyString = typeof(TestParametersMatch).GetMethod(nameof(SetMyString)); @@ -86,5 +73,16 @@ public void TesDbContextMatch() match.PropertiesMatch.MatchedPropertiesInOrder.First().MatchSource.ShouldEqual(MatchSources.Property); match.PropertiesMatch.MatchedPropertiesInOrder.Last().MatchSource.ShouldEqual(MatchSources.DbContext); } +#pragma warning disable xUnit1013 // Public method should be marked as test + public void ParemeterlessMethod() { } + public void SetMyInt(int myInt) { } + + public void SetMyString(string myString) { } + + public void NotMatch(string myString, int notMyInt) { } + + public int MyInt { get; set; } + public string MyString { get; set; } +#pragma warning restore xUnit1013 // Public method should be marked as test } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesPublic/TestAbstractClassAccess.cs b/Tests/UnitTests/GenericServicesPublic/TestAbstractClassAccess.cs index 89d0950..d68a689 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestAbstractClassAccess.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestAbstractClassAccess.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; using GenericServices.PublicButHidden; @@ -129,6 +129,5 @@ public void TestCreateViaDtoWithAbstractBaseOk() context.DddCtorEntities.Single().MyInt.ShouldEqual(123); } } - } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesPublic/TestCreateViaDto.cs b/Tests/UnitTests/GenericServicesPublic/TestCreateViaDto.cs index 67112f9..bfce52c 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestCreateViaDto.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestCreateViaDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; @@ -27,13 +27,6 @@ public TestCreateViaDto(ITestOutputHelper output) _output = output; } - public class AuthorDto : ILinkToEntity - { - public int AuthorId { get; set; } - public string Name { get; set; } - public string Email { get; set; } - } - [Fact] public void TestCreateAuthorViaAutoMapperOk() { @@ -170,17 +163,6 @@ public void TestCreateEntityNotCopyKeyBackBecauseDtoPropertyHasPrivateSetterOk() } } - - - //------------------------------------------------------ - //via ctors/statics - - public class DtoCtorCreate : ILinkToEntity - { - public int MyInt { get; set; } - public string MyString { get; set; } - } - [Fact] public void TestCreateEntityViaDtoCtorCreateCtor2Ok() { @@ -292,12 +274,6 @@ public void TestCreateEntityViaDtoCtorCreateCtorMatchesLongerOne() } } - public class DtoCtorCreateBad : ILinkToEntity - { - public int YourInt { get; set; } - public bool MyString { get; set; } - } - [Fact] public void TestCreateEntityViaDtoCtorNoMatchOk() { @@ -325,12 +301,6 @@ public void TestCreateEntityViaDtoCtorNoMatchOk() } } - public class DtoStaticCreate : ILinkToEntity - { - public int MyInt { get; set; } - public string MyString { get; set; } - } - [Fact] public void TestCreateEntityUsingStaticCreatorOk() { @@ -385,5 +355,34 @@ public void TestCreateEntityUsingStaticCreateWithBadStatusOk() context.DddStaticFactEntities.Count().ShouldEqual(0); } } + + public class AuthorDto : ILinkToEntity + { + public int AuthorId { get; set; } + public string Name { get; set; } + public string Email { get; set; } + } + + + //------------------------------------------------------ + //via ctors/statics + + public class DtoCtorCreate : ILinkToEntity + { + public int MyInt { get; set; } + public string MyString { get; set; } + } + + public class DtoCtorCreateBad : ILinkToEntity + { + public int YourInt { get; set; } + public bool MyString { get; set; } + } + + public class DtoStaticCreate : ILinkToEntity + { + public int MyInt { get; set; } + public string MyString { get; set; } + } } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesPublic/TestDbQueryCrud.cs b/Tests/UnitTests/GenericServicesPublic/TestDbQueryCrud.cs index 8dc860e..774735b 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestDbQueryCrud.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestDbQueryCrud.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; diff --git a/Tests/UnitTests/GenericServicesPublic/TestDeleteWithQueryFilter.cs b/Tests/UnitTests/GenericServicesPublic/TestDeleteWithQueryFilter.cs index 0949a68..b552b03 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestDeleteWithQueryFilter.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestDeleteWithQueryFilter.cs @@ -1,9 +1,7 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; -using System.Threading.Tasks; -using GenericServices; using GenericServices.PublicButHidden; using GenericServices.Setup; using Microsoft.EntityFrameworkCore; @@ -50,7 +48,7 @@ public void TestDeleteWithQueryFilterOk() context.SoftDelEntities.IgnoreQueryFilters().Count().ShouldEqual(1); } } - + [Fact] public void TestDeleteWithActionWithQueryFilterOk() { @@ -128,6 +126,5 @@ public void TestDeleteWithActionWithQueryFilterError() context.SoftDelEntities.IgnoreQueryFilters().Count().ShouldEqual(1); } } - } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesPublic/TestDirectAccess.cs b/Tests/UnitTests/GenericServicesPublic/TestDirectAccess.cs index 8dd1efe..1cf8246 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestDirectAccess.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestDirectAccess.cs @@ -1,16 +1,14 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; using DataLayer.EfClasses; using DataLayer.EfCode; -using GenericServices; using GenericServices.PublicButHidden; using GenericServices.Setup; using Microsoft.EntityFrameworkCore; using StatusGeneric; -using Tests.Dtos; using Tests.Helpers; using TestSupport.EfHelpers; using Xunit; @@ -20,8 +18,6 @@ namespace Tests.UnitTests.GenericServicesPublic { public class TestDirectAccess { - - [Fact] public void TestGetSingleOnEntityOk() { diff --git a/Tests/UnitTests/GenericServicesPublic/TestGenericServicesConfig.cs b/Tests/UnitTests/GenericServicesPublic/TestGenericServicesConfig.cs index e14ae27..427182f 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestGenericServicesConfig.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestGenericServicesConfig.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Reflection; diff --git a/Tests/UnitTests/GenericServicesPublic/TestIncludeThenAttribute.cs b/Tests/UnitTests/GenericServicesPublic/TestIncludeThenAttribute.cs index 2fa9eb9..ea78fac 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestIncludeThenAttribute.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestIncludeThenAttribute.cs @@ -1,7 +1,6 @@ -// Copyright (c) 2020 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. -using System; using System.Linq; using DataLayer.EfClasses; using DataLayer.EfCode; @@ -122,17 +121,10 @@ public void TestIncludeThenTwoLevelManuallyLoad() //VERIFY var names = books.SelectMany(x => x.AuthorsLink.Select(y => y.Author.Name)).ToArray(); - names.ShouldEqual(new String[] { "Martin Fowler", "Martin Fowler", "Eric Evans", "Future Person" }); + names.ShouldEqual(new string[] { "Martin Fowler", "Martin Fowler", "Eric Evans", "Future Person" }); } } - [IncludeThen(nameof(Book.Reviews))] - [IncludeThen(nameof(Book.AuthorsLink), nameof(BookAuthor.Author))] - private class AnotherDto : ILinkToEntity - { - - } - [Fact] public void TestIncludeThenTwiceGetAttributesOk() { @@ -188,5 +180,9 @@ private IQueryable ApplyAnyIncludeStringsAtDbSetLevel(DbSet db return query; } + [IncludeThen(nameof(Book.Reviews))] + [IncludeThen(nameof(Book.AuthorsLink), nameof(BookAuthor.Author))] + private class AnotherDto : ILinkToEntity + {} } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesPublic/TestJsonPatch.cs b/Tests/UnitTests/GenericServicesPublic/TestJsonPatch.cs index 43a8010..3b0e536 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestJsonPatch.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestJsonPatch.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using DataLayer.EfClasses; @@ -7,7 +7,6 @@ using GenericServices.PublicButHidden; using GenericServices.Setup; using Microsoft.AspNetCore.JsonPatch; -using Microsoft.AspNetCore.JsonPatch.Exceptions; using Tests.Helpers; using TestSupport.EfHelpers; using Xunit; @@ -17,7 +16,6 @@ namespace Tests.UnitTests.GenericServicesPublic { public class TestJsonPatch { - [Fact] public void TestUpdateJsonPatchKeysOk() { @@ -132,6 +130,5 @@ public void TestUpdateJsonPatchNoUpdateBecauseSetterIsPrivateOk() service.GetAllErrors().ShouldStartWith("The property at path 'Title' could not be updated."); } } - } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesPublic/TestMultipleMatch.cs b/Tests/UnitTests/GenericServicesPublic/TestMultipleMatch.cs index e888565..daff32b 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestMultipleMatch.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestMultipleMatch.cs @@ -1,11 +1,8 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. -using System.Linq; -using GenericServices; using GenericServices.PublicButHidden; using GenericServices.Setup; -using Microsoft.EntityFrameworkCore; using Tests.Dtos; using Tests.EfClasses; using Tests.EfCode; diff --git a/Tests/UnitTests/GenericServicesPublic/TestNestedDtos.cs b/Tests/UnitTests/GenericServicesPublic/TestNestedDtos.cs index b68165d..b441317 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestNestedDtos.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestNestedDtos.cs @@ -1,16 +1,11 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using System; using System.Linq; -using DataLayer.EfClasses; using DataLayer.EfCode; -using GenericServices; using GenericServices.PublicButHidden; using GenericServices.Setup; using Tests.Dtos; -using Tests.EfClasses; -using Tests.EfCode; using Tests.Helpers; using TestSupport.EfHelpers; using Xunit; diff --git a/Tests/UnitTests/GenericServicesPublic/TestNestedInDtosIssue13.cs b/Tests/UnitTests/GenericServicesPublic/TestNestedInDtosIssue13.cs index 5179835..35f0dce 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestNestedInDtosIssue13.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestNestedInDtosIssue13.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; using GenericServices.PublicButHidden; @@ -14,7 +14,6 @@ namespace Tests.UnitTests.GenericServicesPublic { public class TestNestedInDtosIssue13 { - [Fact] public void TestInDtosNestedOk() { @@ -46,8 +45,5 @@ public void TestInDtosNestedOk() contact.Address.Address1.ShouldEqual("some street"); } } - - - } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesPublic/TestProjectFromEntityToDto.cs b/Tests/UnitTests/GenericServicesPublic/TestProjectFromEntityToDto.cs index f8afa42..e0fff67 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestProjectFromEntityToDto.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestProjectFromEntityToDto.cs @@ -1,11 +1,9 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using System; using System.Linq; using DataLayer.EfClasses; using DataLayer.EfCode; -using GenericServices; using GenericServices.PublicButHidden; using GenericServices.Setup; using Microsoft.EntityFrameworkCore; diff --git a/Tests/UnitTests/GenericServicesPublic/TestReadViaDto.cs b/Tests/UnitTests/GenericServicesPublic/TestReadViaDto.cs index 5b3466b..5b05bc7 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestReadViaDto.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestReadViaDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; @@ -231,7 +231,6 @@ public void TestProjectBookTitleManyWithConfigOk() } - //[Fact] //public void TestUpdateEntityOk() //{ diff --git a/Tests/UnitTests/GenericServicesPublic/TestSaveChangesWithValidation.cs b/Tests/UnitTests/GenericServicesPublic/TestSaveChangesWithValidation.cs index 43c9e09..1319ed7 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestSaveChangesWithValidation.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestSaveChangesWithValidation.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using DataLayer.EfClasses; @@ -16,23 +16,6 @@ namespace Tests.UnitTests.GenericServicesPublic { public class TestSaveChangesWithValidation { - public class LocalAuthorDto : ILinkToEntity - { - public string Name { get; set; } - public string Email { get; set; } - } - - public class LocalAuthorDtoWithConfig : ILinkToEntity - { - public string Name { get; set; } - public string Email { get; set; } - } - - public class CongfigWithValidation : PerDtoConfig - { - public override bool? UseSaveChangesWithValidation => true; - } - [Fact] public void TestCreateAuthorNameGoodNoValidationOk() { @@ -100,6 +83,21 @@ public void TestCreateAuthorNameNullPerDtoConfigValidationOk() } } + public class LocalAuthorDto : ILinkToEntity + { + public string Name { get; set; } + public string Email { get; set; } + } + + public class LocalAuthorDtoWithConfig : ILinkToEntity + { + public string Name { get; set; } + public string Email { get; set; } + } + public class CongfigWithValidation : PerDtoConfig + { + public override bool? UseSaveChangesWithValidation => true; + } } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesPublic/TestUpdateViaDto.cs b/Tests/UnitTests/GenericServicesPublic/TestUpdateViaDto.cs index 235361e..d6246a0 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestUpdateViaDto.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestUpdateViaDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.ComponentModel; @@ -20,14 +20,6 @@ namespace Tests.UnitTests.GenericServicesPublic { public class TestUpdateViaDto { - public class AuthorDto : ILinkToEntity - { - public int AuthorId { get; set; } - [ReadOnly(true)] - public string Name { get; set; } - public string Email { get; set; } - } - [Fact] public void TestUpdateViaAutoMapperOk() { @@ -179,17 +171,6 @@ public void TestUpdateAddPromotionWithMessageOk() } } - public class ConfigSettingMethod : PerDtoConfig - { - public override string UpdateMethod { get; } = nameof(Book.RemovePromotion); - } - - public class DtoWithConfig : ILinkToEntity - { - public int BookId { get; set; } - public string Title { get; set; } - } - [Fact] public void TestUpdateViaStatedMethodInPerDtoConfigOk() { @@ -236,5 +217,26 @@ public void TestUpdateViaStatedMethodBad() ex.Message.ShouldStartWith("Could not find a method of name AddReview. The method that fit the properties in the DTO/VM are:"); } } + + public class AuthorDto : ILinkToEntity + { + public int AuthorId { get; set; } + + [ReadOnly(true)] + public string Name { get; set; } + + public string Email { get; set; } + } + + public class ConfigSettingMethod : PerDtoConfig + { + public override string UpdateMethod { get; } = nameof(Book.RemovePromotion); + } + + public class DtoWithConfig : ILinkToEntity + { + public int BookId { get; set; } + public string Title { get; set; } + } } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesPublic/TestUpdateWithIncludeThenAttribute.cs b/Tests/UnitTests/GenericServicesPublic/TestUpdateWithIncludeThenAttribute.cs index 9c7772d..dfeb5e2 100644 --- a/Tests/UnitTests/GenericServicesPublic/TestUpdateWithIncludeThenAttribute.cs +++ b/Tests/UnitTests/GenericServicesPublic/TestUpdateWithIncludeThenAttribute.cs @@ -1,7 +1,6 @@ -// Copyright (c) 2020 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. -using System; using System.Linq; using System.Threading.Tasks; using DataLayer.EfCode; @@ -86,7 +85,7 @@ public void TestCallUpdateBookWithExistingAuthorWithTwoIncludes() .Where(x => x.BookId == bookId) .SelectMany(x => x.AuthorsLink.Select(y => y.Author.Name)) .ToArray(); - bookAuthorsName.ShouldEqual(new String[] {"Martin Fowler", "Future Person"}); + bookAuthorsName.ShouldEqual(new string[] {"Martin Fowler", "Future Person"}); } } @@ -161,7 +160,7 @@ public async Task TestCallUpdateBookWithExistingAuthorWithTwoIncludesAsync() .Where(x => x.BookId == bookId) .SelectMany(x => x.AuthorsLink.Select(y => y.Author.Name)) .ToArray(); - bookAuthorsName.ShouldEqual(new String[] {"Martin Fowler", "Future Person"}); + bookAuthorsName.ShouldEqual(new string[] {"Martin Fowler", "Future Person"}); } } } diff --git a/Tests/UnitTests/GenericServicesPublicAsync/TestCreateViaDtoAsync.cs b/Tests/UnitTests/GenericServicesPublicAsync/TestCreateViaDtoAsync.cs index 5ebefd8..47e1c06 100644 --- a/Tests/UnitTests/GenericServicesPublicAsync/TestCreateViaDtoAsync.cs +++ b/Tests/UnitTests/GenericServicesPublicAsync/TestCreateViaDtoAsync.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; @@ -12,7 +12,6 @@ using Tests.Dtos; using Tests.EfClasses; using Tests.EfCode; -using Tests.Helpers; using TestSupport.EfHelpers; using Xunit; using Xunit.Extensions.AssertExtensions; @@ -21,12 +20,6 @@ namespace Tests.UnitTests.GenericServicesPublicAsync { public class TestCreateViaDtoAsync { - public class AuthorDto : ILinkToEntity - { - public string Name { get; set; } - public string Email { get; set; } - } - [Fact] public async Task TestCreateAuthorViaAutoMapperOk() { @@ -166,21 +159,6 @@ public async Task TestCreateEntityNotCopyKeyBackBecauseDtoPropertyHasPrivateSett } } - //------------------------------------------------------ - //via ctors/statics - - public class DtoCtorCreate : ILinkToEntity - { - public int MyInt { get; set; } - public string MyString { get; set; } - } - - public class DtoStaticCreate : ILinkToEntity - { - public int MyInt { get; set; } - public string MyString { get; set; } - } - [Fact] public async Task TestCreateEntityUsingStaticCreateOk() { @@ -235,5 +213,26 @@ public async Task TestCreateEntityUsingStaticCreateWithBadStatusOk() context.DddStaticFactEntities.Count().ShouldEqual(0); } } + + public class AuthorDto : ILinkToEntity + { + public string Name { get; set; } + public string Email { get; set; } + } + + //------------------------------------------------------ + //via ctors/statics + + public class DtoCtorCreate : ILinkToEntity + { + public int MyInt { get; set; } + public string MyString { get; set; } + } + + public class DtoStaticCreate : ILinkToEntity + { + public int MyInt { get; set; } + public string MyString { get; set; } + } } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesPublicAsync/TestDbQueryCrudAsync.cs b/Tests/UnitTests/GenericServicesPublicAsync/TestDbQueryCrudAsync.cs index b7258c8..24f8492 100644 --- a/Tests/UnitTests/GenericServicesPublicAsync/TestDbQueryCrudAsync.cs +++ b/Tests/UnitTests/GenericServicesPublicAsync/TestDbQueryCrudAsync.cs @@ -1,9 +1,8 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using GenericServices.PublicButHidden; using GenericServices.Setup; diff --git a/Tests/UnitTests/GenericServicesPublicAsync/TestDeleteWithQueryFilter.cs b/Tests/UnitTests/GenericServicesPublicAsync/TestDeleteWithQueryFilter.cs index 9cf4344..656f309 100644 --- a/Tests/UnitTests/GenericServicesPublicAsync/TestDeleteWithQueryFilter.cs +++ b/Tests/UnitTests/GenericServicesPublicAsync/TestDeleteWithQueryFilter.cs @@ -1,9 +1,8 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; using System.Threading.Tasks; -using GenericServices; using GenericServices.PublicButHidden; using GenericServices.Setup; using Microsoft.EntityFrameworkCore; @@ -18,7 +17,6 @@ namespace Tests.UnitTests.GenericServicesPublicAsync { public class TestDeleteWithQueryFilter { - private Task DelHandlerAsync(DbContext context, SoftDelEntity entity) { var status = new StatusGenericHandler(); @@ -125,7 +123,5 @@ public async Task TestDeleteWithActionAsyncWithQueryFilterError() context.SoftDelEntities.IgnoreQueryFilters().Count().ShouldEqual(1); } } - - } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesPublicAsync/TestDirectAccessAsync.cs b/Tests/UnitTests/GenericServicesPublicAsync/TestDirectAccessAsync.cs index f9d3124..55e12b3 100644 --- a/Tests/UnitTests/GenericServicesPublicAsync/TestDirectAccessAsync.cs +++ b/Tests/UnitTests/GenericServicesPublicAsync/TestDirectAccessAsync.cs @@ -1,17 +1,15 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; using System.Threading.Tasks; using DataLayer.EfClasses; using DataLayer.EfCode; -using GenericServices; using GenericServices.PublicButHidden; using GenericServices.Setup; using Microsoft.EntityFrameworkCore; using StatusGeneric; -using Tests.Dtos; using Tests.Helpers; using TestSupport.EfHelpers; using Xunit; diff --git a/Tests/UnitTests/GenericServicesPublicAsync/TestJsonPatchAsync.cs b/Tests/UnitTests/GenericServicesPublicAsync/TestJsonPatchAsync.cs index ee5e2ec..97b81c5 100644 --- a/Tests/UnitTests/GenericServicesPublicAsync/TestJsonPatchAsync.cs +++ b/Tests/UnitTests/GenericServicesPublicAsync/TestJsonPatchAsync.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Threading.Tasks; @@ -8,7 +8,6 @@ using GenericServices.PublicButHidden; using GenericServices.Setup; using Microsoft.AspNetCore.JsonPatch; -using Microsoft.AspNetCore.JsonPatch.Exceptions; using Tests.Helpers; using TestSupport.EfHelpers; using Xunit; @@ -18,7 +17,6 @@ namespace Tests.UnitTests.GenericServicesPublicAsync { public class TestJsonPatchAsync { - [Fact] public async Task TestUpdateJsonPatchKeysOk() { @@ -132,6 +130,5 @@ public async Task TestUpdateJsonPatchNoUpdateBecauseSetterIsPrivateOk() service.GetAllErrors().ShouldStartWith("The property at path 'Title' could not be updated."); } } - } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesPublicAsync/TestProjectFromEntityToDto.cs b/Tests/UnitTests/GenericServicesPublicAsync/TestProjectFromEntityToDto.cs index 35fa07a..a4bb7fc 100644 --- a/Tests/UnitTests/GenericServicesPublicAsync/TestProjectFromEntityToDto.cs +++ b/Tests/UnitTests/GenericServicesPublicAsync/TestProjectFromEntityToDto.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; using System.Threading.Tasks; diff --git a/Tests/UnitTests/GenericServicesPublicAsync/TestReadViaDtoAsync.cs b/Tests/UnitTests/GenericServicesPublicAsync/TestReadViaDtoAsync.cs index 24ce5e4..80be78a 100644 --- a/Tests/UnitTests/GenericServicesPublicAsync/TestReadViaDtoAsync.cs +++ b/Tests/UnitTests/GenericServicesPublicAsync/TestReadViaDtoAsync.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; @@ -133,7 +133,6 @@ public async Task TestProjectSingleWhereBad() } } - //------------------------------------------------------- //Read Single - including collection @@ -212,7 +211,6 @@ public async Task TestProjectBookTitleManyWithConfigOk() } - //[Fact] //public async Task TestUpdateEntityOk() //{ diff --git a/Tests/UnitTests/GenericServicesPublicAsync/TestSaveChangesWithValidationAsync.cs b/Tests/UnitTests/GenericServicesPublicAsync/TestSaveChangesWithValidationAsync.cs index 7a7a1a7..544561b 100644 --- a/Tests/UnitTests/GenericServicesPublicAsync/TestSaveChangesWithValidationAsync.cs +++ b/Tests/UnitTests/GenericServicesPublicAsync/TestSaveChangesWithValidationAsync.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Threading.Tasks; @@ -17,23 +17,6 @@ namespace Tests.UnitTests.GenericServicesPublicAsync { public class TestSaveChangesWithValidationAsync { - public class LocalAuthorDto : ILinkToEntity - { - public string Name { get; set; } - public string Email { get; set; } - } - - public class LocalAuthorDtoWithConfig : ILinkToEntity - { - public string Name { get; set; } - public string Email { get; set; } - } - - public class CongfigWithValidation : PerDtoConfig - { - public override bool? UseSaveChangesWithValidation => true; - } - [Fact] public async Task TestCreateAuthorNameGoodNoValidationOk() { @@ -101,6 +84,21 @@ public async Task TestCreateAuthorNameNullPerDtoConfigValidationOk() } } + public class LocalAuthorDto : ILinkToEntity + { + public string Name { get; set; } + public string Email { get; set; } + } + + public class LocalAuthorDtoWithConfig : ILinkToEntity + { + public string Name { get; set; } + public string Email { get; set; } + } + public class CongfigWithValidation : PerDtoConfig + { + public override bool? UseSaveChangesWithValidation => true; + } } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesPublicAsync/TestUpdateViaDtoAsync.cs b/Tests/UnitTests/GenericServicesPublicAsync/TestUpdateViaDtoAsync.cs index 7d918f6..8377689 100644 --- a/Tests/UnitTests/GenericServicesPublicAsync/TestUpdateViaDtoAsync.cs +++ b/Tests/UnitTests/GenericServicesPublicAsync/TestUpdateViaDtoAsync.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.ComponentModel; @@ -20,14 +20,6 @@ namespace Tests.UnitTests.GenericServicesPublicAsync { public class TestUpdateViaDtoAsync { - public class AuthorDto : ILinkToEntity - { - public int AuthorId { get; set; } - [ReadOnly(true)] - public string Name { get; set; } - public string Email { get; set; } - } - [Fact] public async Task TestUpdateViaAutoMapperOk() { @@ -65,11 +57,11 @@ public async Task TestUpdateViaDefaultMethodOk() context.Database.EnsureCreated(); context.SeedDatabaseFourBooks(); - var utData = context.SetupSingleDtoAndEntities(); + var utData = context.SetupSingleDtoAndEntities(); var service = new CrudServicesAsync(context, utData.ConfigAndMapper); //ATTEMPT - var dto = new Tests.Dtos.ChangePubDateDto { BookId = 4, PublishedOn = new DateTime(2000,1,1) }; + var dto = new Dtos.ChangePubDateDto { BookId = 4, PublishedOn = new DateTime(2000,1,1) }; await service.UpdateAndSaveAsync(dto); //VERIFY @@ -90,11 +82,11 @@ public async Task TestUpdatePublicationDateViaAutoMapperOk() context.Database.EnsureCreated(); context.SeedDatabaseFourBooks(); - var utData = context.SetupSingleDtoAndEntities(); + var utData = context.SetupSingleDtoAndEntities(); var service = new CrudServicesAsync(context, utData.ConfigAndMapper); //ATTEMPT - var dto = new Tests.Dtos.ChangePubDateDto { BookId = 4, PublishedOn = new DateTime(2000, 1, 1) }; + var dto = new Dtos.ChangePubDateDto { BookId = 4, PublishedOn = new DateTime(2000, 1, 1) }; await service.UpdateAndSaveAsync(dto, CrudValues.UseAutoMapper); //VERIFY @@ -115,11 +107,11 @@ public async Task TestUpdateViaStatedMethodOk() context.Database.EnsureCreated(); context.SeedDatabaseFourBooks(); - var utData = context.SetupSingleDtoAndEntities(); + var utData = context.SetupSingleDtoAndEntities(); var service = new CrudServicesAsync(context, utData.ConfigAndMapper); //ATTEMPT - var dto = new Tests.Dtos.ChangePubDateDto { BookId = 4, PublishedOn = new DateTime(2000, 1, 1) }; + var dto = new Dtos.ChangePubDateDto { BookId = 4, PublishedOn = new DateTime(2000, 1, 1) }; await service.UpdateAndSaveAsync(dto, nameof(Book.RemovePromotion)); //VERIFY @@ -141,11 +133,11 @@ public async Task TestUpdateAddReviewOk() context.SeedDatabaseFourBooks(); //ATTEMPT - var utData = context.SetupSingleDtoAndEntities(); + var utData = context.SetupSingleDtoAndEntities(); var service = new CrudServicesAsync(context, utData.ConfigAndMapper); //ATTEMPT - var dto = new Tests.Dtos.AddReviewDto {BookId = 1, Comment = "comment", NumStars = 3, VoterName = "user" }; + var dto = new Dtos.AddReviewDto {BookId = 1, Comment = "comment", NumStars = 3, VoterName = "user" }; await service.UpdateAndSaveAsync(dto, nameof(Book.AddReview)); //VERIFY @@ -155,17 +147,6 @@ public async Task TestUpdateAddReviewOk() } } - public class ConfigSettingMethod : PerDtoConfig - { - public override string UpdateMethod { get; } = nameof(Book.RemovePromotion); - } - - public class DtoWithConfig : ILinkToEntity - { - public int BookId { get; set; } - public string Title { get; set; } - } - [Fact] public async Task TestUpdateViaStatedMethodInPerDtoConfigOk() { @@ -201,11 +182,11 @@ public async Task TestUpdateViaStatedMethodBad() context.Database.EnsureCreated(); context.SeedDatabaseFourBooks(); - var utData = context.SetupSingleDtoAndEntities(); + var utData = context.SetupSingleDtoAndEntities(); var service = new CrudServicesAsync(context, utData.ConfigAndMapper); //ATTEMPT - var dto = new Tests.Dtos.ChangePubDateDto { BookId = 4, PublishedOn = new DateTime(2000, 1, 1) }; + var dto = new Dtos.ChangePubDateDto { BookId = 4, PublishedOn = new DateTime(2000, 1, 1) }; var ex = await Assert.ThrowsAsync(() => service.UpdateAndSaveAsync(dto, nameof(Book.AddReview))); //VERIFY @@ -213,5 +194,25 @@ public async Task TestUpdateViaStatedMethodBad() } } + public class AuthorDto : ILinkToEntity + { + public int AuthorId { get; set; } + + [ReadOnly(true)] + public string Name { get; set; } + + public string Email { get; set; } + } + + public class ConfigSettingMethod : PerDtoConfig + { + public override string UpdateMethod { get; } = nameof(Book.RemovePromotion); + } + + public class DtoWithConfig : ILinkToEntity + { + public int BookId { get; set; } + public string Title { get; set; } + } } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesSetup/TestBeforeSaveChangesAsync.cs b/Tests/UnitTests/GenericServicesSetup/TestBeforeSaveChangesAsync.cs index 1994bf1..11c41de 100644 --- a/Tests/UnitTests/GenericServicesSetup/TestBeforeSaveChangesAsync.cs +++ b/Tests/UnitTests/GenericServicesSetup/TestBeforeSaveChangesAsync.cs @@ -1,9 +1,8 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; using System.Threading.Tasks; -using GenericServices; using GenericServices.Configuration; using GenericServices.PublicButHidden; using GenericServices.Setup; @@ -119,6 +118,5 @@ private IStatusGeneric FailOnBadWord(DbContext context) return status; } - } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesSetup/TestBeforeSaveChangesSync.cs b/Tests/UnitTests/GenericServicesSetup/TestBeforeSaveChangesSync.cs index e1c9244..60c9b62 100644 --- a/Tests/UnitTests/GenericServicesSetup/TestBeforeSaveChangesSync.cs +++ b/Tests/UnitTests/GenericServicesSetup/TestBeforeSaveChangesSync.cs @@ -1,8 +1,7 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; -using GenericServices; using GenericServices.Configuration; using GenericServices.PublicButHidden; using GenericServices.Setup; @@ -118,6 +117,5 @@ private IStatusGeneric FailOnBadWord(DbContext context) return status; } - } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesSetup/TestReadSingleNull.cs b/Tests/UnitTests/GenericServicesSetup/TestReadSingleNull.cs index ace75f7..1320113 100644 --- a/Tests/UnitTests/GenericServicesSetup/TestReadSingleNull.cs +++ b/Tests/UnitTests/GenericServicesSetup/TestReadSingleNull.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System.Threading.Tasks; using DataLayer.EfClasses; @@ -8,10 +8,10 @@ using GenericServices.PublicButHidden; using GenericServices.Setup; using Tests.Dtos; +using Tests.Helpers; using TestSupport.EfHelpers; using Xunit; using Xunit.Extensions.AssertExtensions; -using Tests.Helpers; namespace Tests.UnitTests.GenericServicesSetup { diff --git a/Tests/UnitTests/GenericServicesSetup/TestSetupDtosAndMappings.cs b/Tests/UnitTests/GenericServicesSetup/TestSetupDtosAndMappings.cs index 55d82b4..13528eb 100644 --- a/Tests/UnitTests/GenericServicesSetup/TestSetupDtosAndMappings.cs +++ b/Tests/UnitTests/GenericServicesSetup/TestSetupDtosAndMappings.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using DataLayer.EfCode; using GenericServices.Configuration; @@ -16,6 +16,7 @@ namespace Tests.UnitTests.GenericServicesSetup public class TestSetupDtosAndMappings { private IGenericServicesConfig config = new GenericServicesConfig(); + [Fact] public void TestSetupSingleDtoAndEntitiesOk() { @@ -98,7 +99,5 @@ public void TestSetupSingleDtoAndEntitiesTestAssemblyEfCoreContextAndTestDbConte setupDtos.IsValid.ShouldBeFalse(); setupDtos.Errors.Count.ShouldEqual(5); } - - } } \ No newline at end of file diff --git a/Tests/UnitTests/GenericServicesSetup/TestSqlErrorHandlerAsync.cs b/Tests/UnitTests/GenericServicesSetup/TestSqlErrorHandlerAsync.cs index ac6cdc0..ffc325c 100644 --- a/Tests/UnitTests/GenericServicesSetup/TestSqlErrorHandlerAsync.cs +++ b/Tests/UnitTests/GenericServicesSetup/TestSqlErrorHandlerAsync.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; @@ -8,7 +8,6 @@ using DataLayer.Dtos; using DataLayer.EfClasses; using DataLayer.EfCode; -using GenericServices; using GenericServices.Configuration; using GenericServices.PublicButHidden; using GenericServices.Setup; diff --git a/Tests/UnitTests/GenericServicesSetup/TestSqlErrorHandlerSync.cs b/Tests/UnitTests/GenericServicesSetup/TestSqlErrorHandlerSync.cs index f0ba978..bb2b4aa 100644 --- a/Tests/UnitTests/GenericServicesSetup/TestSqlErrorHandlerSync.cs +++ b/Tests/UnitTests/GenericServicesSetup/TestSqlErrorHandlerSync.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Collections.Generic; @@ -7,7 +7,6 @@ using DataLayer.Dtos; using DataLayer.EfClasses; using DataLayer.EfCode; -using GenericServices; using GenericServices.Configuration; using GenericServices.PublicButHidden; using GenericServices.Setup; @@ -17,10 +16,10 @@ using Tests.Dtos; using Tests.EfClasses; using Tests.EfCode; +using Tests.Helpers; using TestSupport.EfHelpers; using Xunit; using Xunit.Extensions.AssertExtensions; -using Tests.Helpers; namespace Tests.UnitTests.GenericServicesSetup { diff --git a/Tests/UnitTests/GenericServicesSetup/TestUnitTestSetup.cs b/Tests/UnitTests/GenericServicesSetup/TestUnitTestSetup.cs index 409a161..7cdfe70 100644 --- a/Tests/UnitTests/GenericServicesSetup/TestUnitTestSetup.cs +++ b/Tests/UnitTests/GenericServicesSetup/TestUnitTestSetup.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using DataLayer.EfClasses; @@ -16,16 +16,6 @@ namespace Tests.UnitTests.GenericServicesSetup { public class TestUnitTestSetup { - public class DtoWithTwoIlinks : ILinkToEntity, ILinkToEntity {} - - public class DtoWithTwoConfigs : ILinkToEntity { } - public class Congfig1 : PerDtoConfig { } - public class Congfig2 : PerDtoConfig { } - - public class DtoWithoutILink { } - - private class PrivateDto : ILinkToEntity { } - [Fact] public void TestSetupSingleDtoAndEntitiesOk() { @@ -116,5 +106,17 @@ public void TestSetupPrivateDto() ex.Message.ShouldEndWith("PrivateDto: Sorry, but the DTO/ViewModel class 'PrivateDto' must be public for GenericServices to work."); } } + + public class DtoWithTwoIlinks : ILinkToEntity, ILinkToEntity {} + + public class DtoWithTwoConfigs : ILinkToEntity {} + + public class Congfig1 : PerDtoConfig {} + + public class Congfig2 : PerDtoConfig {} + + public class DtoWithoutILink {} + + private class PrivateDto : ILinkToEntity {} } } \ No newline at end of file diff --git a/Tests/UnitTests/Libraries/TestAutoMapper.cs b/Tests/UnitTests/Libraries/TestAutoMapper.cs index d76bb7c..3534c72 100644 --- a/Tests/UnitTests/Libraries/TestAutoMapper.cs +++ b/Tests/UnitTests/Libraries/TestAutoMapper.cs @@ -1,15 +1,12 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. -using System.Collections.Generic; using System.ComponentModel; -using System.ComponentModel.DataAnnotations; using System.Linq; using System.Reflection; using AutoMapper; using AutoMapper.QueryableExtensions; using DataLayer.EfClasses; -using Microsoft.AspNetCore.Mvc; using Tests.Configs; using Tests.Dtos; using Tests.Helpers; diff --git a/Tests/UnitTests/Performance/CompareAgainstHandCoded.cs b/Tests/UnitTests/Performance/CompareAgainstHandCoded.cs index 8940132..92bd9c1 100644 --- a/Tests/UnitTests/Performance/CompareAgainstHandCoded.cs +++ b/Tests/UnitTests/Performance/CompareAgainstHandCoded.cs @@ -1,23 +1,18 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using System.Linq; using DataLayer.EfClasses; using DataLayer.EfCode; -using GenericServices; using GenericServices.PublicButHidden; using GenericServices.Setup; -using GenericServices.Internal.Decoders; -using Microsoft.EntityFrameworkCore; using Tests.Dtos; using Tests.EfClasses; using Tests.EfCode; using Tests.Helpers; using TestSupport.EfHelpers; -using TestSupport.Helpers; using Xunit; using Xunit.Abstractions; -using Xunit.Extensions.AssertExtensions; using AddReviewDto = ServiceLayer.HomeController.Dtos.AddReviewDto; namespace Tests.UnitTests.Performance @@ -31,16 +26,6 @@ public CompareAgainstHandCoded(ITestOutputHelper output) _output = output; } - private class Test where T : class - { - public Test(T value) - { - Value = value; - } - - public T Value { get; set; } - } - [Fact] public void TestPerformanceGenericTypeCreate() { @@ -289,5 +274,15 @@ private void RunHandCodedAddReview(EfCoreContext context) book.AddReview(5, "comment", "user", context); context.SaveChanges(); } + + private class Test where T : class + { + public Test(T value) + { + Value = value; + } + + public T Value { get; set; } + } } } \ No newline at end of file diff --git a/Tests/UnitTests/Performance/TestNewCreateMapper.cs b/Tests/UnitTests/Performance/TestNewCreateMapper.cs index 271ed92..0282ff7 100644 --- a/Tests/UnitTests/Performance/TestNewCreateMapper.cs +++ b/Tests/UnitTests/Performance/TestNewCreateMapper.cs @@ -1,5 +1,5 @@ -// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ -// Licensed under MIT licence. See License.txt in the project root for license information. +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Licensed under MIT license. See License.txt in the project root for license information. using System; using System.Linq; diff --git a/Tests/UnitTests/TestIssues/TestIssue30.cs b/Tests/UnitTests/TestIssues/TestIssue30.cs index 8b423e2..664c88c 100644 --- a/Tests/UnitTests/TestIssues/TestIssue30.cs +++ b/Tests/UnitTests/TestIssues/TestIssue30.cs @@ -1,8 +1,7 @@ -// Copyright (c) 2019 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using System; -using System.ComponentModel; using GenericServices; using GenericServices.Setup; using Microsoft.EntityFrameworkCore; @@ -14,7 +13,6 @@ namespace Tests.UnitTests.TestIssues { public class TestIssue30 { - [Fact] public void Dto_with_no_properties_causes_null_exception() { @@ -34,6 +32,7 @@ public class SomeContext : DbContext { public SomeContext(DbContextOptions options) : base(options) { } public DbSet Entities { get; set; } + protected override void OnModelCreating(ModelBuilder builder) { builder.Entity().Property(e => e.Id).ValueGeneratedNever(); @@ -48,13 +47,12 @@ public ImutableEntity(int id, string name) Id = id; Name = name; } + public int Id { get; private set; } public string Name { get; private set; } } public class ImutableDto : ILinkToEntity - { - - } + {} } } \ No newline at end of file diff --git a/Tests/UnitTests/TestIssues/TestIssue31.cs b/Tests/UnitTests/TestIssues/TestIssue31.cs index fb1d24e..2e97ac6 100644 --- a/Tests/UnitTests/TestIssues/TestIssue31.cs +++ b/Tests/UnitTests/TestIssues/TestIssue31.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using System; @@ -15,7 +15,6 @@ namespace Tests.UnitTests.TestIssues { public class TestIssue31 { - [Fact] public async Task Root_method_call_fails() { @@ -41,12 +40,14 @@ public class SetItemDto : ILinkToEntity { [ReadOnly(true)] public int Id { get; set; } + public string Item { get; set; } } public class Root { public int Id { get; set; } + public void SetItem(string item, RootContext context = null) { if (item is null) @@ -58,6 +59,7 @@ public void SetItem(string item, RootContext context = null) public class RootContext : DbContext { public RootContext(DbContextOptions options) : base(options) { } + protected override void OnModelCreating(ModelBuilder builder) { builder.Entity().Property(e => e.Id).ValueGeneratedNever(); diff --git a/Tests/UnitTests/TestIssues/TestIssue41.cs b/Tests/UnitTests/TestIssues/TestIssue41.cs index 500cf8e..0b5bf69 100644 --- a/Tests/UnitTests/TestIssues/TestIssue41.cs +++ b/Tests/UnitTests/TestIssues/TestIssue41.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using GenericServices.PublicButHidden; diff --git a/Tests/UnitTests/TestIssues/TestIssue43.cs b/Tests/UnitTests/TestIssues/TestIssue43.cs index 02fe6a9..e337aab 100644 --- a/Tests/UnitTests/TestIssues/TestIssue43.cs +++ b/Tests/UnitTests/TestIssues/TestIssue43.cs @@ -1,8 +1,7 @@ -// Copyright (c) 2020 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using System; -using GenericServices.PublicButHidden; using GenericServices.Setup; using Tests.Dtos; using Tests.EfCode; diff --git a/Tests/UnitTests/TestIssues/TestIssue47.cs b/Tests/UnitTests/TestIssues/TestIssue47.cs index a93af0f..7c8615c 100644 --- a/Tests/UnitTests/TestIssues/TestIssue47.cs +++ b/Tests/UnitTests/TestIssues/TestIssue47.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ +// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ // Licensed under MIT license. See License.txt in the project root for license information. using System; @@ -49,7 +49,7 @@ public class Issue47Dto : ILinkToEntity public class Issue47DtoConfig : PerDtoConfig { - public override Action> AlterReadMapping + public override Action> AlterReadMapping { get { @@ -57,6 +57,6 @@ public override Action> AlterRead opt => opt.MapFrom(s => s.OneToOne.MyString)); } } + } } -} } \ No newline at end of file