added more tests for the documents implementing the IDocument<TKey> interface
This commit is contained in:
@@ -8,7 +8,6 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace IntegrationTests
|
||||
{
|
||||
|
||||
public class CreateTestsPartitionedTKeyDocument : IDocument<Guid>, IPartitionedDocument
|
||||
{
|
||||
[BsonId]
|
||||
|
||||
@@ -63,13 +63,18 @@
|
||||
<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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,8 +39,6 @@ namespace IntegrationTests
|
||||
|
||||
public class ProjectTKeyTests : BaseMongoDbRepositoryTests<ProjectTestsTKeyDocument>
|
||||
{
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task ProjectOneAsync()
|
||||
{
|
||||
|
||||
@@ -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,61 @@
|
||||
using IntegrationTests.Infrastructure;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
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";
|
||||
}
|
||||
public string PartitionKey { get; set; }
|
||||
public string SomeContent { 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using IntegrationTests.Infrastructure;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
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;
|
||||
}
|
||||
public string SomeContent { 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user