Skip to content

Commit

Permalink
Merge branch 'AddingTKey'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-spieser committed Oct 1, 2017
2 parents 833263e + 9c0cd0f commit bfe1652
Show file tree
Hide file tree
Showing 31 changed files with 7,108 additions and 1,158 deletions.
5 changes: 4 additions & 1 deletion CoreIntegrationTests/CoreIntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" />
<PackageReference Include="MongoDB.Driver" Version="2.4.4" />
<PackageReference Include="MongoDbGenericRepository" Version="1.2.1" />
<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>
Expand Down
8 changes: 8 additions & 0 deletions IntegrationTests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@
<connectionStrings>
<add name="MongoDbTests" connectionString="mongodb://localhost:27017" />
</connectionStrings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
76 changes: 76 additions & 0 deletions IntegrationTests/CreateTKeyPartitionedTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using IntegrationTests.Infrastructure;
using MongoDB.Bson.Serialization.Attributes;
using MongoDbGenericRepository.Models;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace IntegrationTests
{
public class CreateTestsPartitionedTKeyDocument : IDocument<Guid>, IPartitionedDocument
{
[BsonId]
public Guid Id { get; set; }
public int Version { get; set; }
public CreateTestsPartitionedTKeyDocument()
{
Id = Guid.NewGuid();
Version = 2;
PartitionKey = "TestPartitionKey";
}
public string PartitionKey { get; set; }
public string SomeContent { get; set; }
}

public class CreatePartitionedTKeyTests : BaseMongoDbRepositoryTests<CreateTestsPartitionedTKeyDocument>
{
[Test]
public void PartitionedAddOne()
{
// Arrange
var document = new CreateTestsPartitionedTKeyDocument();
// Act
SUT.AddOne<CreateTestsPartitionedTKeyDocument, Guid>(document);
// Assert
long count = SUT.Count<CreateTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey);
Assert.AreEqual(1, count);
}

[Test]
public async Task PartitionedAddOneAsync()
{
// Arrange
var document = new CreateTestsPartitionedTKeyDocument();
// Act
await SUT.AddOneAsync<CreateTestsPartitionedTKeyDocument, Guid>(document);
// Assert
long count = SUT.Count<CreateTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey);
Assert.AreEqual(1, count);
}

[Test]
public void PartitionedAddMany()
{
// Arrange
var documents = new List<CreateTestsPartitionedTKeyDocument> { new CreateTestsPartitionedTKeyDocument(), new CreateTestsPartitionedTKeyDocument() };
// Act
SUT.AddMany<CreateTestsPartitionedTKeyDocument, Guid>(documents);
// Assert
long count = SUT.Count<CreateTestsPartitionedTKeyDocument, Guid>(e => e.Id == documents[0].Id || e.Id == documents[1].Id, PartitionKey);
Assert.AreEqual(2, count);
}

[Test]
public async Task PartitionedAddManyAsync()
{
// Arrange
var documents = new List<CreateTestsPartitionedTKeyDocument> { new CreateTestsPartitionedTKeyDocument(), new CreateTestsPartitionedTKeyDocument() };
// Act
await SUT.AddManyAsync<CreateTestsPartitionedTKeyDocument, Guid>(documents);
// Assert
long count = SUT.Count<CreateTestsPartitionedTKeyDocument, Guid>(e => e.Id == documents[0].Id || e.Id == documents[1].Id, PartitionKey);
Assert.AreEqual(2, count);
}
}
}
75 changes: 75 additions & 0 deletions IntegrationTests/CreateTKeyTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using IntegrationTests.Infrastructure;
using MongoDB.Bson.Serialization.Attributes;
using MongoDbGenericRepository.Models;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace IntegrationTests
{
public class CreateTestsTKeyDocument : IDocument<Guid>
{
[BsonId]
public Guid Id { get; set; }
public int Version { get; set; }
public CreateTestsTKeyDocument()
{
Id = Guid.NewGuid();
Version = 2;
}
public string SomeContent { get; set; }
}

[TestFixture]
public class CreateTKeyTests : BaseMongoDbRepositoryTests<CreateTestsTKeyDocument>
{
[Test]
public void TKeyAddOne()
{
// Arrange
var document = new CreateTestsTKeyDocument();
// Act
SUT.AddOne<CreateTestsTKeyDocument, Guid>(document);
// Assert
long count = SUT.Count<CreateTestsTKeyDocument, Guid>(e => e.Id == document.Id);
Assert.AreEqual(1, count);
}

[Test]
public async Task TKeyAddOneAsync()
{
// Arrange
var document = new CreateTestsTKeyDocument();
// Act
await SUT.AddOneAsync<CreateTestsTKeyDocument, Guid>(document);
// Assert
long count = SUT.Count<CreateTestsTKeyDocument, Guid>(e => e.Id == document.Id);
Assert.AreEqual(1, count);
}

[Test]
public void TKeyAddMany()
{
// Arrange
var documents = new List<CreateTestsTKeyDocument> { new CreateTestsTKeyDocument(), new CreateTestsTKeyDocument() };
// Act
SUT.AddMany<CreateTestsTKeyDocument, Guid>(documents);
// Assert
long count = SUT.Count<CreateTestsTKeyDocument, Guid>(e => e.Id == documents[0].Id || e.Id == documents[1].Id);
Assert.AreEqual(2, count);
}

[Test]
public async Task TKeyAddManyAsync()
{
// Arrange
var documents = new List<CreateTestsTKeyDocument> { new CreateTestsTKeyDocument(), new CreateTestsTKeyDocument() };
// Act
await SUT.AddManyAsync<CreateTestsTKeyDocument, Guid>(documents);
// Assert
long count = SUT.Count<CreateTestsTKeyDocument, Guid>(e => e.Id == documents[0].Id || e.Id == documents[1].Id);
Assert.AreEqual(2, count);
}
}
}
137 changes: 137 additions & 0 deletions IntegrationTests/DeletePartitionedTKeyTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using IntegrationTests.Infrastructure;
using MongoDB.Bson.Serialization.Attributes;
using MongoDbGenericRepository.Models;
using NUnit.Framework;
using System;
using System.Threading.Tasks;

