Added projection tests on partitioned collections
This commit is contained in:
@@ -63,6 +63,7 @@
|
|||||||
<Compile Include="Infrastructure\ITestRepository.cs" />
|
<Compile Include="Infrastructure\ITestRepository.cs" />
|
||||||
<Compile Include="Infrastructure\TestRepository.cs" />
|
<Compile Include="Infrastructure\TestRepository.cs" />
|
||||||
<Compile Include="CreateTests.cs" />
|
<Compile Include="CreateTests.cs" />
|
||||||
|
<Compile Include="ProjectPartitionedTests.cs" />
|
||||||
<Compile Include="ProjectTests.cs" />
|
<Compile Include="ProjectTests.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="ReadPartitionedTests.cs" />
|
<Compile Include="ReadPartitionedTests.cs" />
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
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, MyProjection>(
|
||||||
|
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(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.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, MyProjection>(
|
||||||
|
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(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.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,12 @@ namespace IntegrationTests
|
|||||||
public class Nested
|
public class Nested
|
||||||
{
|
{
|
||||||
public DateTime SomeDate { get; set; }
|
public DateTime SomeDate { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MyProjection
|
||||||
|
{
|
||||||
|
public DateTime SomeDate { get; set; }
|
||||||
|
public string SomeContent { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ProjectTestsDocument : Document
|
public class ProjectTestsDocument : Document
|
||||||
@@ -31,11 +36,7 @@ namespace IntegrationTests
|
|||||||
|
|
||||||
public class ProjectTests : BaseMongoDbRepositoryTests<ProjectTestsDocument>
|
public class ProjectTests : BaseMongoDbRepositoryTests<ProjectTestsDocument>
|
||||||
{
|
{
|
||||||
private class MyProjection
|
|
||||||
{
|
|
||||||
public DateTime SomeDate { get; set; }
|
|
||||||
public string SomeContent { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task ProjectOneAsync()
|
public async Task ProjectOneAsync()
|
||||||
|
|||||||
Reference in New Issue
Block a user