Added tests for IdentityUsers
This commit is contained in:
@@ -5,11 +5,13 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.4.4" />
|
||||
<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" />
|
||||
<PackageReference Include="xunit" Version="2.3.0" />
|
||||
<PackageReference Include="xunit.runner.console" Version="2.3.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0" />
|
||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta4-build3742" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
using IntegrationTests.Infrastructure;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CoreIntegrationTests
|
||||
{
|
||||
public class MongoIdentityUser<TKey> : IdentityUser<TKey>, IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
public int Version { get; set; }
|
||||
}
|
||||
|
||||
public class IdentityUserTest : MongoIdentityUser<Guid>, IDocument<Guid>
|
||||
{
|
||||
public IdentityUserTest()
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
Version = 2;
|
||||
}
|
||||
public string SomeContent { get; set; }
|
||||
}
|
||||
|
||||
public class IdentityUserTests : BaseMongoDbRepositoryTests<IdentityUserTest>
|
||||
{
|
||||
[Fact]
|
||||
public void AddOne()
|
||||
{
|
||||
// Arrange
|
||||
var document = new IdentityUserTest();
|
||||
// Act
|
||||
SUT.AddOne<IdentityUserTest, Guid>(document);
|
||||
// Assert
|
||||
long count = SUT.Count<IdentityUserTest, Guid>(e => e.Id == document.Id);
|
||||
Assert.Equal(1, count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddOneAsync()
|
||||
{
|
||||
// Arrange
|
||||
var document = new IdentityUserTest();
|
||||
// Act
|
||||
await SUT.AddOneAsync<IdentityUserTest, Guid>(document);
|
||||
// Assert
|
||||
long count = SUT.Count<IdentityUserTest, Guid>(e => e.Id == document.Id);
|
||||
Assert.Equal(1, count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddMany()
|
||||
{
|
||||
// Arrange
|
||||
var documents = new List<IdentityUserTest> { new IdentityUserTest(), new IdentityUserTest() };
|
||||
// Act
|
||||
SUT.AddMany<IdentityUserTest, Guid>(documents);
|
||||
// Assert
|
||||
long count = SUT.Count<IdentityUserTest, Guid>(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<IdentityUserTest> { new IdentityUserTest(), new IdentityUserTest() };
|
||||
// Act
|
||||
await SUT.AddManyAsync<IdentityUserTest, Guid>(documents);
|
||||
// Assert
|
||||
long count = SUT.Count<IdentityUserTest, Guid>(e => e.Id == documents[0].Id || e.Id == documents[1].Id);
|
||||
Assert.Equal(2, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using System;
|
||||
namespace IntegrationTests.Infrastructure
|
||||
{
|
||||
|
||||
public class BaseMongoDbRepositoryTests<T> : IDisposable where T : Document, new()
|
||||
public class BaseMongoDbRepositoryTests<T> : IDisposable where T : new()
|
||||
{
|
||||
public T CreateTestDocument()
|
||||
{
|
||||
@@ -44,6 +44,7 @@ namespace IntegrationTests.Infrastructure
|
||||
|
||||
public void Init()
|
||||
{
|
||||
MongoDbConfig.EnsureConfigured();
|
||||
SUT = TestRepository.Instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
using CoreIntegrationTests;
|
||||
using MongoDB.Bson.Serialization;
|
||||
using MongoDB.Bson.Serialization.Conventions;
|
||||
using System.Threading;
|
||||
|
||||
namespace IntegrationTests.Infrastructure
|
||||
{
|
||||
internal static class MongoDbConfig
|
||||
{
|
||||
private static bool _initialized = false;
|
||||
private static object _initializationLock = new object();
|
||||
private static object _initializationTarget;
|
||||
|
||||
public static void EnsureConfigured()
|
||||
{
|
||||
EnsureConfiguredImpl();
|
||||
}
|
||||
|
||||
private static void EnsureConfiguredImpl()
|
||||
{
|
||||
LazyInitializer.EnsureInitialized(ref _initializationTarget, ref _initialized, ref _initializationLock, () =>
|
||||
{
|
||||
Configure();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private static void Configure()
|
||||
{
|
||||
RegisterConventions();
|
||||
}
|
||||
|
||||
private static void RegisterConventions()
|
||||
{
|
||||
var pack = new ConventionPack
|
||||
{
|
||||
new IgnoreIfNullConvention(false),
|
||||
new CamelCaseElementNameConvention(),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ namespace MongoDbGenericRepository.Models
|
||||
/// The Primary Key, which must be decorated with the [BsonId] attribute
|
||||
/// if you want the MongoDb C# driver to consider it to be the document ID.
|
||||
/// </summary>
|
||||
[BsonId]
|
||||
TKey Id { get; set; }
|
||||
/// <summary>
|
||||
/// A version number, to indicate the version of the schema.
|
||||
@@ -25,7 +24,7 @@ namespace MongoDbGenericRepository.Models
|
||||
/// This class represents a basic document that can be stored in MongoDb.
|
||||
/// Your document must implement this class in order for the MongoDbRepository to handle them.
|
||||
/// </summary>
|
||||
public interface IDocument: IDocument<Guid>
|
||||
public interface IDocument : IDocument<Guid>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||
<Relationship Type="http://schemas.microsoft.com/packaging/2010/07/manifest" Target="/MongoDbGenericRepository.nuspec" Id="Rd7ba7aa97a7d4fb2" />
|
||||
<Relationship Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="/package/services/metadata/core-properties/e5080d3094a649a39d247315f4dcd1ba.psmdcp" Id="Rcfffb2818c774b93" />
|
||||
</Relationships>
|
||||
Reference in New Issue
Block a user