Test refactoring, continued.
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ namespace IntegrationTests
|
|||||||
public string PartitionKey { get; set; }
|
public string PartitionKey { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TKeyPartitionedCollectionNameAttributeTests : MongoDBTestBase<TKeyPartitionedCollectionNameDoc, Guid>
|
public class CRUDTKeyPartitionedCollectionNameAttributeTests : MongoDBTestBase<TKeyPartitionedCollectionNameDoc, Guid>
|
||||||
{
|
{
|
||||||
public override string GetClassName()
|
public override string GetClassName()
|
||||||
{
|
{
|
||||||
@@ -5,6 +5,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -31,28 +32,29 @@ namespace IntegrationTests.Infrastructure
|
|||||||
|
|
||||||
public Nested Nested { get; set; }
|
public Nested Nested { get; set; }
|
||||||
|
|
||||||
private void InitializeFields()
|
public TId Init<TId>()
|
||||||
{
|
{
|
||||||
var idTypeName = typeof(TKey).Name;
|
var idTypeName = typeof(TKey).Name;
|
||||||
switch (idTypeName)
|
switch (idTypeName)
|
||||||
{
|
{
|
||||||
case "Guid":
|
case "Guid":
|
||||||
Id = (TKey)(object)Guid.NewGuid();
|
return (TId)(object)Guid.NewGuid();
|
||||||
break;
|
|
||||||
case "Int16":
|
case "Int16":
|
||||||
Id = (TKey)(object)GlobalVariables.Random.Next(1, short.MaxValue);
|
return (TId)(object)GlobalVariables.Random.Next(1, short.MaxValue);
|
||||||
break;
|
|
||||||
case "Int32":
|
case "Int32":
|
||||||
Id = (TKey)(object)GlobalVariables.Random.Next(1, int.MaxValue);
|
return (TId)(object)GlobalVariables.Random.Next(1, int.MaxValue);
|
||||||
break;
|
|
||||||
case "Int64":
|
case "Int64":
|
||||||
Id = (TKey)(object)(GlobalVariables.Random.NextLong(1, long.MaxValue));
|
return (TId)(object)(GlobalVariables.Random.NextLong(1, long.MaxValue));
|
||||||
break;
|
|
||||||
case "String":
|
case "String":
|
||||||
Id = (TKey)(object)Guid.NewGuid().ToString();
|
return (TId)(object)Guid.NewGuid().ToString();
|
||||||
break;
|
default:
|
||||||
|
throw new NotSupportedException($"{idTypeName} is not supported.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void InitializeFields()
|
||||||
|
{
|
||||||
|
Id = Init<TKey>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,6 +194,176 @@ namespace IntegrationTests.Infrastructure
|
|||||||
|
|
||||||
#endregion Add
|
#endregion Add
|
||||||
|
|
||||||
|
#region Read
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetByIdAsync()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = CreateTestDocument();
|
||||||
|
SUT.AddOne<T, TKey>(document);
|
||||||
|
// Act
|
||||||
|
var result = await SUT.GetByIdAsync<T, TKey>(document.Id, PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.IsNotNull(result, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetById()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = CreateTestDocument();
|
||||||
|
SUT.AddOne<T, TKey>(document);
|
||||||
|
// Act
|
||||||
|
var result = SUT.GetById<T, TKey>(document.Id, PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.IsNotNull(result, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task PartitionedGetOneAsync()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = CreateTestDocument();
|
||||||
|
SUT.AddOne<T, TKey>(document);
|
||||||
|
// Act
|
||||||
|
var result = await SUT.GetOneAsync<T, TKey>(x => x.Id.Equals(document.Id), PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.IsNotNull(result, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = CreateTestDocument();
|
||||||
|
SUT.AddOne<T, TKey>(document);
|
||||||
|
// Act
|
||||||
|
var result = SUT.GetOne<T, TKey>(x => x.Id.Equals(document.Id), PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.IsNotNull(result, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetCursor()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = CreateTestDocument();
|
||||||
|
SUT.AddOne<T, TKey>(document);
|
||||||
|
// Act
|
||||||
|
var cursor = SUT.GetCursor<T, TKey>(x => x.Id.Equals(document.Id), PartitionKey);
|
||||||
|
var count = cursor.Count();
|
||||||
|
// Assert
|
||||||
|
Assert.AreEqual(1, count, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task AnyAsyncReturnsTrue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = CreateTestDocument();
|
||||||
|
SUT.AddOne<T, TKey>(document);
|
||||||
|
// Act
|
||||||
|
var result = await SUT.AnyAsync<T, TKey>(x => x.Id.Equals(document.Id), PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.AreEqual(true, result, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task AnyAsyncReturnsFalse()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = CreateTestDocument();
|
||||||
|
SUT.AddOne<T, TKey>(document);
|
||||||
|
// Act
|
||||||
|
var result = await SUT.AnyAsync<T, TKey>(x => x.Id.Equals(document.Init<TKey>()), PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.AreEqual(false, result, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AnyReturnsTrue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = CreateTestDocument();
|
||||||
|
SUT.AddOne<T, TKey>(document);
|
||||||
|
// Act
|
||||||
|
var result = SUT.Any<T, TKey>(x => x.Id.Equals(document.Id), PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.AreEqual(true, result, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AnyReturnsFalse()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var document = CreateTestDocument();
|
||||||
|
SUT.AddOne<T, TKey>(document);
|
||||||
|
// Act
|
||||||
|
var result = SUT.Any<T, TKey>(x => x.Id.Equals(document.Init<TKey>()), PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.AreEqual(false, result, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetAllAsync()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var documents = CreateTestDocuments(5);
|
||||||
|
var content = GetContent();
|
||||||
|
documents.ForEach(e => e.SomeContent = content);
|
||||||
|
SUT.AddMany<T, TKey>(documents);
|
||||||
|
// Act
|
||||||
|
var result = await SUT.GetAllAsync<T, TKey>(x => x.SomeContent == content, PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.AreEqual(5, result.Count, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var documents = CreateTestDocuments(5);
|
||||||
|
var content = GetContent();
|
||||||
|
documents.ForEach(e => e.SomeContent = content);
|
||||||
|
SUT.AddMany<T, TKey>(documents);
|
||||||
|
// Act
|
||||||
|
var result = SUT.GetAll<T, TKey>(x => x.SomeContent == content, PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.AreEqual(5, result.Count, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task CountAsync()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var documents = CreateTestDocuments(5);
|
||||||
|
var content = GetContent();
|
||||||
|
documents.ForEach(e => e.SomeContent = content);
|
||||||
|
SUT.AddMany<T, TKey>(documents);
|
||||||
|
// Act
|
||||||
|
var result = await SUT.CountAsync<T, TKey>(x => x.SomeContent == content, PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.AreEqual(5, result, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Count()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var documents = CreateTestDocuments(5);
|
||||||
|
var content = GetContent();
|
||||||
|
documents.ForEach(e => e.SomeContent = content);
|
||||||
|
SUT.AddMany<T, TKey>(documents);
|
||||||
|
// Act
|
||||||
|
var result = SUT.Count<T, TKey>(x => x.SomeContent == content, PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.AreEqual(5, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Read
|
||||||
|
|
||||||
#region Delete
|
#region Delete
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -310,11 +482,120 @@ namespace IntegrationTests.Infrastructure
|
|||||||
|
|
||||||
#region Project
|
#region Project
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ProjectOneAsync()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var someContent = GetContent();
|
||||||
|
var someDate = DateTime.UtcNow;
|
||||||
|
var document = CreateTestDocument();
|
||||||
|
document.SomeContent = someContent;
|
||||||
|
document.Nested.SomeDate = someDate;
|
||||||
|
SUT.AddOne<T, TKey>(document);
|
||||||
|
// Act
|
||||||
|
var result = await SUT.ProjectOneAsync<T, MyTestProjection, TKey>(
|
||||||
|
x => x.Id.Equals(document.Id),
|
||||||
|
x => new MyTestProjection
|
||||||
|
{
|
||||||
|
SomeContent = x.SomeContent,
|
||||||
|
SomeDate = x.Nested.SomeDate
|
||||||
|
},
|
||||||
|
PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.IsNotNull(result, GetTestName());
|
||||||
|
Assert.AreEqual(someContent, result.SomeContent, GetTestName());
|
||||||
|
Assert.AreEqual(someDate.Minute, result.SomeDate.Minute, GetTestName());
|
||||||
|
Assert.AreEqual(someDate.Second, result.SomeDate.Second, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProjectOne()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var someContent = GetContent();
|
||||||
|
var someDate = DateTime.UtcNow;
|
||||||
|
var document = CreateTestDocument();
|
||||||
|
document.SomeContent = someContent;
|
||||||
|
document.Nested.SomeDate = someDate;
|
||||||
|
SUT.AddOne<T, TKey>(document);
|
||||||
|
// Act
|
||||||
|
var result = SUT.ProjectOne<T, MyTestProjection, TKey>(
|
||||||
|
x => x.Id.Equals(document.Id),
|
||||||
|
x => new MyTestProjection
|
||||||
|
{
|
||||||
|
SomeContent = x.SomeContent,
|
||||||
|
SomeDate = x.Nested.SomeDate
|
||||||
|
},
|
||||||
|
PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.IsNotNull(result, GetTestName());
|
||||||
|
Assert.AreEqual(someContent, result.SomeContent, GetTestName());
|
||||||
|
Assert.AreEqual(someDate.Minute, result.SomeDate.Minute, GetTestName());
|
||||||
|
Assert.AreEqual(someDate.Second, result.SomeDate.Second, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task ProjectManyAsync()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var someContent = GetContent();
|
||||||
|
var someDate = DateTime.UtcNow;
|
||||||
|
var documents = CreateTestDocuments(5);
|
||||||
|
documents.ForEach(e =>
|
||||||
|
{
|
||||||
|
e.SomeContent = someContent;
|
||||||
|
e.Nested.SomeDate = someDate;
|
||||||
|
});
|
||||||
|
|
||||||
|
SUT.AddMany<T, TKey>(documents);
|
||||||
|
// Act
|
||||||
|
var result = await SUT.ProjectManyAsync<T, MyTestProjection, TKey>(
|
||||||
|
x => x.SomeContent == someContent,
|
||||||
|
x => new MyTestProjection
|
||||||
|
{
|
||||||
|
SomeContent = x.SomeContent,
|
||||||
|
SomeDate = x.Nested.SomeDate
|
||||||
|
},
|
||||||
|
PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.AreEqual(5, result.Count, GetTestName());
|
||||||
|
Assert.AreEqual(someContent, result.First().SomeContent, GetTestName());
|
||||||
|
Assert.AreEqual(someDate.Minute, result.First().SomeDate.Minute, GetTestName());
|
||||||
|
Assert.AreEqual(someDate.Second, result.First().SomeDate.Second, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProjectMany()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var someContent = GetContent();
|
||||||
|
var someDate = DateTime.UtcNow;
|
||||||
|
var documents = CreateTestDocuments(5);
|
||||||
|
documents.ForEach(e =>
|
||||||
|
{
|
||||||
|
e.SomeContent = someContent;
|
||||||
|
e.Nested.SomeDate = someDate;
|
||||||
|
});
|
||||||
|
|
||||||
|
SUT.AddMany<T, TKey>(documents);
|
||||||
|
// Act
|
||||||
|
var result = SUT.ProjectMany<T, MyTestProjection, TKey>(
|
||||||
|
x => x.SomeContent == someContent,
|
||||||
|
x => new MyTestProjection
|
||||||
|
{
|
||||||
|
SomeContent = x.SomeContent,
|
||||||
|
SomeDate = x.Nested.SomeDate
|
||||||
|
},
|
||||||
|
PartitionKey);
|
||||||
|
// Assert
|
||||||
|
Assert.AreEqual(5, result.Count, GetTestName());
|
||||||
|
Assert.AreEqual(someContent, result.First().SomeContent, GetTestName());
|
||||||
|
Assert.AreEqual(someDate.Minute, result.First().SomeDate.Minute, GetTestName());
|
||||||
|
Assert.AreEqual(someDate.Second, result.First().SomeDate.Second, GetTestName());
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Project
|
#endregion Project
|
||||||
|
|
||||||
|
|
||||||
#region Test Utils
|
#region Test Utils
|
||||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
private string GetCurrentMethod()
|
private string GetCurrentMethod()
|
||||||
@@ -325,9 +606,23 @@ namespace IntegrationTests.Infrastructure
|
|||||||
return sf.GetMethod().Name;
|
return sf.GetMethod().Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
|
private string GetParentMethod()
|
||||||
|
{
|
||||||
|
StackTrace st = new StackTrace();
|
||||||
|
StackFrame sf = st.GetFrame(2);
|
||||||
|
var method = sf.GetMethod().DeclaringType.Name;
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
private string GetTestName()
|
private string GetTestName()
|
||||||
{
|
{
|
||||||
return $"{TestClassName}.{GetCurrentMethod()}";
|
return $"{TestClassName}{PartitionKey}.{GetParentMethod()}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetContent()
|
||||||
|
{
|
||||||
|
return $"{TestClassName}{PartitionKey}.{Guid.NewGuid()}.{GetParentMethod()}";
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Test Utils
|
#endregion Test Utils
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="DeleteTests.cs" />
|
<Compile Include="DeleteTests.cs" />
|
||||||
<Compile Include="TKeyPartitionedCollectionNameAttributeTests.cs" />
|
<Compile Include="CRUDTKeyPartitionedCollectionNameAttributeTests.cs" />
|
||||||
<Compile Include="CRUDTKeyPartitionedTests.cs" />
|
<Compile Include="CRUDTKeyPartitionedTests.cs" />
|
||||||
<Compile Include="CRUDTKeyTests.cs" />
|
<Compile Include="CRUDTKeyTests.cs" />
|
||||||
<Compile Include="DeletePartitionedTests.cs" />
|
<Compile Include="DeletePartitionedTests.cs" />
|
||||||
@@ -63,14 +63,10 @@
|
|||||||
<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="CreateTests.cs" />
|
||||||
<Compile Include="ProjectPartitionedTKeyTests.cs" />
|
|
||||||
<Compile Include="ProjectPartitionedTests.cs" />
|
<Compile Include="ProjectPartitionedTests.cs" />
|
||||||
<Compile Include="ProjectTKeyTests.cs" />
|
|
||||||
<Compile Include="ProjectTests.cs" />
|
<Compile Include="ProjectTests.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="ReadPartitionedTKeyTests.cs" />
|
|
||||||
<Compile Include="ReadPartitionedTests.cs" />
|
<Compile Include="ReadPartitionedTests.cs" />
|
||||||
<Compile Include="ReadTKeyTests.cs" />
|
|
||||||
<Compile Include="ReadTests.cs" />
|
<Compile Include="ReadTests.cs" />
|
||||||
<Compile Include="UpdatePartitionedTKeyTests.cs" />
|
<Compile Include="UpdatePartitionedTKeyTests.cs" />
|
||||||
<Compile Include="UpdatePartitionedTests.cs" />
|
<Compile Include="UpdatePartitionedTests.cs" />
|
||||||
|
|||||||
@@ -1,143 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -36,9 +36,9 @@ namespace IntegrationTests
|
|||||||
document.Nested.SomeDate = someDate;
|
document.Nested.SomeDate = someDate;
|
||||||
SUT.AddOne(document);
|
SUT.AddOne(document);
|
||||||
// Act
|
// Act
|
||||||
var result = await SUT.ProjectOneAsync<ProjectTestsPartitionedDocument, MyProjection>(
|
var result = await SUT.ProjectOneAsync<ProjectTestsPartitionedDocument, MyTestProjection>(
|
||||||
x => x.Id == document.Id,
|
x => x.Id == document.Id,
|
||||||
x => new MyProjection
|
x => new MyTestProjection
|
||||||
{
|
{
|
||||||
SomeContent = x.SomeContent,
|
SomeContent = x.SomeContent,
|
||||||
SomeDate = x.Nested.SomeDate
|
SomeDate = x.Nested.SomeDate
|
||||||
@@ -62,9 +62,9 @@ namespace IntegrationTests
|
|||||||
document.Nested.SomeDate = someDate;
|
document.Nested.SomeDate = someDate;
|
||||||
SUT.AddOne(document);
|
SUT.AddOne(document);
|
||||||
// Act
|
// Act
|
||||||
var result = SUT.ProjectOne<ProjectTestsPartitionedDocument, MyProjection>(
|
var result = SUT.ProjectOne<ProjectTestsPartitionedDocument, MyTestProjection>(
|
||||||
x => x.Id == document.Id,
|
x => x.Id == document.Id,
|
||||||
x => new MyProjection
|
x => new MyTestProjection
|
||||||
{
|
{
|
||||||
SomeContent = x.SomeContent,
|
SomeContent = x.SomeContent,
|
||||||
SomeDate = x.Nested.SomeDate
|
SomeDate = x.Nested.SomeDate
|
||||||
@@ -92,9 +92,9 @@ namespace IntegrationTests
|
|||||||
|
|
||||||
SUT.AddMany(document);
|
SUT.AddMany(document);
|
||||||
// Act
|
// Act
|
||||||
var result = await SUT.ProjectManyAsync<ProjectTestsPartitionedDocument, MyProjection>(
|
var result = await SUT.ProjectManyAsync<ProjectTestsPartitionedDocument, MyTestProjection>(
|
||||||
x => x.SomeContent == someContent,
|
x => x.SomeContent == someContent,
|
||||||
x => new MyProjection
|
x => new MyTestProjection
|
||||||
{
|
{
|
||||||
SomeContent = x.SomeContent,
|
SomeContent = x.SomeContent,
|
||||||
SomeDate = x.Nested.SomeDate
|
SomeDate = x.Nested.SomeDate
|
||||||
@@ -122,9 +122,9 @@ namespace IntegrationTests
|
|||||||
|
|
||||||
SUT.AddMany(document);
|
SUT.AddMany(document);
|
||||||
// Act
|
// Act
|
||||||
var result = SUT.ProjectMany<ProjectTestsPartitionedDocument, MyProjection>(
|
var result = SUT.ProjectMany<ProjectTestsPartitionedDocument, MyTestProjection>(
|
||||||
x => x.SomeContent == someContent,
|
x => x.SomeContent == someContent,
|
||||||
x => new MyProjection
|
x => new MyTestProjection
|
||||||
{
|
{
|
||||||
SomeContent = x.SomeContent,
|
SomeContent = x.SomeContent,
|
||||||
SomeDate = x.Nested.SomeDate
|
SomeDate = x.Nested.SomeDate
|
||||||
|
|||||||
@@ -1,150 +0,0 @@
|
|||||||
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 NestedTKey
|
|
||||||
{
|
|
||||||
public DateTime SomeDate { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class MyProjectionTKey
|
|
||||||
{
|
|
||||||
public DateTime SomeDate { get; set; }
|
|
||||||
public string SomeContent { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ProjectTestsTKeyDocument : IDocument<Guid>
|
|
||||||
{
|
|
||||||
[BsonId]
|
|
||||||
public Guid Id { get; set; }
|
|
||||||
public int Version { get; set; }
|
|
||||||
public ProjectTestsTKeyDocument()
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid();
|
|
||||||
Version = 2;
|
|
||||||
Nested = new NestedTKey
|
|
||||||
{
|
|
||||||
SomeDate = DateTime.UtcNow
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public string SomeContent { get; set; }
|
|
||||||
public NestedTKey Nested { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ProjectTKeyTests : BaseMongoDbRepositoryTests<ProjectTestsTKeyDocument>
|
|
||||||
{
|
|
||||||
[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<ProjectTestsTKeyDocument, Guid>(document);
|
|
||||||
// Act
|
|
||||||
var result = await SUT.ProjectOneAsync<ProjectTestsTKeyDocument, MyProjection, Guid>(
|
|
||||||
x => x.Id == document.Id,
|
|
||||||
x => new MyProjection
|
|
||||||
{
|
|
||||||
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<ProjectTestsTKeyDocument, Guid>(document);
|
|
||||||
// Act
|
|
||||||
var result = SUT.ProjectOne<ProjectTestsTKeyDocument, MyProjection, Guid>(
|
|
||||||
x => x.Id == document.Id,
|
|
||||||
x => new MyProjection
|
|
||||||
{
|
|
||||||
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<ProjectTestsTKeyDocument, Guid>(document);
|
|
||||||
// Act
|
|
||||||
var result = await SUT.ProjectManyAsync<ProjectTestsTKeyDocument, MyProjection, Guid>(
|
|
||||||
x => x.SomeContent == someContent,
|
|
||||||
x => new MyProjection
|
|
||||||
{
|
|
||||||
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<ProjectTestsTKeyDocument, Guid>(document);
|
|
||||||
// Act
|
|
||||||
var result = SUT.ProjectMany<ProjectTestsTKeyDocument, MyProjection, Guid>(
|
|
||||||
x => x.SomeContent == someContent,
|
|
||||||
x => new MyProjection
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,7 @@ namespace IntegrationTests
|
|||||||
public DateTime SomeDate { get; set; }
|
public DateTime SomeDate { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MyProjection
|
public class MyTestProjection
|
||||||
{
|
{
|
||||||
public DateTime SomeDate { get; set; }
|
public DateTime SomeDate { get; set; }
|
||||||
public string SomeContent { get; set; }
|
public string SomeContent { get; set; }
|
||||||
@@ -49,9 +49,9 @@ namespace IntegrationTests
|
|||||||
document.Nested.SomeDate = someDate;
|
document.Nested.SomeDate = someDate;
|
||||||
SUT.AddOne(document);
|
SUT.AddOne(document);
|
||||||
// Act
|
// Act
|
||||||
var result = await SUT.ProjectOneAsync<ProjectTestsDocument, MyProjection>(
|
var result = await SUT.ProjectOneAsync<ProjectTestsDocument, MyTestProjection>(
|
||||||
x => x.Id == document.Id,
|
x => x.Id == document.Id,
|
||||||
x => new MyProjection
|
x => new MyTestProjection
|
||||||
{
|
{
|
||||||
SomeContent = x.SomeContent,
|
SomeContent = x.SomeContent,
|
||||||
SomeDate = x.Nested.SomeDate
|
SomeDate = x.Nested.SomeDate
|
||||||
@@ -74,9 +74,9 @@ namespace IntegrationTests
|
|||||||
document.Nested.SomeDate = someDate;
|
document.Nested.SomeDate = someDate;
|
||||||
SUT.AddOne(document);
|
SUT.AddOne(document);
|
||||||
// Act
|
// Act
|
||||||
var result = SUT.ProjectOne<ProjectTestsDocument, MyProjection>(
|
var result = SUT.ProjectOne<ProjectTestsDocument, MyTestProjection>(
|
||||||
x => x.Id == document.Id,
|
x => x.Id == document.Id,
|
||||||
x => new MyProjection
|
x => new MyTestProjection
|
||||||
{
|
{
|
||||||
SomeContent = x.SomeContent,
|
SomeContent = x.SomeContent,
|
||||||
SomeDate = x.Nested.SomeDate
|
SomeDate = x.Nested.SomeDate
|
||||||
@@ -103,9 +103,9 @@ namespace IntegrationTests
|
|||||||
|
|
||||||
SUT.AddMany(document);
|
SUT.AddMany(document);
|
||||||
// Act
|
// Act
|
||||||
var result = await SUT.ProjectManyAsync<ProjectTestsDocument, MyProjection>(
|
var result = await SUT.ProjectManyAsync<ProjectTestsDocument, MyTestProjection>(
|
||||||
x => x.SomeContent == someContent,
|
x => x.SomeContent == someContent,
|
||||||
x => new MyProjection
|
x => new MyTestProjection
|
||||||
{
|
{
|
||||||
SomeContent = x.SomeContent,
|
SomeContent = x.SomeContent,
|
||||||
SomeDate = x.Nested.SomeDate
|
SomeDate = x.Nested.SomeDate
|
||||||
@@ -132,9 +132,9 @@ namespace IntegrationTests
|
|||||||
|
|
||||||
SUT.AddMany(document);
|
SUT.AddMany(document);
|
||||||
// Act
|
// Act
|
||||||
var result = SUT.ProjectMany<ProjectTestsDocument, MyProjection>(
|
var result = SUT.ProjectMany<ProjectTestsDocument, MyTestProjection>(
|
||||||
x => x.SomeContent == someContent,
|
x => x.SomeContent == someContent,
|
||||||
x => new MyProjection
|
x => new MyTestProjection
|
||||||
{
|
{
|
||||||
SomeContent = x.SomeContent,
|
SomeContent = x.SomeContent,
|
||||||
SomeDate = x.Nested.SomeDate
|
SomeDate = x.Nested.SomeDate
|
||||||
|
|||||||
@@ -1,189 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,29 +17,9 @@ namespace IntegrationTests
|
|||||||
|
|
||||||
public class ReadPartitionedTests : BaseMongoDbRepositoryTests<ReadTestsPartitionedDocument>
|
public class ReadPartitionedTests : BaseMongoDbRepositoryTests<ReadTestsPartitionedDocument>
|
||||||
{
|
{
|
||||||
[Test]
|
|
||||||
public async Task PartitionedGetByIdAsync()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var document = CreateTestDocument();
|
|
||||||
SUT.AddOne(document);
|
|
||||||
// Act
|
|
||||||
var result = await SUT.GetByIdAsync<ReadTestsPartitionedDocument>(document.Id, PartitionKey);
|
|
||||||
// Assert
|
|
||||||
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]
|
[Test]
|
||||||
public async Task PartitionedGetOneAsync()
|
public async Task PartitionedGetOneAsync()
|
||||||
|
|||||||
@@ -1,187 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user