diff --git a/.github/workflows/createrelease.yml b/.github/workflows/createrelease.yml index afe0bffa..469e1a37 100644 --- a/.github/workflows/createrelease.yml +++ b/.github/workflows/createrelease.yml @@ -29,6 +29,12 @@ jobs: - name: Build Code run: dotnet build TransactionProcessor.sln --configuration Release + + - name: Run Unit Tests + run: | + echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" + dotnet test "TransactionProcessor.BusinessLogic.Tests\TransactionProcessor.BusinessLogic.Tests.csproj" + dotnet test "TransactionProcessor.Tests\TransactionProcessor.Tests.csproj" - name: Build Docker Images run: | diff --git a/.github/workflows/nightlybuild.yml b/.github/workflows/nightlybuild.yml index fd89f627..fea6aba3 100644 --- a/.github/workflows/nightlybuild.yml +++ b/.github/workflows/nightlybuild.yml @@ -26,5 +26,11 @@ jobs: - name: Build Code run: dotnet build TransactionProcessor.sln --configuration Release + - name: Run Unit Tests + run: | + echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" + dotnet test "TransactionProcessor.BusinessLogic.Tests\TransactionProcessor.BusinessLogic.Tests.csproj" + dotnet test "TransactionProcessor.Tests\TransactionProcessor.Tests.csproj" + - name: Build Docker Image run: docker build . --file TransactionProcessor/Dockerfile --tag transactionprocessor:latest diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index c7bf4c49..adcfcc99 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -27,6 +27,12 @@ jobs: - name: Build Code run: dotnet build TransactionProcessor.sln --configuration Release + - name: Run Unit Tests + run: | + echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" + dotnet test "TransactionProcessor.BusinessLogic.Tests\TransactionProcessor.BusinessLogic.Tests.csproj" + dotnet test "TransactionProcessor.Tests\TransactionProcessor.Tests.csproj" + - name: Build Docker Image run: docker build . --file TransactionProcessor/Dockerfile --tag transactionprocessor:latest diff --git a/TransactionProcessor.BusinessLogic.Tests/CommandHandler/CommandRouterTests.cs b/TransactionProcessor.BusinessLogic.Tests/CommandHandler/CommandRouterTests.cs new file mode 100644 index 00000000..6246f91d --- /dev/null +++ b/TransactionProcessor.BusinessLogic.Tests/CommandHandler/CommandRouterTests.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TransactionProcessor.BusinessLogic.Tests.CommandHandler +{ + using System.Threading; + using System.Threading.Tasks; + using BusinessLogic.Commands; + using CommandHandlers; + using Commands; + using Moq; + using Services; + using Shared.DomainDrivenDesign.CommandHandling; + using Shouldly; + using Testing; + using Xunit; + + public class CommandRouterTests + { + [Fact] + public void CommandRouter_ProcessLogonTransactionCommand_IsRouted() + { + Mock transactionDomainService = new Mock(); + ICommandRouter router = new CommandRouter(transactionDomainService.Object); + + ProcessLogonTransactionCommand command = TestData.ProcessLogonTransactionCommand; + + Should.NotThrow(async () => + { + await router.Route(command, CancellationToken.None); + }); + } + } + + public class TransactionDomainServiceTests + { + [Fact(Skip = "Complete once aggregate in place")] + public async Task TransactionDomainService_ProcessLogonTransaction_LogonTransactionIsProcesses() + { + //Mock> estateAggregateRepository = new Mock>(); + //estateAggregateRepository.Setup(m => m.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(new EstateAggregate()); + //estateAggregateRepository.Setup(m => m.SaveChanges(It.IsAny(), It.IsAny())).Returns(Task.CompletedTask); + + //Mock aggregateRepositoryManager = new Mock(); + //aggregateRepositoryManager.Setup(x => x.GetAggregateRepository(It.IsAny())).Returns(estateAggregateRepository.Object); + + //EstateDomainService domainService = new EstateDomainService(aggregateRepositoryManager.Object); + + //Should.NotThrow(async () => + //{ + // await domainService.CreateEstate(TestData.EstateId, + // TestData.EstateName, + // CancellationToken.None); + //}); + throw new NotImplementedException(); + } + } +} + + diff --git a/TransactionProcessor.BusinessLogic.Tests/CommandHandler/TransactionCommandHandlerTests.cs b/TransactionProcessor.BusinessLogic.Tests/CommandHandler/TransactionCommandHandlerTests.cs new file mode 100644 index 00000000..ef8249ae --- /dev/null +++ b/TransactionProcessor.BusinessLogic.Tests/CommandHandler/TransactionCommandHandlerTests.cs @@ -0,0 +1,31 @@ +namespace TransactionProcessor.BusinessLogic.Tests.CommandHandler +{ + using System.Threading; + using BusinessLogic.Commands; + using CommandHandlers; + using Commands; + using Moq; + using Services; + using Shared.DomainDrivenDesign.CommandHandling; + using Shouldly; + using Testing; + using Xunit; + + public class TransactionCommandHandlerTests + { + [Fact] + public void EstateCommandHandler_CreateEstateCommand_IsHandled() + { + Mock transactionDomainService = new Mock(); + ICommandHandler handler = new TransactionCommandHandler(transactionDomainService.Object); + + ProcessLogonTransactionCommand command = TestData.ProcessLogonTransactionCommand; + + Should.NotThrow(async () => + { + await handler.Handle(command, CancellationToken.None); + }); + + } + } +} \ No newline at end of file diff --git a/TransactionProcessor.BusinessLogic.Tests/Commands/CommandTests.cs b/TransactionProcessor.BusinessLogic.Tests/Commands/CommandTests.cs new file mode 100644 index 00000000..ff788f85 --- /dev/null +++ b/TransactionProcessor.BusinessLogic.Tests/Commands/CommandTests.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TransactionProcessor.BusinessLogic.Tests.Commands +{ + using BusinessLogic.Commands; + using Shouldly; + using Testing; + using Xunit; + + public class CommandTests + { + [Fact] + public void ProcessLogonTransactionCommand_CanBeCreated_IsCreated() + { + ProcessLogonTransactionCommand processLogonTransactionCommand = ProcessLogonTransactionCommand.Create(TestData.EstateId, TestData.MerchantId, TestData.IMEINumber,TestData.TransactionType, TestData.TransactionDateTime, + TestData.TransactionNumber); + + processLogonTransactionCommand.ShouldNotBeNull(); + processLogonTransactionCommand.CommandId.ShouldNotBe(Guid.Empty); + processLogonTransactionCommand.EstateId.ShouldBe(TestData.EstateId); + processLogonTransactionCommand.MerchantId.ShouldBe(TestData.MerchantId); + processLogonTransactionCommand.IMEINumber.ShouldBe(TestData.IMEINumber); + processLogonTransactionCommand.TransactionType.ShouldBe(TestData.TransactionType); + processLogonTransactionCommand.TransactionDateTime.ShouldBe(TestData.TransactionDateTime); + processLogonTransactionCommand.TransactionNumber.ShouldBe(TestData.TransactionNumber); + } + } +} diff --git a/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj b/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj new file mode 100644 index 00000000..506432db --- /dev/null +++ b/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj @@ -0,0 +1,35 @@ + + + + netcoreapp3.0 + None + false + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + diff --git a/TransactionProcessor.BusinessLogic/Commands/ProcessLogonTransactionCommand.cs b/TransactionProcessor.BusinessLogic/Commands/ProcessLogonTransactionCommand.cs index 8f5433cd..e926ba86 100644 --- a/TransactionProcessor.BusinessLogic/Commands/ProcessLogonTransactionCommand.cs +++ b/TransactionProcessor.BusinessLogic/Commands/ProcessLogonTransactionCommand.cs @@ -13,11 +13,105 @@ public class ProcessLogonTransactionCommand : Command - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// + /// The estate identifier. + /// The merchant identifier. + /// The imei number. + /// Type of the transaction. + /// The transaction date time. + /// The transaction number. /// The command identifier. - public ProcessLogonTransactionCommand(Guid commandId) : base(commandId) + private ProcessLogonTransactionCommand(Guid estateId, + Guid merchantId, + String imeiNumber, + String transactionType, + DateTime transactionDateTime, + String transactionNumber, + Guid commandId) : base(commandId) { + this.EstateId = estateId; + this.IMEINumber = imeiNumber; + this.MerchantId = merchantId; + this.TransactionDateTime = transactionDateTime; + this.TransactionNumber = transactionNumber; + this.TransactionType = transactionType; + } + + #endregion + + #region Properties + + /// + /// Gets the estate identifier. + /// + /// + /// The estate identifier. + /// + public Guid EstateId { get; } + + /// + /// Gets the imei number. + /// + /// + /// The imei number. + /// + public String IMEINumber { get; } + + /// + /// Gets the merchant identifier. + /// + /// + /// The merchant identifier. + /// + public Guid MerchantId { get; } + + /// + /// Gets the transaction date time. + /// + /// + /// The transaction date time. + /// + public DateTime TransactionDateTime { get; } + + /// + /// Gets the transaction number. + /// + /// + /// The transaction number. + /// + public String TransactionNumber { get; } + + /// + /// Gets the type of the transaction. + /// + /// + /// The type of the transaction. + /// + public String TransactionType { get; } + + #endregion + + #region Methods + + /// + /// Creates the specified estate identifier. + /// + /// The estate identifier. + /// The merchant identifier. + /// The imei number. + /// Type of the transaction. + /// The transaction date time. + /// The transaction number. + /// + public static ProcessLogonTransactionCommand Create(Guid estateId, + Guid merchantId, + String imeiNumber, + String transactionType, + DateTime transactionDateTime, + String transactionNumber) + { + return new ProcessLogonTransactionCommand(estateId, merchantId, imeiNumber, transactionType, transactionDateTime, transactionNumber, Guid.NewGuid()); } #endregion diff --git a/TransactionProcessor.DataTransferObjects/LogonTransactionRequest.cs b/TransactionProcessor.DataTransferObjects/LogonTransactionRequest.cs index d570e116..ad84df66 100644 --- a/TransactionProcessor.DataTransferObjects/LogonTransactionRequest.cs +++ b/TransactionProcessor.DataTransferObjects/LogonTransactionRequest.cs @@ -1,10 +1,12 @@ namespace TransactionProcessor.DataTransferObjects { using System; + using System.Diagnostics.CodeAnalysis; /// /// /// + [ExcludeFromCodeCoverage] public class LogonTransactionRequest { #region Properties @@ -25,6 +27,14 @@ public class LogonTransactionRequest /// public Guid MerchantId { get; set; } + /// + /// Gets or sets the estate identifier. + /// + /// + /// The estate identifier. + /// + public Guid EstateId { get; set; } + /// /// Gets or sets the transaction date time. /// diff --git a/TransactionProcessor.DataTransferObjects/LogonTransactionResponse.cs b/TransactionProcessor.DataTransferObjects/LogonTransactionResponse.cs index 3c59e218..dc4dff50 100644 --- a/TransactionProcessor.DataTransferObjects/LogonTransactionResponse.cs +++ b/TransactionProcessor.DataTransferObjects/LogonTransactionResponse.cs @@ -1,10 +1,12 @@ namespace TransactionProcessor.DataTransferObjects { using System; + using System.Diagnostics.CodeAnalysis; /// /// /// + [ExcludeFromCodeCoverage] public class LogonTransactionResponse { #region Properties diff --git a/TransactionProcessor.Models/ProcessLogonTransactionResponse.cs b/TransactionProcessor.Models/ProcessLogonTransactionResponse.cs index c394e426..ded9081e 100644 --- a/TransactionProcessor.Models/ProcessLogonTransactionResponse.cs +++ b/TransactionProcessor.Models/ProcessLogonTransactionResponse.cs @@ -1,10 +1,12 @@ namespace TransactionProcessor.Models { using System; + using System.Diagnostics.CodeAnalysis; /// /// /// + [ExcludeFromCodeCoverage] public class ProcessLogonTransactionResponse { #region Properties diff --git a/TransactionProcessor.Testing/TestData.cs b/TransactionProcessor.Testing/TestData.cs new file mode 100644 index 00000000..f9c327e1 --- /dev/null +++ b/TransactionProcessor.Testing/TestData.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TransactionProcessor.Testing +{ + using BusinessLogic.Commands; + using Models; + + public class TestData + { + public static ProcessLogonTransactionResponse ProcessLogonTransactionResponseModel = new ProcessLogonTransactionResponse + { + ResponseMessage = TestData.ResponseMessage, + ResponseCode = TestData.ResponseCode + }; + + public static String ResponseMessage = "SUCCESS"; + + public static Int32 ResponseCode= 0; + + public static Guid EstateId = Guid.Parse("A522FA27-F9D0-470A-A88D-325DED3B62EE"); + public static Guid MerchantId = Guid.Parse("833B5AAC-A5C5-46C2-A499-F2B4252B2942"); + + public static ProcessLogonTransactionCommand ProcessLogonTransactionCommand = ProcessLogonTransactionCommand.Create(TestData.EstateId, TestData.MerchantId, + TestData.IMEINumber, TestData.TransactionType, + TestData.TransactionDateTime, + TestData.TransactionNumber); + + public static String IMEINumber = "1234567890"; + + public static String TransactionType = "1000"; + + public static DateTime TransactionDateTime = DateTime.Now; + + public static String TransactionNumber = "0001"; + } +} diff --git a/TransactionProcessor.Testing/TransactionProcessor.Testing.csproj b/TransactionProcessor.Testing/TransactionProcessor.Testing.csproj new file mode 100644 index 00000000..6af20116 --- /dev/null +++ b/TransactionProcessor.Testing/TransactionProcessor.Testing.csproj @@ -0,0 +1,13 @@ + + + + netcoreapp3.0 + None + + + + + + + + diff --git a/TransactionProcessor.Tests/Common/TransactionProcessorWebFactory.cs b/TransactionProcessor.Tests/Common/TransactionProcessorWebFactory.cs new file mode 100644 index 00000000..ababf495 --- /dev/null +++ b/TransactionProcessor.Tests/Common/TransactionProcessorWebFactory.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TransactionProcessor.Tests.Common +{ + using System.Net.Http; + using System.Threading; + using System.Threading.Tasks; + using BusinessLogic.Commands; + using Microsoft.AspNetCore.Hosting; + using Microsoft.AspNetCore.Mvc.Authorization; + using Microsoft.AspNetCore.Mvc.Testing; + using Microsoft.Extensions.DependencyInjection; + using Models; + using Moq; + using Newtonsoft.Json; + using Shared.DomainDrivenDesign.CommandHandling; + using Xunit; + + public class TransactionProcessorWebFactory : WebApplicationFactory where TStartup : class + { + protected override void ConfigureWebHost(IWebHostBuilder builder) + { + // Setup my mocks in here + Mock commandRouterMock = this.CreateCommandRouterMock(); + + builder.ConfigureServices((builderContext, services) => + { + if (commandRouterMock != null) + { + services.AddSingleton(commandRouterMock.Object); + } + + services.AddMvc(options => + { + options.Filters.Add(new AllowAnonymousFilter()); + }) + .AddApplicationPart(typeof(Startup).Assembly); + }); + ; + } + + private Mock CreateCommandRouterMock() + { + Mock commandRouterMock = new Mock(MockBehavior.Strict); + + commandRouterMock.Setup(c => c.Route(It.IsAny(), It.IsAny())).Returns((ProcessLogonTransactionCommand command, CancellationToken cancellationToken) => + { + command.Response = new ProcessLogonTransactionResponse + { + ResponseMessage = "SUCCESS", + ResponseCode = 0 + }; + return Task.CompletedTask; + }); + + return commandRouterMock; + } + + } + + /// + /// + /// + [CollectionDefinition("TestCollection")] + public class TestCollection : ICollectionFixture> + { + // A class with no code, only used to define the collection + } + + public static class Helpers + { + #region Methods + + /// + /// Creates the content of the string. + /// + /// + /// The request object. + /// + public static StringContent CreateStringContent(T requestObject) + { + return new StringContent(JsonConvert.SerializeObject(requestObject), Encoding.UTF8, "application/json"); + } + + #endregion + } +} diff --git a/TransactionProcessor.Tests/ControllerTests/TransactionControllerTests.cs b/TransactionProcessor.Tests/ControllerTests/TransactionControllerTests.cs new file mode 100644 index 00000000..161ee70e --- /dev/null +++ b/TransactionProcessor.Tests/ControllerTests/TransactionControllerTests.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TransactionProcessor.Tests.ControllerTests +{ + using System.Net; + using System.Net.Http; + using System.Threading; + using System.Threading.Tasks; + using Common; + using DataTransferObjects; + using Newtonsoft.Json; + using Shouldly; + using Xunit; + + [Collection("TestCollection")] + public class TransactionControllerTests : IClassFixture> + { + #region Fields + + /// + /// The web application factory + /// + private readonly TransactionProcessorWebFactory WebApplicationFactory; + + #endregion + + #region Constructors + + public TransactionControllerTests(TransactionProcessorWebFactory webApplicationFactory) + { + this.WebApplicationFactory = webApplicationFactory; + } + + #endregion + + [Fact] + public async Task TransactionController_POST_LogonTransaction_LogonTransactionResponseIsReturned() + { + HttpClient client = this.WebApplicationFactory.CreateClient(); + + LogonTransactionRequest logonTransactionRequest = new LogonTransactionRequest(); + + String uri = "api/transactions"; + StringContent content = Helpers.CreateStringContent(logonTransactionRequest); + client.DefaultRequestHeaders.Add("api-version", "1.0"); + + HttpResponseMessage response = await client.PostAsync(uri, content, CancellationToken.None); + + response.StatusCode.ShouldBe(HttpStatusCode.Created); + + String responseAsJson = await response.Content.ReadAsStringAsync(); + responseAsJson.ShouldNotBeNullOrEmpty(); + + LogonTransactionResponse responseObject = JsonConvert.DeserializeObject(responseAsJson); + responseObject.ShouldNotBeNull(); + responseObject.ResponseCode.ShouldBe(0); + responseObject.ResponseMessage.ShouldBe("SUCCESS"); + } + } +} diff --git a/TransactionProcessor.Tests/Factories/ModelFactoryTests.cs b/TransactionProcessor.Tests/Factories/ModelFactoryTests.cs new file mode 100644 index 00000000..ec25da2a --- /dev/null +++ b/TransactionProcessor.Tests/Factories/ModelFactoryTests.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TransactionProcessor.Tests.Factories +{ + using DataTransferObjects; + using Models; + using Shouldly; + using Testing; + using TransactionProcessor.Factories; + using Xunit; + + public class ModelFactoryTests + { + [Fact] + public void ModelFactory_ProcessLogonTransactionResponseModel_IsConverted() + { + ProcessLogonTransactionResponse processLogonTransactionResponseModel = TestData.ProcessLogonTransactionResponseModel; + + ModelFactory modelFactory = new ModelFactory(); + + LogonTransactionResponse logonTransactionResponse = modelFactory.ConvertFrom(processLogonTransactionResponseModel); + + logonTransactionResponse.ShouldNotBeNull(); + logonTransactionResponse.ResponseMessage.ShouldBe(processLogonTransactionResponseModel.ResponseMessage); + logonTransactionResponse.ResponseCode.ShouldBe(processLogonTransactionResponseModel.ResponseCode); + } + + [Fact] + public void ModelFactory_ProcessLogonTransactionResponseModel_NullInput_IsConverted() + { + ProcessLogonTransactionResponse processLogonTransactionResponseModel = null; + + ModelFactory modelFactory = new ModelFactory(); + + LogonTransactionResponse logonTransactionResponse = modelFactory.ConvertFrom(processLogonTransactionResponseModel); + + logonTransactionResponse.ShouldBeNull(); + } + } +} diff --git a/TransactionProcessor.Tests/General/BootstrapperTests.cs b/TransactionProcessor.Tests/General/BootstrapperTests.cs new file mode 100644 index 00000000..20f6ebb6 --- /dev/null +++ b/TransactionProcessor.Tests/General/BootstrapperTests.cs @@ -0,0 +1,84 @@ +namespace TransactionProcessor.Tests.General +{ + using System; + using System.Collections.Generic; + using System.Diagnostics; + using Autofac; + using Autofac.Extensions.DependencyInjection; + using Microsoft.AspNetCore.Hosting; + using Microsoft.Extensions.DependencyInjection; + using Moq; + using Xunit; + + /// + /// + /// + public class BootstrapperTests + { + #region Methods + + /// + /// Verifies the bootstrapper is valid. + /// + [Fact] + public void VerifyBootstrapperIsValid() + { + Mock hostingEnvironment = new Mock(); + hostingEnvironment.Setup(he => he.EnvironmentName).Returns("Development"); + hostingEnvironment.Setup(he => he.ContentRootPath).Returns("/home"); + hostingEnvironment.Setup(he => he.ApplicationName).Returns("Test Application"); + + IServiceCollection services = new ServiceCollection(); + Startup s = new Startup(hostingEnvironment.Object); + s.ConfigureServices(services); + + //Startup.Configuration = this.SetupMemoryConfiguration(); + this.AddTestRegistrations(services, hostingEnvironment.Object); + + ContainerBuilder builder = new ContainerBuilder(); + builder.Populate(services); + + s.ConfigureContainer(builder); + + IContainer container = builder.Build(); + + using(ILifetimeScope scope = container.BeginLifetimeScope()) + { + scope.ResolveAll(new List()); + } + } + + //private IConfigurationRoot SetupMemoryConfiguration() + //{ + // Dictionary configuration = new Dictionary(); + + // IConfigurationBuilder builder = new ConfigurationBuilder(); + + // configuration.Add("EventStoreSettings:ConnectionString", "ConnectTo=tcp://admin:changeit@127.0.0.1:1112;VerboseLogging=true;"); + // configuration.Add("EventStoreSettings:ConnectionName", "UnitTestConnection"); + // configuration.Add("EventStoreSettings:HttpPort", "2113"); + // configuration.Add("AppSettings:UseConnectionStringConfig", "false"); + + // builder.AddInMemoryCollection(configuration); + + // return builder.Build(); + //} + + /// + /// Adds the test registrations. + /// + /// The services. + /// The hosting environment. + private void AddTestRegistrations(IServiceCollection services, + IWebHostEnvironment hostingEnvironment) + { + services.AddLogging(); + DiagnosticListener diagnosticSource = new DiagnosticListener(hostingEnvironment.ApplicationName); + services.AddSingleton(diagnosticSource); + services.AddSingleton(diagnosticSource); + services.AddSingleton(hostingEnvironment); + } + + #endregion + } +} \ No newline at end of file diff --git a/TransactionProcessor.Tests/General/ScopeExtensions.cs b/TransactionProcessor.Tests/General/ScopeExtensions.cs new file mode 100644 index 00000000..edc11c9d --- /dev/null +++ b/TransactionProcessor.Tests/General/ScopeExtensions.cs @@ -0,0 +1,57 @@ +namespace TransactionProcessor.Tests.General +{ + using System; + using System.Collections.Generic; + using System.Linq; + using Autofac; + using Autofac.Core; + + /// + /// + /// + public static class ScopeExtensions + { + #region Methods + + /// + /// Filters the specified ignored assemblies. + /// + /// The services. + /// The ignored assemblies. + /// + public static IList Filter(this IEnumerable services, + IEnumerable ignoredAssemblies) + { + return services.Where(serviceWithType => ignoredAssemblies.All(ignored => ignored != serviceWithType.ServiceType.FullName)).ToList(); + } + + /// + /// Resolves all. + /// + /// The scope. + /// The ignored assemblies. + /// + public static IList ResolveAll(this ILifetimeScope scope, + IEnumerable ignoredAssemblies) + { + var services = scope.ComponentRegistry.Registrations.SelectMany(x => x.Services).OfType().Filter(ignoredAssemblies).ToList(); + + foreach (var serviceWithType in services) + { + try + { + scope.Resolve(serviceWithType.ServiceType); + } + catch(Exception e) + { + Console.WriteLine(e); + throw; + } + } + + return services.Select(x => x.ServiceType).Select(scope.Resolve).ToList(); + } + + #endregion + } +} \ No newline at end of file diff --git a/TransactionProcessor.Tests/TransactionProcessor.Tests.csproj b/TransactionProcessor.Tests/TransactionProcessor.Tests.csproj new file mode 100644 index 00000000..e6af1398 --- /dev/null +++ b/TransactionProcessor.Tests/TransactionProcessor.Tests.csproj @@ -0,0 +1,30 @@ + + + + netcoreapp3.0 + None + false + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/TransactionProcessor.sln b/TransactionProcessor.sln index 4f3265f2..25eabeec 100644 --- a/TransactionProcessor.sln +++ b/TransactionProcessor.sln @@ -9,11 +9,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{749ADE74-A6F EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{71B30DC4-AB27-4D30-8481-B4C326D074CB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransactionProcessor.DataTransferObjects", "TransactionProcessor.DataTransferObjects\TransactionProcessor.DataTransferObjects.csproj", "{405F1DE4-9BAA-4B5D-8707-C78B2C3E9040}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransactionProcessor.DataTransferObjects", "TransactionProcessor.DataTransferObjects\TransactionProcessor.DataTransferObjects.csproj", "{405F1DE4-9BAA-4B5D-8707-C78B2C3E9040}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransactionProcessor.BusinessLogic", "TransactionProcessor.BusinessLogic\TransactionProcessor.BusinessLogic.csproj", "{6CCAAA44-AC4F-40DA-B5D4-F4390DD729C0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransactionProcessor.BusinessLogic", "TransactionProcessor.BusinessLogic\TransactionProcessor.BusinessLogic.csproj", "{6CCAAA44-AC4F-40DA-B5D4-F4390DD729C0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransactionProcessor.Models", "TransactionProcessor.Models\TransactionProcessor.Models.csproj", "{97B646C6-7BF7-4F84-A74A-10E50A70CB91}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransactionProcessor.Models", "TransactionProcessor.Models\TransactionProcessor.Models.csproj", "{97B646C6-7BF7-4F84-A74A-10E50A70CB91}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransactionProcessor.Tests", "TransactionProcessor.Tests\TransactionProcessor.Tests.csproj", "{99D19D28-C5ED-409B-9A34-DCCBCD8A9532}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransactionProcessor.Testing", "TransactionProcessor.Testing\TransactionProcessor.Testing.csproj", "{7BDDFAA7-0391-4672-94F1-6817E55020FD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransactionProcessor.BusinessLogic.Tests", "TransactionProcessor.BusinessLogic.Tests\TransactionProcessor.BusinessLogic.Tests.csproj", "{8EAA1681-4095-473B-900B-C09FA823ACD7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -37,6 +43,18 @@ Global {97B646C6-7BF7-4F84-A74A-10E50A70CB91}.Debug|Any CPU.Build.0 = Debug|Any CPU {97B646C6-7BF7-4F84-A74A-10E50A70CB91}.Release|Any CPU.ActiveCfg = Release|Any CPU {97B646C6-7BF7-4F84-A74A-10E50A70CB91}.Release|Any CPU.Build.0 = Release|Any CPU + {99D19D28-C5ED-409B-9A34-DCCBCD8A9532}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {99D19D28-C5ED-409B-9A34-DCCBCD8A9532}.Debug|Any CPU.Build.0 = Debug|Any CPU + {99D19D28-C5ED-409B-9A34-DCCBCD8A9532}.Release|Any CPU.ActiveCfg = Release|Any CPU + {99D19D28-C5ED-409B-9A34-DCCBCD8A9532}.Release|Any CPU.Build.0 = Release|Any CPU + {7BDDFAA7-0391-4672-94F1-6817E55020FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7BDDFAA7-0391-4672-94F1-6817E55020FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7BDDFAA7-0391-4672-94F1-6817E55020FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7BDDFAA7-0391-4672-94F1-6817E55020FD}.Release|Any CPU.Build.0 = Release|Any CPU + {8EAA1681-4095-473B-900B-C09FA823ACD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8EAA1681-4095-473B-900B-C09FA823ACD7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8EAA1681-4095-473B-900B-C09FA823ACD7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8EAA1681-4095-473B-900B-C09FA823ACD7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -46,6 +64,9 @@ Global {405F1DE4-9BAA-4B5D-8707-C78B2C3E9040} = {749ADE74-A6F0-4469-A638-8FD7E82A8667} {6CCAAA44-AC4F-40DA-B5D4-F4390DD729C0} = {749ADE74-A6F0-4469-A638-8FD7E82A8667} {97B646C6-7BF7-4F84-A74A-10E50A70CB91} = {749ADE74-A6F0-4469-A638-8FD7E82A8667} + {99D19D28-C5ED-409B-9A34-DCCBCD8A9532} = {71B30DC4-AB27-4D30-8481-B4C326D074CB} + {7BDDFAA7-0391-4672-94F1-6817E55020FD} = {71B30DC4-AB27-4D30-8481-B4C326D074CB} + {8EAA1681-4095-473B-900B-C09FA823ACD7} = {71B30DC4-AB27-4D30-8481-B4C326D074CB} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {193D13DE-424B-4D50-B674-01F9E4CC2CA9} diff --git a/TransactionProcessor/Controllers/TransactionController.cs b/TransactionProcessor/Controllers/TransactionController.cs index 752a3f27..739a3f54 100644 --- a/TransactionProcessor/Controllers/TransactionController.cs +++ b/TransactionProcessor/Controllers/TransactionController.cs @@ -63,11 +63,17 @@ public TransactionController(ICommandRouter commandRouter, public async Task LogonTransaction([FromBody] LogonTransactionRequest logonTransactionRequest, CancellationToken cancellationToken) { - ProcessLogonTransactionCommand command = new ProcessLogonTransactionCommand(Guid.NewGuid()); + ProcessLogonTransactionCommand command = ProcessLogonTransactionCommand.Create(logonTransactionRequest.EstateId, + logonTransactionRequest.MerchantId, + logonTransactionRequest.IMEINumber, + logonTransactionRequest.TransactionType, + logonTransactionRequest.TransactionDateTime, + logonTransactionRequest.TransactionNumber); await this.CommandRouter.Route(command, cancellationToken); - return this.Ok(this.ModelFactory.ConvertFrom(command.Response)); + // TODO: Populate the GET route + return this.Created("", this.ModelFactory.ConvertFrom(command.Response)); } #endregion diff --git a/TransactionProcessor/Factories/ModelFactory.cs b/TransactionProcessor/Factories/ModelFactory.cs index af473e19..e4b07ddd 100644 --- a/TransactionProcessor/Factories/ModelFactory.cs +++ b/TransactionProcessor/Factories/ModelFactory.cs @@ -18,6 +18,11 @@ public class ModelFactory : IModelFactory /// public LogonTransactionResponse ConvertFrom(ProcessLogonTransactionResponse processLogonTransactionResponse) { + if (processLogonTransactionResponse == null) + { + return null; + } + return new LogonTransactionResponse { ResponseMessage = processLogonTransactionResponse.ResponseMessage, diff --git a/TransactionProcessor/TransactionProcessor.csproj b/TransactionProcessor/TransactionProcessor.csproj index b5216dd1..4719e150 100644 --- a/TransactionProcessor/TransactionProcessor.csproj +++ b/TransactionProcessor/TransactionProcessor.csproj @@ -6,8 +6,6 @@ -