cleanup redundant tests.
This commit is contained in:
@@ -1,68 +0,0 @@
|
|||||||
using IntegrationTests.Infrastructure;
|
|
||||||
using MongoDbGenericRepository.Models;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace IntegrationTests
|
|
||||||
{
|
|
||||||
public class CreateTestsPartitionedDocument : PartitionedDocument
|
|
||||||
{
|
|
||||||
public CreateTestsPartitionedDocument() : base("TestPartitionKey")
|
|
||||||
{
|
|
||||||
Version = 1;
|
|
||||||
}
|
|
||||||
public string SomeContent { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CreatePartitionedTests : BaseMongoDbRepositoryTests<CreateTestsPartitionedDocument>
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void PartitionedAddOne()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var document = new CreateTestsPartitionedDocument();
|
|
||||||
// Act
|
|
||||||
SUT.AddOne(document);
|
|
||||||
// Assert
|
|
||||||
long count = SUT.Count<CreateTestsPartitionedDocument>(e => e.Id == document.Id, PartitionKey);
|
|
||||||
Assert.AreEqual(1, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public async Task PartitionedAddOneAsync()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var document = new CreateTestsPartitionedDocument();
|
|
||||||
// Act
|
|
||||||
await SUT.AddOneAsync(document);
|
|
||||||
// Assert
|
|
||||||
long count = SUT.Count<CreateTestsPartitionedDocument>(e => e.Id == document.Id, PartitionKey);
|
|
||||||
Assert.AreEqual(1, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void PartitionedAddMany()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var documents = new List<CreateTestsPartitionedDocument> { new CreateTestsPartitionedDocument(), new CreateTestsPartitionedDocument() };
|
|
||||||
// Act
|
|
||||||
SUT.AddMany(documents);
|
|
||||||
// Assert
|
|
||||||
long count = SUT.Count<CreateTestsPartitionedDocument>(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<CreateTestsPartitionedDocument> { new CreateTestsPartitionedDocument(), new CreateTestsPartitionedDocument() };
|
|
||||||
// Act
|
|
||||||
await SUT.AddManyAsync(documents);
|
|
||||||
// Assert
|
|
||||||
long count = SUT.Count<CreateTestsPartitionedDocument>(e => e.Id == documents[0].Id || e.Id == documents[1].Id, PartitionKey);
|
|
||||||
Assert.AreEqual(2, count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
using IntegrationTests.Infrastructure;
|
|
||||||
using MongoDbGenericRepository.Models;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace IntegrationTests
|
|
||||||
{
|
|
||||||
public class CreateTestsDocument : Document
|
|
||||||
{
|
|
||||||
public CreateTestsDocument()
|
|
||||||
{
|
|
||||||
Version = 2;
|
|
||||||
}
|
|
||||||
public string SomeContent { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
public class CreateTests : BaseMongoDbRepositoryTests<CreateTestsDocument>
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void AddOne()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var document = new CreateTestsDocument();
|
|
||||||
// Act
|
|
||||||
SUT.AddOne(document);
|
|
||||||
// Assert
|
|
||||||
long count = SUT.Count<CreateTestsDocument>(e => e.Id == document.Id);
|
|
||||||
Assert.AreEqual(1, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public async Task AddOneAsync()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var document = new CreateTestsDocument();
|
|
||||||
// Act
|
|
||||||
await SUT.AddOneAsync(document);
|
|
||||||
// Assert
|
|
||||||
long count = SUT.Count<CreateTestsDocument>(e => e.Id == document.Id);
|
|
||||||
Assert.AreEqual(1, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void AddMany()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var documents = new List<CreateTestsDocument> { new CreateTestsDocument(), new CreateTestsDocument() };
|
|
||||||
// Act
|
|
||||||
SUT.AddMany(documents);
|
|
||||||
// Assert
|
|
||||||
long count = SUT.Count<CreateTestsDocument>(e => e.Id == documents[0].Id || e.Id == documents[1].Id);
|
|
||||||
Assert.AreEqual(2, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public async Task AddManyAsync()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var documents = new List<CreateTestsDocument> { new CreateTestsDocument(), new CreateTestsDocument() };
|
|
||||||
// Act
|
|
||||||
await SUT.AddManyAsync(documents);
|
|
||||||
// Assert
|
|
||||||
long count = SUT.Count<CreateTestsDocument>(e => e.Id == documents[0].Id || e.Id == documents[1].Id);
|
|
||||||
Assert.AreEqual(2, count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
using IntegrationTests.Infrastructure;
|
|
||||||
using MongoDbGenericRepository.Models;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace IntegrationTests
|
|
||||||
{
|
|
||||||
public class DeleteTestsPartitionedDocument : PartitionedDocument
|
|
||||||
{
|
|
||||||
public DeleteTestsPartitionedDocument() : base("TestPartitionKey")
|
|
||||||
{
|
|
||||||
Version = 1;
|
|
||||||
}
|
|
||||||
public string SomeContent { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeletePartitionedTests : BaseMongoDbRepositoryTests<DeleteTestsPartitionedDocument>
|
|
||||||
{
|
|
||||||
[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<DeleteTestsPartitionedDocument>(e => e.Id == document.Id, PartitionKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void PartitionedDeleteOneLinq()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var document = CreateTestDocument();
|
|
||||||
SUT.AddOne(document);
|
|
||||||
// Act
|
|
||||||
var result = SUT.DeleteOne<DeleteTestsPartitionedDocument>(e => e.Id == document.Id, PartitionKey);
|
|
||||||
// Assert
|
|
||||||
Assert.AreEqual(1, result);
|
|
||||||
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedDocument>(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<DeleteTestsPartitionedDocument>(e => e.Id == document.Id, PartitionKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public async Task PartitionedDeleteOneAsyncLinq()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var document = CreateTestDocument();
|
|
||||||
SUT.AddOne(document);
|
|
||||||
// Act
|
|
||||||
var result = await SUT.DeleteOneAsync<DeleteTestsPartitionedDocument>(e => e.Id == document.Id, PartitionKey);
|
|
||||||
// Assert
|
|
||||||
Assert.AreEqual(1, result);
|
|
||||||
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedDocument>(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<DeleteTestsPartitionedDocument>(e => e.SomeContent == "DeleteManyAsyncLinqContent", PartitionKey);
|
|
||||||
// Assert
|
|
||||||
Assert.AreEqual(5, result);
|
|
||||||
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedDocument>(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<DeleteTestsPartitionedDocument>(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<DeleteTestsPartitionedDocument>(e => e.SomeContent == content, PartitionKey);
|
|
||||||
// Assert
|
|
||||||
Assert.AreEqual(5, result);
|
|
||||||
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedDocument>(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<DeleteTestsPartitionedDocument>(e => e.SomeContent == content, PartitionKey));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
using IntegrationTests.Infrastructure;
|
|
||||||
using MongoDbGenericRepository.Models;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace IntegrationTests
|
|
||||||
{
|
|
||||||
public class DeleteTestsDocument : Document
|
|
||||||
{
|
|
||||||
public DeleteTestsDocument()
|
|
||||||
{
|
|
||||||
Version = 2;
|
|
||||||
}
|
|
||||||
public string SomeContent { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeleteTests : BaseMongoDbRepositoryTests<DeleteTestsDocument>
|
|
||||||
{
|
|
||||||
[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<DeleteTestsDocument>(e => e.Id == document.Id));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void DeleteOneLinq()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var document = CreateTestDocument();
|
|
||||||
SUT.AddOne(document);
|
|
||||||
// Act
|
|
||||||
var result = SUT.DeleteOne<DeleteTestsDocument>(e => e.Id == document.Id);
|
|
||||||
// Assert
|
|
||||||
Assert.AreEqual(1, result);
|
|
||||||
Assert.IsFalse(SUT.Any<DeleteTestsDocument>(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<DeleteTestsDocument>(e => e.Id == document.Id));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public async Task DeleteOneAsyncLinq()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var document = CreateTestDocument();
|
|
||||||
SUT.AddOne(document);
|
|
||||||
// Act
|
|
||||||
var result = await SUT.DeleteOneAsync<DeleteTestsDocument>(e => e.Id == document.Id);
|
|
||||||
// Assert
|
|
||||||
Assert.AreEqual(1, result);
|
|
||||||
Assert.IsFalse(SUT.Any<DeleteTestsDocument>(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<DeleteTestsDocument>(e => e.SomeContent == "DeleteManyAsyncLinqContent");
|
|
||||||
// Assert
|
|
||||||
Assert.AreEqual(5, result);
|
|
||||||
Assert.IsFalse(SUT.Any<DeleteTestsDocument>(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<DeleteTestsDocument>(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<DeleteTestsDocument>(e => e.SomeContent == content);
|
|
||||||
// Assert
|
|
||||||
Assert.AreEqual(5, result);
|
|
||||||
Assert.IsFalse(SUT.Any<DeleteTestsDocument>(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<DeleteTestsDocument>(e => e.SomeContent == content));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using MongoDB.Bson.Serialization.Attributes;
|
using MongoDbGenericRepository.Models;
|
||||||
using MongoDbGenericRepository.Models;
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -11,6 +10,12 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace IntegrationTests.Infrastructure
|
namespace IntegrationTests.Infrastructure
|
||||||
{
|
{
|
||||||
|
public class MyTestProjection
|
||||||
|
{
|
||||||
|
public string SomeContent { get; set; }
|
||||||
|
public DateTime SomeDate { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class TestDoc : Document
|
public class TestDoc : Document
|
||||||
{
|
{
|
||||||
public TestDoc()
|
public TestDoc()
|
||||||
@@ -31,6 +36,10 @@ namespace IntegrationTests.Infrastructure
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class Nested
|
||||||
|
{
|
||||||
|
public DateTime SomeDate { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public abstract class MongoDbDocumentTestBase<T>
|
public abstract class MongoDbDocumentTestBase<T>
|
||||||
@@ -722,6 +731,7 @@ namespace IntegrationTests.Infrastructure
|
|||||||
#endregion Project
|
#endregion Project
|
||||||
|
|
||||||
#region Test Utils
|
#region Test Utils
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
private string GetCurrentMethod()
|
private string GetCurrentMethod()
|
||||||
{
|
{
|
||||||
@@ -752,4 +762,6 @@ namespace IntegrationTests.Infrastructure
|
|||||||
|
|
||||||
#endregion Test Utils
|
#endregion Test Utils
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,14 +51,11 @@
|
|||||||
<Compile Include="CRUDPartitionedTests.cs" />
|
<Compile Include="CRUDPartitionedTests.cs" />
|
||||||
<Compile Include="CRUDTKeyPartitionedCollectionNameAttributeTests.cs" />
|
<Compile Include="CRUDTKeyPartitionedCollectionNameAttributeTests.cs" />
|
||||||
<Compile Include="CRUDTests.cs" />
|
<Compile Include="CRUDTests.cs" />
|
||||||
<Compile Include="DeleteTests.cs" />
|
|
||||||
<Compile Include="CRUDPartitionedCollectionNameAttributeTests.cs" />
|
<Compile Include="CRUDPartitionedCollectionNameAttributeTests.cs" />
|
||||||
<Compile Include="CRUDTKeyPartitionedTests.cs" />
|
<Compile Include="CRUDTKeyPartitionedTests.cs" />
|
||||||
<Compile Include="CRUDTKeyTests.cs" />
|
<Compile Include="CRUDTKeyTests.cs" />
|
||||||
<Compile Include="DeletePartitionedTests.cs" />
|
|
||||||
<Compile Include="GroupTests\GroupingTests.cs" />
|
<Compile Include="GroupTests\GroupingTests.cs" />
|
||||||
<Compile Include="Infrastructure\BaseMongoDbRepositoryTests.cs" />
|
<Compile Include="Infrastructure\BaseMongoDbRepositoryTests.cs" />
|
||||||
<Compile Include="CreatePartitionedTests.cs" />
|
|
||||||
<Compile Include="Infrastructure\Child.cs" />
|
<Compile Include="Infrastructure\Child.cs" />
|
||||||
<Compile Include="Infrastructure\GlobalVariables.cs" />
|
<Compile Include="Infrastructure\GlobalVariables.cs" />
|
||||||
<Compile Include="Infrastructure\ITestRepository.cs" />
|
<Compile Include="Infrastructure\ITestRepository.cs" />
|
||||||
@@ -66,14 +63,7 @@
|
|||||||
<Compile Include="Infrastructure\MongoDbTKeyDocumentTestBase.cs" />
|
<Compile Include="Infrastructure\MongoDbTKeyDocumentTestBase.cs" />
|
||||||
<Compile Include="Infrastructure\RandomExtensions.cs" />
|
<Compile Include="Infrastructure\RandomExtensions.cs" />
|
||||||
<Compile Include="Infrastructure\TestRepository.cs" />
|
<Compile Include="Infrastructure\TestRepository.cs" />
|
||||||
<Compile Include="CreateTests.cs" />
|
|
||||||
<Compile Include="ProjectPartitionedTests.cs" />
|
|
||||||
<Compile Include="ProjectTests.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="ReadPartitionedTests.cs" />
|
|
||||||
<Compile Include="ReadTests.cs" />
|
|
||||||
<Compile Include="UpdatePartitionedTests.cs" />
|
|
||||||
<Compile Include="UpdateTests.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config">
|
<None Include="App.config">
|
||||||
|
|||||||
@@ -1,140 +0,0 @@
|
|||||||
using IntegrationTests.Infrastructure;
|
|
||||||
using MongoDbGenericRepository.Models;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace IntegrationTests
|
|
||||||
{
|
|
||||||
public class ProjectTestsPartitionedDocument : PartitionedDocument
|
|
||||||
{
|
|
||||||
public ProjectTestsPartitionedDocument() : base("TestPartitionKey")
|
|
||||||
{
|
|
||||||
Version = 2;
|
|
||||||
Nested = new Nested
|
|
||||||
{
|
|
||||||
SomeDate = DateTime.UtcNow
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public string SomeContent { get; set; }
|
|
||||||
|
|
||||||
public Nested Nested { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ProjectPartitionedTests : BaseMongoDbRepositoryTests<ProjectTestsPartitionedDocument>
|
|
||||||
{
|
|
||||||
[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<ProjectTestsPartitionedDocument, MyTestProjection>(
|
|
||||||
x => x.Id == document.Id,
|
|
||||||
x => new MyTestProjection
|
|
||||||
{
|
|
||||||
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<ProjectTestsPartitionedDocument, MyTestProjection>(
|
|
||||||
x => x.Id == document.Id,
|
|
||||||
x => new MyTestProjection
|
|
||||||
{
|
|
||||||
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<ProjectTestsPartitionedDocument, MyTestProjection>(
|
|
||||||
x => x.SomeContent == someContent,
|
|
||||||
x => new MyTestProjection
|
|
||||||
{
|
|
||||||
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<ProjectTestsPartitionedDocument, MyTestProjection>(
|
|
||||||
x => x.SomeContent == someContent,
|
|
||||||
x => new MyTestProjection
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
using IntegrationTests.Infrastructure;
|
|
||||||
using MongoDbGenericRepository.Models;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace IntegrationTests
|
|
||||||
{
|
|
||||||
public class Nested
|
|
||||||
{
|
|
||||||
public DateTime SomeDate { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class MyTestProjection
|
|
||||||
{
|
|
||||||
public DateTime SomeDate { get; set; }
|
|
||||||
public string SomeContent { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ProjectTestsDocument : Document
|
|
||||||
{
|
|
||||||
public ProjectTestsDocument()
|
|
||||||
{
|
|
||||||
Version = 2;
|
|
||||||
Nested = new Nested
|
|
||||||
{
|
|
||||||
SomeDate = DateTime.UtcNow
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public string SomeContent { get; set; }
|
|
||||||
|
|
||||||
public Nested Nested { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ProjectTests : BaseMongoDbRepositoryTests<ProjectTestsDocument>
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
[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<ProjectTestsDocument, MyTestProjection>(
|
|
||||||
x => x.Id == document.Id,
|
|
||||||
x => new MyTestProjection
|
|
||||||
{
|
|
||||||
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<ProjectTestsDocument, MyTestProjection>(
|
|
||||||
x => x.Id == document.Id,
|
|
||||||
x => new MyTestProjection
|
|
||||||
{
|
|
||||||
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<ProjectTestsDocument, MyTestProjection>(
|
|
||||||
x => x.SomeContent == someContent,
|
|
||||||
x => new MyTestProjection
|
|
||||||
{
|
|
||||||
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<ProjectTestsDocument, MyTestProjection>(
|
|
||||||
x => x.SomeContent == someContent,
|
|
||||||
x => new MyTestProjection
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,161 +0,0 @@
|
|||||||
using IntegrationTests.Infrastructure;
|
|
||||||
using MongoDbGenericRepository.Models;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace IntegrationTests
|
|
||||||
{
|
|
||||||
public class ReadTestsPartitionedDocument : PartitionedDocument
|
|
||||||
{
|
|
||||||
public ReadTestsPartitionedDocument() : base("TestPartitionKey")
|
|
||||||
{
|
|
||||||
Version = 1;
|
|
||||||
}
|
|
||||||
public string SomeContent { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ReadPartitionedTests : BaseMongoDbRepositoryTests<ReadTestsPartitionedDocument>
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public async Task PartitionedGetOneAsync()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var document = CreateTestDocument();
|
|
||||||
SUT.AddOne(document);
|
|
||||||
// Act
|
|
||||||
var result = await SUT.GetOneAsync<ReadTestsPartitionedDocument>(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<ReadTestsPartitionedDocument>(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<ReadTestsPartitionedDocument>(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<ReadTestsPartitionedDocument>(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<ReadTestsPartitionedDocument>(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<ReadTestsPartitionedDocument>(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<ReadTestsPartitionedDocument>(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<ReadTestsPartitionedDocument>(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<ReadTestsPartitionedDocument>(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<ReadTestsPartitionedDocument>(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<ReadTestsPartitionedDocument>(x => x.SomeContent == "CountContent", PartitionKey);
|
|
||||||
// Assert
|
|
||||||
Assert.AreEqual(5, result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,182 +0,0 @@
|
|||||||
using IntegrationTests.Infrastructure;
|
|
||||||
using MongoDbGenericRepository.Models;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace IntegrationTests
|
|
||||||
{
|
|
||||||
public class ReadTestsDocument : Document
|
|
||||||
{
|
|
||||||
public ReadTestsDocument()
|
|
||||||
{
|
|
||||||
Version = 2;
|
|
||||||
}
|
|
||||||
public string SomeContent { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
public class ReadTests : BaseMongoDbRepositoryTests<ReadTestsDocument>
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public async Task GetByIdAsync()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var document = CreateTestDocument();
|
|
||||||
SUT.AddOne(document);
|
|
||||||
// Act
|
|
||||||
var result = await SUT.GetByIdAsync<ReadTestsDocument>(document.Id);
|
|
||||||
// Assert
|
|
||||||
Assert.IsNotNull(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetById()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var document = CreateTestDocument();
|
|
||||||
SUT.AddOne(document);
|
|
||||||
// Act
|
|
||||||
var result = SUT.GetById<ReadTestsDocument>(document.Id);
|
|
||||||
// Assert
|
|
||||||
Assert.IsNotNull(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public async Task GetOneAsync()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var document = CreateTestDocument();
|
|
||||||
SUT.AddOne(document);
|
|
||||||
// Act
|
|
||||||
var result = await SUT.GetOneAsync<ReadTestsDocument>(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<ReadTestsDocument>(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<ReadTestsDocument>(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<ReadTestsDocument>(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<ReadTestsDocument>(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<ReadTestsDocument>(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<ReadTestsDocument>(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<ReadTestsDocument>(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<ReadTestsDocument>(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<ReadTestsDocument>(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<ReadTestsDocument>(x => x.SomeContent == "CountContent");
|
|
||||||
// Assert
|
|
||||||
Assert.AreEqual(5, result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,205 +0,0 @@
|
|||||||
using IntegrationTests.Infrastructure;
|
|
||||||
using MongoDB.Driver;
|
|
||||||
using MongoDbGenericRepository.Models;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace IntegrationTests
|
|
||||||
{
|
|
||||||
public class UpdateTestsPartitionedDocument : PartitionedDocument
|
|
||||||
{
|
|
||||||
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>
|
|
||||||
{
|
|
||||||
[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<UpdateTestsPartitionedDocument>(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<UpdateTestsPartitionedDocument>(document.Id, PartitionKey);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,205 +0,0 @@
|
|||||||
using IntegrationTests.Infrastructure;
|
|
||||||
using MongoDB.Driver;
|
|
||||||
using MongoDbGenericRepository.Models;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace IntegrationTests
|
|
||||||
{
|
|
||||||
public class UpdateTestsDocument : Document
|
|
||||||
{
|
|
||||||
public UpdateTestsDocument()
|
|
||||||
{
|
|
||||||
Version = 2;
|
|
||||||
Children = new List<Child>();
|
|
||||||
}
|
|
||||||
public string SomeContent { get; set; }
|
|
||||||
public List<Child> Children { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class UpdateTests : BaseMongoDbRepositoryTests<UpdateTestsDocument>
|
|
||||||
{
|
|
||||||
[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<UpdateTestsDocument>(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<UpdateTestsDocument>(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<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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user