namespace IntegrationTests
{
public class DeleteTestsPartitionedTKeyDocument : IPartitionedDocument, IDocument<Guid>
{
[BsonId]
public Guid Id { get; set; }
public int Version { get; set; }
public DeleteTestsPartitionedTKeyDocument()
{
Id = Guid.NewGuid();
Version = 2;
PartitionKey = "TestPartitionKey";
}
public string PartitionKey { get; set; }
public string SomeContent { get; set; }
}

public class DeletePartitionedTKeyTests : BaseMongoDbRepositoryTests<DeleteTestsPartitionedTKeyDocument>
{
[Test]
public void PartitionedDeleteOne()
{
// Arrange
var document = CreateTestDocument();
SUT.AddOne<DeleteTestsPartitionedTKeyDocument, Guid>(document);
// Act
var result = SUT.DeleteOne<DeleteTestsPartitionedTKeyDocument, Guid>(document);
// Assert
Assert.AreEqual(1, result);
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey));
}

[Test]
public void PartitionedDeleteOneLinq()
{
// Arrange
var document = CreateTestDocument();
SUT.AddOne<DeleteTestsPartitionedTKeyDocument, Guid>(document);
// Act
var result = SUT.DeleteOne<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey);
// Assert
Assert.AreEqual(1, result);
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey));
}

[Test]
public async Task PartitionedDeleteOneAsync()
{
// Arrange
var document = CreateTestDocument();
SUT.AddOne<DeleteTestsPartitionedTKeyDocument, Guid>(document);
// Act
var result = await SUT.DeleteOneAsync<DeleteTestsPartitionedTKeyDocument, Guid>(document);
// Assert
Assert.AreEqual(1, result);
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey));
}

[Test]
public async Task PartitionedDeleteOneAsyncLinq()
{
// Arrange
var document = CreateTestDocument();
SUT.AddOne<DeleteTestsPartitionedTKeyDocument, Guid>(document);
// Act
var result = await SUT.DeleteOneAsync<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey);
// Assert
Assert.AreEqual(1, result);
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.Id == document.Id, PartitionKey));
}

[Test]
public async Task PartitionedDeleteManyAsyncLinq()
{
// Arrange
var documents = CreateTestDocuments(5);
documents.ForEach(e => e.SomeContent = "DeleteManyAsyncLinqContent");
SUT.AddMany<DeleteTestsPartitionedTKeyDocument, Guid>(documents);
// Act
var result = await SUT.DeleteManyAsync<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.SomeContent == "DeleteManyAsyncLinqContent", PartitionKey);
// Assert
Assert.AreEqual(5, result);
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.SomeContent == "DeleteManyAsyncLinqContent", PartitionKey));
}

[Test]
public async Task PartitionedDeleteManyAsync()
{
// Arrange
var documents = CreateTestDocuments(5);
documents.ForEach(e => e.SomeContent = "DeleteManyAsyncLinqContent");
SUT.AddMany<DeleteTestsPartitionedTKeyDocument, Guid>(documents);
// Act
var result = await SUT.DeleteManyAsync<DeleteTestsPartitionedTKeyDocument, Guid>(documents);
// Assert
Assert.AreEqual(5, result);
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.SomeContent == "DeleteManyAsyncLinqContent", PartitionKey));
}

[Test]
public void PartitionedDeleteManyLinq()
{
// Arrange
var content = "DeleteManyLinqContent";
var documents = CreateTestDocuments(5);
documents.ForEach(e => e.SomeContent = content);
SUT.AddMany<DeleteTestsPartitionedTKeyDocument, Guid>(documents);
// Act
var result = SUT.DeleteMany<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.SomeContent == content, PartitionKey);
// Assert
Assert.AreEqual(5, result);
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.SomeContent == content, PartitionKey));
}

[Test]
public void PartitionedDeleteMany()
{
// Arrange
var content = "DeleteManyContent";
var documents = CreateTestDocuments(5);
documents.ForEach(e => e.SomeContent = content);
SUT.AddMany<DeleteTestsPartitionedTKeyDocument, Guid>(documents);
// Act
var result = SUT.DeleteMany<DeleteTestsPartitionedTKeyDocument, Guid>(documents);
// Assert
Assert.AreEqual(5, result);
Assert.IsFalse(SUT.Any<DeleteTestsPartitionedTKeyDocument, Guid>(e => e.SomeContent == content, PartitionKey));
}
}
}
Loading

0 comments on commit bfe1652

Please sign in to comment.