+ Tips
+ Memberships - DDD - FutureCreator - UserTransactions
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System.Data.Common;
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using Hutopy.Infrastructure.Data;
|
||||
using Hutopy.Web;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
@@ -14,29 +13,20 @@ namespace Hutopy.Application.FunctionalTests;
|
||||
|
||||
using static Testing;
|
||||
|
||||
public class CustomWebApplicationFactory : WebApplicationFactory<Program>
|
||||
public class CustomWebApplicationFactory(
|
||||
DbConnection connection)
|
||||
: WebApplicationFactory<Program>
|
||||
{
|
||||
private readonly DbConnection _connection;
|
||||
|
||||
public CustomWebApplicationFactory(DbConnection connection)
|
||||
{
|
||||
_connection = connection;
|
||||
}
|
||||
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
builder.ConfigureTestServices(services =>
|
||||
{
|
||||
services
|
||||
.RemoveAll<IUser>()
|
||||
.AddTransient(provider => Mock.Of<IUser>(s => s.Id == GetUserId()));
|
||||
|
||||
services
|
||||
.RemoveAll<DbContextOptions<ApplicationDbContext>>()
|
||||
.AddDbContext<ApplicationDbContext>((sp, options) =>
|
||||
{
|
||||
options.AddInterceptors(sp.GetServices<ISaveChangesInterceptor>());
|
||||
options.UseSqlServer(_connection);
|
||||
options.UseSqlServer(connection);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<RootNamespace>Hutopy.Application.UnitTests</RootNamespace>
|
||||
<AssemblyName>Hutopy.Application.UnitTests</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="nunit" />
|
||||
<PackageReference Include="NUnit.Analyzers">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NUnit3TestAdapter" />
|
||||
<PackageReference Include="coverlet.collector" />
|
||||
<PackageReference Include="FluentAssertions" />
|
||||
<PackageReference Include="Moq" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Application\Application.csproj" />
|
||||
<ProjectReference Include="..\..\src\Infrastructure\Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,18 +0,0 @@
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Hutopy.Application.UnitTests.Common.Behaviours;
|
||||
|
||||
public class RequestLoggerTests
|
||||
{
|
||||
private Mock<IUser> _user = null!;
|
||||
private Mock<IIdentityService> _identityService = null!;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_user = new Mock<IUser>();
|
||||
_identityService = new Mock<IIdentityService>();
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
using Hutopy.Application.Common.Exceptions;
|
||||
using FluentAssertions;
|
||||
using FluentValidation.Results;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Hutopy.Application.UnitTests.Common.Exceptions;
|
||||
|
||||
public class ValidationExceptionTests
|
||||
{
|
||||
[Test]
|
||||
public void DefaultConstructorCreatesAnEmptyErrorDictionary()
|
||||
{
|
||||
var actual = new ValidationException().Errors;
|
||||
|
||||
actual.Keys.Should().BeEquivalentTo(Array.Empty<string>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SingleValidationFailureCreatesASingleElementErrorDictionary()
|
||||
{
|
||||
var failures = new List<ValidationFailure>
|
||||
{
|
||||
new ValidationFailure("Age", "must be over 18"),
|
||||
};
|
||||
|
||||
var actual = new ValidationException(failures).Errors;
|
||||
|
||||
actual.Keys.Should().BeEquivalentTo(new string[] { "Age" });
|
||||
actual["Age"].Should().BeEquivalentTo(new string[] { "must be over 18" });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MulitpleValidationFailureForMultiplePropertiesCreatesAMultipleElementErrorDictionaryEachWithMultipleValues()
|
||||
{
|
||||
var failures = new List<ValidationFailure>
|
||||
{
|
||||
new ValidationFailure("Age", "must be 18 or older"),
|
||||
new ValidationFailure("Age", "must be 25 or younger"),
|
||||
new ValidationFailure("Password", "must contain at least 8 characters"),
|
||||
new ValidationFailure("Password", "must contain a digit"),
|
||||
new ValidationFailure("Password", "must contain upper case letter"),
|
||||
new ValidationFailure("Password", "must contain lower case letter"),
|
||||
};
|
||||
|
||||
var actual = new ValidationException(failures).Errors;
|
||||
|
||||
actual.Keys.Should().BeEquivalentTo(new string[] { "Password", "Age" });
|
||||
|
||||
actual["Age"].Should().BeEquivalentTo(new string[]
|
||||
{
|
||||
"must be 25 or younger",
|
||||
"must be 18 or older",
|
||||
});
|
||||
|
||||
actual["Password"].Should().BeEquivalentTo(new string[]
|
||||
{
|
||||
"must contain lower case letter",
|
||||
"must contain upper case letter",
|
||||
"must contain at least 8 characters",
|
||||
"must contain a digit",
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using AutoMapper;
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Hutopy.Application.UnitTests.Common.Mappings;
|
||||
|
||||
public class MappingTests
|
||||
{
|
||||
private readonly IConfigurationProvider _configuration;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public MappingTests()
|
||||
{
|
||||
_configuration = new MapperConfiguration(config =>
|
||||
config.AddMaps(Assembly.GetAssembly(typeof(IApplicationDbContext))));
|
||||
|
||||
_mapper = _configuration.CreateMapper();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShouldHaveValidConfiguration()
|
||||
{
|
||||
_configuration.AssertConfigurationIsValid();
|
||||
}
|
||||
|
||||
private object GetInstanceOf(Type type)
|
||||
{
|
||||
if (type.GetConstructor(Type.EmptyTypes) != null)
|
||||
return Activator.CreateInstance(type)!;
|
||||
|
||||
// Type without parameterless constructor
|
||||
return RuntimeHelpers.GetUninitializedObject(type);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user