diff --git a/CoreIntegrationTests/CoreIntegrationTests.csproj b/CoreIntegrationTests/CoreIntegrationTests.csproj
index 2e4ad1b..4edac06 100644
--- a/CoreIntegrationTests/CoreIntegrationTests.csproj
+++ b/CoreIntegrationTests/CoreIntegrationTests.csproj
@@ -7,13 +7,16 @@
-
+
+
+
+
Always
diff --git a/IntegrationTests/App.config b/IntegrationTests/App.config
index 139995c..6d19a67 100644
--- a/IntegrationTests/App.config
+++ b/IntegrationTests/App.config
@@ -7,4 +7,12 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/IntegrationTests/CreateTKeyPartitionedTests.cs b/IntegrationTests/CreateTKeyPartitionedTests.cs
new file mode 100644
index 0000000..4d00dd5
--- /dev/null
+++ b/IntegrationTests/CreateTKeyPartitionedTests.cs
@@ -0,0 +1,76 @@
+using IntegrationTests.Infrastructure;
+using MongoDB.Bson.Serialization.Attributes;
+using MongoDbGenericRepository.Models;
+using NUnit.Framework;
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace IntegrationTests
+{
+ public class CreateTestsPartitionedTKeyDocument : IDocument, IPartitionedDocument
+ {
+ [BsonId]
+ public Guid Id { get; set; }
+ public int Version { get; set; }
+ public CreateTestsPartitionedTKeyDocument()
+ {
+ Id = Guid.NewGuid();
+ Version = 2;
+ PartitionKey = "TestPartitionKey";
+ }
+ public string PartitionKey { get; set; }
+ public string SomeContent { get; set; }
+ }
+
+ public class CreatePartitionedTKeyTests : BaseMongoDbRepositoryTests
+ {
+ [Test]
+ public void PartitionedAddOne()
+ {
+ // Arrange
+ var document = new CreateTestsPartitionedTKeyDocument();
+ // Act
+ SUT.AddOne(document);
+ // Assert
+ long count = SUT.Count(e => e.Id == document.Id, PartitionKey);
+ Assert.AreEqual(1, count);
+ }
+
+ [Test]
+ public async Task PartitionedAddOneAsync()
+ {
+ // Arrange
+ var document = new CreateTestsPartitionedTKeyDocument();
+ // Act
+ await SUT.AddOneAsync(document);
+ // Assert
+ long count = SUT.Count(e => e.Id == document.Id, PartitionKey);
+ Assert.AreEqual(1, count);
+ }
+
+ [Test]
+ public void PartitionedAddMany()
+ {
+ // Arrange
+ var documents = new List { new CreateTestsPartitionedTKeyDocument(), new CreateTestsPartitionedTKeyDocument() };
+ // Act
+ SUT.AddMany(documents);
+ // Assert
+ long count = SUT.Count(e => e.Id == documents[0].Id || e.Id == documents[1].Id, PartitionKey);
+ Assert.AreEqual(2, count);
+ }
+
+ [Test]
+ public async Task PartitionedAddManyAsync()
+ {
+ // Arrange
+ var documents = new List { new CreateTestsPartitionedTKeyDocument(), new CreateTestsPartitionedTKeyDocument() };
+ // Act
+ await SUT.AddManyAsync(documents);
+ // Assert
+ long count = SUT.Count(e => e.Id == documents[0].Id || e.Id == documents[1].Id, PartitionKey);
+ Assert.AreEqual(2, count);
+ }
+ }
+}
diff --git a/IntegrationTests/CreateTKeyTests.cs b/IntegrationTests/CreateTKeyTests.cs
new file mode 100644
index 0000000..f709ba7
--- /dev/null
+++ b/IntegrationTests/CreateTKeyTests.cs
@@ -0,0 +1,75 @@
+using IntegrationTests.Infrastructure;
+using MongoDB.Bson.Serialization.Attributes;
+using MongoDbGenericRepository.Models;
+using NUnit.Framework;
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace IntegrationTests
+{
+ public class CreateTestsTKeyDocument : IDocument
+ {
+ [BsonId]
+ public Guid Id { get; set; }
+ public int Version { get; set; }
+ public CreateTestsTKeyDocument()
+ {
+ Id = Guid.NewGuid();
+ Version = 2;
+ }
+ public string SomeContent { get; set; }
+ }
+
+ [TestFixture]
+ public class CreateTKeyTests : BaseMongoDbRepositoryTests
+ {
+ [Test]
+ public void TKeyAddOne()
+ {
+ // Arrange
+ var document = new CreateTestsTKeyDocument();
+ // Act
+ SUT.AddOne(document);
+ // Assert
+ long count = SUT.Count(e => e.Id == document.Id);
+ Assert.AreEqual(1, count);
+ }
+
+ [Test]
+ public async Task TKeyAddOneAsync()
+ {
+ // Arrange
+ var document = new CreateTestsTKeyDocument();
+ // Act
+ await SUT.AddOneAsync(document);
+ // Assert
+ long count = SUT.Count(e => e.Id == document.Id);
+ Assert.AreEqual(1, count);
+ }
+
+ [Test]
+ public void TKeyAddMany()
+ {
+ // Arrange
+ var documents = new List { new CreateTestsTKeyDocument(), new CreateTestsTKeyDocument() };
+ // Act
+ SUT.AddMany(documents);
+ // Assert
+ long count = SUT.Count(e => e.Id == documents[0].Id || e.Id == documents[1].Id);
+ Assert.AreEqual(2, count);
+ }
+
+ [Test]
+ public async Task TKeyAddManyAsync()
+ {
+ // Arrange
+ var documents = new List { new CreateTestsTKeyDocument(), new CreateTestsTKeyDocument() };
+ // Act
+ await SUT.AddManyAsync(documents);
+ // Assert
+ long count = SUT.Count(e => e.Id == documents[0].Id || e.Id == documents[1].Id);
+ Assert.AreEqual(2, count);
+ }
+ }
+}
diff --git a/IntegrationTests/DeletePartitionedTKeyTests.cs b/IntegrationTests/DeletePartitionedTKeyTests.cs
new file mode 100644
index 0000000..b213cb4
--- /dev/null
+++ b/IntegrationTests/DeletePartitionedTKeyTests.cs
@@ -0,0 +1,137 @@
+using IntegrationTests.Infrastructure;
+using MongoDB.Bson.Serialization.Attributes;
+using MongoDbGenericRepository.Models;
+using NUnit.Framework;
+using System;
+using System.Threading.Tasks;
+
+namespace IntegrationTests
+{
+ public class DeleteTestsPartitionedTKeyDocument : IPartitionedDocument, IDocument
+ {
+ [BsonId]
+ public Guid Id { get; set; }
+ public int Version { get; set; }
+ public DeleteTestsPartitionedTKeyDocument()
+ {
+ Id = Guid.NewGuid();
+ Version = 2;
+ PartitionKey = "TestPartitionKey";
+ }
+ public string PartitionKey { get; set; }
+ public string SomeContent { get; set; }
+ }
+
+ public class DeletePartitionedTKeyTests : BaseMongoDbRepositoryTests
+ {
+ [Test]
+ public void PartitionedDeleteOne()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ // Act
+ var result = SUT.DeleteOne(document);
+ // Assert
+ Assert.AreEqual(1, result);
+ Assert.IsFalse(SUT.Any(e => e.Id == document.Id, PartitionKey));
+ }
+
+ [Test]
+ public void PartitionedDeleteOneLinq()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ // Act
+ var result = SUT.DeleteOne(e => e.Id == document.Id, PartitionKey);
+ // Assert
+ Assert.AreEqual(1, result);
+ Assert.IsFalse(SUT.Any(e => e.Id == document.Id, PartitionKey));
+ }
+
+ [Test]
+ public async Task PartitionedDeleteOneAsync()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ // Act
+ var result = await SUT.DeleteOneAsync(document);
+ // Assert
+ Assert.AreEqual(1, result);
+ Assert.IsFalse(SUT.Any(e => e.Id == document.Id, PartitionKey));
+ }
+
+ [Test]
+ public async Task PartitionedDeleteOneAsyncLinq()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ // Act
+ var result = await SUT.DeleteOneAsync(e => e.Id == document.Id, PartitionKey);
+ // Assert
+ Assert.AreEqual(1, result);
+ Assert.IsFalse(SUT.Any(e => e.Id == document.Id, PartitionKey));
+ }
+
+ [Test]
+ public async Task PartitionedDeleteManyAsyncLinq()
+ {
+ // Arrange
+ var documents = CreateTestDocuments(5);
+ documents.ForEach(e => e.SomeContent = "DeleteManyAsyncLinqContent");
+ SUT.AddMany(documents);
+ // Act
+ var result = await SUT.DeleteManyAsync(e => e.SomeContent == "DeleteManyAsyncLinqContent", PartitionKey);
+ // Assert
+ Assert.AreEqual(5, result);
+ Assert.IsFalse(SUT.Any(e => e.SomeContent == "DeleteManyAsyncLinqContent", PartitionKey));
+ }
+
+ [Test]
+ public async Task PartitionedDeleteManyAsync()
+ {
+ // Arrange
+ var documents = CreateTestDocuments(5);
+ documents.ForEach(e => e.SomeContent = "DeleteManyAsyncLinqContent");
+ SUT.AddMany(documents);
+ // Act
+ var result = await SUT.DeleteManyAsync(documents);
+ // Assert
+ Assert.AreEqual(5, result);
+ Assert.IsFalse(SUT.Any(e => e.SomeContent == "DeleteManyAsyncLinqContent", PartitionKey));
+ }
+
+ [Test]
+ public void PartitionedDeleteManyLinq()
+ {
+ // Arrange
+ var content = "DeleteManyLinqContent";
+ var documents = CreateTestDocuments(5);
+ documents.ForEach(e => e.SomeContent = content);
+ SUT.AddMany(documents);
+ // Act
+ var result = SUT.DeleteMany(e => e.SomeContent == content, PartitionKey);
+ // Assert
+ Assert.AreEqual(5, result);
+ Assert.IsFalse(SUT.Any(e => e.SomeContent == content, PartitionKey));
+ }
+
+ [Test]
+ public void PartitionedDeleteMany()
+ {
+ // Arrange
+ var content = "DeleteManyContent";
+ var documents = CreateTestDocuments(5);
+ documents.ForEach(e => e.SomeContent = content);
+ SUT.AddMany(documents);
+ // Act
+ var result = SUT.DeleteMany(documents);
+ // Assert
+ Assert.AreEqual(5, result);
+ Assert.IsFalse(SUT.Any(e => e.SomeContent == content, PartitionKey));
+ }
+ }
+}
diff --git a/IntegrationTests/DeleteTKeyTests.cs b/IntegrationTests/DeleteTKeyTests.cs
new file mode 100644
index 0000000..dd90c09
--- /dev/null
+++ b/IntegrationTests/DeleteTKeyTests.cs
@@ -0,0 +1,135 @@
+using IntegrationTests.Infrastructure;
+using MongoDB.Bson.Serialization.Attributes;
+using MongoDbGenericRepository.Models;
+using NUnit.Framework;
+using System;
+using System.Threading.Tasks;
+
+namespace IntegrationTests
+{
+ public class DeleteTestsTKeyDocument : IDocument
+ {
+ [BsonId]
+ public Guid Id { get; set; }
+ public int Version { get; set; }
+ public DeleteTestsTKeyDocument()
+ {
+ Id = Guid.NewGuid();
+ Version = 2;
+ }
+ public string SomeContent { get; set; }
+ }
+
+ public class DeleteTKeyTests : BaseMongoDbRepositoryTests
+ {
+ [Test]
+ public void DeleteOne()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ // Act
+ var result = SUT.DeleteOne(document);
+ // Assert
+ Assert.AreEqual(1, result);
+ Assert.IsFalse(SUT.Any(e => e.Id == document.Id));
+ }
+
+ [Test]
+ public void DeleteOneLinq()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ // Act
+ var result = SUT.DeleteOne(e => e.Id == document.Id);
+ // Assert
+ Assert.AreEqual(1, result);
+ Assert.IsFalse(SUT.Any(e => e.Id == document.Id));
+ }
+
+ [Test]
+ public async Task DeleteOneAsync()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ // Act
+ var result = await SUT.DeleteOneAsync(document);
+ // Assert
+ Assert.AreEqual(1, result);
+ Assert.IsFalse(SUT.Any(e => e.Id == document.Id));
+ }
+
+ [Test]
+ public async Task DeleteOneAsyncLinq()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ // Act
+ var result = await SUT.DeleteOneAsync(e => e.Id == document.Id);
+ // Assert
+ Assert.AreEqual(1, result);
+ Assert.IsFalse(SUT.Any(e => e.Id == document.Id));
+ }
+
+ [Test]
+ public async Task DeleteManyAsyncLinq()
+ {
+ // Arrange
+ var documents = CreateTestDocuments(5);
+ documents.ForEach(e => e.SomeContent = "DeleteManyAsyncLinqContent");
+ SUT.AddMany(documents);
+ // Act
+ var result = await SUT.DeleteManyAsync(e => e.SomeContent == "DeleteManyAsyncLinqContent");
+ // Assert
+ Assert.AreEqual(5, result);
+ Assert.IsFalse(SUT.Any(e => e.SomeContent == "DeleteManyAsyncLinqContent"));
+ }
+
+ [Test]
+ public async Task DeleteManyAsync()
+ {
+ // Arrange
+ var documents = CreateTestDocuments(5);
+ documents.ForEach(e => e.SomeContent = "DeleteManyAsyncLinqContent");
+ SUT.AddMany(documents);
+ // Act
+ var result = await SUT.DeleteManyAsync(documents);
+ // Assert
+ Assert.AreEqual(5, result);
+ Assert.IsFalse(SUT.Any(e => e.SomeContent == "DeleteManyAsyncLinqContent"));
+ }
+
+ [Test]
+ public void DeleteManyLinq()
+ {
+ // Arrange
+ var content = "DeleteManyLinqContent";
+ var documents = CreateTestDocuments(5);
+ documents.ForEach(e => e.SomeContent = content);
+ SUT.AddMany(documents);
+ // Act
+ var result = SUT.DeleteMany(e => e.SomeContent == content);
+ // Assert
+ Assert.AreEqual(5, result);
+ Assert.IsFalse(SUT.Any(e => e.SomeContent == content));
+ }
+
+ [Test]
+ public void DeleteMany()
+ {
+ // Arrange
+ var content = "DeleteManyContent";
+ var documents = CreateTestDocuments(5);
+ documents.ForEach(e => e.SomeContent = content);
+ SUT.AddMany(documents);
+ // Act
+ var result = SUT.DeleteMany(documents);
+ // Assert
+ Assert.AreEqual(5, result);
+ Assert.IsFalse(SUT.Any(e => e.SomeContent == content));
+ }
+ }
+}
diff --git a/IntegrationTests/GroupTests/GroupingTests.cs b/IntegrationTests/GroupTests/GroupingTests.cs
new file mode 100644
index 0000000..751af45
--- /dev/null
+++ b/IntegrationTests/GroupTests/GroupingTests.cs
@@ -0,0 +1,108 @@
+using IntegrationTests.Infrastructure;
+using MongoDbGenericRepository.Models;
+using NUnit.Framework;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace IntegrationTests.GroupTests
+{
+ public class GroupingTestsDocument : Document
+ {
+ public GroupingTestsDocument()
+ {
+ Version = 2;
+ Children = new List();
+ }
+ public string SomeContent { get; set; }
+ public int GroupingKey { get; set; }
+ public List Children { get; set; }
+ }
+
+ public class ProjectedGroup
+ {
+ public int Key { get; set; }
+ public List Content { get; set; }
+ }
+
+ public class GroupingTests : BaseMongoDbRepositoryTests
+ {
+ [Test]
+ public void GroupByTProjection()
+ {
+ // Arrange
+ var documents = CreateTestDocuments(5);
+ for(var i = 0; i < documents.Count - 2; i++)
+ {
+ documents[i].GroupingKey = 1;
+ documents[i].SomeContent = $"content-{i}";
+ }
+ for (var i = 3; i < documents.Count; i++)
+ {
+ documents[i].GroupingKey = 2;
+ documents[i].SomeContent = $"content-{i}";
+ }
+ SUT.AddMany(documents);
+
+ // Act
+
+ var result = SUT.GroupBy(
+ e => e.GroupingKey, g => new ProjectedGroup {
+ Key = g.Key,
+ Content = g.Select(doc => doc.SomeContent).ToList()
+ });
+
+ // Assert
+ var key1Group = result.First(e => e.Key == 1);
+ Assert.NotNull(key1Group);
+ Assert.AreEqual(3, key1Group.Content.Count);
+ var key2Group = result.First(e => e.Key == 2);
+ Assert.NotNull(key2Group);
+ Assert.AreEqual(2, key2Group.Content.Count);
+ }
+
+ [Test]
+ public void FilteredGroupByTProjection()
+ {
+ // Arrange
+ var documents = CreateTestDocuments(5);
+ for (var i = 0; i < documents.Count - 2; i++)
+ {
+ documents[i].GroupingKey = 4;
+ documents[i].SomeContent = $"content-{i}";
+ }
+ for (var i = 3; i < documents.Count; i++)
+ {
+ documents[i].GroupingKey = 5;
+ documents[i].SomeContent = $"content-{i}";
+ }
+ var guid1 = Guid.NewGuid().ToString("n");
+ var guid2 = Guid.NewGuid().ToString("n");
+ for (var i = 0; i < documents.Count - 1; i++)
+ {
+ documents[i].Children = new List {
+ new Child(guid1, guid2)
+ };
+ }
+
+ SUT.AddMany(documents);
+
+ // Act
+ var result = SUT.GroupBy(
+ e => e.Children.Any(c => c.Type == guid1),
+ e => e.GroupingKey, g => new ProjectedGroup
+ {
+ Key = g.Key,
+ Content = g.Select(doc => doc.SomeContent).ToList()
+ });
+
+ // Assert
+ var key1Group = result.First(e => e.Key == 4);
+ Assert.NotNull(key1Group);
+ Assert.AreEqual(3, key1Group.Content.Count);
+ var key2Group = result.First(e => e.Key == 5);
+ Assert.NotNull(key2Group);
+ Assert.AreEqual(1, key2Group.Content.Count);
+ }
+ }
+}
diff --git a/IntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs b/IntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs
index 74d358e..1c7b43f 100644
--- a/IntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs
+++ b/IntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs
@@ -5,7 +5,7 @@ using System.Configuration;
namespace IntegrationTests.Infrastructure
{
- public class BaseMongoDbRepositoryTests where T : Document, new()
+ public class BaseMongoDbRepositoryTests where T : class, new()
{
public T CreateTestDocument()
{
diff --git a/IntegrationTests/Infrastructure/Child.cs b/IntegrationTests/Infrastructure/Child.cs
new file mode 100644
index 0000000..cf9d1ec
--- /dev/null
+++ b/IntegrationTests/Infrastructure/Child.cs
@@ -0,0 +1,14 @@
+namespace IntegrationTests.Infrastructure
+{
+ public class Child
+ {
+ public Child(string type, string value)
+ {
+ Type = type;
+ Value = value;
+ }
+
+ public string Type { get; set; }
+ public string Value { get; set; }
+ }
+}
diff --git a/IntegrationTests/IntegrationTests.csproj b/IntegrationTests/IntegrationTests.csproj
index 58a2d21..d3bb63c 100644
--- a/IntegrationTests/IntegrationTests.csproj
+++ b/IntegrationTests/IntegrationTests.csproj
@@ -31,16 +31,13 @@
- ..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDB.Bson.dll
+ ..\packages\MongoDB.Bson.2.4.4\lib\net45\MongoDB.Bson.dll
- ..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDB.Driver.dll
+ ..\packages\MongoDB.Driver.2.4.4\lib\net45\MongoDB.Driver.dll
- ..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDB.Driver.Core.dll
-
-
- ..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDbGenericRepository.dll
+ ..\packages\MongoDB.Driver.Core.2.4.4\lib\net45\MongoDB.Driver.Core.dll
..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll
@@ -49,24 +46,37 @@
-
- ..\packages\MongoDbGenericRepository.1.2.1\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll
+
+ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll
+ True
+
+
+
+
+
+
+
+
+
+
+
+
@@ -78,5 +88,11 @@
+
+
+ {efc776c4-2af3-440c-be80-3fbe335817a5}
+ MongoDbGenericRepository
+
+
\ No newline at end of file
diff --git a/IntegrationTests/ProjectPartitionedTKeyTests.cs b/IntegrationTests/ProjectPartitionedTKeyTests.cs
new file mode 100644
index 0000000..9d80dde
--- /dev/null
+++ b/IntegrationTests/ProjectPartitionedTKeyTests.cs
@@ -0,0 +1,143 @@
+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/ProjectTKeyTests.cs b/IntegrationTests/ProjectTKeyTests.cs
new file mode 100644
index 0000000..cec8606
--- /dev/null
+++ b/IntegrationTests/ProjectTKeyTests.cs
@@ -0,0 +1,150 @@
+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/ReadPartitionedTKeyTests.cs b/IntegrationTests/ReadPartitionedTKeyTests.cs
new file mode 100644
index 0000000..ceab08e
--- /dev/null
+++ b/IntegrationTests/ReadPartitionedTKeyTests.cs
@@ -0,0 +1,189 @@
+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/ReadTKeyTests.cs b/IntegrationTests/ReadTKeyTests.cs
new file mode 100644
index 0000000..e2e6330
--- /dev/null
+++ b/IntegrationTests/ReadTKeyTests.cs
@@ -0,0 +1,187 @@
+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);
+ }
+ }
+}
diff --git a/IntegrationTests/UpdatePartitionedTKeyTests.cs b/IntegrationTests/UpdatePartitionedTKeyTests.cs
new file mode 100644
index 0000000..41c66cf
--- /dev/null
+++ b/IntegrationTests/UpdatePartitionedTKeyTests.cs
@@ -0,0 +1,117 @@
+using IntegrationTests.Infrastructure;
+using MongoDB.Bson.Serialization.Attributes;
+using MongoDB.Driver;
+using MongoDbGenericRepository.Models;
+using NUnit.Framework;
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace IntegrationTests
+{
+
+ public class UpdateTestsPartitionedTKeyDocument : IDocument, IPartitionedDocument
+ {
+ [BsonId]
+ public Guid Id { get; set; }
+ public int Version { get; set; }
+ public UpdateTestsPartitionedTKeyDocument()
+ {
+ Id = Guid.NewGuid();
+ Version = 2;
+ PartitionKey = "TestPartitionKey";
+ Children = new List();
+ }
+ public string PartitionKey { get; set; }
+ public string SomeContent { get; set; }
+ public List Children { get; set; }
+ }
+
+ [TestFixture]
+ public class UpdatePartitionedTKeyTests : BaseMongoDbRepositoryTests
+ {
+ [Test]
+ public void PartitionedUpdateOne()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ document.SomeContent = "UpdateOneContent";
+ // Act
+ var result = SUT.UpdateOne(document);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id, PartitionKey);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual("UpdateOneContent", updatedDocument.SomeContent);
+ }
+
+ [Test]
+ public async Task PartitionedUpdateOneAsync()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ document.SomeContent = "UpdateOneAsyncContent";
+ // Act
+ var result = await SUT.UpdateOneAsync(document);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id, PartitionKey);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual("UpdateOneAsyncContent", updatedDocument.SomeContent);
+ }
+
+ [Test]
+ public async Task UpdateOneAsyncWithUpdateDefinition()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd);
+
+ // Act
+ var result = await SUT.UpdateOneAsync(document, updateDef);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id, document.PartitionKey);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
+
+ [Test]
+ public void UpdateOneWithUpdateDefinition()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd);
+
+ // Act
+ var result = SUT.UpdateOne(document, updateDef);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id, document.PartitionKey);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
+ }
+}
diff --git a/IntegrationTests/UpdatePartitionedTests.cs b/IntegrationTests/UpdatePartitionedTests.cs
index 3c0fa8a..fd7e3f9 100644
--- a/IntegrationTests/UpdatePartitionedTests.cs
+++ b/IntegrationTests/UpdatePartitionedTests.cs
@@ -1,6 +1,8 @@
using IntegrationTests.Infrastructure;
+using MongoDB.Driver;
using MongoDbGenericRepository.Models;
using NUnit.Framework;
+using System.Collections.Generic;
using System.Threading.Tasks;
namespace IntegrationTests
@@ -10,8 +12,10 @@ namespace IntegrationTests
public UpdateTestsPartitionedDocument() : base("TestPartitionKey")
{
Version = 2;
+ Children = new List();
}
public string SomeContent { get; set; }
+ public List Children { get; set; }
}
public class UpdatePartitionedTests : BaseMongoDbRepositoryTests
@@ -47,5 +51,155 @@ namespace IntegrationTests
Assert.IsNotNull(updatedDocument);
Assert.AreEqual("UpdateOneAsyncContent", updatedDocument.SomeContent);
}
+
+ [Test]
+ public async Task UpdateOneAsyncWithUpdateDefinition()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd);
+
+ // Act
+ var result = await SUT.UpdateOneAsync(document, updateDef);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id, document.PartitionKey);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
+
+ [Test]
+ public void UpdateOneWithUpdateDefinition()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd);
+
+ // Act
+ var result = SUT.UpdateOne(document, updateDef);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id, document.PartitionKey);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
+
+ [Test]
+ public void UpdateOneWithFieldSelector()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ // Act
+ var result = SUT.UpdateOne(document, x => x.Children, childrenToAdd);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id, document.PartitionKey);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
+
+ [Test]
+ public async Task UpdateOneAsyncWithFieldSelector()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ // Act
+ var result = await SUT.UpdateOneAsync(document, x => x.Children, childrenToAdd);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id, document.PartitionKey);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
+
+ [Test]
+ public void UpdateOneWithFilterAndFieldSelector()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ // Act
+ var filter = Builders.Filter.Eq("Id", document.Id);
+ var result = SUT.UpdateOne(filter, x => x.Children, childrenToAdd, document.PartitionKey);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id, document.PartitionKey);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
+
+ [Test]
+ public async Task UpdateOneAsyncWithFilterAndFieldSelector()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ // Act
+ var filter = Builders.Filter.Eq("Id", document.Id);
+ var result = await SUT.UpdateOneAsync(filter, x => x.Children, childrenToAdd, document.PartitionKey);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id, document.PartitionKey);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
}
}
diff --git a/IntegrationTests/UpdateTKeyTests.cs b/IntegrationTests/UpdateTKeyTests.cs
new file mode 100644
index 0000000..f981196
--- /dev/null
+++ b/IntegrationTests/UpdateTKeyTests.cs
@@ -0,0 +1,195 @@
+using IntegrationTests.Infrastructure;
+using MongoDB.Bson.Serialization.Attributes;
+using MongoDB.Driver;
+using MongoDbGenericRepository.Models;
+using NUnit.Framework;
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace IntegrationTests
+{
+
+ public class UpdateTestsTKeyDocument : IDocument
+ {
+ [BsonId]
+ public Guid Id { get; set; }
+ public int Version { get; set; }
+ public UpdateTestsTKeyDocument()
+ {
+ Id = Guid.NewGuid();
+ Version = 2;
+ Children = new List();
+ }
+ public string SomeContent { get; set; }
+ public List Children { get; set; }
+ }
+
+ [TestFixture]
+ public class UpdateTKeyTests : BaseMongoDbRepositoryTests
+ {
+ [Test]
+ public void UpdateOne()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ document.SomeContent = "UpdateOneContent";
+ // Act
+ var result = SUT.UpdateOne(document);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual("UpdateOneContent", updatedDocument.SomeContent);
+ }
+
+ [Test]
+ public async Task UpdateOneAsync()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ document.SomeContent = "UpdateOneAsyncContent";
+ // Act
+ var result = await SUT.UpdateOneAsync(document);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual("UpdateOneAsyncContent", updatedDocument.SomeContent);
+ }
+
+ [Test]
+ public async Task UpdateOneAsyncWithUpdateDefinition()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd);
+ // Act
+ var result = await SUT.UpdateOneAsync(document, updateDef);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
+
+ [Test]
+ public void UpdateOneWithUpdateDefinition()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd);
+
+ // Act
+ var result = SUT.UpdateOne(document, updateDef);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
+
+ [Test]
+ public void UpdateOneWithFieldSelector()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ var filter = Builders.Filter.Eq("Id", document.Id);
+
+ // Act
+ var result = SUT.UpdateOne>(document, x => x.Children, childrenToAdd);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
+
+ [Test]
+ public async Task UpdateOneAsyncWithFieldSelector()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ var filter = Builders.Filter.Eq("Id", document.Id);
+
+ // Act
+ var result = await SUT.UpdateOneAsync>(document, x => x.Children, childrenToAdd);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
+
+ [Test]
+ public void UpdateOneWithFilterAndFieldSelector()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ var filter = Builders.Filter.Eq("Id", document.Id);
+
+ // Act
+ var result = SUT.UpdateOne>(filter, x => x.Children, childrenToAdd);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
+ }
+}
diff --git a/IntegrationTests/UpdateTests.cs b/IntegrationTests/UpdateTests.cs
index 328c3f3..ee5bb17 100644
--- a/IntegrationTests/UpdateTests.cs
+++ b/IntegrationTests/UpdateTests.cs
@@ -1,6 +1,8 @@
using IntegrationTests.Infrastructure;
+using MongoDB.Driver;
using MongoDbGenericRepository.Models;
using NUnit.Framework;
+using System.Collections.Generic;
using System.Threading.Tasks;
namespace IntegrationTests
@@ -10,8 +12,10 @@ namespace IntegrationTests
public UpdateTestsDocument()
{
Version = 2;
+ Children = new List();
}
public string SomeContent { get; set; }
+ public List Children { get; set; }
}
public class UpdateTests : BaseMongoDbRepositoryTests
@@ -47,5 +51,155 @@ namespace IntegrationTests
Assert.IsNotNull(updatedDocument);
Assert.AreEqual("UpdateOneAsyncContent", updatedDocument.SomeContent);
}
+
+ [Test]
+ public async Task UpdateOneAsyncWithUpdateDefinition()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd);
+
+ // Act
+ var result = await SUT.UpdateOneAsync(document, updateDef);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
+
+ [Test]
+ public void UpdateOneWithUpdateDefinition()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ var updateDef = Builders.Update.AddToSetEach(p => p.Children, childrenToAdd);
+
+ // Act
+ var result = SUT.UpdateOne(document, updateDef);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
+
+ [Test]
+ public void UpdateOneWithFieldSelector()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ // Act
+ var result = SUT.UpdateOne(document, x => x.Children, childrenToAdd);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById(document.Id);
+ Assert.IsNotNull(updatedDocument);
+ Assert.AreEqual(childrenToAdd[0].Type, updatedDocument.Children[0].Type);
+ Assert.AreEqual(childrenToAdd[0].Value, updatedDocument.Children[0].Value);
+ Assert.AreEqual(childrenToAdd[1].Type, updatedDocument.Children[1].Type);
+ Assert.AreEqual(childrenToAdd[1].Value, updatedDocument.Children[1].Value);
+ }
+
+ [Test]
+ public async Task UpdateOneAsyncWithFieldSelector()
+ {
+ // Arrange
+ var document = CreateTestDocument();
+ SUT.AddOne(document);
+ var childrenToAdd = new List
+ {
+ new Child("testType1", "testValue1"),
+ new Child("testType2", "testValue2")
+ };
+
+ // Act
+ var result = await SUT.UpdateOneAsync(document, x => x.Children, childrenToAdd);
+ // Assert
+ Assert.IsTrue(result);
+ var updatedDocument = SUT.GetById