Commit 1b8283bb authored by hasan khaddour's avatar hasan khaddour

add architecture test

parent eb28e1fd
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Api
{
public class AssemblyReference
{
public static readonly Assembly Assembly = typeof(AssemblyReference).Assembly;
}
}
......@@ -14,27 +14,16 @@ namespace PSManagement.Api.DI
{
public static IServiceCollection AddAPI(this IServiceCollection services)
{
services
.AddApiSwagger()
.AddApiCors()
.AddMapper()
.AddMyControllers();
;
return services;
}
#region Configure controllers
private static IServiceCollection AddMyControllers(this IServiceCollection services) {
services
.AddControllers()
.AddApplicationPart(Presentation.AssemblyReference.Assembly);
return services;
}
#endregion Configure controllers
#region Api Docs Swagger
private static IServiceCollection AddApiSwagger(this IServiceCollection services)
{
......@@ -99,25 +88,7 @@ namespace PSManagement.Api.DI
}
#endregion Cors
#region Mappers
private static IServiceCollection AddMapper(this IServiceCollection services ) {
services.AddScoped<Mapper>();
services.AddAutoMapper(cfg => {
cfg.AddProfile<CustomerMapperConfiguration>();
cfg.AddProfile<ProjectMapperConfiguration>();
cfg.AddProfile<MappersConfigurations>();
cfg.AddProfile<EmployeeMapperConfiguration>();
});
return services;
}
#endregion Mappers
}
......
......@@ -28,6 +28,7 @@ namespace PSManagement.Api
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// adding dependency injection
......@@ -39,6 +40,7 @@ namespace PSManagement.Api
.AddInfrastructureSevices(Configuration);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Application
{
public class AssemblyReference
{
public static readonly Assembly Assembly = typeof(AssemblyReference).Assembly;
}
}
......@@ -40,6 +40,9 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CreateProject
return Result.Invalid(ProjectTypesErrors.InvalidEntryError);
}
//using builder from domain layer to build the project
Project project = _projectBuilder
.WithProjectAggreement(request.ProjectAggreement)
.WithProjectInfo(request.ProjectInfo)
......
using NetArchTest.Rules;
using FluentAssertions;
using Xunit;
namespace PSManagement.ArchitectureTests
{
public partial class ArchitectureDomainTests : ArchitectureTest
{
[Fact]
public void Domain_Should_Not_DependOnOtherProject()
{
// Arrange
var otherProject = new[]
{
ApplicationNamespace,
InfrastructureNamespace,
PresentationNamespace,
ApiNamespace
};
// Act
var result = Types
.InAssembly(PSManagement.Domain.AssemblyReference.Assembly)
.ShouldNot()
.HaveDependencyOnAll(otherProject)
.GetResult();
// Assert
result.IsSuccessful.Should().BeTrue();
}
}
}
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 System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.ArchitectureTests
{
public class ArchitectureTest
{
protected const string DomainNamespace = "PSManagement.Domain";
protected const string ApplicationNamespace = "PSManagement.Application";
protected const string InfrastructureNamespace = "PSManagement.Infrastructure.Services";
protected const string DataNamespace = "PSManagement.Infrastructure.Persistence";
protected const string PresentationNamespace = "PSManagement.Presentation";
protected const string ApiNamespace = "PSManagement.Api";
}
}

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.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">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PSManagement.Api\PSManagement.Api.csproj" />
<ProjectReference Include="..\PSManagement.Application\PSManagement.Application.csproj" />
<ProjectReference Include="..\PSManagement.Contracts\PSManagement.Contracts.csproj" />
<ProjectReference Include="..\PSManagement.Domain\PSManagement.Domain.csproj" />
<ProjectReference Include="..\PSManagement.Infrastructure.Persistence\PSManagement.Infrastructure.Persistence.csproj" />
<ProjectReference Include="..\PSManagement.Infrastructure\PSManagement.Infrastructure.Services.csproj" />
<ProjectReference Include="..\PSManagement.Presentation\PSManagement.Presentation.csproj" />
<ProjectReference Include="..\PSManagement.SharedKernel\PSManagement.SharedKernel.csproj" />
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Domain
{
public class AssemblyReference
{
public static readonly Assembly Assembly = typeof(AssemblyReference).Assembly;
}
}
......@@ -207,9 +207,20 @@ namespace PSManagement.Domain.Projects.Entities
}
}
// Convert the dictionary values to a list for the final result
var contributions = contributionsByEmployee.Values.ToList();
// normalize the values
var totalContribution= Tracks.Count() ;
foreach(var contr in contributions ){
contr.ContributionRatio=contr.ContributionRatio/totalContribution;
}
return contributions.AsEnumerable();
}
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Infrastructure.Persistence
{
public class AssemblyReference
{
public static readonly Assembly Assembly = typeof(AssemblyReference).Assembly;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Infrastructure.Services
{
public class AssemblyReference
{
public static readonly Assembly Assembly = typeof(AssemblyReference).Assembly;
}
}
using Microsoft.Extensions.Configuration;
using AutoMapper;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PSManagement.Api.Mappers;
namespace PSManagement.Presentaion.DI
{
......@@ -7,9 +9,45 @@ namespace PSManagement.Presentaion.DI
{
public static IServiceCollection AddPresentation(this IServiceCollection services)
{
services
.AddMapper()
.AddMyControllers()
;
return services;
}
#region Configure controllers
private static IServiceCollection AddMyControllers(this IServiceCollection services)
{
services
.AddControllers()
.AddApplicationPart(Presentation.AssemblyReference.Assembly);
return services;
}
#endregion Configure controllers
#region Mappers
private static IServiceCollection AddMapper(this IServiceCollection services)
{
services.AddScoped<Mapper>();
services.AddAutoMapper(cfg => {
cfg.AddProfile<CustomerMapperConfiguration>();
cfg.AddProfile<ProjectMapperConfiguration>();
cfg.AddProfile<MappersConfigurations>();
cfg.AddProfile<EmployeeMapperConfiguration>();
});
return services;
}
#endregion Mappers
}
}
......@@ -39,6 +39,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Persistence", "Persistence"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{2FF0133A-7AC6-4346-AEC2-CB5C36939AC7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{A01E75A3-EF06-4880-8EFE-2E2D8EC0FA9F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ArchitectureTests", "ArchitectureTests", "{EECB1F9F-F97D-4A58-BC3D-62490B931836}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{9E74DD5B-202D-4DAD-9A08-3C7340CEF939}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "IntegerationTests", "IntegerationTests", "{83FB2F8C-3B65-44D8-A4A7-8E87166233CD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PSManagement.ArchitectureTests", "PSManagement.ArchitectureTests\PSManagement.ArchitectureTests.csproj", "{394812BD-ECB4-4B7B-A6FF-4310E145450A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -77,6 +87,10 @@ Global
{430FC82E-16C9-453F-92D3-F4E35F52E0F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{430FC82E-16C9-453F-92D3-F4E35F52E0F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{430FC82E-16C9-453F-92D3-F4E35F52E0F0}.Release|Any CPU.Build.0 = Release|Any CPU
{394812BD-ECB4-4B7B-A6FF-4310E145450A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{394812BD-ECB4-4B7B-A6FF-4310E145450A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{394812BD-ECB4-4B7B-A6FF-4310E145450A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{394812BD-ECB4-4B7B-A6FF-4310E145450A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -99,6 +113,10 @@ Global
{430FC82E-16C9-453F-92D3-F4E35F52E0F0} = {E40CD9A8-20E3-4D39-992B-F7DA048E3B4C}
{E40CD9A8-20E3-4D39-992B-F7DA048E3B4C} = {7C209DBF-1DB8-4E86-BD78-F689B70D5BD1}
{2FF0133A-7AC6-4346-AEC2-CB5C36939AC7} = {7C209DBF-1DB8-4E86-BD78-F689B70D5BD1}
{EECB1F9F-F97D-4A58-BC3D-62490B931836} = {A01E75A3-EF06-4880-8EFE-2E2D8EC0FA9F}
{9E74DD5B-202D-4DAD-9A08-3C7340CEF939} = {A01E75A3-EF06-4880-8EFE-2E2D8EC0FA9F}
{83FB2F8C-3B65-44D8-A4A7-8E87166233CD} = {A01E75A3-EF06-4880-8EFE-2E2D8EC0FA9F}
{394812BD-ECB4-4B7B-A6FF-4310E145450A} = {EECB1F9F-F97D-4A58-BC3D-62490B931836}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5B34709A-AE37-4026-9182-CB9C7ADDEAF5}
......
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