Skip to content

Commit d9d26be

Browse files
committed
Adapt test cases to new order flow
Create new service test cases
1 parent d043e10 commit d9d26be

15 files changed

Lines changed: 253 additions & 104 deletions

File tree

src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/OrderStartedIntegrationEventHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Basket.API.IntegrationEvents.Events;
22
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
3+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
34
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
45
using System;
56
using System.Threading.Tasks;

src/Services/Basket/Basket.API/IntegrationEvents/Events/OrderStartedIntegrationEvent.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ namespace Basket.API.IntegrationEvents.Events
77
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
88
public class OrderStartedIntegrationEvent : IntegrationEvent
99
{
10-
public string UserId { get; }
10+
public string UserId { get; set; }
1111

12-
public OrderStartedIntegrationEvent(string userId) =>
13-
UserId = userId;
12+
public OrderStartedIntegrationEvent(string userId)
13+
=> UserId = userId;
1414
}
1515
}

src/Services/Basket/Basket.API/Startup.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
using Basket.API.Infrastructure.Filters;
1+
using Autofac;
2+
using Autofac.Extensions.DependencyInjection;
3+
using Basket.API.Infrastructure.Filters;
24
using Basket.API.IntegrationEvents.EventHandling;
35
using Basket.API.IntegrationEvents.Events;
46
using Microsoft.AspNetCore.Builder;
57
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.Http;
69
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
710
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
811
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
912
using Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server;
1013
using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.EventHandling;
1114
using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events;
1215
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
16+
using Microsoft.eShopOnContainers.Services.Basket.API.Services;
1317
using Microsoft.Extensions.Configuration;
1418
using Microsoft.Extensions.DependencyInjection;
1519
using Microsoft.Extensions.HealthChecks;
1620
using Microsoft.Extensions.Logging;
1721
using Microsoft.Extensions.Options;
1822
using RabbitMQ.Client;
1923
using StackExchange.Redis;
24+
using System;
2025
using System.Linq;
2126
using System.Net;
2227
using System.Threading.Tasks;
23-
using System;
24-
using Microsoft.eShopOnContainers.Services.Basket.API.Services;
25-
using Microsoft.AspNetCore.Http;
26-
using Autofac;
27-
using Autofac.Extensions.DependencyInjection;
2828

2929
namespace Microsoft.eShopOnContainers.Services.Basket.API
3030
{
@@ -114,6 +114,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
114114
services.AddTransient<IBasketRepository, RedisBasketRepository>();
115115
services.AddTransient<IIdentityService, IdentityService>();
116116
RegisterServiceBus(services);
117+
services.AddOptions();
117118

118119
var container = new ContainerBuilder();
119120
container.Populate(services);
@@ -127,7 +128,6 @@ private void RegisterServiceBus(IServiceCollection services)
127128

128129
services.AddTransient<ProductPriceChangedIntegrationEventHandler>();
129130
services.AddTransient<OrderStartedIntegrationEventHandler>();
130-
131131
}
132132

133133
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -165,14 +165,13 @@ protected virtual void ConfigureAuth(IApplicationBuilder app)
165165

166166
protected virtual void ConfigureEventBus(IApplicationBuilder app)
167167
{
168-
var catalogPriceHandler = app.ApplicationServices
169-
.GetService<IIntegrationEventHandler<ProductPriceChangedIntegrationEvent>>();
168+
//var catalogPriceHandler = app.ApplicationServices
169+
// .GetService<IIntegrationEventHandler<ProductPriceChangedIntegrationEvent>>();
170170

171-
var orderStartedHandler = app.ApplicationServices
172-
.GetService<IIntegrationEventHandler<OrderStartedIntegrationEvent>>();
171+
//var orderStartedHandler = app.ApplicationServices
172+
// .GetService<IIntegrationEventHandler<OrderStartedIntegrationEvent>>();
173173

174174
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
175-
176175
eventBus.Subscribe<ProductPriceChangedIntegrationEvent, ProductPriceChangedIntegrationEventHandler>();
177176
eventBus.Subscribe<OrderStartedIntegrationEvent, OrderStartedIntegrationEventHandler>();
178177
}

