Commit 3a3ec9b2 authored by hasan khaddour's avatar hasan khaddour

Add Tests for dependency and naming convention

parent 1b8283bb
......@@ -6,7 +6,6 @@ using System.Reflection;
using Microsoft.OpenApi.Models;
using System;
using AutoMapper;
using PSManagement.Api.Mappers;
namespace PSManagement.Api.DI
{
......
......@@ -5,7 +5,6 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using PSManagement.Presentaion.DI;
using PSManagement.Infrastructure.DI;
using PSManagement.Application.DI;
using Microsoft.OpenApi.Models;
......@@ -15,6 +14,7 @@ using System.Linq;
using System.Threading.Tasks;
using PSManagement.Infrastructure.Persistence.DI;
using PSManagement.Api.DI;
using PSManagement.Presentation.DependencyInjection;
namespace PSManagement.Api
{
......
using NetArchTest.Rules;
using FluentAssertions;
using Xunit;
using PSManagement.SharedKernel.CQRS.Command;
using PSManagement.SharedKernel.CQRS.Query;
using PSManagement.SharedKernel.Events;
using PSManagement.SharedKernel.DomainEvents;
namespace PSManagement.ArchitectureTests
{
public partial class ArchitectureApplicationTests : ArchitectureTest
{
#region Events Handler Naming Convention
[Fact]
public void EventHandler_ShouldHave_NameEndingWith_EventHandler()
{
var result = Types.InAssembly(PSManagement.Application.AssemblyReference.Assembly)
.That()
.ImplementInterface(typeof(IDomainEventHandler<>))
.Should()
.HaveNameEndingWith("EventHandler")
.GetResult();
result.IsSuccessful.Should().BeTrue();
}
#endregion Events Handler Naming Convention
#region Command Handler Naming Convention
[Fact]
public void CommandHandlers_ShouldHave_NameEndingWith_CommandHandler()
{
var result = Types.InAssembly(PSManagement.Application.AssemblyReference.Assembly)
.That()
.ImplementInterface(typeof(ICommandHandler<,>))
.Should()
.HaveNameEndingWith("CommandHandler")
.GetResult();
result.IsSuccessful.Should().BeTrue();
}
#endregion Command Handler Naming Convention
#region Command Naming Convention
[Fact]
public void Commands_ShouldHave_NameEndingWith_Command()
{
var result = Types.InAssembly(PSManagement.Application.AssemblyReference.Assembly)
.That()
.ImplementInterface(typeof(ICommand<>))
.Should()
.HaveNameEndingWith("Command")
.GetResult();
result.IsSuccessful.Should().BeTrue();
}
#endregion Command Naming Convention
#region Query Handler Naming Convention
[Fact]
public void QueryHandlers_ShouldHave_NameEndingWith_QueryHandler()
{
var result = Types.InAssembly(PSManagement.Application.AssemblyReference.Assembly)
.That()
.ImplementInterface(typeof(IQueryHandler<,>))
.Should()
.HaveNameEndingWith("QueryHandler")
.GetResult();
result.IsSuccessful.Should().BeTrue();
}
#endregion Query Handler Convention
#region Query Naming Convention
[Fact]
public void Queries_ShouldHave_NameEndingWith_Query()
{
var result = Types.InAssembly(PSManagement.Application.AssemblyReference.Assembly)
.That()
.ImplementInterface(typeof(IQuery<>))
.Should()
.HaveNameEndingWith("Query")
.GetResult();
result.IsSuccessful.Should().BeTrue();
}
#endregion Query Convention
#region Dummy Test
//[Fact]
//public void Application_Should_Have_DependOnDomain()
//{
// // Arrange
// var otherProject = new[]
// {
// DomainNamespace
// };
// // Act
// var result = Types
// .InAssembly(Application.AssemblyReference.Assembly)
// .That()
// .HaveNameEndingWith("Handler")
// .Should()
// .HaveDependencyOnAll(otherProject)
// .GetResult();
// // Assert
// result.IsSuccessful.Should().BeTrue();
//}
#endregion Dummy Test
}
}
using NetArchTest.Rules;
using FluentAssertions;
using FluentAssertions;
using NetArchTest.Rules;
using PSManagement.SharedKernel.Events;
using PSManagement.SharedKernel.Repositories;
using Xunit;
namespace PSManagement.ArchitectureTests
{
public partial class ArchitectureDomainTests : ArchitectureTest
public class ArchitectureDomainTests : ArchitectureTest
{
#region Events Naming Convention
[Fact]
public void Domain_Should_Not_DependOnOtherProject()
public void Event_ShouldHave_NameEndingWith_Event()
{
var result = Types.InAssembly(PSManagement.Domain.AssemblyReference.Assembly)
.That()
.ImplementInterface(typeof(IDomainEvent))
.Should()
.HaveNameEndingWith("Event")
.GetResult();
result.IsSuccessful.Should().BeTrue();
}
// Arrange
var otherProject = new[]
#endregion Events Naming Convention
#region Repository Naming Convention
[Fact]
public void Repositories_ShouldHave_NameEndingWith_Repository()
{
ApplicationNamespace,
InfrastructureNamespace,
PresentationNamespace,
ApiNamespace
};
// Act
var result = Types
.InAssembly(PSManagement.Domain.AssemblyReference.Assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProject)
var result = Types.InAssembly(PSManagement.Domain.AssemblyReference.Assembly)
.That()
.ImplementInterface(typeof(IRepository<>))
.Should()
.HaveNameEndingWith("Repository")
.GetResult();
// Assert
result.IsSuccessful.Should().BeTrue();
}
#endregion Repository Naming Convention
}
}
using NetArchTest.Rules;
using FluentAssertions;
using Xunit;
namespace PSManagement.ArchitectureTests
{
public class ArchitectureInfrastrutureServicesTests : ArchitectureTest
{
[Fact]
public void Services_Should_Not_DependOnOtherProject()
{
// Arrange
var otherProject = new[]
{
PresentationNamespace,
ApiNamespace,
DataNamespace
};
// Act
var result = Types
.InAssembly(PSManagement.Infrastructure.Services.AssemblyReference.Assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProject)
.GetResult();
// Assert
result.IsSuccessful.Should().BeTrue();
}
}
}
using NetArchTest.Rules;
using FluentAssertions;
using Xunit;
namespace PSManagement.ArchitectureTests
{
public class DependencyTests : ArchitectureTest
{
#region Presentation Layer
[Fact]
public void Presentation_Should_Not_DependOnOtherProjectExceptApplicationAndContracts()
{
// Arrange
var otherProject = new[]
{
InfrastructureNamespace,
DataNamespace,
DomainNamespace
};
// Act
var result = Types
.InAssembly(Presentation.AssemblyReference.Assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProject)
.GetResult();
// Assert
result.IsSuccessful.Should().BeTrue();
}
#endregion Presentation Layer
#region Application Layer
[Fact]
public void Application_Should_Not_DependOnOtherProjectExceptDmain()
{
// Arrange
var otherProject = new[]
{
InfrastructureNamespace,
PresentationNamespace,
DataNamespace,
ApiNamespace
};
// Act
var result = Types
.InAssembly(Application.AssemblyReference.Assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProject)
.GetResult();
// Assert
result.IsSuccessful.Should().BeTrue();
}
#endregion Application Layer
#region Domain Layer
[Fact]
public void Domain_Should_Not_DependOnOtherProjectExceptSharedKernel()
{
// Arrange
var otherProject = new[]
{
ApplicationNamespace,
InfrastructureNamespace,
DataNamespace,
PresentationNamespace,
ApiNamespace
};
// Act
var result = Types
.InAssembly(PSManagement.Domain.AssemblyReference.Assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProject)
.GetResult();
// Assert
result.IsSuccessful.Should().BeTrue();
}
#endregion Domain Laye
#region PersistenceLayer Layer
[Fact]
public void Persistence_Should_Not_DependOnOtherProjectExceptDomain()
{
// Arrange
var otherProject = new[]
{
ApplicationNamespace,
InfrastructureNamespace,
PresentationNamespace,
ApiNamespace
};
// Act
var result = Types
.InAssembly(PSManagement.Infrastructure.Persistence.AssemblyReference.Assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProject)
.GetResult();
// Assert
result.IsSuccessful.Should().BeTrue();
}
#endregion Persistence Layer
#region Services Layer
[Fact]
public void Services_Should_Not_DependOnOtherProjectExceptApplication()
{
// Arrange
var otherProject = new[]
{
PresentationNamespace,
ApiNamespace,
DataNamespace,
DomainNamespace
};
// Act
var result = Types
.InAssembly(PSManagement.Infrastructure.Services.AssemblyReference.Assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProject)
.GetResult();
// Assert
result.IsSuccessful.Should().BeTrue();
}
#endregion Services Layer
}
}
......@@ -7,6 +7,7 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="16.11.0" />
<PackageReference Include="NetArchTest.Rules" Version="1.3.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
......
using AutoMapper;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PSManagement.Api.Mappers;
using PSManagement.Presentation.Mappers;
namespace PSManagement.Presentaion.DI
namespace PSManagement.Presentation.DependencyInjection
{
public static class DependencyInjection
{
......@@ -23,7 +23,7 @@ namespace PSManagement.Presentaion.DI
services
.AddControllers()
.AddApplicationPart(Presentation.AssemblyReference.Assembly);
.AddApplicationPart(AssemblyReference.Assembly);
return services;
}
......@@ -35,7 +35,8 @@ namespace PSManagement.Presentaion.DI
services.AddScoped<Mapper>();
services.AddAutoMapper(cfg => {
services.AddAutoMapper(cfg =>
{
cfg.AddProfile<CustomerMapperConfiguration>();
cfg.AddProfile<ProjectMapperConfiguration>();
......
......@@ -13,7 +13,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PSManagement.Api.Mappers
namespace PSManagement.Presentation.Mappers
{
public class CustomerMapperConfiguration : Profile
{
......@@ -31,7 +31,7 @@ namespace PSManagement.Api.Mappers
CreateMap<IEnumerable<CustomerResponse>, ListCustomersResponse>()
.ConstructUsing(src => new ListCustomersResponse(src));
CreateMap<AuthenticationResult,AuthenticationResponse>().ReverseMap();
CreateMap<AuthenticationResult, AuthenticationResponse>().ReverseMap();
}
}
}
......@@ -3,7 +3,7 @@ using PSManagement.Application.Employees.Common;
using PSManagement.Application.Projects.Common;
using PSManagement.Contracts.Projects.Response;
namespace PSManagement.Api.Mappers
namespace PSManagement.Presentation.Mappers
{
public class EmployeeMapperConfiguration : Profile
{
......
......@@ -5,9 +5,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PSManagement.Api.Mappers
namespace PSManagement.Presentation.Mappers
{
public class MappersConfigurations :Profile
public class MappersConfigurations : Profile
{
public MappersConfigurations()
{
......
......@@ -12,7 +12,7 @@ using PSManagement.Contracts.Projects.Requests;
using PSManagement.Contracts.Projects.Response;
using PSManagement.Contracts.Tracks.Response;
namespace PSManagement.Api.Mappers
namespace PSManagement.Presentation.Mappers
{
public class ProjectMapperConfiguration : Profile
{
......@@ -25,9 +25,9 @@ namespace PSManagement.Api.Mappers
CreateMap<AddProjectStepRequest, AddProjectStepCommand>().ReverseMap();
CreateMap<ChangeProjectTeamLeaderRequest, ChangeProjectTeamLeaderCommand>().ReverseMap();
CreateMap<RemoveParticipantRequest, RemoveParticipantCommand>().ReverseMap();
CreateMap<ProjectDTO,ProjectResponse>().ReverseMap();
CreateMap<GetProjectsByProjectManagerRequest,GetProjectsByFilterQuery>().ConstructUsing(
s => new GetProjectsByFilterQuery(null,null,null,null,s.ProjectManagerId,null,null,null)
CreateMap<ProjectDTO, ProjectResponse>().ReverseMap();
CreateMap<GetProjectsByProjectManagerRequest, GetProjectsByFilterQuery>().ConstructUsing(
s => new GetProjectsByFilterQuery(null, null, null, null, s.ProjectManagerId, null, null, null)
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment