Browse Source

Merge branch 'order-processflow-redesign' of https://github.com/dotnet-architecture/eShopOnContainers into order-processflow-redesign

# Conflicts:
#	src/Services/Ordering/Ordering.API/Startup.cs
pull/809/head
Christian Arenas 7 years ago
parent
commit
a2eb2a348d
23 changed files with 339 additions and 119 deletions
  1. +36
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Models/Basket/BasketCheckout.cs
  2. +9
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Basket/BasketService.cs
  3. +1
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Basket/IBasketService.cs
  4. +4
    -2
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Order/IOrderService.cs
  5. +17
    -10
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Order/OrderMockService.cs
  6. +18
    -12
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Order/OrderService.cs
  7. +4
    -2
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/CheckoutViewModel.cs
  8. +6
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/eShopOnContainers.Core.csproj
  9. +1
    -0
      src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/OrderStartedIntegrationEventHandler.cs
  10. +3
    -3
      src/Services/Basket/Basket.API/IntegrationEvents/Events/OrderStartedIntegrationEvent.cs
  11. +7
    -8
      src/Services/Basket/Basket.API/Startup.cs
  12. +3
    -3
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStartedIntegrationEvent.cs
  13. +0
    -3
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs
  14. +17
    -0
      src/Services/Ordering/Ordering.API/Application/Validations/CancelOrderCommandValidator.cs
  15. +17
    -0
      src/Services/Ordering/Ordering.API/Application/Validations/ShipOrderCommandValidator.cs
  16. +2
    -1
      src/Services/Ordering/Ordering.API/Startup.cs
  17. +1
    -0
      test/Services/FunctionalTests/Services/Basket/BasketScenariosBase.cs
  18. +153
    -62
      test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs
  19. +13
    -0
      test/Services/FunctionalTests/Services/Ordering/OrderingScenariosBase.cs
  20. +3
    -3
      test/Services/IntegrationTests/Services/Basket/BasketScenarioBase.cs
  21. +10
    -5
      test/Services/IntegrationTests/Services/Basket/BasketScenarios.cs
  22. +9
    -1
      test/Services/IntegrationTests/Services/Basket/appsettings.json
  23. +5
    -4
      test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs

+ 36
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Models/Basket/BasketCheckout.cs View File

@ -0,0 +1,36 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace eShopOnContainers.Core.Models.Basket
{
public class BasketCheckout
{
[Required]
public string City { get; set; }
[Required]
public string Street { get; set; }
[Required]
public string State { get; set; }
[Required]
public string Country { get; set; }
public string ZipCode { get; set; }
[Required]
public string CardNumber { get; set; }
[Required]
public string CardHolderName { get; set; }
[Required]
public DateTime CardExpiration { get; set; }
[Required]
public string CardSecurityNumber { get; set; }
public int CardTypeId { get; set; }
public string Buyer { get; set; }
[Required]
public Guid RequestId { get; set; }
}
}

+ 9
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Basket/BasketService.cs View File

@ -42,6 +42,15 @@ namespace eShopOnContainers.Core.Services.Basket
return result;
}
public async Task CheckoutAsync(BasketCheckout basketCheckout, string token)
{
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.BasketEndpoint + "/checkout");
string uri = builder.ToString();
await _requestProvider.PostAsync(uri, basketCheckout, token);
}
public async Task ClearBasketAsync(string guidUser, string token)
{
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.BasketEndpoint);


+ 1
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Basket/IBasketService.cs View File

@ -7,6 +7,7 @@ namespace eShopOnContainers.Core.Services.Basket
{
Task<CustomerBasket> GetBasketAsync(string guidUser, string token);
Task<CustomerBasket> UpdateBasketAsync(CustomerBasket customerBasket, string token);
Task CheckoutAsync(BasketCheckout basketCheckout, string token);
Task ClearBasketAsync(string guidUser, string token);
}
}

+ 4
- 2
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Order/IOrderService.cs View File

@ -1,13 +1,15 @@
using System.Collections.ObjectModel;
using eShopOnContainers.Core.Models.Basket;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
namespace eShopOnContainers.Core.Services.Order
{
public interface IOrderService
{
Task CreateOrderAsync(Models.Orders.Order newOrder, string token);
//Task CreateOrderAsync(Models.Orders.Order newOrder, string token);
Task<ObservableCollection<Models.Orders.Order>> GetOrdersAsync(string token);
Task<Models.Orders.Order> GetOrderAsync(int orderId, string token);
Task<ObservableCollection<Models.Orders.CardType>> GetCardTypesAsync(string token);
BasketCheckout MapOrderToBasket(Models.Orders.Order order);
}
}

+ 17
- 10
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Order/OrderMockService.cs View File

@ -1,4 +1,5 @@
using eShopOnContainers.Core.Extensions;
using eShopOnContainers.Core.Models.Basket;
using eShopOnContainers.Core.Models.Orders;
using eShopOnContainers.Core.Models.User;
using System;
@ -64,17 +65,18 @@ namespace eShopOnContainers.Core.Services.Order
new CardType { Id = 3, Name = "MasterCard" },
};
public async Task CreateOrderAsync(Models.Orders.Order newOrder, string token)
private static BasketCheckout MockBasketCheckout = new BasketCheckout()
{
await Task.Delay(500);
if (!string.IsNullOrEmpty(token))
{
newOrder.OrderNumber = string.Format("{0}", MockOrders.Count + 1);
MockOrders.Insert(0, newOrder);
}
}
CardExpiration = DateTime.UtcNow,
CardHolderName = "FakeCardHolderName",
CardNumber = "122333423224",
CardSecurityNumber = "1234",
CardTypeId = 1,
City = "FakeCity",
Country = "FakeCountry",
ZipCode = "FakeZipCode",
Street = "FakeStreet"
};
public async Task<ObservableCollection<Models.Orders.Order>> GetOrdersAsync(string token)
{
@ -111,5 +113,10 @@ namespace eShopOnContainers.Core.Services.Order
else
return new ObservableCollection<CardType>();
}
public BasketCheckout MapOrderToBasket(Models.Orders.Order order)
{
return MockBasketCheckout;
}
}
}

+ 18
- 12
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Order/OrderService.cs View File

@ -1,4 +1,5 @@
using eShopOnContainers.Core.Services.RequestProvider;
using eShopOnContainers.Core.Models.Basket;
using eShopOnContainers.Core.Services.RequestProvider;
using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
@ -14,17 +15,6 @@ namespace eShopOnContainers.Core.Services.Order
_requestProvider = requestProvider;
}
public async Task CreateOrderAsync(Models.Orders.Order newOrder, string token)
{
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.OrdersEndpoint);
builder.Path = "api/v1/orders/new";
string uri = builder.ToString();
await _requestProvider.PostAsync(uri, newOrder, token, "x-requestid");
}
public async Task<ObservableCollection<Models.Orders.Order>> GetOrdersAsync(string token)
{
@ -82,5 +72,21 @@ namespace eShopOnContainers.Core.Services.Order
return new ObservableCollection<Models.Orders.CardType>();
}
}
public BasketCheckout MapOrderToBasket(Models.Orders.Order order)
{
return new BasketCheckout()
{
CardExpiration = order.CardExpiration,
CardHolderName = order.CardHolderName,
CardNumber = order.CardNumber,
CardSecurityNumber = order.CardSecurityNumber,
CardTypeId = order.CardTypeId,
City = order.ShippingCity,
Country = order.ShippingCountry,
ZipCode = order.ShippingZipCode,
Street = order.ShippingStreet
};
}
}
}

+ 4
- 2
src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/CheckoutViewModel.cs View File

@ -132,8 +132,10 @@ namespace eShopOnContainers.Core.ViewModels
{
var authToken = Settings.AuthAccessToken;
// Create new order
await _orderService.CreateOrderAsync(Order, authToken);
var basket = _orderService.MapOrderToBasket(Order);
// Create basket checkout
await _basketService.CheckoutAsync(basket, authToken);
// Clean Basket
await _basketService.ClearBasketAsync(_shippingAddress.Id.ToString(), authToken);


+ 6
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Core/eShopOnContainers.Core.csproj View File

@ -65,6 +65,7 @@
<Compile Include="Helpers\EasingHelper.cs" />
<Compile Include="Helpers\ServicesHelper.cs" />
<Compile Include="Helpers\Settings.cs" />
<Compile Include="Models\Basket\BasketCheckout.cs" />
<Compile Include="Models\Basket\BasketItem.cs" />
<Compile Include="Models\Basket\CustomerBasket.cs" />
<Compile Include="Models\Catalog\CatalogBrand.cs" />
@ -260,6 +261,11 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Reference Include="System.ComponentModel.Annotations">
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.6\Profile\Profile44\System.ComponentModel.Annotations.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>


+ 1
- 0
src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/OrderStartedIntegrationEventHandler.cs View File

@ -1,5 +1,6 @@
using Basket.API.IntegrationEvents.Events;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using System;
using System.Threading.Tasks;


+ 3
- 3
src/Services/Basket/Basket.API/IntegrationEvents/Events/OrderStartedIntegrationEvent.cs View File

@ -7,9 +7,9 @@ namespace Basket.API.IntegrationEvents.Events
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
public class OrderStartedIntegrationEvent : IntegrationEvent
{
public string UserId { get; }
public string UserId { get; set; }
public OrderStartedIntegrationEvent(string userId) =>
UserId = userId;
public OrderStartedIntegrationEvent(string userId)
=> UserId = userId;
}
}

+ 7
- 8
src/Services/Basket/Basket.API/Startup.cs View File

@ -1,8 +1,11 @@
using Basket.API.Infrastructure.Filters;
using Autofac;
using Autofac.Extensions.DependencyInjection;
using Basket.API.Infrastructure.Filters;
using Basket.API.IntegrationEvents.EventHandling;
using Basket.API.IntegrationEvents.Events;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
@ -10,6 +13,7 @@ using Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server;
using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.EventHandling;
using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using Microsoft.eShopOnContainers.Services.Basket.API.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.HealthChecks;
@ -17,14 +21,10 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using RabbitMQ.Client;
using StackExchange.Redis;
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System;
using Microsoft.eShopOnContainers.Services.Basket.API.Services;
using Microsoft.AspNetCore.Http;
using Autofac;
using Autofac.Extensions.DependencyInjection;
namespace Microsoft.eShopOnContainers.Services.Basket.API
{
@ -114,6 +114,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
services.AddTransient<IBasketRepository, RedisBasketRepository>();
services.AddTransient<IIdentityService, IdentityService>();
RegisterServiceBus(services);
services.AddOptions();
var container = new ContainerBuilder();
container.Populate(services);
@ -127,7 +128,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
services.AddTransient<ProductPriceChangedIntegrationEventHandler>();
services.AddTransient<OrderStartedIntegrationEventHandler>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -166,7 +166,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
protected virtual void ConfigureEventBus(IApplicationBuilder app)
{
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
eventBus.Subscribe<ProductPriceChangedIntegrationEvent, ProductPriceChangedIntegrationEventHandler>();
eventBus.Subscribe<OrderStartedIntegrationEvent, OrderStartedIntegrationEventHandler>();
}


+ 3
- 3
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStartedIntegrationEvent.cs View File

@ -11,9 +11,9 @@ namespace Ordering.API.Application.IntegrationEvents.Events
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
public class OrderStartedIntegrationEvent : IntegrationEvent
{
public string UserId { get; }
public string UserId { get; set; }
public OrderStartedIntegrationEvent(string userId) =>
UserId = userId;
public OrderStartedIntegrationEvent(string userId)
=> UserId = userId;
}
}

+ 0
- 3
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs View File

@ -1,9 +1,6 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using Ordering.API.Application.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Ordering.API.Application.IntegrationEvents.Events
{


+ 17
- 0
src/Services/Ordering/Ordering.API/Application/Validations/CancelOrderCommandValidator.cs View File

@ -0,0 +1,17 @@
using FluentValidation;
using Ordering.API.Application.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Ordering.API.Application.Validations
{
public class CancelOrderCommandValidator : AbstractValidator<CancelOrderCommand>
{
public CancelOrderCommandValidator()
{
RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found");
}
}
}

+ 17
- 0
src/Services/Ordering/Ordering.API/Application/Validations/ShipOrderCommandValidator.cs View File

@ -0,0 +1,17 @@
using FluentValidation;
using Ordering.API.Application.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Ordering.API.Application.Validations
{
public class ShipOrderCommandValidator : AbstractValidator<ShipOrderCommand>
{
public ShipOrderCommandValidator()
{
RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found");
}
}
}

+ 2
- 1
src/Services/Ordering/Ordering.API/Startup.cs View File

@ -4,6 +4,7 @@
using Autofac;
using Autofac.Extensions.DependencyInjection;
using global::Ordering.API.Application.IntegrationEvents;
using global::Ordering.API.Application.IntegrationEvents.EventHandling;
using global::Ordering.API.Application.IntegrationEvents.Events;
using global::Ordering.API.Infrastructure.Middlewares;
using Infrastructure;
@ -121,7 +122,7 @@
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
RegisterServiceBus(services);
RegisterServiceBus(services);
services.AddOptions();
//configure autofac


+ 1
- 0
test/Services/FunctionalTests/Services/Basket/BasketScenariosBase.cs View File

@ -29,6 +29,7 @@ namespace FunctionalTests.Services.Basket
public static class Post
{
public static string CreateBasket = "/";
public static string Checkout = "/checkout";
}
}
}

+ 153
- 62
test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs View File

