.NET Core tests with xunit
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
For more information on how to configure your ASP.NET application, please visit
|
||||
http://go.microsoft.com/fwlink/?LinkId=169433
|
||||
-->
|
||||
<configuration>
|
||||
<connectionStrings>
|
||||
<add name="MongoDbTests" connectionString="mongodb://localhost:27017" />
|
||||
</connectionStrings>
|
||||
</configuration>
|
||||
@@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.4.4" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.0" />
|
||||
<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>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,67 @@
|
||||
using IntegrationTests.Infrastructure;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using Xunit;
|
||||
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>
|
||||
{
|
||||
private void PartitionedAddOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = new CreateTestsPartitionedDocument();
|
||||
// Act
|
||||
SUT.AddOne(document);
|
||||
// Assert
|
||||
long count = SUT.Count<CreateTestsPartitionedDocument>(e => e.Id == document.Id, PartitionKey);
|
||||
Xunit.Assert.Equal(1, count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(1, count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(2, count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(2, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using IntegrationTests.Infrastructure;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using Xunit;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IntegrationTests
|
||||
{
|
||||
public class CreateTestsDocument : Document
|
||||
{
|
||||
public CreateTestsDocument()
|
||||
{
|
||||
Version = 2;
|
||||
}
|
||||
public string SomeContent { get; set; }
|
||||
}
|
||||
|
||||
public class CreateTests : BaseMongoDbRepositoryTests<CreateTestsDocument>
|
||||
{
|
||||
[Fact]
|
||||
public void AddOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = new CreateTestsDocument();
|
||||
// Act
|
||||
SUT.AddOne(document);
|
||||
// Assert
|
||||
long count = SUT.Count<CreateTestsDocument>(e => e.Id == document.Id);
|
||||
Assert.Equal(1, count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(1, count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(2, count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(2, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
using IntegrationTests.Infrastructure;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using Xunit;
|
||||
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>
|
||||
{
|
||||
[Fact]
|
||||
public void PartitionedDeleteOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = SUT.DeleteOne(document);
|
||||
// Assert
|
||||
Assert.Equal(1, result);
|
||||
Assert.False(SUT.Any<DeleteTestsPartitionedDocument>(e => e.Id == document.Id, PartitionKey));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PartitionedDeleteOneLinq()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = SUT.DeleteOne<DeleteTestsPartitionedDocument>(e => e.Id == document.Id, PartitionKey);
|
||||
// Assert
|
||||
Assert.Equal(1, result);
|
||||
Assert.False(SUT.Any<DeleteTestsPartitionedDocument>(e => e.Id == document.Id, PartitionKey));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PartitionedDeleteOneAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = await SUT.DeleteOneAsync(document);
|
||||
// Assert
|
||||
Assert.Equal(1, result);
|
||||
Assert.False(SUT.Any<DeleteTestsPartitionedDocument>(e => e.Id == document.Id, PartitionKey));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(1, result);
|
||||
Assert.False(SUT.Any<DeleteTestsPartitionedDocument>(e => e.Id == document.Id, PartitionKey));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result);
|
||||
Assert.False(SUT.Any<DeleteTestsPartitionedDocument>(e => e.SomeContent == "DeleteManyAsyncLinqContent", PartitionKey));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result);
|
||||
Assert.False(SUT.Any<DeleteTestsPartitionedDocument>(e => e.SomeContent == "DeleteManyAsyncLinqContent", PartitionKey));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result);
|
||||
Assert.False(SUT.Any<DeleteTestsPartitionedDocument>(e => e.SomeContent == content, PartitionKey));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result);
|
||||
Assert.False(SUT.Any<DeleteTestsPartitionedDocument>(e => e.SomeContent == content, PartitionKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
using IntegrationTests.Infrastructure;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using Xunit;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IntegrationTests
|
||||
{
|
||||
public class DeleteTestsDocument : Document
|
||||
{
|
||||
public DeleteTestsDocument()
|
||||
{
|
||||
Version = 2;
|
||||
}
|
||||
public string SomeContent { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteTests : BaseMongoDbRepositoryTests<DeleteTestsDocument>
|
||||
{
|
||||
[Fact]
|
||||
public void DeleteOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = SUT.DeleteOne(document);
|
||||
// Assert
|
||||
Assert.Equal(1, result);
|
||||
Assert.False(SUT.Any<DeleteTestsDocument>(e => e.Id == document.Id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeleteOneLinq()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = SUT.DeleteOne<DeleteTestsDocument>(e => e.Id == document.Id);
|
||||
// Assert
|
||||
Assert.Equal(1, result);
|
||||
Assert.False(SUT.Any<DeleteTestsDocument>(e => e.Id == document.Id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteOneAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = await SUT.DeleteOneAsync(document);
|
||||
// Assert
|
||||
Assert.Equal(1, result);
|
||||
Assert.False(SUT.Any<DeleteTestsDocument>(e => e.Id == document.Id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(1, result);
|
||||
Assert.False(SUT.Any<DeleteTestsDocument>(e => e.Id == document.Id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result);
|
||||
Assert.False(SUT.Any<DeleteTestsDocument>(e => e.SomeContent == "DeleteManyAsyncLinqContent"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result);
|
||||
Assert.False(SUT.Any<DeleteTestsDocument>(e => e.SomeContent == "DeleteManyAsyncLinqContent"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result);
|
||||
Assert.False(SUT.Any<DeleteTestsDocument>(e => e.SomeContent == content));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result);
|
||||
Assert.False(SUT.Any<DeleteTestsDocument>(e => e.SomeContent == content));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using MongoDbGenericRepository.Models;
|
||||
using Xunit;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System;
|
||||
|
||||
namespace IntegrationTests.Infrastructure
|
||||
{
|
||||
|
||||
public class BaseMongoDbRepositoryTests<T> : IDisposable where T : Document, new()
|
||||
{
|
||||
public T CreateTestDocument()
|
||||
{
|
||||
return new T();
|
||||
}
|
||||
|
||||
public List<T> CreateTestDocuments(int numberOfDocumentsToCreate)
|
||||
{
|
||||
var docs = new List<T>();
|
||||
for(var i = 0; i < numberOfDocumentsToCreate; i++)
|
||||
{
|
||||
docs.Add(new T());
|
||||
}
|
||||
return docs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor, init code
|
||||
/// </summary>
|
||||
public BaseMongoDbRepositoryTests()
|
||||
{
|
||||
Init();
|
||||
var type = CreateTestDocument();
|
||||
if (type is IPartitionedDocument)
|
||||
{
|
||||
PartitionKey = ((IPartitionedDocument)type).PartitionKey;
|
||||
}
|
||||
}
|
||||
|
||||
public string PartitionKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// SUT: System Under Test
|
||||
/// </summary>
|
||||
protected static ITestRepository SUT { get; set; }
|
||||
|
||||
public void Init()
|
||||
{
|
||||
SUT = TestRepository.Instance;
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
// We drop the collection at the end of each test session.
|
||||
if (!string.IsNullOrEmpty(PartitionKey))
|
||||
{
|
||||
SUT.DropTestCollection<T>(PartitionKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
SUT.DropTestCollection<T>();
|
||||
}
|
||||
}
|
||||
|
||||
#region IDisposable Support
|
||||
private bool disposedValue = false; // Pour détecter les appels redondants
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Ce code est ajouté pour implémenter correctement le modèle supprimable.
|
||||
public void Dispose()
|
||||
{
|
||||
// Ne modifiez pas ce code. Placez le code de nettoyage dans Dispose(bool disposing) ci-dessus.
|
||||
Dispose(true);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using MongoDbGenericRepository;
|
||||
|
||||
namespace IntegrationTests
|
||||
{
|
||||
public interface ITestRepository : IBaseMongoRepository
|
||||
{
|
||||
void DropTestCollection<TDocument>();
|
||||
void DropTestCollection<TDocument>(string partitionKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using MongoDbGenericRepository;
|
||||
|
||||
namespace IntegrationTests.Infrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// A singleton implementation of the TestRepository
|
||||
/// </summary>
|
||||
public sealed class TestRepository : BaseMongoRepository, ITestRepository
|
||||
{
|
||||
|
||||
const string connectionString = "mongodb://localhost:27017";
|
||||
private static readonly ITestRepository instance = new TestRepository(connectionString, "MongoDbTests");
|
||||
|
||||
// Explicit static constructor to tell C# compiler
|
||||
// not to mark type as beforefieldinit
|
||||
static TestRepository()
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
private TestRepository(string connectionString, string databaseName) : base(connectionString, databaseName)
|
||||
{
|
||||
}
|
||||
|
||||
public static ITestRepository Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
public void DropTestCollection<TDocument>()
|
||||
{
|
||||
MongoDbContext.DropCollection<TDocument>();
|
||||
}
|
||||
|
||||
public void DropTestCollection<TDocument>(string partitionKey)
|
||||
{
|
||||
MongoDbContext.DropCollection<TDocument>(partitionKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
using IntegrationTests.Infrastructure;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using Xunit;
|
||||
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>
|
||||
{
|
||||
[Fact]
|
||||
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, MyProjection>(
|
||||
x => x.Id == document.Id,
|
||||
x => new MyProjection
|
||||
{
|
||||
SomeContent = x.SomeContent,
|
||||
SomeDate = x.Nested.SomeDate
|
||||
},
|
||||
PartitionKey);
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(someContent, result.SomeContent);
|
||||
Assert.Equal(someDate.Minute, result.SomeDate.Minute);
|
||||
Assert.Equal(someDate.Second, result.SomeDate.Second);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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, MyProjection>(
|
||||
x => x.Id == document.Id,
|
||||
x => new MyProjection
|
||||
{
|
||||
SomeContent = x.SomeContent,
|
||||
SomeDate = x.Nested.SomeDate
|
||||
},
|
||||
PartitionKey);
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(someContent, result.SomeContent);
|
||||
Assert.Equal(someDate.Minute, result.SomeDate.Minute);
|
||||
Assert.Equal(someDate.Second, result.SomeDate.Second);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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, MyProjection>(
|
||||
x => x.SomeContent == someContent,
|
||||
x => new MyProjection
|
||||
{
|
||||
SomeContent = x.SomeContent,
|
||||
SomeDate = x.Nested.SomeDate
|
||||
},
|
||||
PartitionKey);
|
||||
// Assert
|
||||
Assert.Equal(5, result.Count);
|
||||
Assert.Equal(someContent, result.First().SomeContent);
|
||||
Assert.Equal(someDate.Minute, result.First().SomeDate.Minute);
|
||||
Assert.Equal(someDate.Second, result.First().SomeDate.Second);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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, MyProjection>(
|
||||
x => x.SomeContent == someContent,
|
||||
x => new MyProjection
|
||||
{
|
||||
SomeContent = x.SomeContent,
|
||||
SomeDate = x.Nested.SomeDate
|
||||
},
|
||||
PartitionKey);
|
||||
// Assert
|
||||
Assert.Equal(5, result.Count);
|
||||
Assert.Equal(someContent, result.First().SomeContent);
|
||||
Assert.Equal(someDate.Minute, result.First().SomeDate.Minute);
|
||||
Assert.Equal(someDate.Second, result.First().SomeDate.Second);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
using IntegrationTests.Infrastructure;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using Xunit;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IntegrationTests
|
||||
{
|
||||
public class Nested
|
||||
{
|
||||
public DateTime SomeDate { get; set; }
|
||||
}
|
||||
|
||||
public class MyProjection
|
||||
{
|
||||
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>
|
||||
{
|
||||
|
||||
|
||||
[Fact]
|
||||
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, MyProjection>(
|
||||
x => x.Id == document.Id,
|
||||
x => new MyProjection
|
||||
{
|
||||
SomeContent = x.SomeContent,
|
||||
SomeDate = x.Nested.SomeDate
|
||||
});
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(someContent, result.SomeContent);
|
||||
Assert.Equal(someDate.Minute, result.SomeDate.Minute);
|
||||
Assert.Equal(someDate.Second, result.SomeDate.Second);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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, MyProjection>(
|
||||
x => x.Id == document.Id,
|
||||
x => new MyProjection
|
||||
{
|
||||
SomeContent = x.SomeContent,
|
||||
SomeDate = x.Nested.SomeDate
|
||||
});
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(someContent, result.SomeContent);
|
||||
Assert.Equal(someDate.Minute, result.SomeDate.Minute);
|
||||
Assert.Equal(someDate.Second, result.SomeDate.Second);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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, MyProjection>(
|
||||
x => x.SomeContent == someContent,
|
||||
x => new MyProjection
|
||||
{
|
||||
SomeContent = x.SomeContent,
|
||||
SomeDate = x.Nested.SomeDate
|
||||
});
|
||||
// Assert
|
||||
Assert.Equal(5, result.Count);
|
||||
Assert.Equal(someContent, result.First().SomeContent);
|
||||
Assert.Equal(someDate.Minute, result.First().SomeDate.Minute);
|
||||
Assert.Equal(someDate.Second, result.First().SomeDate.Second);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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, MyProjection>(
|
||||
x => x.SomeContent == someContent,
|
||||
x => new MyProjection
|
||||
{
|
||||
SomeContent = x.SomeContent,
|
||||
SomeDate = x.Nested.SomeDate
|
||||
});
|
||||
// Assert
|
||||
Assert.Equal(5, result.Count);
|
||||
Assert.Equal(someContent, result.First().SomeContent);
|
||||
Assert.Equal(someDate.Minute, result.First().SomeDate.Minute);
|
||||
Assert.Equal(someDate.Second, result.First().SomeDate.Second);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
using IntegrationTests.Infrastructure;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using Xunit;
|
||||
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>
|
||||
{
|
||||
[Fact]
|
||||
public async Task PartitionedGetByIdAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = await SUT.GetByIdAsync<ReadTestsPartitionedDocument>(document.Id, PartitionKey);
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PartitionedGetById()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = SUT.GetById<ReadTestsPartitionedDocument>(document.Id, PartitionKey);
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PartitionedGetOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = SUT.GetOne<ReadTestsPartitionedDocument>(x => x.Id == document.Id, PartitionKey);
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(1, count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PartitionedAnyReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = SUT.Any<ReadTestsPartitionedDocument>(x => x.Id == document.Id, PartitionKey);
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PartitionedAnyReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = SUT.Any<ReadTestsPartitionedDocument>(x => x.Id == Guid.NewGuid(), PartitionKey);
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
using IntegrationTests.Infrastructure;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using Xunit;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IntegrationTests
|
||||
{
|
||||
public class ReadTestsDocument : Document
|
||||
{
|
||||
public ReadTestsDocument()
|
||||
{
|
||||
Version = 2;
|
||||
}
|
||||
public string SomeContent { get; set; }
|
||||
}
|
||||
|
||||
public class ReadTests : BaseMongoDbRepositoryTests<ReadTestsDocument>
|
||||
{
|
||||
[Fact]
|
||||
public async Task GetByIdAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = await SUT.GetByIdAsync<ReadTestsDocument>(document.Id);
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetById()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = SUT.GetById<ReadTestsDocument>(document.Id);
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = SUT.GetOne<ReadTestsDocument>(x => x.Id == document.Id);
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(1, count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnyReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = SUT.Any<ReadTestsDocument>(x => x.Id == document.Id);
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnyReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
// Act
|
||||
var result = SUT.Any<ReadTestsDocument>(x => x.Id == Guid.NewGuid());
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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.Equal(5, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using IntegrationTests.Infrastructure;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using Xunit;
|
||||
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>
|
||||
{
|
||||
[Fact]
|
||||
public void PartitionedUpdateOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
document.SomeContent = "UpdateOneContent";
|
||||
// Act
|
||||
var result = SUT.UpdateOne(document);
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsPartitionedDocument>(document.Id, PartitionKey);
|
||||
Assert.NotNull(updatedDocument);
|
||||
Assert.Equal("UpdateOneContent", updatedDocument.SomeContent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PartitionedUpdateOneAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
document.SomeContent = "UpdateOneAsyncContent";
|
||||
// Act
|
||||
var result = await SUT.UpdateOneAsync(document);
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsPartitionedDocument>(document.Id, PartitionKey);
|
||||
Assert.NotNull(updatedDocument);
|
||||
Assert.Equal("UpdateOneAsyncContent", updatedDocument.SomeContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using IntegrationTests.Infrastructure;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using Xunit;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IntegrationTests
|
||||
{
|
||||
public class UpdateTestsDocument : Document
|
||||
{
|
||||
public UpdateTestsDocument()
|
||||
{
|
||||
Version = 2;
|
||||
}
|
||||
public string SomeContent { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateTests : BaseMongoDbRepositoryTests<UpdateTestsDocument>
|
||||
{
|
||||
[Fact]
|
||||
public void UpdateOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
document.SomeContent = "UpdateOneContent";
|
||||
// Act
|
||||
var result = SUT.UpdateOne(document);
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsDocument>(document.Id);
|
||||
Assert.NotNull(updatedDocument);
|
||||
Assert.Equal("UpdateOneContent", updatedDocument.SomeContent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateOneAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = CreateTestDocument();
|
||||
SUT.AddOne(document);
|
||||
document.SomeContent = "UpdateOneAsyncContent";
|
||||
// Act
|
||||
var result = await SUT.UpdateOneAsync(document);
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
var updatedDocument = SUT.GetById<UpdateTestsDocument>(document.Id);
|
||||
Assert.NotNull(updatedDocument);
|
||||
Assert.Equal("UpdateOneAsyncContent", updatedDocument.SomeContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,9 @@ VisualStudioVersion = 15.0.26730.12
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationTests", "IntegrationTests\IntegrationTests.csproj", "{A484A355-A015-40CC-9B35-A4E872421128}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDbGenericRepository", "MongoDbGenericRepository\MongoDbGenericRepository.csproj", "{EFC776C4-2AF3-440C-BE80-3FBE335817A5}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoDbGenericRepository", "MongoDbGenericRepository\MongoDbGenericRepository.csproj", "{EFC776C4-2AF3-440C-BE80-3FBE335817A5}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreIntegrationTests", "CoreIntegrationTests\CoreIntegrationTests.csproj", "{C640C106-7A25-4E49-A0CF-E4F248E5A97F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -13,10 +15,6 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D154E7D0-9A3C-43AB-8E90-ED92BC4343F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D154E7D0-9A3C-43AB-8E90-ED92BC4343F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D154E7D0-9A3C-43AB-8E90-ED92BC4343F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D154E7D0-9A3C-43AB-8E90-ED92BC4343F0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A484A355-A015-40CC-9B35-A4E872421128}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A484A355-A015-40CC-9B35-A4E872421128}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A484A355-A015-40CC-9B35-A4E872421128}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@@ -25,6 +23,10 @@ Global
|
||||
{EFC776C4-2AF3-440C-BE80-3FBE335817A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EFC776C4-2AF3-440C-BE80-3FBE335817A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EFC776C4-2AF3-440C-BE80-3FBE335817A5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C640C106-7A25-4E49-A0CF-E4F248E5A97F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C640C106-7A25-4E49-A0CF-E4F248E5A97F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C640C106-7A25-4E49-A0CF-E4F248E5A97F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C640C106-7A25-4E49-A0CF-E4F248E5A97F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user