From bf2119432e737577a9285e3d882877b28882bb73 Mon Sep 17 00:00:00 2001 From: alexandre-spieser Date: Sat, 10 Feb 2018 14:13:10 +0000 Subject: [PATCH] Test refactoring, continued. --- ...artitionedCollectionNameAttributeTests.cs} | 2 +- .../Infrastructure/MongoDBTestBase.cs | 321 +++++++++++++++++- IntegrationTests/IntegrationTests.csproj | 6 +- .../ProjectPartitionedTKeyTests.cs | 143 -------- IntegrationTests/ProjectPartitionedTests.cs | 16 +- IntegrationTests/ProjectTKeyTests.cs | 150 -------- IntegrationTests/ProjectTests.cs | 18 +- IntegrationTests/ReadPartitionedTKeyTests.cs | 189 ----------- IntegrationTests/ReadPartitionedTests.cs | 24 +- IntegrationTests/ReadTKeyTests.cs | 187 ---------- 10 files changed, 329 insertions(+), 727 deletions(-) rename IntegrationTests/{TKeyPartitionedCollectionNameAttributeTests.cs => CRUDTKeyPartitionedCollectionNameAttributeTests.cs} (85%) delete mode 100644 IntegrationTests/ProjectPartitionedTKeyTests.cs delete mode 100644 IntegrationTests/ProjectTKeyTests.cs delete mode 100644 IntegrationTests/ReadPartitionedTKeyTests.cs delete mode 100644 IntegrationTests/ReadTKeyTests.cs diff --git a/IntegrationTests/TKeyPartitionedCollectionNameAttributeTests.cs b/IntegrationTests/CRUDTKeyPartitionedCollectionNameAttributeTests.cs similarity index 85% rename from IntegrationTests/TKeyPartitionedCollectionNameAttributeTests.cs rename to IntegrationTests/CRUDTKeyPartitionedCollectionNameAttributeTests.cs index 3c5ab25..3ecc77b 100644 --- a/IntegrationTests/TKeyPartitionedCollectionNameAttributeTests.cs +++ b/IntegrationTests/CRUDTKeyPartitionedCollectionNameAttributeTests.cs @@ -17,7 +17,7 @@ namespace IntegrationTests public string PartitionKey { get; set; } } - public class TKeyPartitionedCollectionNameAttributeTests : MongoDBTestBase + public class CRUDTKeyPartitionedCollectionNameAttributeTests : MongoDBTestBase { public override string GetClassName() { diff --git a/IntegrationTests/Infrastructure/MongoDBTestBase.cs b/IntegrationTests/Infrastructure/MongoDBTestBase.cs index 1bd0eaf..be2ca7d 100644 --- a/IntegrationTests/Infrastructure/MongoDBTestBase.cs +++ b/IntegrationTests/Infrastructure/MongoDBTestBase.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Configuration; using System.Diagnostics; +using System.Linq; using System.Runtime.CompilerServices; using System.Threading.Tasks; @@ -31,28 +32,29 @@ namespace IntegrationTests.Infrastructure public Nested Nested { get; set; } - private void InitializeFields() + public TId Init() { var idTypeName = typeof(TKey).Name; switch (idTypeName) { case "Guid": - Id = (TKey)(object)Guid.NewGuid(); - break; + return (TId)(object)Guid.NewGuid(); case "Int16": - Id = (TKey)(object)GlobalVariables.Random.Next(1, short.MaxValue); - break; + return (TId)(object)GlobalVariables.Random.Next(1, short.MaxValue); case "Int32": - Id = (TKey)(object)GlobalVariables.Random.Next(1, int.MaxValue); - break; + return (TId)(object)GlobalVariables.Random.Next(1, int.MaxValue); case "Int64": - Id = (TKey)(object)(GlobalVariables.Random.NextLong(1, long.MaxValue)); - break; + return (TId)(object)(GlobalVariables.Random.NextLong(1, long.MaxValue)); case "String": - Id = (TKey)(object)Guid.NewGuid().ToString(); - break; + return (TId)(object)Guid.NewGuid().ToString(); + default: + throw new NotSupportedException($"{idTypeName} is not supported."); } + } + private void InitializeFields() + { + Id = Init(); } } @@ -192,6 +194,176 @@ namespace IntegrationTests.Infrastructure #endregion Add + #region Read + + [Test] + public async Task GetByIdAsync() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.GetByIdAsync(document.Id, PartitionKey); + // Assert + Assert.IsNotNull(result, GetTestName()); + } + + [Test] + public void GetById() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.GetById(document.Id, PartitionKey); + // Assert + Assert.IsNotNull(result, GetTestName()); + } + + + [Test] + public async Task PartitionedGetOneAsync() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.GetOneAsync(x => x.Id.Equals(document.Id), PartitionKey); + // Assert + Assert.IsNotNull(result, GetTestName()); + } + + [Test] + public void GetOne() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.GetOne(x => x.Id.Equals(document.Id), PartitionKey); + // Assert + Assert.IsNotNull(result, GetTestName()); + } + + [Test] + public void GetCursor() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var cursor = SUT.GetCursor(x => x.Id.Equals(document.Id), PartitionKey); + var count = cursor.Count(); + // Assert + Assert.AreEqual(1, count, GetTestName()); + } + + [Test] + public async Task AnyAsyncReturnsTrue() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.AnyAsync(x => x.Id.Equals(document.Id), PartitionKey); + // Assert + Assert.AreEqual(true, result, GetTestName()); + } + + [Test] + public async Task AnyAsyncReturnsFalse() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = await SUT.AnyAsync(x => x.Id.Equals(document.Init()), PartitionKey); + // Assert + Assert.AreEqual(false, result, GetTestName()); + } + + [Test] + public void AnyReturnsTrue() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.Any(x => x.Id.Equals(document.Id), PartitionKey); + // Assert + Assert.AreEqual(true, result, GetTestName()); + } + + [Test] + public void AnyReturnsFalse() + { + // Arrange + var document = CreateTestDocument(); + SUT.AddOne(document); + // Act + var result = SUT.Any(x => x.Id.Equals(document.Init()), PartitionKey); + // Assert + Assert.AreEqual(false, result, GetTestName()); + } + + [Test] + public async Task GetAllAsync() + { + // Arrange + var documents = CreateTestDocuments(5); + var content = GetContent(); + documents.ForEach(e => e.SomeContent = content); + SUT.AddMany(documents); + // Act + var result = await SUT.GetAllAsync(x => x.SomeContent == content, PartitionKey); + // Assert + Assert.AreEqual(5, result.Count, GetTestName()); + } + + [Test] + public void GetAll() + { + // Arrange + var documents = CreateTestDocuments(5); + var content = GetContent(); + documents.ForEach(e => e.SomeContent = content); + SUT.AddMany(documents); + // Act + var result = SUT.GetAll(x => x.SomeContent == content, PartitionKey); + // Assert + Assert.AreEqual(5, result.Count, GetTestName()); + } + + [Test] + public async Task CountAsync() + { + // Arrange + var documents = CreateTestDocuments(5); + var content = GetContent(); + documents.ForEach(e => e.SomeContent = content); + SUT.AddMany(documents); + // Act + var result = await SUT.CountAsync(x => x.SomeContent == content, PartitionKey); + // Assert + Assert.AreEqual(5, result, GetTestName()); + } + + [Test] + public void Count() + { + // Arrange + var documents = CreateTestDocuments(5); + var content = GetContent(); + documents.ForEach(e => e.SomeContent = content); + SUT.AddMany(documents); + // Act + var result = SUT.Count(x => x.SomeContent == content, PartitionKey); + // Assert + Assert.AreEqual(5, result); + } + + #endregion Read + #region Delete [Test] @@ -310,11 +482,120 @@ namespace IntegrationTests.Infrastructure #region Project + [Test] + public async Task ProjectOneAsync() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var document = CreateTestDocument(); + document.SomeContent = someContent; + document.Nested.SomeDate = someDate; + SUT.AddOne(document); + // Act + var result = await SUT.ProjectOneAsync( + x => x.Id.Equals(document.Id), + x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + PartitionKey); + // Assert + Assert.IsNotNull(result, GetTestName()); + Assert.AreEqual(someContent, result.SomeContent, GetTestName()); + Assert.AreEqual(someDate.Minute, result.SomeDate.Minute, GetTestName()); + Assert.AreEqual(someDate.Second, result.SomeDate.Second, GetTestName()); + } + [Test] + public void ProjectOne() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var document = CreateTestDocument(); + document.SomeContent = someContent; + document.Nested.SomeDate = someDate; + SUT.AddOne(document); + // Act + var result = SUT.ProjectOne( + x => x.Id.Equals(document.Id), + x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + PartitionKey); + // Assert + Assert.IsNotNull(result, GetTestName()); + Assert.AreEqual(someContent, result.SomeContent, GetTestName()); + Assert.AreEqual(someDate.Minute, result.SomeDate.Minute, GetTestName()); + Assert.AreEqual(someDate.Second, result.SomeDate.Second, GetTestName()); + } + + [Test] + public async Task ProjectManyAsync() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var documents = CreateTestDocuments(5); + documents.ForEach(e => + { + e.SomeContent = someContent; + e.Nested.SomeDate = someDate; + }); + + SUT.AddMany(documents); + // Act + var result = await SUT.ProjectManyAsync( + x => x.SomeContent == someContent, + x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + PartitionKey); + // Assert + Assert.AreEqual(5, result.Count, GetTestName()); + Assert.AreEqual(someContent, result.First().SomeContent, GetTestName()); + Assert.AreEqual(someDate.Minute, result.First().SomeDate.Minute, GetTestName()); + Assert.AreEqual(someDate.Second, result.First().SomeDate.Second, GetTestName()); + } + + [Test] + public void ProjectMany() + { + // Arrange + var someContent = GetContent(); + var someDate = DateTime.UtcNow; + var documents = CreateTestDocuments(5); + documents.ForEach(e => + { + e.SomeContent = someContent; + e.Nested.SomeDate = someDate; + }); + + SUT.AddMany(documents); + // Act + var result = SUT.ProjectMany( + x => x.SomeContent == someContent, + x => new MyTestProjection + { + SomeContent = x.SomeContent, + SomeDate = x.Nested.SomeDate + }, + PartitionKey); + // Assert + Assert.AreEqual(5, result.Count, GetTestName()); + Assert.AreEqual(someContent, result.First().SomeContent, GetTestName()); + Assert.AreEqual(someDate.Minute, result.First().SomeDate.Minute, GetTestName()); + Assert.AreEqual(someDate.Second, result.First().SomeDate.Second, GetTestName()); + } #endregion Project - #region Test Utils [MethodImpl(MethodImplOptions.NoInlining)] private string GetCurrentMethod() @@ -325,9 +606,23 @@ namespace IntegrationTests.Infrastructure return sf.GetMethod().Name; } + [MethodImpl(MethodImplOptions.NoInlining)] + private string GetParentMethod() + { + StackTrace st = new StackTrace(); + StackFrame sf = st.GetFrame(2); + var method = sf.GetMethod().DeclaringType.Name; + return method; + } + private string GetTestName() { - return $"{TestClassName}.{GetCurrentMethod()}"; + return $"{TestClassName}{PartitionKey}.{GetParentMethod()}"; + } + + private string GetContent() + { + return $"{TestClassName}{PartitionKey}.{Guid.NewGuid()}.{GetParentMethod()}"; } #endregion Test Utils diff --git a/IntegrationTests/IntegrationTests.csproj b/IntegrationTests/IntegrationTests.csproj index c5b061e..d1f40cd 100644 --- a/IntegrationTests/IntegrationTests.csproj +++ b/IntegrationTests/IntegrationTests.csproj @@ -49,7 +49,7 @@ - + @@ -63,14 +63,10 @@ - - - - diff --git a/IntegrationTests/ProjectPartitionedTKeyTests.cs b/IntegrationTests/ProjectPartitionedTKeyTests.cs deleted file mode 100644 index 9d80dde..0000000 --- a/IntegrationTests/ProjectPartitionedTKeyTests.cs +++ /dev/null @@ -1,143 +0,0 @@ -using IntegrationTests.Infrastructure; -using MongoDB.Bson.Serialization.Attributes; -using MongoDbGenericRepository.Models; -using NUnit.Framework; -using System; -using System.Linq; -using System.Threading.Tasks; - -namespace IntegrationTests -{ - - public class ProjectTestsPartitionedTKeyDocument : IDocument, IPartitionedDocument - { - [BsonId] - public Guid Id { get; set; } - public int Version { get; set; } - public ProjectTestsPartitionedTKeyDocument() - { - Id = Guid.NewGuid(); - Version = 2; - PartitionKey = "TestPartitionKey"; - Nested = new NestedTKey(); - } - public string PartitionKey { get; set; } - public NestedTKey Nested { get; set; } - public string SomeContent { get; set; } - } - - public class ProjectPartitionedTKeyTests : BaseMongoDbRepositoryTests - { - [Test] - public async Task PartitionedProjectOneAsync() - { - // Arrange - const string someContent = "ProjectOneAsyncContent"; - var someDate = DateTime.UtcNow; - var document = CreateTestDocument(); - document.SomeContent = someContent; - document.Nested.SomeDate = someDate; - SUT.AddOne(document); - // Act - var result = await SUT.ProjectOneAsync( - x => x.Id == document.Id, - x => new MyProjection - { - SomeContent = x.SomeContent, - SomeDate = x.Nested.SomeDate - }, - PartitionKey); - // Assert - Assert.IsNotNull(result); - Assert.AreEqual(someContent, result.SomeContent); - Assert.AreEqual(someDate.Minute, result.SomeDate.Minute); - Assert.AreEqual(someDate.Second, result.SomeDate.Second); - } - - [Test] - public void PartitionedProjectOne() - { - // Arrange - const string someContent = "ProjectOneContent"; - var someDate = DateTime.UtcNow; - var document = CreateTestDocument(); - document.SomeContent = someContent; - document.Nested.SomeDate = someDate; - SUT.AddOne(document); - // Act - var result = SUT.ProjectOne( - x => x.Id == document.Id, - x => new MyProjection - { - SomeContent = x.SomeContent, - SomeDate = x.Nested.SomeDate - }, - PartitionKey); - // Assert - Assert.IsNotNull(result); - Assert.AreEqual(someContent, result.SomeContent); - Assert.AreEqual(someDate.Minute, result.SomeDate.Minute); - Assert.AreEqual(someDate.Second, result.SomeDate.Second); - } - - [Test] - public async Task PartitionedProjectManyAsync() - { - // Arrange - const string someContent = "ProjectManyAsyncContent"; - var someDate = DateTime.UtcNow; - var document = CreateTestDocuments(5); - document.ForEach(e => - { - e.SomeContent = someContent; - e.Nested.SomeDate = someDate; - }); - - SUT.AddMany(document); - // Act - var result = await SUT.ProjectManyAsync( - x => x.SomeContent == someContent, - x => new MyProjection - { - SomeContent = x.SomeContent, - SomeDate = x.Nested.SomeDate - }, - PartitionKey); - // Assert - Assert.AreEqual(5, result.Count); - Assert.AreEqual(someContent, result.First().SomeContent); - Assert.AreEqual(someDate.Minute, result.First().SomeDate.Minute); - Assert.AreEqual(someDate.Second, result.First().SomeDate.Second); - } - - [Test] - public void PartitionedProjectMany() - { - // Arrange - const string someContent = "ProjectManyContent"; - var someDate = DateTime.UtcNow; - var document = CreateTestDocuments(5); - document.ForEach(e => - { - e.SomeContent = someContent; - e.Nested.SomeDate = someDate; - }); - - SUT.AddMany(document); - // Act - var result = SUT.ProjectMany( - x => x.SomeContent == someContent, - x => new MyProjection - { - SomeContent = x.SomeContent, - SomeDate = x.Nested.SomeDate - }, - PartitionKey); - // Assert - Assert.AreEqual(5, result.Count); - Assert.AreEqual(someContent, result.First().SomeContent); - Assert.AreEqual(someDate.Minute, result.First().SomeDate.Minute); - Assert.AreEqual(someDate.Second, result.First().SomeDate.Second); - } - } -} diff --git a/IntegrationTests/ProjectPartitionedTests.cs b/IntegrationTests/ProjectPartitionedTests.cs index 11c3a69..6efcfe1 100644 --- a/IntegrationTests/ProjectPartitionedTests.cs +++ b/IntegrationTests/ProjectPartitionedTests.cs @@ -36,9 +36,9 @@ namespace IntegrationTests document.Nested.SomeDate = someDate; SUT.AddOne(document); // Act - var result = await SUT.ProjectOneAsync( + var result = await SUT.ProjectOneAsync( x => x.Id == document.Id, - x => new MyProjection + x => new MyTestProjection { SomeContent = x.SomeContent, SomeDate = x.Nested.SomeDate @@ -62,9 +62,9 @@ namespace IntegrationTests document.Nested.SomeDate = someDate; SUT.AddOne(document); // Act - var result = SUT.ProjectOne( + var result = SUT.ProjectOne( x => x.Id == document.Id, - x => new MyProjection + x => new MyTestProjection { SomeContent = x.SomeContent, SomeDate = x.Nested.SomeDate @@ -92,9 +92,9 @@ namespace IntegrationTests SUT.AddMany(document); // Act - var result = await SUT.ProjectManyAsync( + var result = await SUT.ProjectManyAsync( x => x.SomeContent == someContent, - x => new MyProjection + x => new MyTestProjection { SomeContent = x.SomeContent, SomeDate = x.Nested.SomeDate @@ -122,9 +122,9 @@ namespace IntegrationTests SUT.AddMany(document); // Act - var result = SUT.ProjectMany( + var result = SUT.ProjectMany( x => x.SomeContent == someContent, - x => new MyProjection + x => new MyTestProjection { SomeContent = x.SomeContent, SomeDate = x.Nested.SomeDate diff --git a/IntegrationTests/ProjectTKeyTests.cs b/IntegrationTests/ProjectTKeyTests.cs deleted file mode 100644 index cec8606..0000000 --- a/IntegrationTests/ProjectTKeyTests.cs +++ /dev/null @@ -1,150 +0,0 @@ -using IntegrationTests.Infrastructure; -using MongoDB.Bson.Serialization.Attributes; -using MongoDbGenericRepository.Models; -using NUnit.Framework; -using System; -using System.Linq; -using System.Threading.Tasks; - -namespace IntegrationTests -{ - public class NestedTKey - { - public DateTime SomeDate { get; set; } - } - - public class MyProjectionTKey - { - public DateTime SomeDate { get; set; } - public string SomeContent { get; set; } - } - - public class ProjectTestsTKeyDocument : IDocument - { - [BsonId] - public Guid Id { get; set; } - public int Version { get; set; } - public ProjectTestsTKeyDocument() - { - Id = Guid.NewGuid(); - Version = 2; - Nested = new NestedTKey - { - SomeDate = DateTime.UtcNow - }; - } - public string SomeContent { get; set; } - public NestedTKey Nested { get; set; } - } - - public class ProjectTKeyTests : BaseMongoDbRepositoryTests - { - [Test] - public async Task ProjectOneAsync() - { - // Arrange - const string someContent = "ProjectOneAsyncContent"; - var someDate = DateTime.UtcNow; - var document = CreateTestDocument(); - document.SomeContent = someContent; - document.Nested.SomeDate = someDate; - SUT.AddOne(document); - // Act - var result = await SUT.ProjectOneAsync( - x => x.Id == document.Id, - x => new MyProjection - { - SomeContent = x.SomeContent, - SomeDate = x.Nested.SomeDate - }); - // Assert - Assert.IsNotNull(result); - Assert.AreEqual(someContent, result.SomeContent); - Assert.AreEqual(someDate.Minute, result.SomeDate.Minute); - Assert.AreEqual(someDate.Second, result.SomeDate.Second); - } - - [Test] - public void ProjectOne() - { - // Arrange - const string someContent = "ProjectOneContent"; - var someDate = DateTime.UtcNow; - var document = CreateTestDocument(); - document.SomeContent = someContent; - document.Nested.SomeDate = someDate; - SUT.AddOne(document); - // Act - var result = SUT.ProjectOne( - x => x.Id == document.Id, - x => new MyProjection - { - SomeContent = x.SomeContent, - SomeDate = x.Nested.SomeDate - }); - // Assert - Assert.IsNotNull(result); - Assert.AreEqual(someContent, result.SomeContent); - Assert.AreEqual(someDate.Minute, result.SomeDate.Minute); - Assert.AreEqual(someDate.Second, result.SomeDate.Second); - } - - [Test] - public async Task ProjectManyAsync() - { - // Arrange - const string someContent = "ProjectManyAsyncContent"; - var someDate = DateTime.UtcNow; - var document = CreateTestDocuments(5); - document.ForEach(e => - { - e.SomeContent = someContent; - e.Nested.SomeDate = someDate; - }); - - SUT.AddMany(document); - // Act - var result = await SUT.ProjectManyAsync( - x => x.SomeContent == someContent, - x => new MyProjection - { - SomeContent = x.SomeContent, - SomeDate = x.Nested.SomeDate - }); - // Assert - Assert.AreEqual(5, result.Count); - Assert.AreEqual(someContent, result.First().SomeContent); - Assert.AreEqual(someDate.Minute, result.First().SomeDate.Minute); - Assert.AreEqual(someDate.Second, result.First().SomeDate.Second); - } - - [Test] - public void ProjectMany() - { - // Arrange - const string someContent = "ProjectManyContent"; - var someDate = DateTime.UtcNow; - var document = CreateTestDocuments(5); - document.ForEach(e => - { - e.SomeContent = someContent; - e.Nested.SomeDate = someDate; - }); - - SUT.AddMany(document); - // Act - var result = SUT.ProjectMany( - x => x.SomeContent == someContent, - x => new MyProjection - { - SomeContent = x.SomeContent, - SomeDate = x.Nested.SomeDate - }); - // Assert - Assert.AreEqual(5, result.Count); - Assert.AreEqual(someContent, result.First().SomeContent); - Assert.AreEqual(someDate.Minute, result.First().SomeDate.Minute); - Assert.AreEqual(someDate.Second, result.First().SomeDate.Second); - } - } -} diff --git a/IntegrationTests/ProjectTests.cs b/IntegrationTests/ProjectTests.cs index 8189a31..8749a3e 100644 --- a/IntegrationTests/ProjectTests.cs +++ b/IntegrationTests/ProjectTests.cs @@ -12,7 +12,7 @@ namespace IntegrationTests public DateTime SomeDate { get; set; } } - public class MyProjection + public class MyTestProjection { public DateTime SomeDate { get; set; } public string SomeContent { get; set; } @@ -49,9 +49,9 @@ namespace IntegrationTests document.Nested.SomeDate = someDate; SUT.AddOne(document); // Act - var result = await SUT.ProjectOneAsync( + var result = await SUT.ProjectOneAsync( x => x.Id == document.Id, - x => new MyProjection + x => new MyTestProjection { SomeContent = x.SomeContent, SomeDate = x.Nested.SomeDate @@ -74,9 +74,9 @@ namespace IntegrationTests document.Nested.SomeDate = someDate; SUT.AddOne(document); // Act - var result = SUT.ProjectOne( + var result = SUT.ProjectOne( x => x.Id == document.Id, - x => new MyProjection + x => new MyTestProjection { SomeContent = x.SomeContent, SomeDate = x.Nested.SomeDate @@ -103,9 +103,9 @@ namespace IntegrationTests SUT.AddMany(document); // Act - var result = await SUT.ProjectManyAsync( + var result = await SUT.ProjectManyAsync( x => x.SomeContent == someContent, - x => new MyProjection + x => new MyTestProjection { SomeContent = x.SomeContent, SomeDate = x.Nested.SomeDate @@ -132,9 +132,9 @@ namespace IntegrationTests SUT.AddMany(document); // Act - var result = SUT.ProjectMany( + var result = SUT.ProjectMany( x => x.SomeContent == someContent, - x => new MyProjection + x => new MyTestProjection { SomeContent = x.SomeContent, SomeDate = x.Nested.SomeDate diff --git a/IntegrationTests/ReadPartitionedTKeyTests.cs b/IntegrationTests/ReadPartitionedTKeyTests.cs deleted file mode 100644 index ceab08e..0000000 --- a/IntegrationTests/ReadPartitionedTKeyTests.cs +++ /dev/null @@ -1,189 +0,0 @@ -using IntegrationTests.Infrastructure; -using MongoDB.Bson.Serialization.Attributes; -using MongoDbGenericRepository.Models; -using NUnit.Framework; -using System; -using System.Threading.Tasks; - -namespace IntegrationTests -{ - public class ReadTestsPartitionedTKeyDocument : IDocument, IPartitionedDocument - { - [BsonId] - public Guid Id { get; set; } - public int Version { get; set; } - public ReadTestsPartitionedTKeyDocument() - { - Id = Guid.NewGuid(); - Version = 2; - PartitionKey = "TestPartitionKey"; - } - public string PartitionKey { get; set; } - public string SomeContent { get; set; } - } - - [TestFixture] - public class ReadPartitionedTKeyTests : BaseMongoDbRepositoryTests - { - [Test] - public async Task PartitionedGetByIdAsync() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = await SUT.GetByIdAsync(document.Id, PartitionKey); - // Assert - Assert.IsNotNull(result); - } - - [Test] - public void PartitionedGetById() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = SUT.GetById(document.Id, PartitionKey); - // Assert - Assert.IsNotNull(result); - } - - [Test] - public async Task PartitionedGetOneAsync() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = await SUT.GetOneAsync(x => x.Id == document.Id, PartitionKey); - // Assert - Assert.IsNotNull(result); - } - - [Test] - public void PartitionedGetOne() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = SUT.GetOne(x => x.Id == document.Id, PartitionKey); - // Assert - Assert.IsNotNull(result); - } - - [Test] - public void PartitionedGetCursor() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var cursor = SUT.GetCursor(x => x.Id == document.Id, PartitionKey); - var count = cursor.Count(); - // Assert - Assert.AreEqual(1, count); - } - - [Test] - public async Task PartitionedAnyAsyncReturnsTrue() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = await SUT.AnyAsync(x => x.Id == document.Id, PartitionKey); - // Assert - Assert.AreEqual(true, result); - } - - [Test] - public async Task PartitionedAnyAsyncReturnsFalse() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = await SUT.AnyAsync(x => x.Id == Guid.NewGuid(), PartitionKey); - // Assert - Assert.AreEqual(false, result); - } - - [Test] - public void PartitionedAnyReturnsTrue() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = SUT.Any(x => x.Id == document.Id, PartitionKey); - // Assert - Assert.AreEqual(true, result); - } - - [Test] - public void PartitionedAnyReturnsFalse() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = SUT.Any(x => x.Id == Guid.NewGuid(), PartitionKey); - // Assert - Assert.AreEqual(false, result); - } - - [Test] - public async Task PartitionedGetAllAsync() - { - // Arrange - var documents = CreateTestDocuments(5); - documents.ForEach(e => e.SomeContent = "GetAllAsyncContent"); - SUT.AddMany(documents); - // Act - var result = await SUT.GetAllAsync(x => x.SomeContent == "GetAllAsyncContent", PartitionKey); - // Assert - Assert.AreEqual(5, result.Count); - } - - [Test] - public void PartitionedGetAll() - { - // Arrange - var documents = CreateTestDocuments(5); - documents.ForEach(e => e.SomeContent = "GetAllContent"); - SUT.AddMany(documents); - // Act - var result = SUT.GetAll(x => x.SomeContent == "GetAllContent", PartitionKey); - // Assert - Assert.AreEqual(5, result.Count); - } - - [Test] - public async Task PartitionedCountAsync() - { - // Arrange - var documents = CreateTestDocuments(5); - documents.ForEach(e => e.SomeContent = "CountAsyncContent"); - SUT.AddMany(documents); - // Act - var result = await SUT.CountAsync(x => x.SomeContent == "CountAsyncContent", PartitionKey); - // Assert - Assert.AreEqual(5, result); - } - - [Test] - public void PartitionedCount() - { - // Arrange - var documents = CreateTestDocuments(5); - documents.ForEach(e => e.SomeContent = "CountContent"); - SUT.AddMany(documents); - // Act - var result = SUT.Count(x => x.SomeContent == "CountContent", PartitionKey); - // Assert - Assert.AreEqual(5, result); - } - } -} diff --git a/IntegrationTests/ReadPartitionedTests.cs b/IntegrationTests/ReadPartitionedTests.cs index cbf662a..d4205ac 100644 --- a/IntegrationTests/ReadPartitionedTests.cs +++ b/IntegrationTests/ReadPartitionedTests.cs @@ -17,29 +17,9 @@ namespace IntegrationTests public class ReadPartitionedTests : BaseMongoDbRepositoryTests { - [Test] - public async Task PartitionedGetByIdAsync() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = await SUT.GetByIdAsync(document.Id, PartitionKey); - // Assert - Assert.IsNotNull(result); - } - [Test] - public void PartitionedGetById() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = SUT.GetById(document.Id, PartitionKey); - // Assert - Assert.IsNotNull(result); - } + + [Test] public async Task PartitionedGetOneAsync() diff --git a/IntegrationTests/ReadTKeyTests.cs b/IntegrationTests/ReadTKeyTests.cs deleted file mode 100644 index e2e6330..0000000 --- a/IntegrationTests/ReadTKeyTests.cs +++ /dev/null @@ -1,187 +0,0 @@ -using IntegrationTests.Infrastructure; -using MongoDB.Bson.Serialization.Attributes; -using MongoDbGenericRepository.Models; -using NUnit.Framework; -using System; -using System.Threading.Tasks; - -namespace IntegrationTests -{ - public class ReadTestsTKeyDocument : IDocument - { - [BsonId] - public Guid Id { get; set; } - public int Version { get; set; } - public ReadTestsTKeyDocument() - { - Id = Guid.NewGuid(); - Version = 2; - } - public string SomeContent { get; set; } - } - - [TestFixture] - public class ReadTKeyTests : BaseMongoDbRepositoryTests - { - [Test] - public async Task GetByIdAsync() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = await SUT.GetByIdAsync(document.Id); - // Assert - Assert.IsNotNull(result); - } - - [Test] - public void GetById() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = SUT.GetById(document.Id); - // Assert - Assert.IsNotNull(result); - } - - [Test] - public async Task GetOneAsync() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = await SUT.GetOneAsync(x => x.Id == document.Id); - // Assert - Assert.IsNotNull(result); - } - - [Test] - public void GetOne() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = SUT.GetOne(x => x.Id == document.Id); - // Assert - Assert.IsNotNull(result); - } - - [Test] - public void GetCursor() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var cursor = SUT.GetCursor(x => x.Id == document.Id); - var count = cursor.Count(); - // Assert - Assert.AreEqual(1, count); - } - - [Test] - public async Task AnyAsyncReturnsTrue() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = await SUT.AnyAsync(x => x.Id == document.Id); - // Assert - Assert.AreEqual(true, result); - } - - [Test] - public async Task AnyAsyncReturnsFalse() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = await SUT.AnyAsync(x => x.Id == Guid.NewGuid()); - // Assert - Assert.AreEqual(false, result); - } - - [Test] - public void AnyReturnsTrue() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = SUT.Any(x => x.Id == document.Id); - // Assert - Assert.AreEqual(true, result); - } - - [Test] - public void AnyReturnsFalse() - { - // Arrange - var document = CreateTestDocument(); - SUT.AddOne(document); - // Act - var result = SUT.Any(x => x.Id == Guid.NewGuid()); - // Assert - Assert.AreEqual(false, result); - } - - [Test] - public async Task GetAllAsync() - { - // Arrange - var documents = CreateTestDocuments(5); - documents.ForEach(e => e.SomeContent = "GetAllAsyncContent"); - SUT.AddMany(documents); - // Act - var result = await SUT.GetAllAsync(x => x.SomeContent == "GetAllAsyncContent"); - // Assert - Assert.AreEqual(5, result.Count); - } - - [Test] - public void GetAll() - { - // Arrange - var documents = CreateTestDocuments(5); - documents.ForEach(e => e.SomeContent = "GetAllContent"); - SUT.AddMany(documents); - // Act - var result = SUT.GetAll(x => x.SomeContent == "GetAllContent"); - // Assert - Assert.AreEqual(5, result.Count); - } - - [Test] - public async Task CountAsync() - { - // Arrange - var documents = CreateTestDocuments(5); - documents.ForEach(e => e.SomeContent = "CountAsyncContent"); - SUT.AddMany(documents); - // Act - var result = await SUT.CountAsync(x => x.SomeContent == "CountAsyncContent"); - // Assert - Assert.AreEqual(5, result); - } - - [Test] - public void Count() - { - // Arrange - var documents = CreateTestDocuments(5); - documents.ForEach(e => e.SomeContent = "CountContent"); - SUT.AddMany(documents); - // Act - var result = SUT.Count(x => x.SomeContent == "CountContent"); - // Assert - Assert.AreEqual(5, result); - } - } -}