@ -1,5 +1,6 @@
using FunctionalTests.Extensions;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using FunctionalTests.Services.Basket;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using Microsoft.eShopOnContainers.WebMVC.ViewModels;
using Newtonsoft.Json;
using System;
@ -8,69 +9,159 @@ using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using WebMVC.Models;
using Xunit;
using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand;
namespace FunctionalTests.Services.Ordering
{
//public class OrderingScenarios : OrderingScenariosBase
//{
// [Fact]
// public async Task Create_order_and_return_the_order_by_id()
// {
// using (var server = CreateServer())
// {
// var client = server.CreateIdempotentClient();
// // GIVEN an order is created
// await client.PostAsync(Post.AddNewOrder, new StringContent(BuildOrder(), UTF8Encoding.UTF8, "application/json"));
// var ordersResponse = await client.GetAsync(Get.Orders);
// var responseBody = await ordersResponse.Content.ReadAsStringAsync();
// var orders = JsonConvert.DeserializeObject<List<Order>>(responseBody);
// string orderId = orders.OrderByDescending(o => o.Date).First().OrderNumber;
// //WHEN we request the order bit its id
// var order= await client.GetAsync(Get.OrderBy(int.Parse(orderId)));
// var orderBody = await order.Content.ReadAsStringAsync();
// var result = JsonConvert.DeserializeObject<Order>(orderBody);
// //THEN the requested order is returned
// Assert.Equal(orderId, result.OrderNumber);
// Assert.Equal("inprocess", result.Status);
// Assert.Equal(1, result.OrderItems.Count);
// Assert.Equal(10, result.OrderItems[0].UnitPrice);
// }
// }
// string BuildOrder()
// {
// List<BasketItem> orderItemsList = new List<BasketItem>();
// orderItemsList.Add(new BasketItem()
// {
// ProductId = "1",
// Discount = 8M,
// UnitPrice = 10,
// Units = 1,
// ProductName = "Some name"
// }
// );
// var order = new CreateOrderCommand(
// orderItemsList,
// cardExpiration: DateTime.UtcNow.AddYears(1),
// cardNumber: "5145-555-5555",
// cardHolderName: "Jhon Senna",
// cardSecurityNumber: "232",
// cardTypeId: 1,
// city: "Redmon",
// country: "USA",
// state: "WA",
// street: "One way",
// zipcode: "zipcode"
// );
// return JsonConvert.SerializeObject(order);
// }
//}
public class OrderingScenarios : OrderingScenariosBase
{
[Fact]
public async Task Checkout_basket_and_check_order_status_submited()
{
using (var orderServer = new OrderingScenariosBase().CreateServer())
using (var basketServer = new BasketScenariosBase().CreateServer())
{
// Expected data
var cityExpected = $"city-{Guid.NewGuid()}";
var orderStatusExpected = "submited";
var basketClient = basketServer.CreateIdempotentClient();
var orderClient = orderServer.CreateIdempotentClient();
// GIVEN a basket is created
var contentBasket = new StringContent(BuildBasket(), UTF8Encoding.UTF8, "application/json");
await basketClient.PostAsync(BasketScenariosBase.Post.CreateBasket, contentBasket);
// AND basket checkout is sent
await basketClient.PostAsync(BasketScenariosBase.Post.Checkout, new StringContent(BuildCheckout(cityExpected), UTF8Encoding.UTF8, "application/json"));
// AND the requested order is retrieved and removed
var newOrder = await TryGetNewOrderCreated(cityExpected, orderClient);
await orderClient.DeleteAsync(OrderingScenariosBase.Delete.OrderBy(int.TryParse(newOrder.OrderNumber, out int id) ? id : 0));
// THEN check status
Assert.Equal(orderStatusExpected, newOrder.Status);
}
}
[Fact]
public async Task Cancel_basket_and_check_order_status_cancelled()
{
using (var orderServer = new OrderingScenariosBase().CreateServer())
using (var basketServer = new BasketScenariosBase().CreateServer())
{
// Expected data
var cityExpected = $"city-{Guid.NewGuid()}";
var orderStatusExpected = "cancelled";
var basketClient = basketServer.CreateIdempotentClient();
var orderClient = orderServer.CreateIdempotentClient();
// GIVEN a basket is created
var contentBasket = new StringContent(BuildBasket(), UTF8Encoding.UTF8, "application/json");
await basketClient.PostAsync(BasketScenariosBase.Post.CreateBasket, contentBasket);
// AND basket checkout is sent
await basketClient.PostAsync(BasketScenariosBase.Post.Checkout, new StringContent(BuildCheckout(cityExpected), UTF8Encoding.UTF8, "application/json"));
// WHEN Order is created in Ordering.api
var newOrder = await TryGetNewOrderCreated(cityExpected, orderClient);
// AND Order is cancelled in Ordering.api
await orderClient.PutAsync(OrderingScenariosBase.Put.CancelOrder, new StringContent(BuildCancelOrder(newOrder.OrderNumber), UTF8Encoding.UTF8, "application/json"));
// AND the requested order is retrieved and removed
var order = await TryGetNewOrderCreated(cityExpected, orderClient);
await orderClient.DeleteAsync(OrderingScenariosBase.Delete.OrderBy(int.TryParse(newOrder.OrderNumber, out int id) ? id : 0));
// THEN check status
Assert.Equal(orderStatusExpected, order.Status);
}
}
private async Task<Order> TryGetNewOrderCreated(string city, HttpClient orderClient)
{
var counter = 0;
Order order = null;
while (counter < 20)
{
//get the orders and verify that the new order has been created
var ordersGetResponse = await orderClient.GetStringAsync(OrderingScenariosBase.Get.Orders);
var orders = JsonConvert.DeserializeObject<List<Order>>(ordersGetResponse);
if (orders != null && orders.Any()) {
var lastOrder = orders.OrderByDescending(o => o.Date).First();
int.TryParse(lastOrder.OrderNumber, out int id);
var orderDetails = await orderClient.GetStringAsync(OrderingScenariosBase.Get.OrderBy(id));
order = JsonConvert.DeserializeObject<Order>(orderDetails);
}
if (IsOrderCreated(order, city))
{
break;
}
else
{
counter++;
await Task.Delay(1000);
}
}
return order;
}
private bool IsOrderCreated(Order order, string city)
{
return order.City == city;
}
string BuildBasket()
{
var order = new CustomerBasket("1234");
order.Items = new List<Microsoft.eShopOnContainers.Services.Basket.API.Model.BasketItem>()
{
new Microsoft.eShopOnContainers.Services.Basket.API.Model.BasketItem()
{
Id = "1",
ProductName = "ProductName",
ProductId = "1",
UnitPrice = 10,
Quantity = 1
}
};
return JsonConvert.SerializeObject(order);
}
string BuildCancelOrder(string orderId)
{
var order = new OrderDTO()
{
OrderNumber = orderId
};
return JsonConvert.SerializeObject(order);
}
string BuildCheckout(string cityExpected)
{
var checkoutBasket = new BasketDTO()
{
City = cityExpected,
Street = "street",
State = "state",
Country = "coutry",
ZipCode = "zipcode",
CardNumber = "CardNumber",
CardHolderName = "CardHolderName",
CardExpiration = DateTime.Now.AddYears(1),
CardSecurityNumber = "1234",
CardTypeId = 1,
Buyer = "Buyer",
RequestId = Guid.NewGuid()
};
return JsonConvert.SerializeObject(checkoutBasket);
}
}
}

