Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bfe1652b9c | |||
| 9c0cd0fe47 | |||
| c07b1a5d7b | |||
| 76862b2caa | |||
| a13800637f | |||
| 1d985e0274 | |||
| 833263edbf | |||
| 6552a01d28 | |||
| 9b1048e318 |
@@ -7,13 +7,16 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.4.4" />
|
||||
<PackageReference Include="MongoDbGenericRepository" Version="1.2.1" />
|
||||
<PackageReference Include="xunit" Version="2.3.0-beta5-build3769" />
|
||||
<PackageReference Include="xunit.runner.console" Version="2.3.0-beta5-build3769" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta5-build3769" />
|
||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta4-build3742" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MongoDbGenericRepository\MongoDbGenericRepository.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="App.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
|
||||
@@ -7,4 +7,12 @@
|
||||
<connectionStrings>
|
||||
<add name="MongoDbTests" connectionString="mongodb://localhost:27017" />
|
||||
</connectionStrings>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -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<Guid>, 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<CreateTestsPartitionedTKeyDocument>
|
||||
{
|
||||
[Test]
|
||||
public void PartitionedAddOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = new CreateTestsPartitionedTKeyDocument();
|
||||
// Act
|
||||
SUT.AddOne<CreateTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Assert
|
||||
long count = SUT.Count<CreateTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey);
|
||||
Assert.AreEqual(1, count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PartitionedAddOneAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = new CreateTestsPartitionedTKeyDocument();
|
||||
// Act
|
||||
await SUT.AddOneAsync<CreateTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Assert
|
||||
long count = SUT.Count<CreateTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey);
|
||||
Assert.AreEqual(1, count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PartitionedAddMany()
|
||||
{
|
||||
// Arrange
|
||||
var documents = new List<CreateTestsPartitionedTKeyDocument> { new CreateTestsPartitionedTKeyDocument(), new CreateTestsPartitionedTKeyDocument() };
|
||||
// Act
|
||||
SUT.AddMany<CreateTestsPartitionedTKeyDocument, Guid>(documents);
|
||||
// Assert
|
||||
long count = SUT.Count<CreateTestsPartitionedTKeyDocument, Guid>(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<CreateTestsPartitionedTKeyDocument> { new CreateTestsPartitionedTKeyDocument(), new CreateTestsPartitionedTKeyDocument() };
|
||||
// Act
|
||||
await SUT.AddManyAsync<CreateTestsPartitionedTKeyDocument, Guid>(documents);
|
||||
// Assert
|
||||
long count = SUT.Count<CreateTestsPartitionedTKeyDocument, Guid>(e => e.Id == documents[0].Id || e.Id == documents[1].Id, PartitionKey);
|
||||
Assert.AreEqual(2, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Guid>
|
||||
{
|
||||
[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<CreateTestsTKeyDocument>
|
||||
{
|
||||
[Test]
|
||||
public void TKeyAddOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = new CreateTestsTKeyDocument();
|
||||
// Act
|
||||
SUT.AddOne<CreateTestsTKeyDocument, Guid>(document);
|
||||
// Assert
|
||||
long count = SUT.Count<CreateTestsTKeyDocument, Guid>(e => e.Id == document.Id);
|
||||
Assert.AreEqual(1, count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TKeyAddOneAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = new CreateTestsTKeyDocument();
|
||||
// Act
|
||||
await SUT.AddOneAsync<CreateTestsTKeyDocument, Guid>(document);
|
||||
// Assert
|
||||
long count = SUT.Count<CreateTestsTKeyDocument, Guid>(e => e.Id == document.Id);
|
||||
Assert.AreEqual(1, count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TKeyAddMany()
|
||||
{
|
||||
// Arrange
|
||||
var documents = new List<CreateTestsTKeyDocument> { new CreateTestsTKeyDocument(), new CreateTestsTKeyDocument() };
|
||||
// Act
|
||||
SUT.AddMany<CreateTestsTKeyDocument, Guid>(documents);
|
||||
// Assert
|
||||
long count = SUT.Count<CreateTestsTKeyDocument, Guid>(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<CreateTestsTKeyDocument> { new CreateTestsTKeyDocument(), new CreateTestsTKeyDocument() };
|
||||
// Act
|
||||
await SUT.AddManyAsync<CreateTestsTKeyDocument, Guid>(documents);
|
||||
// Assert
|
||||
long count = SUT.Count<CreateTestsTKeyDocument, Guid>(e => e.Id == documents[0].Id || e.Id == documents[1].Id);
|
||||
Assert.AreEqual(2, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Guid>
|
||||
{
|
||||
[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<DeleteTestsPartitionedTKeyDocument>
|
||||
{
|
||||
[Test]
|
||||
public void PartitionedDeleteOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<DeleteTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.DeleteOne<DeleteTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Assert
|
||||
Assert.AreEqual(1, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PartitionedDeleteOneLinq()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<DeleteTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.DeleteOne<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey);
|
||||
// Assert
|
||||
Assert.AreEqual(1, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PartitionedDeleteOneAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<DeleteTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.DeleteOneAsync<DeleteTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Assert
|
||||
Assert.AreEqual(1, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PartitionedDeleteOneAsyncLinq()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<DeleteTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.DeleteOneAsync<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey);
|
||||
// Assert
|
||||
Assert.AreEqual(1, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PartitionedDeleteManyAsyncLinq()
|
||||
{
|
||||
// Arrange
|
||||
var documents = CreateTestDocuments(5);
|
||||
documents.ForEach(e => e.SomeContent = "DeleteManyAsyncLinqContent");
|
||||
SUT.AddMany<DeleteTestsPartitionedTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = await SUT.DeleteManyAsync<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.SomeContent == "DeleteManyAsyncLinqContent", PartitionKey);
|
||||
// Assert
|
||||
Assert.AreEqual(5, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.SomeContent == "DeleteManyAsyncLinqContent", PartitionKey));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PartitionedDeleteManyAsync()
|
||||
{
|
||||
// Arrange
|
||||
var documents = CreateTestDocuments(5);
|
||||
documents.ForEach(e => e.SomeContent = "DeleteManyAsyncLinqContent");
|
||||
SUT.AddMany<DeleteTestsPartitionedTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = await SUT.DeleteManyAsync<DeleteTestsPartitionedTKeyDocument, Guid>(documents);
|
||||
// Assert
|
||||
Assert.AreEqual(5, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(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<DeleteTestsPartitionedTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = SUT.DeleteMany<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.SomeContent == content, PartitionKey);
|
||||
// Assert
|
||||
Assert.AreEqual(5, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(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<DeleteTestsPartitionedTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = SUT.DeleteMany<DeleteTestsPartitionedTKeyDocument, Guid>(documents);
|
||||
// Assert
|
||||
Assert.AreEqual(5, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.SomeContent == content, PartitionKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Guid>
|
||||
{
|
||||
[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<DeleteTestsTKeyDocument>
|
||||
{
|
||||
[Test]
|
||||
public void DeleteOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<DeleteTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.DeleteOne<DeleteTestsTKeyDocument, Guid>(document);
|
||||
// Assert
|
||||
Assert.AreEqual(1, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsTKeyDocument, Guid>(e => e.Id == document.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteOneLinq()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<DeleteTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.DeleteOne<DeleteTestsTKeyDocument, Guid>(e => e.Id == document.Id);
|
||||
// Assert
|
||||
Assert.AreEqual(1, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsTKeyDocument, Guid>(e => e.Id == document.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeleteOneAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<DeleteTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.DeleteOneAsync<DeleteTestsTKeyDocument, Guid>(document);
|
||||
// Assert
|
||||
Assert.AreEqual(1, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsTKeyDocument, Guid>(e => e.Id == document.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeleteOneAsyncLinq()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<DeleteTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.DeleteOneAsync<DeleteTestsTKeyDocument, Guid>(e => e.Id == document.Id);
|
||||
// Assert
|
||||
Assert.AreEqual(1, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsTKeyDocument, Guid>(e => e.Id == document.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeleteManyAsyncLinq()
|
||||
{
|
||||
// Arrange
|
||||
var documents = CreateTestDocuments(5);
|
||||
documents.ForEach(e => e.SomeContent = "DeleteManyAsyncLinqContent");
|
||||
SUT.AddMany<DeleteTestsTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = await SUT.DeleteManyAsync<DeleteTestsTKeyDocument, Guid>(e => e.SomeContent == "DeleteManyAsyncLinqContent");
|
||||
// Assert
|
||||
Assert.AreEqual(5, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsTKeyDocument, Guid>(e => e.SomeContent == "DeleteManyAsyncLinqContent"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeleteManyAsync()
|
||||
{
|
||||
// Arrange
|
||||
var documents = CreateTestDocuments(5);
|
||||
documents.ForEach(e => e.SomeContent = "DeleteManyAsyncLinqContent");
|
||||
SUT.AddMany<DeleteTestsTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = await SUT.DeleteManyAsync<DeleteTestsTKeyDocument, Guid>(documents);
|
||||
// Assert
|
||||
Assert.AreEqual(5, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsTKeyDocument, Guid>(e => e.SomeContent == "DeleteManyAsyncLinqContent"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteManyLinq()
|
||||
{
|
||||
// Arrange
|
||||
var content = "DeleteManyLinqContent";
|
||||
var documents = CreateTestDocuments(5);
|
||||
documents.ForEach(e => e.SomeContent = content);
|
||||
SUT.AddMany<DeleteTestsTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = SUT.DeleteMany<DeleteTestsTKeyDocument, Guid>(e => e.SomeContent == content);
|
||||
// Assert
|
||||
Assert.AreEqual(5, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsTKeyDocument, Guid>(e => e.SomeContent == content));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteMany()
|
||||
{
|
||||
// Arrange
|
||||
var content = "DeleteManyContent";
|
||||
var documents = CreateTestDocuments(5);
|
||||
documents.ForEach(e => e.SomeContent = content);
|
||||
SUT.AddMany<DeleteTestsTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = SUT.DeleteMany<DeleteTestsTKeyDocument, Guid>(documents);
|
||||
// Assert
|
||||
Assert.AreEqual(5, result);
|
||||
Assert.IsFalse(SUT.Any<DeleteTestsTKeyDocument, Guid>(e => e.SomeContent == content));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Child>();
|
||||
}
|
||||
public string SomeContent { get; set; }
|
||||
public int GroupingKey { get; set; }
|
||||
public List<Child> Children { get; set; }
|
||||
}
|
||||
|
||||
public class ProjectedGroup
|
||||
{
|
||||
public int Key { get; set; }
|
||||
public List<string> Content { get; set; }
|
||||
}
|
||||
|
||||
public class GroupingTests : BaseMongoDbRepositoryTests<GroupingTestsDocument>
|
||||
{
|
||||
[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<GroupingTestsDocument, int, ProjectedGroup>(
|
||||
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<Child> {
|
||||
new Child(guid1, guid2)
|
||||
};
|
||||
}
|
||||
|
||||
SUT.AddMany(documents);
|
||||
|
||||
// Act
|
||||
var result = SUT.GroupBy<GroupingTestsDocument, int, ProjectedGroup>(
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using System.Configuration;
|
||||
|
||||
namespace IntegrationTests.Infrastructure
|
||||
{
|
||||
public class BaseMongoDbRepositoryTests<T> where T : Document, new()
|
||||
public class BaseMongoDbRepositoryTests<T> where T : class, new()
|
||||
{
|
||||
public T CreateTestDocument()
|
||||
{
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -31,16 +31,13 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MongoDB.Bson, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDB.Bson.dll</HintPath>
|
||||
<HintPath>..\packages\MongoDB.Bson.2.4.4\lib\net45\MongoDB.Bson.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MongoDB.Driver, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDB.Driver.dll</HintPath>
|
||||
<HintPath>..\packages\MongoDB.Driver.2.4.4\lib\net45\MongoDB.Driver.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MongoDB.Driver.Core, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDB.Driver.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MongoDbGenericRepository, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDbGenericRepository.dll</HintPath>
|
||||
<HintPath>..\packages\MongoDB.Driver.Core.2.4.4\lib\net45\MongoDB.Driver.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=3.7.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll</HintPath>
|
||||
@@ -49,24 +46,37 @@
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MongoDbGenericRepository.1.2.1\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
|
||||
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CreateTKeyPartitionedTests.cs" />
|
||||
<Compile Include="CreateTKeyTests.cs" />
|
||||
<Compile Include="DeletePartitionedTKeyTests.cs" />
|
||||
<Compile Include="DeletePartitionedTests.cs" />
|
||||
<Compile Include="DeleteTKeyTests.cs" />
|
||||
<Compile Include="DeleteTests.cs" />
|
||||
<Compile Include="GroupTests\GroupingTests.cs" />
|
||||
<Compile Include="Infrastructure\BaseMongoDbRepositoryTests.cs" />
|
||||
<Compile Include="CreatePartitionedTests.cs" />
|
||||
<Compile Include="Infrastructure\Child.cs" />
|
||||
<Compile Include="Infrastructure\ITestRepository.cs" />
|
||||
<Compile Include="Infrastructure\TestRepository.cs" />
|
||||
<Compile Include="CreateTests.cs" />
|
||||
<Compile Include="ProjectPartitionedTKeyTests.cs" />
|
||||
<Compile Include="ProjectPartitionedTests.cs" />
|
||||
<Compile Include="ProjectTKeyTests.cs" />
|
||||
<Compile Include="ProjectTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ReadPartitionedTKeyTests.cs" />
|
||||
<Compile Include="ReadPartitionedTests.cs" />
|
||||
<Compile Include="ReadTKeyTests.cs" />
|
||||
<Compile Include="ReadTests.cs" />
|
||||
<Compile Include="UpdatePartitionedTKeyTests.cs" />
|
||||
<Compile Include="UpdatePartitionedTests.cs" />
|
||||
<Compile Include="UpdateTKeyTests.cs" />
|
||||
<Compile Include="UpdateTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -78,5 +88,11 @@
|
||||
<ItemGroup>
|
||||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MongoDbGenericRepository\MongoDbGenericRepository.csproj">
|
||||
<Project>{efc776c4-2af3-440c-be80-3fbe335817a5}</Project>
|
||||
<Name>MongoDbGenericRepository</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -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<Guid>, 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<ProjectTestsPartitionedTKeyDocument>
|
||||
{
|
||||
[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<ProjectTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.ProjectOneAsync<ProjectTestsPartitionedTKeyDocument, MyProjection, Guid>(
|
||||
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<ProjectTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.ProjectOne<ProjectTestsPartitionedTKeyDocument, MyProjection, Guid>(
|
||||
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<ProjectTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.ProjectManyAsync<ProjectTestsPartitionedTKeyDocument, MyProjection, Guid>(
|
||||
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<ProjectTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.ProjectMany<ProjectTestsPartitionedTKeyDocument, MyProjection, Guid>(
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Guid>
|
||||
{
|
||||
[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<ProjectTestsTKeyDocument>
|
||||
{
|
||||
[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<ProjectTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.ProjectOneAsync<ProjectTestsTKeyDocument, MyProjection, Guid>(
|
||||
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<ProjectTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.ProjectOne<ProjectTestsTKeyDocument, MyProjection, Guid>(
|
||||
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<ProjectTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.ProjectManyAsync<ProjectTestsTKeyDocument, MyProjection, Guid>(
|
||||
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<ProjectTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.ProjectMany<ProjectTestsTKeyDocument, MyProjection, Guid>(
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Guid>, 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<ReadTestsPartitionedTKeyDocument>
|
||||
{
|
||||
[Test]
|
||||
public async Task PartitionedGetByIdAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.GetByIdAsync<ReadTestsPartitionedTKeyDocument, Guid>(document.Id, PartitionKey);
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PartitionedGetById()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.GetById<ReadTestsPartitionedTKeyDocument, Guid>(document.Id, PartitionKey);
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PartitionedGetOneAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.GetOneAsync<ReadTestsPartitionedTKeyDocument, Guid>(x => x.Id == document.Id, PartitionKey);
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PartitionedGetOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.GetOne<ReadTestsPartitionedTKeyDocument, Guid>(x => x.Id == document.Id, PartitionKey);
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PartitionedGetCursor()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var cursor = SUT.GetCursor<ReadTestsPartitionedTKeyDocument, Guid>(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<ReadTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.AnyAsync<ReadTestsPartitionedTKeyDocument, Guid>(x => x.Id == document.Id, PartitionKey);
|
||||
// Assert
|
||||
Assert.AreEqual(true, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PartitionedAnyAsyncReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.AnyAsync<ReadTestsPartitionedTKeyDocument, Guid>(x => x.Id == Guid.NewGuid(), PartitionKey);
|
||||
// Assert
|
||||
Assert.AreEqual(false, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PartitionedAnyReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.Any<ReadTestsPartitionedTKeyDocument, Guid>(x => x.Id == document.Id, PartitionKey);
|
||||
// Assert
|
||||
Assert.AreEqual(true, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PartitionedAnyReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.Any<ReadTestsPartitionedTKeyDocument, Guid>(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<ReadTestsPartitionedTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = await SUT.GetAllAsync<ReadTestsPartitionedTKeyDocument, Guid>(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<ReadTestsPartitionedTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = SUT.GetAll<ReadTestsPartitionedTKeyDocument, Guid>(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<ReadTestsPartitionedTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = await SUT.CountAsync<ReadTestsPartitionedTKeyDocument, Guid>(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<ReadTestsPartitionedTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = SUT.Count<ReadTestsPartitionedTKeyDocument, Guid>(x => x.SomeContent == "CountContent", PartitionKey);
|
||||
// Assert
|
||||
Assert.AreEqual(5, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Guid>
|
||||
{
|
||||
[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<ReadTestsTKeyDocument>
|
||||
{
|
||||
[Test]
|
||||
public async Task GetByIdAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.GetByIdAsync<ReadTestsTKeyDocument, Guid>(document.Id);
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetById()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.GetById<ReadTestsTKeyDocument, Guid>(document.Id);
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetOneAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.GetOneAsync<ReadTestsTKeyDocument, Guid>(x => x.Id == document.Id);
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.GetOne<ReadTestsTKeyDocument, Guid>(x => x.Id == document.Id);
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetCursor()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var cursor = SUT.GetCursor<ReadTestsTKeyDocument, Guid>(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<ReadTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.AnyAsync<ReadTestsTKeyDocument, Guid>(x => x.Id == document.Id);
|
||||
// Assert
|
||||
Assert.AreEqual(true, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnyAsyncReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = await SUT.AnyAsync<ReadTestsTKeyDocument, Guid>(x => x.Id == Guid.NewGuid());
|
||||
// Assert
|
||||
Assert.AreEqual(false, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnyReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.Any<ReadTestsTKeyDocument, Guid>(x => x.Id == document.Id);
|
||||
// Assert
|
||||
Assert.AreEqual(true, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnyReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<ReadTestsTKeyDocument, Guid>(document);
|
||||
// Act
|
||||
var result = SUT.Any<ReadTestsTKeyDocument, Guid>(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<ReadTestsTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = await SUT.GetAllAsync<ReadTestsTKeyDocument, Guid>(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<ReadTestsTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = SUT.GetAll<ReadTestsTKeyDocument, Guid>(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<ReadTestsTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = await SUT.CountAsync<ReadTestsTKeyDocument, Guid>(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<ReadTestsTKeyDocument, Guid>(documents);
|
||||
// Act
|
||||
var result = SUT.Count<ReadTestsTKeyDocument, Guid>(x => x.SomeContent == "CountContent");
|
||||
// Assert
|
||||
Assert.AreEqual(5, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Guid>, IPartitionedDocument
|
||||
{
|
||||
[BsonId]
|
||||
public Guid Id { get; set; }
|
||||
public int Version { get; set; }
|
||||
public UpdateTestsPartitionedTKeyDocument()
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
Version = 2;
|
||||
PartitionKey = "TestPartitionKey";
|
||||
Children = new List<Child>();
|
||||
}
|
||||
public string PartitionKey { get; set; }
|
||||
public string SomeContent { get; set; }
|
||||
public List<Child> Children { get; set; }
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class UpdatePartitionedTKeyTests : BaseMongoDbRepositoryTests<UpdateTestsPartitionedTKeyDocument>
|
||||
{
|
||||
[Test]
|
||||
public void PartitionedUpdateOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<UpdateTestsPartitionedTKeyDocument, Guid>(document);
|
||||
document.SomeContent = "UpdateOneContent";
|
||||
// Act
|
||||
var result = SUT.UpdateOne<UpdateTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsPartitionedTKeyDocument, Guid>(document.Id, PartitionKey);
|
||||
Assert.IsNotNull(updatedDocument);
|
||||
Assert.AreEqual("UpdateOneContent", updatedDocument.SomeContent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PartitionedUpdateOneAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<UpdateTestsPartitionedTKeyDocument, Guid>(document);
|
||||
document.SomeContent = "UpdateOneAsyncContent";
|
||||
// Act
|
||||
var result = await SUT.UpdateOneAsync<UpdateTestsPartitionedTKeyDocument, Guid>(document);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsPartitionedTKeyDocument, Guid>(document.Id, PartitionKey);
|
||||
Assert.IsNotNull(updatedDocument);
|
||||
Assert.AreEqual("UpdateOneAsyncContent", updatedDocument.SomeContent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateOneAsyncWithUpdateDefinition()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<UpdateTestsPartitionedTKeyDocument, Guid>(document);
|
||||
var childrenToAdd = new List<Child>
|
||||
{
|
||||
new Child("testType1", "testValue1"),
|
||||
new Child("testType2", "testValue2")
|
||||
};
|
||||
|
||||
var updateDef = Builders<UpdateTestsPartitionedTKeyDocument>.Update.AddToSetEach(p => p.Children, childrenToAdd);
|
||||
|
||||
// Act
|
||||
var result = await SUT.UpdateOneAsync<UpdateTestsPartitionedTKeyDocument, Guid>(document, updateDef);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsPartitionedTKeyDocument, Guid>(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<UpdateTestsPartitionedTKeyDocument, Guid>(document);
|
||||
var childrenToAdd = new List<Child>
|
||||
{
|
||||
new Child("testType1", "testValue1"),
|
||||
new Child("testType2", "testValue2")
|
||||
};
|
||||
|
||||
var updateDef = Builders<UpdateTestsPartitionedTKeyDocument>.Update.AddToSetEach(p => p.Children, childrenToAdd);
|
||||
|
||||
// Act
|
||||
var result = SUT.UpdateOne<UpdateTestsPartitionedTKeyDocument, Guid>(document, updateDef);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsPartitionedTKeyDocument, Guid>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Child>();
|
||||
}
|
||||
public string SomeContent { get; set; }
|
||||
public List<Child> Children { get; set; }
|
||||
}
|
||||
|
||||
public class UpdatePartitionedTests : BaseMongoDbRepositoryTests<UpdateTestsPartitionedDocument>
|
||||
@@ -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<UpdateTestsPartitionedDocument>(document);
|
||||
var childrenToAdd = new List<Child>
|
||||
{
|
||||
new Child("testType1", "testValue1"),
|
||||
new Child("testType2", "testValue2")
|
||||
};
|
||||
|
||||
var updateDef = Builders<UpdateTestsPartitionedDocument>.Update.AddToSetEach(p => p.Children, childrenToAdd);
|
||||
|
||||
// Act
|
||||
var result = await SUT.UpdateOneAsync<UpdateTestsPartitionedDocument>(document, updateDef);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsPartitionedDocument>(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<UpdateTestsPartitionedDocument>(document);
|
||||
var childrenToAdd = new List<Child>
|
||||
{
|
||||
new Child("testType1", "testValue1"),
|
||||
new Child("testType2", "testValue2")
|
||||
};
|
||||
|
||||
var updateDef = Builders<UpdateTestsPartitionedDocument>.Update.AddToSetEach(p => p.Children, childrenToAdd);
|
||||
|
||||
// Act
|
||||
var result = SUT.UpdateOne<UpdateTestsPartitionedDocument>(document, updateDef);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsPartitionedDocument>(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<Child>
|
||||
{
|
||||
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<UpdateTestsPartitionedDocument>(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<Child>
|
||||
{
|
||||
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<UpdateTestsPartitionedDocument>(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<Child>
|
||||
{
|
||||
new Child("testType1", "testValue1"),
|
||||
new Child("testType2", "testValue2")
|
||||
};
|
||||
|
||||
// Act
|
||||
var filter = Builders<UpdateTestsPartitionedDocument>.Filter.Eq("Id", document.Id);
|
||||
var result = SUT.UpdateOne(filter, x => x.Children, childrenToAdd, document.PartitionKey);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsPartitionedDocument>(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<Child>
|
||||
{
|
||||
new Child("testType1", "testValue1"),
|
||||
new Child("testType2", "testValue2")
|
||||
};
|
||||
|
||||
// Act
|
||||
var filter = Builders<UpdateTestsPartitionedDocument>.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<UpdateTestsPartitionedDocument>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Guid>
|
||||
{
|
||||
[BsonId]
|
||||
public Guid Id { get; set; }
|
||||
public int Version { get; set; }
|
||||
public UpdateTestsTKeyDocument()
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
Version = 2;
|
||||
Children = new List<Child>();
|
||||
}
|
||||
public string SomeContent { get; set; }
|
||||
public List<Child> Children { get; set; }
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class UpdateTKeyTests : BaseMongoDbRepositoryTests<UpdateTestsTKeyDocument>
|
||||
{
|
||||
[Test]
|
||||
public void UpdateOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<UpdateTestsTKeyDocument, Guid>(document);
|
||||
document.SomeContent = "UpdateOneContent";
|
||||
// Act
|
||||
var result = SUT.UpdateOne<UpdateTestsTKeyDocument, Guid>(document);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsTKeyDocument, Guid>(document.Id);
|
||||
Assert.IsNotNull(updatedDocument);
|
||||
Assert.AreEqual("UpdateOneContent", updatedDocument.SomeContent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateOneAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<UpdateTestsTKeyDocument, Guid>(document);
|
||||
document.SomeContent = "UpdateOneAsyncContent";
|
||||
// Act
|
||||
var result = await SUT.UpdateOneAsync<UpdateTestsTKeyDocument, Guid>(document);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsTKeyDocument, Guid>(document.Id);
|
||||
Assert.IsNotNull(updatedDocument);
|
||||
Assert.AreEqual("UpdateOneAsyncContent", updatedDocument.SomeContent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateOneAsyncWithUpdateDefinition()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne<UpdateTestsTKeyDocument, Guid>(document);
|
||||
var childrenToAdd = new List<Child>
|
||||
{
|
||||
new Child("testType1", "testValue1"),
|
||||
new Child("testType2", "testValue2")
|
||||
};
|
||||
|
||||
var updateDef = Builders<UpdateTestsTKeyDocument>.Update.AddToSetEach(p => p.Children, childrenToAdd);
|
||||
// Act
|
||||
var result = await SUT.UpdateOneAsync<UpdateTestsTKeyDocument, Guid>(document, updateDef);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsTKeyDocument, Guid>(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<UpdateTestsTKeyDocument, Guid>(document);
|
||||
var childrenToAdd = new List<Child>
|
||||
{
|
||||
new Child("testType1", "testValue1"),
|
||||
new Child("testType2", "testValue2")
|
||||
};
|
||||
|
||||
var updateDef = Builders<UpdateTestsTKeyDocument>.Update.AddToSetEach(p => p.Children, childrenToAdd);
|
||||
|
||||
// Act
|
||||
var result = SUT.UpdateOne<UpdateTestsTKeyDocument, Guid>(document, updateDef);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsTKeyDocument, Guid>(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<UpdateTestsTKeyDocument, Guid>(document);
|
||||
|
||||
var childrenToAdd = new List<Child>
|
||||
{
|
||||
new Child("testType1", "testValue1"),
|
||||
new Child("testType2", "testValue2")
|
||||
};
|
||||
|
||||
var filter = Builders<UpdateTestsTKeyDocument>.Filter.Eq("Id", document.Id);
|
||||
|
||||
// Act
|
||||
var result = SUT.UpdateOne<UpdateTestsTKeyDocument, Guid, List<Child>>(document, x => x.Children, childrenToAdd);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsTKeyDocument, Guid>(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<UpdateTestsTKeyDocument, Guid>(document);
|
||||
|
||||
var childrenToAdd = new List<Child>
|
||||
{
|
||||
new Child("testType1", "testValue1"),
|
||||
new Child("testType2", "testValue2")
|
||||
};
|
||||
|
||||
var filter = Builders<UpdateTestsTKeyDocument>.Filter.Eq("Id", document.Id);
|
||||
|
||||
// Act
|
||||
var result = await SUT.UpdateOneAsync<UpdateTestsTKeyDocument, Guid, List<Child>>(document, x => x.Children, childrenToAdd);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsTKeyDocument, Guid>(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<UpdateTestsTKeyDocument, Guid>(document);
|
||||
|
||||
var childrenToAdd = new List<Child>
|
||||
{
|
||||
new Child("testType1", "testValue1"),
|
||||
new Child("testType2", "testValue2")
|
||||
};
|
||||
|
||||
var filter = Builders<UpdateTestsTKeyDocument>.Filter.Eq("Id", document.Id);
|
||||
|
||||
// Act
|
||||
var result = SUT.UpdateOne<UpdateTestsTKeyDocument, Guid, List<Child>>(filter, x => x.Children, childrenToAdd);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsTKeyDocument, Guid>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Child>();
|
||||
}
|
||||
public string SomeContent { get; set; }
|
||||
public List<Child> Children { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateTests : BaseMongoDbRepositoryTests<UpdateTestsDocument>
|
||||
@@ -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<Child>
|
||||
{
|
||||
new Child("testType1", "testValue1"),
|
||||
new Child("testType2", "testValue2")
|
||||
};
|
||||
|
||||
var updateDef = Builders<UpdateTestsDocument>.Update.AddToSetEach(p => p.Children, childrenToAdd);
|
||||
|
||||
// Act
|
||||
var result = await SUT.UpdateOneAsync(document, updateDef);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsDocument>(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<Child>
|
||||
{
|
||||
new Child("testType1", "testValue1"),
|
||||
new Child("testType2", "testValue2")
|
||||
};
|
||||
|
||||
var updateDef = Builders<UpdateTestsDocument>.Update.AddToSetEach(p => p.Children, childrenToAdd);
|
||||
|
||||
// Act
|
||||
var result = SUT.UpdateOne(document, updateDef);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsDocument>(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<Child>
|
||||
{
|
||||
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<UpdateTestsDocument>(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<Child>
|
||||
{
|
||||
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<UpdateTestsDocument>(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<Child>
|
||||
{
|
||||
new Child("testType1", "testValue1"),
|
||||
new Child("testType2", "testValue2")
|
||||
};
|
||||
|
||||
// Act
|
||||
var filter = Builders<UpdateTestsDocument>.Filter.Eq("Id", document.Id);
|
||||
var result = SUT.UpdateOne(filter, x => x.Children, childrenToAdd);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsDocument>(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 UpdateOneAsyncWithFilterAndFieldSelector()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
var childrenToAdd = new List<Child>
|
||||
{
|
||||
new Child("testType1", "testValue1"),
|
||||
new Child("testType2", "testValue2")
|
||||
};
|
||||
|
||||
// Act
|
||||
var filter = Builders<UpdateTestsDocument>.Filter.Eq("Id", document.Id);
|
||||
var result = await SUT.UpdateOneAsync(filter, x => x.Children, childrenToAdd);
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsDocument>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
<package id="MongoDB.Bson" version="2.4.4" targetFramework="net461" />
|
||||
<package id="MongoDB.Driver" version="2.4.4" targetFramework="net461" />
|
||||
<package id="MongoDB.Driver.Core" version="2.4.4" targetFramework="net461" />
|
||||
<package id="MongoDbGenericRepository" version="1.2.1" targetFramework="net461" />
|
||||
<package id="NUnit" version="3.7.1" targetFramework="net461" />
|
||||
<package id="NUnit.ConsoleRunner" version="3.7.0" targetFramework="net461" />
|
||||
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.0.0" targetFramework="net461" />
|
||||
<package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net461" />
|
||||
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" />
|
||||
</packages>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,6 @@
|
||||
using MongoDB.Driver;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using System;
|
||||
|
||||
namespace MongoDbGenericRepository
|
||||
{
|
||||
@@ -31,6 +32,16 @@ namespace MongoDbGenericRepository
|
||||
/// <param name="partitionKey">The value of the partition key.</param>
|
||||
IMongoCollection<TDocument> GetCollection<TDocument>(string partitionKey) where TDocument : IDocument;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection for a document type that has a partition key.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="partitionKey">The value of the partition key.</param>
|
||||
IMongoCollection<TDocument> GetCollection<TDocument, TKey>(string partitionKey)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
|
||||
/// <summary>
|
||||
/// Drops a collection, use very carefully.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
|
||||
namespace MongoDbGenericRepository.Models
|
||||
{
|
||||
@@ -6,16 +7,25 @@ namespace MongoDbGenericRepository.Models
|
||||
/// This class represents a basic document that can be stored in MongoDb.
|
||||
/// Your document must implement this class in order for the MongoDbRepository to handle them.
|
||||
/// </summary>
|
||||
public interface IDocument
|
||||
public interface IDocument<TKey> where TKey : IEquatable<TKey>
|
||||
{
|
||||
/// <summary>
|
||||
/// The Guid, which must be decorated with the [BsonId] attribute
|
||||
/// The Primary Key, which must be decorated with the [BsonId] attribute
|
||||
/// if you want the MongoDb C# driver to consider it to be the document ID.
|
||||
/// </summary>
|
||||
Guid Id { get; set; }
|
||||
[BsonId]
|
||||
TKey Id { get; set; }
|
||||
/// <summary>
|
||||
/// A version number, to indicate the version of the schema.
|
||||
/// </summary>
|
||||
int Version { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This class represents a basic document that can be stored in MongoDb.
|
||||
/// Your document must implement this class in order for the MongoDbRepository to handle them.
|
||||
/// </summary>
|
||||
public interface IDocument: IDocument<Guid>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/// This can be useful if you are planning to build a Software as a Service (SaaS) Platform, or if you want to reduce indexing.
|
||||
/// You could for example insert Logs in different collections based on the week and year they where created, or their Log category/source.
|
||||
/// </summary>
|
||||
public interface IPartitionedDocument : IDocument
|
||||
public interface IPartitionedDocument
|
||||
{
|
||||
/// <summary>
|
||||
/// The partition key used to partition your collection.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using MongoDB.Driver;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using System;
|
||||
|
||||
namespace MongoDbGenericRepository
|
||||
{
|
||||
@@ -48,7 +49,7 @@ namespace MongoDbGenericRepository
|
||||
/// <summary>
|
||||
/// The private GetCollection method
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument"></typeparam>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <returns></returns>
|
||||
public IMongoCollection<TDocument> GetCollection<TDocument>()
|
||||
{
|
||||
@@ -58,17 +59,30 @@ namespace MongoDbGenericRepository
|
||||
/// <summary>
|
||||
/// Returns a collection for a document type that has a partition key.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument"></typeparam>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <param name="partitionKey">The value of the partition key.</param>
|
||||
public IMongoCollection<TDocument> GetCollection<TDocument>(string partitionKey) where TDocument : IDocument
|
||||
{
|
||||
return Database.GetCollection<TDocument>(partitionKey +"-"+ Pluralize<TDocument>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection for a document type that has a partition key.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
|
||||
/// <param name="partitionKey">The value of the partition key.</param>
|
||||
public IMongoCollection<TDocument> GetCollection<TDocument, TKey>(string partitionKey)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
return Database.GetCollection<TDocument>(partitionKey + "-" + Pluralize<TDocument>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Drops a collection, use very carefully.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument"></typeparam>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
public void DropCollection<TDocument>()
|
||||
{
|
||||
Database.DropCollection(Pluralize<TDocument>());
|
||||
@@ -77,7 +91,7 @@ namespace MongoDbGenericRepository
|
||||
/// <summary>
|
||||
/// Drops a collection having a partitionkey, use very carefully.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument"></typeparam>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
public void DropCollection<TDocument>(string partitionKey)
|
||||
{
|
||||
Database.DropCollection(partitionKey + "-" + Pluralize<TDocument>());
|
||||
@@ -86,7 +100,7 @@ namespace MongoDbGenericRepository
|
||||
/// <summary>
|
||||
/// Very naively pluralizes a TDocument type name.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument"></typeparam>
|
||||
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
|
||||
/// <returns></returns>
|
||||
private string Pluralize<TDocument>()
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>MongoDbGenericRepository</id>
|
||||
<version>1.2.1</version>
|
||||
<version>1.3</version>
|
||||
<title>MongoDb Generic Repository</title>
|
||||
<authors>Alexandre Spieser</authors>
|
||||
<owners>Alexandre Spieser</owners>
|
||||
@@ -10,7 +10,7 @@
|
||||
<projectUrl>https://github.com/alexandre-spieser/mongodb-generic-repository</projectUrl>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description>A generic repository implementation using the MongoDB C# Sharp 2.0 driver.</description>
|
||||
<releaseNotes>Exposed core MongoDb driver objects and removed the AddedAtUtc property constraint from the IDocument interface.</releaseNotes>
|
||||
<releaseNotes>Added support for Documents that have an Id of type TKey, and implement the IDocument{TKey} interface.</releaseNotes>
|
||||
<copyright>Copyright 2017 (c) Alexandre Spieser. All rights reserved.</copyright>
|
||||
<tags>MongoDb Repository Generic NoSql</tags>
|
||||
</metadata>
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user