src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStartedIntegrationEvent.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ namespace Ordering.API.Application.IntegrationEvents.Events
1111
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
1212
public class OrderStartedIntegrationEvent : IntegrationEvent
1313
{
14-
public string UserId { get; }
14+
public string UserId { get; set; }
1515

16-
public OrderStartedIntegrationEvent(string userId) =>
17-
UserId = userId;
16+
public OrderStartedIntegrationEvent(string userId)
17+
=> UserId = userId;
1818
}
1919
}

src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
22
using Ordering.API.Application.Models;
33
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Threading.Tasks;
74

85
namespace Ordering.API.Application.IntegrationEvents.Events
96
{
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using FluentValidation;
2+
using Ordering.API.Application.Commands;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
8+
namespace Ordering.API.Application.Validations
9+
{
10+
public class CancelOrderCommandValidator : AbstractValidator<CancelOrderCommand>
11+
{
12+
public CancelOrderCommandValidator()
13+
{
14+
RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found");
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using FluentValidation;
2+
using Ordering.API.Application.Commands;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
8+
namespace Ordering.API.Application.Validations
9+
{
10+
public class ShipOrderCommandValidator : AbstractValidator<ShipOrderCommand>
11+
{
12+
public ShipOrderCommandValidator()
13+
{
14+
RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found");
15+
}
16+
}
17+
}

src/Services/Ordering/Ordering.API/Startup.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
using Autofac.Extensions.DependencyInjection;
66
using global::Ordering.API.Application.IntegrationCommands.Commands;
77
using global::Ordering.API.Application.IntegrationEvents;
8+
using global::Ordering.API.Application.IntegrationEvents.EventHandling;
89
using global::Ordering.API.Application.IntegrationEvents.Events;
910
using global::Ordering.API.Application.Sagas;
1011
using global::Ordering.API.Infrastructure.Middlewares;
11-
using global::Ordering.API.Application.IntegrationCommands.Commands;
12-
using global::Ordering.API.Application.Sagas;
1312
using Infrastructure;
1413
using Infrastructure.Auth;
1514
using Infrastructure.AutofacModules;
@@ -127,10 +126,10 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
127126

128127
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
129128
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
130-
services.AddTransient<IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
129+
services.AddTransient<UserCheckoutAcceptedIntegrationEventHandler>();
131130
services.AddTransient<IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>, OrderProcessSaga>();
132-
services.AddTransient<IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>();
133-
services.AddTransient<IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>>();
131+
services.AddTransient<OrderStockConfirmedIntegrationEventHandler>();
132+
services.AddTransient<OrderStockNotConfirmedIntegrationEventHandler>();
134133
services.AddOptions();
135134

136135
//configure autofac
@@ -175,13 +174,13 @@ private void ConfigureEventBus(IApplicationBuilder app)
175174
{
176175
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
177176

178-
eventBus.Subscribe<UserCheckoutAcceptedIntegrationEvent, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
177+
eventBus.Subscribe<UserCheckoutAcceptedIntegrationEvent, UserCheckoutAcceptedIntegrationEventHandler>();
179178

180179
eventBus.Subscribe<ConfirmGracePeriodCommandMsg, IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>>();
181180

182-
eventBus.Subscribe<OrderStockConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>();
181+
eventBus.Subscribe<OrderStockConfirmedIntegrationEvent, OrderStockConfirmedIntegrationEventHandler>();
183182

184-
eventBus.Subscribe<OrderStockNotConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>>();
183+
eventBus.Subscribe<OrderStockNotConfirmedIntegrationEvent, OrderStockNotConfirmedIntegrationEventHandler>();
185184
}
186185

187186
protected virtual void ConfigureAuth(IApplicationBuilder app)

test/Services/FunctionalTests/Services/Basket/BasketScenariosBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public static string GetBasketByCustomer(string customerId)
2929
public static class Post
3030
{
3131
public static string CreateBasket = "/";
32+
public static string Checkout = "/checkout";
3233
}
3334
}
3435
}

0 commit comments

Comments
 (0)