@ -0,0 +1,29 @@ | |||
#https://github.com/spring2/dockerfiles/tree/master/rabbitmq | |||
FROM microsoft/windowsservercore | |||
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] | |||
ENV chocolateyUseWindowsCompression false | |||
RUN iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')); \ | |||
choco install -y curl; | |||
RUN choco install -y erlang | |||
ENV ERLANG_SERVICE_MANAGER_PATH="C:\Program Files\erl8.2\erts-8.2\bin" | |||
RUN choco install -y rabbitmq | |||
ENV RABBITMQ_SERVER="C:\Program Files\RabbitMQ Server\rabbitmq_server-3.6.5" | |||
ENV RABBITMQ_CONFIG_FILE="c:\rabbitmq" | |||
COPY rabbitmq.config C:/ | |||
COPY rabbitmq.config C:/Users/ContainerAdministrator/AppData/Roaming/RabbitMQ/ | |||
COPY enabled_plugins C:/Users/ContainerAdministrator/AppData/Roaming/RabbitMQ/ | |||
EXPOSE 4369 | |||
EXPOSE 5672 | |||
EXPOSE 5671 | |||
EXPOSE 15672 | |||
WORKDIR C:/Program\ Files/RabbitMQ\ Server/rabbitmq_server-3.6.5/sbin | |||
CMD .\rabbitmq-server.bat |
@ -0,0 +1 @@ | |||
[rabbitmq_amqp1_0,rabbitmq_management]. |
@ -0,0 +1 @@ | |||
[{rabbit, [{loopback_users, []}]}]. |
@ -0,0 +1,79 @@ | |||
version: '2.1' | |||
# The default docker-compose.override file can use the "localhost" as the external name for testing web apps within the same dev machine. | |||
# The ESHOP_EXTERNAL_DNS_NAME_OR_IP environment variable is taken, by default, from the ".env" file defined like: | |||
# ESHOP_EXTERNAL_DNS_NAME_OR_IP=localhost | |||
# but values present in the environment vars at runtime will always override those defined inside the .env file | |||
# An external IP or DNS name has to be used (instead localhost and the 10.0.75.1 IP) when testing the Web apps and the Xamarin apps from remote machines/devices using the same WiFi, for instance. | |||
services: | |||
basket.api: | |||
environment: | |||
- ASPNETCORE_ENVIRONMENT=Development | |||
- ASPNETCORE_URLS=http://0.0.0.0:5103 | |||
- ConnectionString=basket.data | |||
- identityUrl=http://identity.api:5105 #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. | |||
- EventBusConnection=rabbitmq | |||
ports: | |||
- "5103:5103" | |||
catalog.api: | |||
environment: | |||
- ASPNETCORE_ENVIRONMENT=Development | |||
- ASPNETCORE_URLS=http://0.0.0.0:5101 | |||
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word | |||
- ExternalCatalogBaseUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5101 #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. | |||
- EventBusConnection=rabbitmq | |||
ports: | |||
- "5101:5101" | |||
identity.api: | |||
environment: | |||
- ASPNETCORE_ENVIRONMENT=Development | |||
- ASPNETCORE_URLS=http://0.0.0.0:5105 | |||
- SpaClient=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5104 | |||
- ConnectionStrings__DefaultConnection=Server=sql.data;Database=Microsoft.eShopOnContainers.Service.IdentityDb;User Id=sa;Password=Pass@word | |||
- MvcClient=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5100 #Local: You need to open your local dev-machine firewall at range 5100-5105. | |||
ports: | |||
- "5105:5105" | |||
ordering.api: | |||
environment: | |||
- ASPNETCORE_ENVIRONMENT=Development | |||
- ASPNETCORE_URLS=http://0.0.0.0:5102 | |||
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word | |||
- identityUrl=http://identity.api:5105 #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. | |||
- EventBusConnection=rabbitmq | |||
ports: | |||
- "5102:5102" | |||
webspa: | |||
environment: | |||
- ASPNETCORE_ENVIRONMENT=Development | |||
- ASPNETCORE_URLS=http://0.0.0.0:5104 | |||
- CatalogUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5101 | |||
- OrderingUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5102 | |||
- IdentityUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5105 #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. | |||
- BasketUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5103 | |||
ports: | |||
- "5104:5104" | |||
webmvc: | |||
environment: | |||
- ASPNETCORE_ENVIRONMENT=Development | |||
- ASPNETCORE_URLS=http://0.0.0.0:5100 | |||
- CatalogUrl=http://catalog.api:5101 | |||
- OrderingUrl=http://ordering.api:5102 | |||
- BasketUrl=http://basket.api:5103 | |||
- IdentityUrl=http://10.0.75.1:5105 #Local: Use 10.0.75.1 in a "Docker for Windows" environment, if using "localhost" from browser. | |||
#Remote: Use ${ESHOP_EXTERNAL_DNS_NAME_OR_IP} if using external IP or DNS name from browser. | |||
ports: | |||
- "5100:5100" | |||
sql.data: | |||
environment: | |||
- SA_PASSWORD=Pass@word | |||
- ACCEPT_EULA=Y | |||
ports: | |||
- "5433:1433" |
@ -0,0 +1,80 @@ | |||
version: '2.1' | |||
# The Production docker-compose file has to have the external/real IPs or DNS names for the services | |||
# The ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP environment variable is taken, by default, from the ".env" file defined like: | |||
# ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP=192.168.88.248 | |||
# but values present in the environment vars at runtime will always override those defined inside the .env file | |||
# An external IP or DNS name has to be used when testing the Web apps and the Xamarin apps from remote machines/devices using the same WiFi, for instance. | |||
# | |||
# Set ASPNETCORE_ENVIRONMENT=Development to get errors while testing. | |||
# | |||
# You need to start it with the following CLI command: | |||
# docker-compose -f docker-compose-windows.yml -f docker-compose-windows.prod.yml up -d | |||
services: | |||
basket.api: | |||
environment: | |||
- ASPNETCORE_ENVIRONMENT=Production | |||
- ASPNETCORE_URLS=http://0.0.0.0:5103 | |||
- ConnectionString=basket.data | |||
- identityUrl=http://identity.api:5105 #Local: You need to open your host's firewall at range 5100-5105. at range 5100-5105. | |||
ports: | |||
- "5103:5103" | |||
catalog.api: | |||
environment: | |||
- ASPNETCORE_ENVIRONMENT=Production | |||
- ASPNETCORE_URLS=http://0.0.0.0:5101 | |||
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word | |||
- ExternalCatalogBaseUrl=http://${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}:5101 #Local: You need to open your host's firewall at range 5100-5105. at range 5100-5105. | |||
ports: | |||
- "5101:5101" | |||
identity.api: | |||
environment: | |||
- ASPNETCORE_ENVIRONMENT=Production | |||
- ASPNETCORE_URLS=http://0.0.0.0:5105 | |||
- SpaClient=http://${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}:5104 | |||
- ConnectionStrings__DefaultConnection=Server=sql.data;Database=Microsoft.eShopOnContainers.Service.IdentityDb;User Id=sa;Password=Pass@word | |||
- MvcClient=http://${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}:5100 #Local: You need to open your host's firewall at range 5100-5105. | |||
ports: | |||
- "5105:5105" | |||
ordering.api: | |||
environment: | |||
- ASPNETCORE_ENVIRONMENT=Production | |||
- ASPNETCORE_URLS=http://0.0.0.0:5102 | |||
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word | |||
- identityUrl=http://identity.api:5105 #Local: You need to open your host's firewall at range 5100-5105. at range 5100-5105. | |||
ports: | |||
- "5102:5102" | |||
webspa: | |||
environment: | |||
- ASPNETCORE_ENVIRONMENT=Production | |||
- ASPNETCORE_URLS=http://0.0.0.0:5104 | |||
- CatalogUrl=http://${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}:5101 | |||
- OrderingUrl=http://${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}:5102 | |||
- IdentityUrl=http://${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}:5105 #Local: You need to open your host's firewall at range 5100-5105. at range 5100-5105. | |||
- BasketUrl=http://${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}:5103 | |||
ports: | |||
- "5104:5104" | |||
webmvc: | |||
environment: | |||
- ASPNETCORE_ENVIRONMENT=Production | |||
- ASPNETCORE_URLS=http://0.0.0.0:5100 | |||
- CatalogUrl=http://catalog.api:5101 | |||
- OrderingUrl=http://ordering.api:5102 | |||
- IdentityUrl=http://${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}:5105 #Local: Use ${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}, if using external IP or DNS name from browser. | |||
- BasketUrl=http://basket.api:5103 | |||
ports: | |||
- "5100:5100" | |||
sql.data: | |||
environment: | |||
- SA_PASSWORD=Pass@word | |||
- ACCEPT_EULA=Y | |||
ports: | |||
- "5433:1433" |
@ -0,0 +1,80 @@ | |||
version: '2.1' | |||
services: | |||
basket.api: | |||
image: eshop/basket.api | |||
build: | |||
context: ./src/Services/Basket/Basket.API | |||
dockerfile: Dockerfile.nanowin | |||
depends_on: | |||
- basket.data | |||
- identity.api | |||
catalog.api: | |||
image: eshop/catalog.api | |||
build: | |||
context: ./src/Services/Catalog/Catalog.API | |||
dockerfile: Dockerfile.nanowin | |||
depends_on: | |||
- sql.data | |||
identity.api: | |||
image: eshop/identity.api | |||
build: | |||
context: ./src/Services/Identity/Identity.API | |||
dockerfile: Dockerfile.nanowin | |||
depends_on: | |||
- sql.data | |||
ordering.api: | |||
image: eshop/ordering.api | |||
build: | |||
context: ./src/Services/Ordering/Ordering.API | |||
dockerfile: Dockerfile.nanowin | |||
depends_on: | |||
- sql.data | |||
webspa: | |||
image: eshop/webspa | |||
build: | |||
context: ./src/Web/WebSPA | |||
dockerfile: Dockerfile.nanowin | |||
depends_on: | |||
- identity.api | |||
- basket.api | |||
webmvc: | |||
image: eshop/webmvc | |||
build: | |||
context: ./src/Web/WebMVC | |||
dockerfile: Dockerfile.nanowin | |||
depends_on: | |||
- catalog.api | |||
- ordering.api | |||
- identity.api | |||
- basket.api | |||
sql.data: | |||
image: microsoft/mssql-server-windows | |||
basket.data: | |||
image: redis | |||
build: | |||
context: ./_docker/redis | |||
dockerfile: Dockerfile.nanowin | |||
ports: | |||
- "6379:6379" | |||
rabbitmq: | |||
image: rabbitmq | |||
build: | |||
context: ./_docker/rabbitmq | |||
dockerfile: Dockerfile.nanowin | |||
ports: | |||
- "5672:5672" | |||
networks: | |||
default: | |||
external: | |||
name: nat | |||
@ -1,14 +1,15 @@ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Data.Common; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace Catalog.API.IntegrationEvents | |||
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services | |||
{ | |||
public interface IIntegrationEventLogService | |||
{ | |||
Task SaveEventAsync(IntegrationEvent @event); | |||
Task SaveEventAsync(IntegrationEvent @event, DbTransaction transaction); | |||
Task MarkEventAsPublishedAsync(IntegrationEvent @event); | |||
} | |||
} |
@ -1,37 +1,39 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using Microsoft.EntityFrameworkCore; | |||
using Microsoft.EntityFrameworkCore.Infrastructure; | |||
using Microsoft.EntityFrameworkCore.Storage; | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
using System.Data.Common; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; | |||
using Microsoft.EntityFrameworkCore; | |||
using Microsoft.EntityFrameworkCore.Storage; | |||
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF; | |||
using Microsoft.EntityFrameworkCore.Infrastructure; | |||
using System; | |||
namespace Catalog.API.IntegrationEvents | |||
namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services | |||
{ | |||
public class IntegrationEventLogService : IIntegrationEventLogService | |||
{ | |||
private readonly IntegrationEventLogContext _integrationEventLogContext; | |||
private readonly CatalogContext _catalogContext; | |||
private readonly DbConnection _dbConnection; | |||
public IntegrationEventLogService(CatalogContext catalogContext) | |||
public IntegrationEventLogService(DbConnection dbConnection) | |||
{ | |||
_catalogContext = catalogContext; | |||
_dbConnection = dbConnection?? throw new ArgumentNullException("dbConnection"); | |||
_integrationEventLogContext = new IntegrationEventLogContext( | |||
new DbContextOptionsBuilder<IntegrationEventLogContext>() | |||
.UseSqlServer(catalogContext.Database.GetDbConnection()) | |||
.UseSqlServer(_dbConnection) | |||
.ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)) | |||
.Options); | |||
} | |||
public Task SaveEventAsync(IntegrationEvent @event) | |||
public Task SaveEventAsync(IntegrationEvent @event, DbTransaction transaction) | |||
{ | |||
if(transaction == null) | |||
{ | |||
throw new ArgumentNullException("transaction", $"A {typeof(DbTransaction).FullName} is required as a pre-requisite to save the event."); | |||
} | |||
var eventLogEntry = new IntegrationEventLogEntry(@event); | |||
// as a constraint this transaction has to be done together with a catalogContext transaction | |||
_integrationEventLogContext.Database.UseTransaction(_catalogContext.Database.CurrentTransaction.GetDbTransaction()); | |||
_integrationEventLogContext.Database.UseTransaction(transaction); | |||
_integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry); | |||
return _integrationEventLogContext.SaveChangesAsync(); |
@ -0,0 +1,45 @@ | |||
using FluentValidation; | |||
using MediatR; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace Ordering.API.Application.Decorators | |||
{ | |||
public class ValidatorDecorator<TRequest, TResponse> | |||
: IAsyncRequestHandler<TRequest, TResponse> | |||
where TRequest : IAsyncRequest<TResponse> | |||
{ | |||
private readonly IAsyncRequestHandler<TRequest, TResponse> _inner; | |||
private readonly IValidator<TRequest>[] _validators; | |||
public ValidatorDecorator( | |||
IAsyncRequestHandler<TRequest, TResponse> inner, | |||
IValidator<TRequest>[] validators) | |||
{ | |||
_inner = inner; | |||
_validators = validators; | |||
} | |||
public async Task<TResponse> Handle(TRequest message) | |||
{ | |||
var failures = _validators | |||
.Select(v => v.Validate(message)) | |||
.SelectMany(result => result.Errors) | |||
.Where(error => error != null) | |||
.ToList(); | |||
if (failures.Any()) | |||
{ | |||
throw new ValidationException( | |||
$"Command Validation Errors for type {typeof(TRequest).Name}", failures); | |||
} | |||
var response = await _inner.Handle(message); | |||
return response; | |||
} | |||
} | |||
} |
@ -0,0 +1,39 @@ | |||
using FluentValidation; | |||
using MediatR; | |||
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand; | |||
namespace Ordering.API.Application.Validations | |||
{ | |||
public class CreateOrderCommandValidator : AbstractValidator<CreateOrderCommand> | |||
{ | |||
public CreateOrderCommandValidator() | |||
{ | |||
RuleFor(order => order.City).NotEmpty(); | |||
RuleFor(order => order.Street).NotEmpty(); | |||
RuleFor(order => order.State).NotEmpty(); | |||
RuleFor(order => order.Country).NotEmpty(); | |||
RuleFor(order => order.ZipCode).NotEmpty(); | |||
RuleFor(order => order.CardNumber).NotEmpty().Length(12, 19); | |||
RuleFor(order => order.CardHolderName).NotEmpty(); | |||
RuleFor(order => order.CardExpiration).NotEmpty().Must(BeValidExpirationDate).WithMessage("Please specify a valid card expiration date"); | |||
RuleFor(order => order.CardSecurityNumber).NotEmpty().Length(3); | |||
RuleFor(order => order.CardTypeId).NotEmpty(); | |||
RuleFor(order => order.OrderItems).Must(ContainOrderItems).WithMessage("No order items found"); | |||
} | |||
private bool BeValidExpirationDate(DateTime dateTime) | |||
{ | |||
return dateTime >= DateTime.UtcNow; | |||
} | |||
private bool ContainOrderItems(IEnumerable<OrderItemDTO> orderItems) | |||
{ | |||
return orderItems.Any(); | |||
} | |||
} | |||
} |
@ -0,0 +1,17 @@ | |||
using FluentValidation; | |||
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace Ordering.API.Application.Validations | |||
{ | |||
public class IdentifierCommandValidator : AbstractValidator<IdentifiedCommand<CreateOrderCommand,bool>> | |||
{ | |||
public IdentifierCommandValidator() | |||
{ | |||
RuleFor(customer => customer.Id).NotEmpty(); | |||
} | |||
} | |||
} |
@ -0,0 +1,18 @@ | |||
using Microsoft.AspNetCore.TestHost; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Net.Http; | |||
using System.Text; | |||
namespace FunctionalTests.Extensions | |||
{ | |||
static class HttpClientExtensions | |||
{ | |||
public static HttpClient CreateIdempotentClient(this TestServer server) | |||
{ | |||
var client = server.CreateClient(); | |||
client.DefaultRequestHeaders.Add("x-requestid", Guid.NewGuid().ToString()); | |||
return client; | |||
} | |||
} | |||
} |
@ -0,0 +1,18 @@ | |||
using Microsoft.AspNetCore.TestHost; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Net.Http; | |||
using System.Text; | |||
namespace IntegrationTests.Services.Extensions | |||
{ | |||
static class HttpClientExtensions | |||
{ | |||
public static HttpClient CreateIdempotentClient(this TestServer server) | |||
{ | |||
var client = server.CreateClient(); | |||
client.DefaultRequestHeaders.Add("x-requestid", Guid.NewGuid().ToString()); | |||
return client; | |||
} | |||
} | |||
} |