+ 13
- 0
test/Services/FunctionalTests/Services/Ordering/OrderingScenariosBase.cs View File

@ -32,5 +32,18 @@ namespace FunctionalTests.Services.Ordering
{
public static string AddNewOrder = "api/v1/orders/new";
}
public static class Put
{
public static string CancelOrder = "api/v1/orders/cancel";
}
public static class Delete
{
public static string OrderBy(int id)
{
return $"api/v1/orders/{id}";
}
}
}
}

+ 3
- 3
test/Services/IntegrationTests/Services/Basket/BasketScenarioBase.cs View File

@ -23,14 +23,14 @@ namespace IntegrationTests.Services.Basket
{
public static string GetBasket(int id)
{
return $"api/v1/basket/{id}";
return $"{id}";
}
}
public static class Post
{
public static string Basket = "api/v1/basket";
public static string CheckoutOrder = "api/v1/basket/checkout";
public static string Basket = "";
public static string CheckoutOrder = "checkout";
}
}
}

+ 10
- 5
test/Services/IntegrationTests/Services/Basket/BasketScenarios.cs View File

@ -1,4 +1,5 @@
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using IntegrationTests.Services.Extensions;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using Newtonsoft.Json;
using System;
using System.Net.Http;
@ -42,9 +43,13 @@ namespace IntegrationTests.Services.Basket
{
using (var server = CreateServer())
{
var content = new StringContent(BuildCheckout(), UTF8Encoding.UTF8, "application/json");
var response = await server.CreateClient()
.PostAsync(Post.CheckoutOrder, content);
var contentBasket = new StringContent(BuildBasket(), UTF8Encoding.UTF8, "application/json");
await server.CreateClient()
.PostAsync(Post.Basket, contentBasket);
var contentCheckout = new StringContent(BuildCheckout(), UTF8Encoding.UTF8, "application/json");
var response = await server.CreateIdempotentClient()
.PostAsync(Post.CheckoutOrder, contentCheckout);
response.EnsureSuccessStatusCode();
}
@ -52,7 +57,7 @@ namespace IntegrationTests.Services.Basket
string BuildBasket()
{
var order = new CustomerBasket("1");
var order = new CustomerBasket("1234");
return JsonConvert.SerializeObject(order);
}


+ 9
- 1
test/Services/IntegrationTests/Services/Basket/appsettings.json View File

@ -1,6 +1,14 @@
{
"ConnectionString": "127.0.0.1",
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"IdentityUrl": "http://localhost:5105",
"ConnectionString": "127.0.0.1",
"isTest": "true",
"EventBusConnection": "localhost"
}


+ 5
- 4
test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs View File

@ -2,6 +2,7 @@
{
using IntegrationTests.Services.Extensions;
using Newtonsoft.Json;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
@ -24,7 +25,7 @@
}
[Fact]
public async Task Cancel_order_and_response_ok_status_code()
public async Task Cancel_order_no_order_created_response_bad_status_code()
{
using (var server = CreateServer())
{
@ -32,12 +33,12 @@
var response = await server.CreateIdempotentClient()
.PutAsync(Put.CancelOrder, content);
response.EnsureSuccessStatusCode();
Assert.Equal(response.StatusCode, HttpStatusCode.InternalServerError);
}
}
[Fact]
public async Task Ship_order_and_response_bad_status_code()
public async Task Ship_order_no_order_created_response_bad_status_code()
{
using (var server = CreateServer())
{
@ -45,7 +46,7 @@
var response = await server.CreateIdempotentClient()
.PutAsync(Put.ShipOrder, content);
response.EnsureSuccessStatusCode();
Assert.Equal(response.StatusCode, HttpStatusCode.InternalServerError);
}
}


Loading…
Cancel
Save