Added tests for Updating methods

This commit is contained in:
alexandre-spieser
2017-08-27 20:10:52 +00:00
parent bd69797d57
commit af5ba2e98e
7 changed files with 184 additions and 35 deletions
+1
View File
@@ -64,6 +64,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReadPartitionedTests.cs" />
<Compile Include="ReadTests.cs" />
<Compile Include="UpdatePartitionedTests.cs" />
<Compile Include="UpdateTests.cs" />
</ItemGroup>
<ItemGroup>
+13 -1
View File
@@ -18,7 +18,7 @@ namespace IntegrationTests
public class ReadPartitionedTests : BaseMongoDbRepositoryTests<ReadTestsPartitionedDocument>
{
[Test]
public async Task PartitionedGetById()
public async Task PartitionedGetByIdAsync()
{
// Arrange
var document = CreateTestDocument();
@@ -29,6 +29,18 @@ namespace IntegrationTests
Assert.IsNotNull(result);
}
[Test]
public void PartitionedGetById()
{
// Arrange
var document = CreateTestDocument();
SUT.AddOne(document);
// Act
var result = SUT.GetById<ReadTestsPartitionedDocument>(document.Id, PartitionKey);
// Assert
Assert.IsNotNull(result);
}
[Test]
public async Task PartitionedGetOneAsync()
{
+13 -1
View File
@@ -19,7 +19,7 @@ namespace IntegrationTests
public class ReadTests : BaseMongoDbRepositoryTests<ReadTestsDocument>
{
[Test]
public async Task GetById()
public async Task GetByIdAsync()
{
// Arrange
var document = CreateTestDocument();
@@ -30,6 +30,18 @@ namespace IntegrationTests
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()
{
@@ -0,0 +1,51 @@
using IntegrationTests.Infrastructure;
using MongoDbGenericRepository.Models;
using NUnit.Framework;
using System.Threading.Tasks;
namespace IntegrationTests
{
public class UpdateTestsPartitionedDocument : PartitionedDocument
{
public UpdateTestsPartitionedDocument() : base("TestPartitionKey")
{
Version = 2;
}
public string SomeContent { get; set; }
}
public class UpdatePartitionedTests : BaseMongoDbRepositoryTests<UpdateTestsPartitionedDocument>
{
[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<UpdateTestsPartitionedDocument>(document.Id, PartitionKey);
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<UpdateTestsPartitionedDocument>(document.Id, PartitionKey);
Assert.IsNotNull(updatedDocument);
Assert.AreEqual("UpdateOneAsyncContent", updatedDocument.SomeContent);
}
}
}
+47 -2
View File
@@ -1,6 +1,51 @@
namespace IntegrationTests
using IntegrationTests.Infrastructure;
using MongoDbGenericRepository.Models;
using NUnit.Framework;
using System.Threading.Tasks;
namespace IntegrationTests
{
class UpdateTests
public class UpdateTestsDocument : Document
{
public UpdateTestsDocument()
{
Version = 2;
}
public string SomeContent { 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);
}
}
}