From a89b8483b409ef87b416441c222e26725e911838 Mon Sep 17 00:00:00 2001 From: vk Date: Sun, 22 Sep 2019 18:31:23 -0400 Subject: [PATCH] 5.0.1 * fixes #196 - InvalidCastException in SaveAsync; * closes #197 - Add class constraint on entity. --- Directory.Build.props | 54 +++++++++++++++++++ .../Suteki.TardisBank.Domain.csproj | 11 ++-- .../Suteki.TardisBank.Infrastructure.csproj | 12 ++--- .../Suteki.TardisBank.Tasks.csproj | 12 ++--- .../Suteki.TardisBank.Tests.csproj | 17 +++--- .../NHibernate.config | 2 +- Samples/TardisBank/Src/TardisBank.sln | 34 ++++++------ SharpArch.AutoLoad.DotSettings | 2 + Src/Common/NHibernate/TestDatabaseSetup.cs | 3 +- .../PersistenceSupport/ILinqRepository.cs | 1 + .../ILinqRepositoryWithTypedId.cs | 1 + .../PersistenceSupport/IRepository.cs | 1 + .../IRepositoryWithTypedId.cs | 1 + .../RepositoryExtensions.cs | 6 ++- .../Repositories/INHibernateRepository.cs | 1 + .../INHibernateRepositoryWithTypedId.cs | 1 + Src/SharpArch.NHibernate/LinqRepository.cs | 1 + .../LinqRepositoryWithTypedId.cs | 1 + .../NHibernateRepository.cs | 1 + .../NHibernateRepositoryWithTypedId.cs | 6 +-- .../Repositories/IRavenDbRepository.cs | 3 +- .../IRavenDbRepositoryWithTypedId.cs | 1 + Src/SharpArch.RavenDb/RavenDbRepository.cs | 3 +- .../RavenDbRepositoryWithTypedId.cs | 1 + .../HasUniqieDomainSignatureTestsBase.cs | 22 +------- .../TestsPersistenceModelGenerator.cs | 43 +++++++++++++++ .../NHibernateRepositoryTests.cs | 54 +++++++++++++++++++ .../NHibernateTestsSetup.cs | 21 ++++++++ build.cake | 46 ++++++++++++---- 29 files changed, 276 insertions(+), 86 deletions(-) create mode 100644 Directory.Build.props create mode 100644 Src/Tests/SharpArch.XunitTests.NHibernate/Mappings/TestsPersistenceModelGenerator.cs create mode 100644 Src/Tests/SharpArch.XunitTests.NHibernate/NHibernateRepositoryTests.cs create mode 100644 Src/Tests/SharpArch.XunitTests.NHibernate/NHibernateTestsSetup.cs diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 000000000..b16b34e58 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,54 @@ + + + Sharp Architecture + Sharp Architecture Dev Team + + netstandard2.0 + false + false + true + true + portable + + false + + + + full + + + + True + + + + BSD-3-Clause + True + https://github.com/sharparchitecture/Sharp-Architecture/raw/master/Artefacts/Documentation/Logo_100x100.png + http://sharparchitecture.github.io/ + false + https://github.com/sharparchitecture/Sharp-Architecture/releases/tag/5.0.0 + true + True + snupkg + sharp-architecture;sharp-arch + + + + true + true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + + + + true + false + $(NoWarn);0618;1591 + + + + false + $(NoWarn);1591 + + + diff --git a/Samples/TardisBank/Src/Suteki.TardisBank.Domain/Suteki.TardisBank.Domain.csproj b/Samples/TardisBank/Src/Suteki.TardisBank.Domain/Suteki.TardisBank.Domain.csproj index 7bf97acb9..a18869096 100644 --- a/Samples/TardisBank/Src/Suteki.TardisBank.Domain/Suteki.TardisBank.Domain.csproj +++ b/Samples/TardisBank/Src/Suteki.TardisBank.Domain/Suteki.TardisBank.Domain.csproj @@ -1,12 +1,9 @@ - - - - netstandard2.0 - + - - + + + diff --git a/Samples/TardisBank/Src/Suteki.TardisBank.Infrastructure/Suteki.TardisBank.Infrastructure.csproj b/Samples/TardisBank/Src/Suteki.TardisBank.Infrastructure/Suteki.TardisBank.Infrastructure.csproj index 45706023b..11477e252 100644 --- a/Samples/TardisBank/Src/Suteki.TardisBank.Infrastructure/Suteki.TardisBank.Infrastructure.csproj +++ b/Samples/TardisBank/Src/Suteki.TardisBank.Infrastructure/Suteki.TardisBank.Infrastructure.csproj @@ -1,15 +1,11 @@ - - - - netstandard2.0 - + - + - - + + diff --git a/Samples/TardisBank/Src/Suteki.TardisBank.Tasks/Suteki.TardisBank.Tasks.csproj b/Samples/TardisBank/Src/Suteki.TardisBank.Tasks/Suteki.TardisBank.Tasks.csproj index 1243f0cf8..51cc2fed6 100644 --- a/Samples/TardisBank/Src/Suteki.TardisBank.Tasks/Suteki.TardisBank.Tasks.csproj +++ b/Samples/TardisBank/Src/Suteki.TardisBank.Tasks/Suteki.TardisBank.Tasks.csproj @@ -1,14 +1,10 @@ - - - - netstandard2.0 - + - - - + + + diff --git a/Samples/TardisBank/Src/Suteki.TardisBank.Tests/Suteki.TardisBank.Tests.csproj b/Samples/TardisBank/Src/Suteki.TardisBank.Tests/Suteki.TardisBank.Tests.csproj index 496a0bff4..5a87cd3a7 100644 --- a/Samples/TardisBank/Src/Suteki.TardisBank.Tests/Suteki.TardisBank.Tests.csproj +++ b/Samples/TardisBank/Src/Suteki.TardisBank.Tests/Suteki.TardisBank.Tests.csproj @@ -1,19 +1,20 @@ - + - netcoreapp2.2 + netcoreapp2.2 - - - - - + + + + + + - + all diff --git a/Samples/TardisBank/Src/Suteki.TardisBank.Web.Mvc/NHibernate.config b/Samples/TardisBank/Src/Suteki.TardisBank.Web.Mvc/NHibernate.config index 0d3dd6506..0c4d4f0f3 100644 --- a/Samples/TardisBank/Src/Suteki.TardisBank.Web.Mvc/NHibernate.config +++ b/Samples/TardisBank/Src/Suteki.TardisBank.Web.Mvc/NHibernate.config @@ -1,7 +1,7 @@  - Data Source=localhost,2433;Initial Catalog=TardisBank;Integrated Security=False;User ID=sa;Password=Password;Application Name=Suteki.TardisBank; + Data Source=localhost,2433;Initial Catalog=TardisBank;Integrated Security=False;User ID=sa;Password=Password12!;Application Name=Suteki.TardisBank; NHibernate.Dialect.MsSql2012Dialect NHibernate.Connection.DriverConnectionProvider NHibernate.Driver.Sql2008ClientDriver diff --git a/Samples/TardisBank/Src/TardisBank.sln b/Samples/TardisBank/Src/TardisBank.sln index 93c93dc45..1408d47e3 100644 --- a/Samples/TardisBank/Src/TardisBank.sln +++ b/Samples/TardisBank/Src/TardisBank.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26124.0 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29306.81 MinimumVisualStudioVersion = 15.0.26124.0 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Suteki.TardisBank.Domain", "Suteki.TardisBank.Domain\Suteki.TardisBank.Domain.csproj", "{E417A9B0-AC34-44BB-8CFB-B4E5D3CE17D2}" EndProject @@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Suteki.TardisBank.Infrastru EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Suteki.TardisBank.Tasks", "Suteki.TardisBank.Tasks\Suteki.TardisBank.Tasks.csproj", "{80AA7007-BD1D-4860-8D73-BA46C906012A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Suteki.TardisBank.Tests", "Suteki.TardisBank.Tests\Suteki.TardisBank.Tests.csproj", "{25546298-ABBE-41EA-9B62-ABE7C4587D19}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SharpArch", "SharpArch", "{B514E7EC-7D43-4DD8-97A9-FD520ECB3B7D}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TardisBank", "TardisBank", "{6D3106CE-B30A-4DC6-88A4-EE7E09370F48}" @@ -40,6 +38,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpArch.Testing.Xunit", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpArch.Infrastructure", "..\..\..\Src\SharpArch.Infrastructure\SharpArch.Infrastructure.csproj", "{45A30CE8-6DBD-4AFB-82C2-E5BD96BB9D4A}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Suteki.TardisBank.Tests", "Suteki.TardisBank.Tests\Suteki.TardisBank.Tests.csproj", "{25EA8BD3-9E0C-48C2-B784-1229A7D8EF16}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -86,18 +86,6 @@ Global {80AA7007-BD1D-4860-8D73-BA46C906012A}.Release|x64.Build.0 = Release|Any CPU {80AA7007-BD1D-4860-8D73-BA46C906012A}.Release|x86.ActiveCfg = Release|Any CPU {80AA7007-BD1D-4860-8D73-BA46C906012A}.Release|x86.Build.0 = Release|Any CPU - {25546298-ABBE-41EA-9B62-ABE7C4587D19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {25546298-ABBE-41EA-9B62-ABE7C4587D19}.Debug|Any CPU.Build.0 = Debug|Any CPU - {25546298-ABBE-41EA-9B62-ABE7C4587D19}.Debug|x64.ActiveCfg = Debug|Any CPU - {25546298-ABBE-41EA-9B62-ABE7C4587D19}.Debug|x64.Build.0 = Debug|Any CPU - {25546298-ABBE-41EA-9B62-ABE7C4587D19}.Debug|x86.ActiveCfg = Debug|Any CPU - {25546298-ABBE-41EA-9B62-ABE7C4587D19}.Debug|x86.Build.0 = Debug|Any CPU - {25546298-ABBE-41EA-9B62-ABE7C4587D19}.Release|Any CPU.ActiveCfg = Release|Any CPU - {25546298-ABBE-41EA-9B62-ABE7C4587D19}.Release|Any CPU.Build.0 = Release|Any CPU - {25546298-ABBE-41EA-9B62-ABE7C4587D19}.Release|x64.ActiveCfg = Release|Any CPU - {25546298-ABBE-41EA-9B62-ABE7C4587D19}.Release|x64.Build.0 = Release|Any CPU - {25546298-ABBE-41EA-9B62-ABE7C4587D19}.Release|x86.ActiveCfg = Release|Any CPU - {25546298-ABBE-41EA-9B62-ABE7C4587D19}.Release|x86.Build.0 = Release|Any CPU {AE52B0E4-022D-45E0-AB04-010FACA6C897}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {AE52B0E4-022D-45E0-AB04-010FACA6C897}.Debug|Any CPU.Build.0 = Debug|Any CPU {AE52B0E4-022D-45E0-AB04-010FACA6C897}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -206,6 +194,18 @@ Global {45A30CE8-6DBD-4AFB-82C2-E5BD96BB9D4A}.Release|x64.Build.0 = Release|Any CPU {45A30CE8-6DBD-4AFB-82C2-E5BD96BB9D4A}.Release|x86.ActiveCfg = Release|Any CPU {45A30CE8-6DBD-4AFB-82C2-E5BD96BB9D4A}.Release|x86.Build.0 = Release|Any CPU + {25EA8BD3-9E0C-48C2-B784-1229A7D8EF16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {25EA8BD3-9E0C-48C2-B784-1229A7D8EF16}.Debug|Any CPU.Build.0 = Debug|Any CPU + {25EA8BD3-9E0C-48C2-B784-1229A7D8EF16}.Debug|x64.ActiveCfg = Debug|Any CPU + {25EA8BD3-9E0C-48C2-B784-1229A7D8EF16}.Debug|x64.Build.0 = Debug|Any CPU + {25EA8BD3-9E0C-48C2-B784-1229A7D8EF16}.Debug|x86.ActiveCfg = Debug|Any CPU + {25EA8BD3-9E0C-48C2-B784-1229A7D8EF16}.Debug|x86.Build.0 = Debug|Any CPU + {25EA8BD3-9E0C-48C2-B784-1229A7D8EF16}.Release|Any CPU.ActiveCfg = Release|Any CPU + {25EA8BD3-9E0C-48C2-B784-1229A7D8EF16}.Release|Any CPU.Build.0 = Release|Any CPU + {25EA8BD3-9E0C-48C2-B784-1229A7D8EF16}.Release|x64.ActiveCfg = Release|Any CPU + {25EA8BD3-9E0C-48C2-B784-1229A7D8EF16}.Release|x64.Build.0 = Release|Any CPU + {25EA8BD3-9E0C-48C2-B784-1229A7D8EF16}.Release|x86.ActiveCfg = Release|Any CPU + {25EA8BD3-9E0C-48C2-B784-1229A7D8EF16}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -214,7 +214,6 @@ Global {E417A9B0-AC34-44BB-8CFB-B4E5D3CE17D2} = {FCDFE7DD-5575-47CA-B4C0-5D02EBA4A4A1} {D0ACCE2E-D477-4AAF-86DD-6C2C4900B9EE} = {FCDFE7DD-5575-47CA-B4C0-5D02EBA4A4A1} {80AA7007-BD1D-4860-8D73-BA46C906012A} = {FCDFE7DD-5575-47CA-B4C0-5D02EBA4A4A1} - {25546298-ABBE-41EA-9B62-ABE7C4587D19} = {1CB314F4-5E98-4A3A-8017-FB5F8CD8A76F} {FCDFE7DD-5575-47CA-B4C0-5D02EBA4A4A1} = {6D3106CE-B30A-4DC6-88A4-EE7E09370F48} {1CB314F4-5E98-4A3A-8017-FB5F8CD8A76F} = {6D3106CE-B30A-4DC6-88A4-EE7E09370F48} {AE52B0E4-022D-45E0-AB04-010FACA6C897} = {B514E7EC-7D43-4DD8-97A9-FD520ECB3B7D} @@ -226,6 +225,7 @@ Global {F47EC00C-58C9-4E8A-BB80-CDB2C492DBF6} = {B514E7EC-7D43-4DD8-97A9-FD520ECB3B7D} {CDF31748-EA55-4C67-B571-160F432E592C} = {B514E7EC-7D43-4DD8-97A9-FD520ECB3B7D} {45A30CE8-6DBD-4AFB-82C2-E5BD96BB9D4A} = {B514E7EC-7D43-4DD8-97A9-FD520ECB3B7D} + {25EA8BD3-9E0C-48C2-B784-1229A7D8EF16} = {1CB314F4-5E98-4A3A-8017-FB5F8CD8A76F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB1F64E9-9827-4B3E-AC78-5D56782B8A7D} diff --git a/SharpArch.AutoLoad.DotSettings b/SharpArch.AutoLoad.DotSettings index ce44a12ea..d0589f952 100644 --- a/SharpArch.AutoLoad.DotSettings +++ b/SharpArch.AutoLoad.DotSettings @@ -58,6 +58,8 @@ FluentAssertions.AssertionExtensions.Should($EXPR$).NotBeNull() RequiredForMultiline RequiredForMultiline RequiredForMultiline + Implicit + Implicit diff --git a/Src/Common/NHibernate/TestDatabaseSetup.cs b/Src/Common/NHibernate/TestDatabaseSetup.cs index a1d0d3e53..b864a19d3 100644 --- a/Src/Common/NHibernate/TestDatabaseSetup.cs +++ b/Src/Common/NHibernate/TestDatabaseSetup.cs @@ -38,7 +38,8 @@ public class TestDatabaseSetup : IDisposable public TestDatabaseSetup([NotNull] string basePath, [NotNull] Assembly[] mappingAssemblies) { _basePath = basePath ?? throw new ArgumentNullException(nameof(basePath)); - _mappingAssemblies = mappingAssemblies ?? throw new ArgumentNullException(nameof(mappingAssemblies)); + if (mappingAssemblies == null) throw new ArgumentNullException(nameof(mappingAssemblies)); + _mappingAssemblies = mappingAssemblies.Distinct().ToArray(); } diff --git a/Src/SharpArch.Domain/PersistenceSupport/ILinqRepository.cs b/Src/SharpArch.Domain/PersistenceSupport/ILinqRepository.cs index 395077fc4..fb2c6cac6 100644 --- a/Src/SharpArch.Domain/PersistenceSupport/ILinqRepository.cs +++ b/Src/SharpArch.Domain/PersistenceSupport/ILinqRepository.cs @@ -8,5 +8,6 @@ /// The entity type. [PublicAPI] public interface ILinqRepository : ILinqRepositoryWithTypedId + where T : class { } } diff --git a/Src/SharpArch.Domain/PersistenceSupport/ILinqRepositoryWithTypedId.cs b/Src/SharpArch.Domain/PersistenceSupport/ILinqRepositoryWithTypedId.cs index ad5cdcce1..863a21c40 100644 --- a/Src/SharpArch.Domain/PersistenceSupport/ILinqRepositoryWithTypedId.cs +++ b/Src/SharpArch.Domain/PersistenceSupport/ILinqRepositoryWithTypedId.cs @@ -13,6 +13,7 @@ namespace SharpArch.Domain.PersistenceSupport /// [PublicAPI] public interface ILinqRepositoryWithTypedId : IRepositoryWithTypedId + where T: class { /// /// Finds an item by ID. diff --git a/Src/SharpArch.Domain/PersistenceSupport/IRepository.cs b/Src/SharpArch.Domain/PersistenceSupport/IRepository.cs index 24f7f65dc..ada78e542 100644 --- a/Src/SharpArch.Domain/PersistenceSupport/IRepository.cs +++ b/Src/SharpArch.Domain/PersistenceSupport/IRepository.cs @@ -12,5 +12,6 @@ /// [PublicAPI] public interface IRepository : IRepositoryWithTypedId + where T: class { } } diff --git a/Src/SharpArch.Domain/PersistenceSupport/IRepositoryWithTypedId.cs b/Src/SharpArch.Domain/PersistenceSupport/IRepositoryWithTypedId.cs index c7be809a3..7098ce1f0 100644 --- a/Src/SharpArch.Domain/PersistenceSupport/IRepositoryWithTypedId.cs +++ b/Src/SharpArch.Domain/PersistenceSupport/IRepositoryWithTypedId.cs @@ -11,6 +11,7 @@ namespace SharpArch.Domain.PersistenceSupport /// The type of the entity ID. [PublicAPI] public interface IRepositoryWithTypedId + where T: class { /// /// Returns the database context, which provides a handle to application wide DB diff --git a/Src/SharpArch.Domain/PersistenceSupport/RepositoryExtensions.cs b/Src/SharpArch.Domain/PersistenceSupport/RepositoryExtensions.cs index 3663231ae..d0be1cf5e 100644 --- a/Src/SharpArch.Domain/PersistenceSupport/RepositoryExtensions.cs +++ b/Src/SharpArch.Domain/PersistenceSupport/RepositoryExtensions.cs @@ -12,10 +12,12 @@ public static class RepositoryExtensions /// /// Saves the specified object to the repository and evicts it from the session. /// - /// is . - public static void SaveAndEvict(this IRepositoryWithTypedId repository, T entity) + /// or is . + public static void SaveAndEvict([NotNull] this IRepositoryWithTypedId repository, [NotNull] T entity) + where T: class { if (repository == null) throw new ArgumentNullException(nameof(repository)); + if (entity == null) throw new ArgumentNullException(nameof(entity)); repository.Evict(repository.Save(entity)); } } diff --git a/Src/SharpArch.NHibernate/Contracts/Repositories/INHibernateRepository.cs b/Src/SharpArch.NHibernate/Contracts/Repositories/INHibernateRepository.cs index af5baace6..ae730495d 100644 --- a/Src/SharpArch.NHibernate/Contracts/Repositories/INHibernateRepository.cs +++ b/Src/SharpArch.NHibernate/Contracts/Repositories/INHibernateRepository.cs @@ -12,5 +12,6 @@ namespace SharpArch.NHibernate.Contracts.Repositories /// [PublicAPI] public interface INHibernateRepository : INHibernateRepositoryWithTypedId, IRepository + where T : class { } } diff --git a/Src/SharpArch.NHibernate/Contracts/Repositories/INHibernateRepositoryWithTypedId.cs b/Src/SharpArch.NHibernate/Contracts/Repositories/INHibernateRepositoryWithTypedId.cs index e28f19a16..f1175a346 100644 --- a/Src/SharpArch.NHibernate/Contracts/Repositories/INHibernateRepositoryWithTypedId.cs +++ b/Src/SharpArch.NHibernate/Contracts/Repositories/INHibernateRepositoryWithTypedId.cs @@ -15,6 +15,7 @@ namespace SharpArch.NHibernate.Contracts.Repositories /// [PublicAPI] public interface INHibernateRepositoryWithTypedId : IRepositoryWithTypedId + where T: class { /// /// Looks for zero or more instances using the properties provided. diff --git a/Src/SharpArch.NHibernate/LinqRepository.cs b/Src/SharpArch.NHibernate/LinqRepository.cs index ed08787bd..562e1ab40 100644 --- a/Src/SharpArch.NHibernate/LinqRepository.cs +++ b/Src/SharpArch.NHibernate/LinqRepository.cs @@ -12,6 +12,7 @@ /// [PublicAPI] public class LinqRepository : LinqRepositoryWithTypedId, ILinqRepository + where T : class { /// /// Initializes a new instance of the class. diff --git a/Src/SharpArch.NHibernate/LinqRepositoryWithTypedId.cs b/Src/SharpArch.NHibernate/LinqRepositoryWithTypedId.cs index 49aaf7006..0d7000e71 100644 --- a/Src/SharpArch.NHibernate/LinqRepositoryWithTypedId.cs +++ b/Src/SharpArch.NHibernate/LinqRepositoryWithTypedId.cs @@ -15,6 +15,7 @@ namespace SharpArch.NHibernate /// [PublicAPI] public class LinqRepositoryWithTypedId : NHibernateRepositoryWithTypedId, ILinqRepositoryWithTypedId + where T : class { /// /// Initializes a new instance of the class. diff --git a/Src/SharpArch.NHibernate/NHibernateRepository.cs b/Src/SharpArch.NHibernate/NHibernateRepository.cs index 71e0493d0..d844475db 100644 --- a/Src/SharpArch.NHibernate/NHibernateRepository.cs +++ b/Src/SharpArch.NHibernate/NHibernateRepository.cs @@ -12,6 +12,7 @@ /// [PublicAPI] public class NHibernateRepository : NHibernateRepositoryWithTypedId, INHibernateRepository + where T : class { /// /// Initializes a new instance of the class. diff --git a/Src/SharpArch.NHibernate/NHibernateRepositoryWithTypedId.cs b/Src/SharpArch.NHibernate/NHibernateRepositoryWithTypedId.cs index 05d8b7b28..fa76b07d2 100644 --- a/Src/SharpArch.NHibernate/NHibernateRepositoryWithTypedId.cs +++ b/Src/SharpArch.NHibernate/NHibernateRepositoryWithTypedId.cs @@ -23,7 +23,7 @@ namespace SharpArch.NHibernate [PublicAPI] public class NHibernateRepositoryWithTypedId : INHibernateRepositoryWithTypedId, IAsyncNHibernateRepositoryWithTypedId - + where T: class { /// /// Gets NHibernate session. @@ -156,8 +156,8 @@ public Task LoadAsync( /// public async Task SaveAsync(T entity, CancellationToken cancellationToken = default(CancellationToken)) { - var res = await Session.SaveAsync(entity, cancellationToken).ConfigureAwait(false); - return (T) res; + await Session.SaveAsync(entity, cancellationToken).ConfigureAwait(false); + return entity; } /// diff --git a/Src/SharpArch.RavenDb/Contracts/Repositories/IRavenDbRepository.cs b/Src/SharpArch.RavenDb/Contracts/Repositories/IRavenDbRepository.cs index 07dbaeff9..56dde3f13 100644 --- a/Src/SharpArch.RavenDb/Contracts/Repositories/IRavenDbRepository.cs +++ b/Src/SharpArch.RavenDb/Contracts/Repositories/IRavenDbRepository.cs @@ -10,6 +10,7 @@ namespace SharpArch.RavenDb.Contracts.Repositories /// [PublicAPI] public interface IRavenDbRepository : IRavenDbRepositoryWithTypedId, IRepository + where T : class { } -} \ No newline at end of file +} diff --git a/Src/SharpArch.RavenDb/Contracts/Repositories/IRavenDbRepositoryWithTypedId.cs b/Src/SharpArch.RavenDb/Contracts/Repositories/IRavenDbRepositoryWithTypedId.cs index d53823946..e16b21b15 100644 --- a/Src/SharpArch.RavenDb/Contracts/Repositories/IRavenDbRepositoryWithTypedId.cs +++ b/Src/SharpArch.RavenDb/Contracts/Repositories/IRavenDbRepositoryWithTypedId.cs @@ -15,6 +15,7 @@ namespace SharpArch.RavenDb.Contracts.Repositories /// Todo: Consider replacing lambda with expression tree. [PublicAPI] public interface IRavenDbRepositoryWithTypedId : IRepositoryWithTypedId + where T: class { /// /// RavenDB Document Session. diff --git a/Src/SharpArch.RavenDb/RavenDbRepository.cs b/Src/SharpArch.RavenDb/RavenDbRepository.cs index 6c0365dc0..2a50df9e7 100644 --- a/Src/SharpArch.RavenDb/RavenDbRepository.cs +++ b/Src/SharpArch.RavenDb/RavenDbRepository.cs @@ -18,6 +18,7 @@ namespace SharpArch.RavenDb public class RavenDbRepository : RavenDbRepositoryWithTypedId, IRavenDbRepository, ILinqRepository + where T : class { /// /// Initializes a new instance of the class. @@ -27,4 +28,4 @@ public RavenDbRepository(IDocumentSession session) : base(session) { } } -} \ No newline at end of file +} diff --git a/Src/SharpArch.RavenDb/RavenDbRepositoryWithTypedId.cs b/Src/SharpArch.RavenDb/RavenDbRepositoryWithTypedId.cs index 44d59522e..b1832c1fb 100644 --- a/Src/SharpArch.RavenDb/RavenDbRepositoryWithTypedId.cs +++ b/Src/SharpArch.RavenDb/RavenDbRepositoryWithTypedId.cs @@ -21,6 +21,7 @@ namespace SharpArch.RavenDb [PublicAPI] public class RavenDbRepositoryWithTypedId : IRavenDbRepositoryWithTypedId, ILinqRepositoryWithTypedId + where T: class { /// /// Initializes a new instance of the class. diff --git a/Src/Tests/SharpArch.XunitTests.NHibernate/HasUniqieDomainSignatureTestsBase.cs b/Src/Tests/SharpArch.XunitTests.NHibernate/HasUniqieDomainSignatureTestsBase.cs index d08b652d0..f602521a8 100644 --- a/Src/Tests/SharpArch.XunitTests.NHibernate/HasUniqieDomainSignatureTestsBase.cs +++ b/Src/Tests/SharpArch.XunitTests.NHibernate/HasUniqieDomainSignatureTestsBase.cs @@ -2,37 +2,19 @@ { using System; using System.ComponentModel.DataAnnotations; - using System.Reflection; - using Domain; using global::SharpArch.Domain.PersistenceSupport; using global::SharpArch.NHibernate; - using global::SharpArch.Testing.NHibernate; using global::SharpArch.Testing.Xunit.NHibernate; - using Mappings; using Moq; - public class DomainSignatureDbSetup : TestDatabaseSetup - { - public DomainSignatureDbSetup() - : base(Assembly.GetExecutingAssembly().CodeBase, - new[] - { - typeof(ObjectWithGuidId).Assembly, - typeof(TestsPersistenceModelGenerator).Assembly - }) - { - } - } - - - public abstract class HasUniqueDomainSignatureTestsBase : TransientDatabaseTests + public abstract class HasUniqueDomainSignatureTestsBase : TransientDatabaseTests { protected Mock ServiceProviderMock; protected ValidationContext ValidationContext; public HasUniqueDomainSignatureTestsBase() - : base(new DomainSignatureDbSetup()) + : base(new NHibernateTestsSetup()) { ServiceProviderMock = new Mock(); ServiceProviderMock.Setup(sp => sp.GetService(typeof(IEntityDuplicateChecker))) diff --git a/Src/Tests/SharpArch.XunitTests.NHibernate/Mappings/TestsPersistenceModelGenerator.cs b/Src/Tests/SharpArch.XunitTests.NHibernate/Mappings/TestsPersistenceModelGenerator.cs new file mode 100644 index 000000000..9291dfdc6 --- /dev/null +++ b/Src/Tests/SharpArch.XunitTests.NHibernate/Mappings/TestsPersistenceModelGenerator.cs @@ -0,0 +1,43 @@ +namespace Tests.SharpArch.NHibernate.Mappings +{ + using System; + using Domain; + using FluentNHibernate.Automapping; + using FluentNHibernate.Conventions; + using global::SharpArch.Domain.DomainModel; + using global::SharpArch.NHibernate.FluentNHibernate; + using global::SharpArch.NHibernate.FluentNHibernate.Conventions; + + + /// + /// Generates the auto-mapping for test entities. + /// + public class TestsPersistenceModelGenerator : IAutoPersistenceModelGenerator + { + /// + /// Generates persistence model. + /// + /// + public AutoPersistenceModel Generate() + { + var mappings = AutoMap.AssemblyOf(new AutomappingConfiguration()); + mappings.IgnoreBase(); + mappings.IgnoreBase(typeof(EntityWithTypedId<>)); + mappings.Conventions.Setup(GetConventions()); + mappings.UseOverridesFromAssemblyOf(); + + return mappings; + } + + static Action GetConventions() + { + return c => + { + c.Add(); + c.Add(); + c.Add(); + c.Add(); + }; + } + } +} diff --git a/Src/Tests/SharpArch.XunitTests.NHibernate/NHibernateRepositoryTests.cs b/Src/Tests/SharpArch.XunitTests.NHibernate/NHibernateRepositoryTests.cs new file mode 100644 index 000000000..6a272c671 --- /dev/null +++ b/Src/Tests/SharpArch.XunitTests.NHibernate/NHibernateRepositoryTests.cs @@ -0,0 +1,54 @@ +namespace Tests.SharpArch.NHibernate +{ + using System.Threading.Tasks; + using Domain; + using FluentAssertions; + using global::SharpArch.NHibernate; + using global::SharpArch.Testing.Xunit.NHibernate; + using Xunit; + + + public class NHibernateRepositoryTests : TransientDatabaseTests + { + readonly NHibernateRepository _repo; + + /// + public NHibernateRepositoryTests(NHibernateTestsSetup setup): base(setup) + { + _repo = new NHibernateRepository(TransactionManager); + } + + /// + protected override void LoadTestData() + { + } + + [Fact] + public async Task CanSaveAsync() + { + var entity = new Contractor + { + Name = "John Doe" + }; + + var res = await _repo.SaveAsync(entity).ConfigureAwait(false); + res.IsTransient().Should().BeFalse(); + res.Id.Should().BeGreaterThan(0); + } + + [Fact] + public async Task CanSaveOrUpdate() + { + var entity = new Contractor + { + Name = "John Doe" + }; + var res = await _repo.SaveOrUpdateAsync(entity).ConfigureAwait(false); + res.IsTransient().Should().BeFalse(); + + entity.Name = "John Doe Jr"; + res = await _repo.SaveOrUpdateAsync(entity).ConfigureAwait(false); + res.Name.Should().Be("John Doe Jr"); + } + } +} diff --git a/Src/Tests/SharpArch.XunitTests.NHibernate/NHibernateTestsSetup.cs b/Src/Tests/SharpArch.XunitTests.NHibernate/NHibernateTestsSetup.cs new file mode 100644 index 000000000..dd689129b --- /dev/null +++ b/Src/Tests/SharpArch.XunitTests.NHibernate/NHibernateTestsSetup.cs @@ -0,0 +1,21 @@ +namespace Tests.SharpArch.NHibernate +{ + using System.Reflection; + using Domain; + using global::SharpArch.Testing.NHibernate; + using Mappings; + + + public class NHibernateTestsSetup : TestDatabaseSetup + { + public NHibernateTestsSetup() + : base(Assembly.GetExecutingAssembly().CodeBase, + new[] + { + typeof(ObjectWithGuidId).Assembly, + typeof(TestsPersistenceModelGenerator).Assembly + }) + { + } + } +} diff --git a/build.cake b/build.cake index 12b13e8e2..fd9f01410 100644 --- a/build.cake +++ b/build.cake @@ -120,15 +120,17 @@ Task("UpdateAppVeyorBuildNumber") .Does(() => { AppVeyor.UpdateBuildVersion(buildVersion); - }); Task("Restore") - .Does(() => - { - DotNetCoreRestore(srcDir); - }); + .DoesForEach(GetFiles(solutionFile).Union(GetFiles($"{samplesDir}/**/*.sln")), + (sln) => { + Information("Running in {0}", sln.GetDirectory().FullPath); + DotNetCoreRestore(sln.GetDirectory().FullPath); + } + ); + Task("InspectCode") .Does(() => { @@ -199,7 +201,7 @@ Task("RunXunitTests") // run open cover for debug build configuration OpenCover( - tool => tool.DotNetCoreTool(projectPath.ToString(), + tool => tool.DotNetCoreTool(projectPath.FullPath, "test", buildProcessArgs("Debug") ), @@ -237,6 +239,7 @@ Task("GenerateCoverageReport") Task("RunUnitTests") .IsDependentOn("BuildLibrary") + .IsDependentOn("BuildSamples") .IsDependentOn("CleanPreviousTestResults") .IsDependentOn("RunXunitTests") .IsDependentOn("GenerateCoverageReport") @@ -246,7 +249,6 @@ Task("RunUnitTests") }); - Task("BuildLibrary") .IsDependentOn("SetVersion") .IsDependentOn("UpdateAppVeyorBuildNumber") @@ -261,7 +263,7 @@ Task("BuildLibrary") Configuration = "Debug", }); } - Information("Running {0} build for code coverage", buildConfig); + Information("Running {0} build", buildConfig); DotNetCoreBuild(srcDir, new DotNetCoreBuildSettings { NoRestore = true, Configuration = buildConfig, @@ -270,10 +272,35 @@ Task("BuildLibrary") + +Task("BuildSamples") + .IsDependentOn("SetVersion") + .IsDependentOn("UpdateAppVeyorBuildNumber") + .IsDependentOn("Restore") + .DoesForEach(GetFiles($"{samplesDir}/**/*.sln"), + (solutionFile) => { + var slnPath = solutionFile.GetDirectory().FullPath; + var sln = solutionFile.GetFilenameWithoutExtension(); + if (isReleaseBuild) { + Information("Running {0} {1} build for code coverage", sln, "Debug"); + // need Debug build for code coverage + DotNetCoreBuild(slnPath, new DotNetCoreBuildSettings { + NoRestore = true, + Configuration = "Debug", + }); + } + Information("Running {0} {1} build in {2}", sln, buildConfig, slnPath); + DotNetCoreBuild(slnPath, new DotNetCoreBuildSettings { + NoRestore = true, + Configuration = buildConfig, + }); + }); + + + Task("CreateNugetPackages") .Does(() => { Action buildPackage = (string projectName) => { - //var projectFileName = $"{srcDir}/{projectName}/{projectName}.csproj"; var projectFileName=projectName; Information("Pack {0}", projectFileName); @@ -319,6 +346,7 @@ Task("CloseMilestone") Task("Default") .IsDependentOn("UpdateAppVeyorBuildNumber") .IsDependentOn("BuildLibrary") + .IsDependentOn("BuildSamples") .IsDependentOn("RunUnitTests") // .IsDependentOn("InspectCode") .IsDependentOn("CreateNugetPackages")