diff --git a/src/Services/Basket/Basket.API/Controllers/BasketController.cs b/src/Services/Basket/Basket.API/Controllers/BasketController.cs index db5fcd318..9a120efc0 100644 --- a/src/Services/Basket/Basket.API/Controllers/BasketController.cs +++ b/src/Services/Basket/Basket.API/Controllers/BasketController.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; using Basket.API.IntegrationEvents.Events; using Microsoft.eShopOnContainers.Services.Basket.API.Services; +using Basket.API.Model; namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers { @@ -50,20 +51,23 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers return Ok(basket); } - [Route("checkouts")] - [HttpPost] - public async Task Checkout() + [Route("checkout")] + [HttpPut] + public async Task Checkout([FromBody]BasketCheckout value) { var userId = _identitySvc.GetUserIdentity(); var basket = await _repository.GetBasketAsync(userId); - _eventBus.Publish(new UserCheckoutAccepted(userId, basket)); + var eventMessage = new UserCheckoutAcceptedIntegrationEvent(userId, value.City, value.Street, + value.State, value.Country, value.ZipCode, value.CardNumber, value.CardHolderName, + value.CardExpiration, value.CardSecurityNumber, value.CardTypeId, value.Buyer, value.RequestId, basket); + + _eventBus.Publish(eventMessage); + if (basket == null) { return BadRequest(); } - - return Accepted(); } diff --git a/src/Services/Basket/Basket.API/IntegrationEvents/Events/UserCheckoutAccepted.cs b/src/Services/Basket/Basket.API/IntegrationEvents/Events/UserCheckoutAccepted.cs deleted file mode 100644 index 2d3e15ff3..000000000 --- a/src/Services/Basket/Basket.API/IntegrationEvents/Events/UserCheckoutAccepted.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; -using Microsoft.eShopOnContainers.Services.Basket.API.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Basket.API.IntegrationEvents.Events -{ - public class UserCheckoutAccepted : IntegrationEvent - { - public string UserId {get; } - CustomerBasket Basket { get; } - public UserCheckoutAccepted(string userId, CustomerBasket basket) - { - UserId = userId; - Basket = basket; - } - - } -} diff --git a/src/Services/Basket/Basket.API/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs b/src/Services/Basket/Basket.API/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs new file mode 100644 index 000000000..4c02612c5 --- /dev/null +++ b/src/Services/Basket/Basket.API/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs @@ -0,0 +1,64 @@ +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; +using Microsoft.eShopOnContainers.Services.Basket.API.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Basket.API.IntegrationEvents.Events +{ + public class UserCheckoutAcceptedIntegrationEvent : IntegrationEvent + { + public string UserId { get; } + + public int OrderNumber { get; set; } + + public string City { get; set; } + + public string Street { get; set; } + + public string State { get; set; } + + public string Country { get; set; } + + public string ZipCode { get; set; } + + public string CardNumber { get; set; } + + public string CardHolderName { get; set; } + + public DateTime CardExpiration { get; set; } + + public string CardSecurityNumber { get; set; } + + public int CardTypeId { get; set; } + + public string Buyer { get; set; } + + public Guid RequestId { get; set; } + + public CustomerBasket Basket { get; } + + public UserCheckoutAcceptedIntegrationEvent(string userId, string city, string street, + string state, string country, string zipCode, string cardNumber, string cardHolderName, + DateTime cardExpiration, string cardSecurityNumber, int cardTypeId, string buyer, Guid requestId, + CustomerBasket basket) + { + UserId = userId; + City = city; + Street = street; + State = state; + Country = country; + ZipCode = zipCode; + CardNumber = cardNumber; + CardHolderName = cardHolderName; + CardExpiration = cardExpiration; + CardSecurityNumber = cardSecurityNumber; + CardTypeId = cardTypeId; + Buyer = buyer; + Basket = basket; + RequestId = requestId; + } + + } +} diff --git a/src/Services/Basket/Basket.API/Model/BasketCheckout.cs b/src/Services/Basket/Basket.API/Model/BasketCheckout.cs new file mode 100644 index 000000000..5241a3672 --- /dev/null +++ b/src/Services/Basket/Basket.API/Model/BasketCheckout.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Basket.API.Model +{ + public class BasketCheckout + { + public string City { get; set; } + + public string Street { get; set; } + + public string State { get; set; } + + public string Country { get; set; } + + public string ZipCode { get; set; } + + public string CardNumber { get; set; } + + public string CardHolderName { get; set; } + + public DateTime CardExpiration { get; set; } + + public string CardSecurityNumber { get; set; } + + public int CardTypeId { get; set; } + + public string Buyer { get; set; } + + public Guid RequestId { get; set; } + } +} + diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/SubmitOrderCommandMsg.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/SubmitOrderCommandMsg.cs deleted file mode 100644 index 5a64a352d..000000000 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/SubmitOrderCommandMsg.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; - -namespace Ordering.API.Application.IntegrationCommands.Commands -{ - public class SubmitOrderCommandMsg : IntegrationEvent - { - public int OrderNumber { get; private set; } - //TODO: message should change to Integration command type once command bus is implemented - } -} diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs deleted file mode 100644 index f846f5031..000000000 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Ordering.API.Application.IntegrationEvents.EventHandling -{ - public class UserCheckoutAcceptedIntegrationEventHandler : IDynamicIntegrationEventHandler - { - public async Task Handle(dynamic eventData) - { - int i = 0; - } - } -} diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs new file mode 100644 index 000000000..92c32069c --- /dev/null +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs @@ -0,0 +1,62 @@ +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 +{ + public class UserCheckoutAcceptedIntegrationEvent : IntegrationEvent + { + public string UserId { get; } + + public string City { get; set; } + + public string Street { get; set; } + + public string State { get; set; } + + public string Country { get; set; } + + public string ZipCode { get; set; } + + public string CardNumber { get; set; } + + public string CardHolderName { get; set; } + + public DateTime CardExpiration { get; set; } + + public string CardSecurityNumber { get; set; } + + public int CardTypeId { get; set; } + + public string Buyer { get; set; } + + public Guid RequestId { get; set; } + + public CustomerBasket Basket { get; } + + public UserCheckoutAcceptedIntegrationEvent(string userId, string city, string street, + string state, string country, string zipCode, string cardNumber, string cardHolderName, + DateTime cardExpiration, string cardSecurityNumber, int cardTypeId, string buyer, Guid requestId, + CustomerBasket basket) + { + UserId = userId; + City = city; + Street = street; + State = state; + Country = country; + ZipCode = zipCode; + CardNumber = cardNumber; + CardHolderName = cardHolderName; + CardExpiration = cardExpiration; + CardSecurityNumber = cardSecurityNumber; + CardTypeId = cardTypeId; + Buyer = buyer; + Basket = basket; + RequestId = requestId; + } + + } +} diff --git a/src/Services/Ordering/Ordering.API/Application/Models/BasketItem.cs b/src/Services/Ordering/Ordering.API/Application/Models/BasketItem.cs new file mode 100644 index 000000000..698bdea3e --- /dev/null +++ b/src/Services/Ordering/Ordering.API/Application/Models/BasketItem.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ordering.API.Application.Models +{ + public class BasketItem + { + public string Id { get; set; } + public string ProductId { get; set; } + public string ProductName { get; set; } + public decimal UnitPrice { get; set; } + public decimal OldUnitPrice { get; set; } + public int Quantity { get; set; } + public string PictureUrl { get; set; } + } +} diff --git a/src/Services/Ordering/Ordering.API/Application/Models/CustomerBasket.cs b/src/Services/Ordering/Ordering.API/Application/Models/CustomerBasket.cs new file mode 100644 index 000000000..0275d1f80 --- /dev/null +++ b/src/Services/Ordering/Ordering.API/Application/Models/CustomerBasket.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ordering.API.Application.Models +{ + public class CustomerBasket + { + public string BuyerId { get; set; } + public List Items { get; set; } + + public CustomerBasket(string customerId) + { + BuyerId = customerId; + Items = new List(); + } + } +} diff --git a/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs b/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs index 32df5b327..91d8dd09f 100644 --- a/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs +++ b/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs @@ -7,6 +7,7 @@ using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure; using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency; using Ordering.API.Application.Commands; using Ordering.API.Application.IntegrationCommands.Commands; +using Ordering.API.Application.IntegrationEvents.Events; using Ordering.Domain.Exceptions; using System; using System.Threading.Tasks; @@ -22,7 +23,7 @@ namespace Ordering.API.Application.Sagas /// with the validations. /// public class OrderProcessSaga : Saga, - IIntegrationEventHandler, + IIntegrationEventHandler, IIntegrationEventHandler, IAsyncRequestHandler { @@ -48,10 +49,10 @@ namespace Ordering.API.Application.Sagas /// order items. /// /// - public async Task Handle(SubmitOrderCommandMsg command) + public async Task Handle(UserCheckoutAcceptedIntegrationEvent command) { - var orderSaga = FindSagaById(command.OrderNumber); - CheckValidSagaId(orderSaga); + + var commanda = command; // TODO: This handler should change to Integration command handler type once command bus is implemented diff --git a/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs b/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs index 902eb007b..2d4ce4059 100644 --- a/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs +++ b/src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries; using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services; +using Ordering.API.Application.Commands; using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -26,23 +27,17 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers _identityService = identityService ?? throw new ArgumentNullException(nameof(identityService)); } - [Route("new")] + [Route("cancel")] [HttpPost] - public async Task CreateOrder([FromBody]CreateOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId) + public async Task CancelOrder([FromBody]CancelOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId) { bool commandResult = false; if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) { - var requestCreateOrder = new IdentifiedCommand(command, guid); - commandResult = await _mediator.SendAsync(requestCreateOrder); + var requestCancelOrder = new IdentifiedCommand(command, guid); + commandResult = await _mediator.SendAsync(requestCancelOrder); } - else - { - // If no x-requestid header is found we process the order anyway. This is just temporary to not break existing clients - // that aren't still updated. When all clients were updated this could be removed. - commandResult = await _mediator.SendAsync(command); - } - + return commandResult ? (IActionResult)Ok() : (IActionResult)BadRequest(); } diff --git a/src/Services/Ordering/Ordering.API/Ordering.API.csproj b/src/Services/Ordering/Ordering.API/Ordering.API.csproj index d5ef524bb..0f2af6382 100644 --- a/src/Services/Ordering/Ordering.API/Ordering.API.csproj +++ b/src/Services/Ordering/Ordering.API/Ordering.API.csproj @@ -80,6 +80,7 @@ + diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index f7af01f3b..0e7742cc6 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -4,7 +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; using Infrastructure.Auth; @@ -124,7 +124,7 @@ services.AddSingleton(); services.AddSingleton(); - services.AddTransient(); + //services.AddTransient(); services.AddOptions(); //configure autofac @@ -168,9 +168,9 @@ private void ConfigureEventBus(IApplicationBuilder app) { var eventBus = app.ApplicationServices.GetRequiredService(); - eventBus.SubscribeDynamic( - "UserCheckoutAccepted", - () => app.ApplicationServices.GetRequiredService()); + + eventBus.Subscribe>( + () => app.ApplicationServices.GetRequiredService>()); } diff --git a/src/Web/WebMVC/Controllers/OrderController.cs b/src/Web/WebMVC/Controllers/OrderController.cs index 83152d697..b8efd930e 100644 --- a/src/Web/WebMVC/Controllers/OrderController.cs +++ b/src/Web/WebMVC/Controllers/OrderController.cs @@ -8,6 +8,7 @@ using Microsoft.eShopOnContainers.WebMVC.ViewModels; using Microsoft.AspNetCore.Authorization; using System.Net.Http; using Polly.CircuitBreaker; +using WebMVC.Models; namespace Microsoft.eShopOnContainers.WebMVC.Controllers { @@ -36,14 +37,16 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers } [HttpPost] - public async Task Create(Order model, string action) + public async Task Checkout(Order model) { try { if (ModelState.IsValid) { var user = _appUserParser.Parse(HttpContext.User); - await _orderSvc.CreateOrder(model); + var basket = _orderSvc.MapOrderToBasket(model); + + await _basketSvc.Checkout(basket); //Redirect to historic list. return RedirectToAction("Index"); @@ -56,6 +59,20 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers return View(model); } + [HttpPut] + public async Task Cancel(Order model) + { + if (ModelState.IsValid) + { + var user = _appUserParser.Parse(HttpContext.User); + await _orderSvc.CancelOrder(model); + + //Redirect to historic list. + return RedirectToAction("Index"); + } + return View(model); + } + public async Task Detail(string orderId) { var user = _appUserParser.Parse(HttpContext.User); diff --git a/src/Web/WebMVC/Infrastructure/API.cs b/src/Web/WebMVC/Infrastructure/API.cs index c837b8067..f23b94288 100644 --- a/src/Web/WebMVC/Infrastructure/API.cs +++ b/src/Web/WebMVC/Infrastructure/API.cs @@ -14,6 +14,11 @@ return baseUri; } + public static string CheckoutBasket(string baseUri) + { + return $"{baseUri}/checkout"; + } + public static string CleanBasket(string baseUri, string basketId) { return $"{baseUri}/{basketId}"; @@ -36,6 +41,11 @@ { return $"{baseUri}/new"; } + + public static string CancelOrder(string baseUri) + { + return $"{baseUri}/cancel"; + } } public static class Catalog diff --git a/src/Web/WebMVC/Models/BasketDTO.cs b/src/Web/WebMVC/Models/BasketDTO.cs new file mode 100644 index 000000000..4609c8533 --- /dev/null +++ b/src/Web/WebMVC/Models/BasketDTO.cs @@ -0,0 +1,37 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace WebMVC.Models +{ + public class BasketDTO + { + [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; } + } +} + diff --git a/src/Web/WebMVC/Services/BasketService.cs b/src/Web/WebMVC/Services/BasketService.cs index bd418ea26..538980052 100644 --- a/src/Web/WebMVC/Services/BasketService.cs +++ b/src/Web/WebMVC/Services/BasketService.cs @@ -7,6 +7,7 @@ using Newtonsoft.Json; using System.Collections.Generic; using System.Threading.Tasks; using WebMVC.Infrastructure; +using WebMVC.Models; namespace Microsoft.eShopOnContainers.WebMVC.Services { @@ -54,6 +55,16 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services return basket; } + public async Task Checkout(BasketDTO basket) + { + var token = await GetUserTokenAsync(); + var updateBasketUri = API.Basket.CheckoutBasket(_remoteServiceBaseUrl); + + var response = await _apiClient.PutAsync(updateBasketUri, basket, token); + + response.EnsureSuccessStatusCode(); + } + public async Task SetQuantities(ApplicationUser user, Dictionary quantities) { var basket = await GetBasket(user); diff --git a/src/Web/WebMVC/Services/IBasketService.cs b/src/Web/WebMVC/Services/IBasketService.cs index 114246d5e..215a958f1 100644 --- a/src/Web/WebMVC/Services/IBasketService.cs +++ b/src/Web/WebMVC/Services/IBasketService.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using WebMVC.Models; namespace Microsoft.eShopOnContainers.WebMVC.Services { @@ -11,6 +12,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services Task GetBasket(ApplicationUser user); Task AddItemToBasket(ApplicationUser user, BasketItem product); Task UpdateBasket(Basket basket); + Task Checkout(BasketDTO basket); Task SetQuantities(ApplicationUser user, Dictionary quantities); Order MapBasketToOrder(Basket basket); Task CleanBasket(ApplicationUser user); diff --git a/src/Web/WebMVC/Services/IOrderingService.cs b/src/Web/WebMVC/Services/IOrderingService.cs index e1a7e6f83..fca0151f1 100644 --- a/src/Web/WebMVC/Services/IOrderingService.cs +++ b/src/Web/WebMVC/Services/IOrderingService.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using WebMVC.Models; namespace Microsoft.eShopOnContainers.WebMVC.Services { @@ -10,8 +11,9 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services { Task> GetMyOrders(ApplicationUser user); Task GetOrder(ApplicationUser user, string orderId); - Task CreateOrder(Order order); + Task CancelOrder(Order order); Order MapUserInfoIntoOrder(ApplicationUser user, Order order); + BasketDTO MapOrderToBasket(Order order); void OverrideUserInfoIntoOrder(Order original, Order destination); } } diff --git a/src/Web/WebMVC/Services/OrderingService.cs b/src/Web/WebMVC/Services/OrderingService.cs index 8f198fbed..7329d1d14 100644 --- a/src/Web/WebMVC/Services/OrderingService.cs +++ b/src/Web/WebMVC/Services/OrderingService.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using WebMVC.Infrastructure; +using WebMVC.Models; namespace Microsoft.eShopOnContainers.WebMVC.Services { @@ -65,22 +66,17 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services return order; } - async public Task CreateOrder(Order order) + async public Task CancelOrder(Order order) { var token = await GetUserTokenAsync(); var requestId = order.RequestId.ToString(); - var addNewOrderUri = API.Order.AddNewOrder(_remoteServiceBaseUrl); - - order.CardTypeId = 1; - order.CardExpirationApiFormat(); - - SetFakeIdToProducts(order); - - var response = await _apiClient.PostAsync(addNewOrderUri, order, token, requestId); + var cancelOrderUri = API.Order.CancelOrder(_remoteServiceBaseUrl); + + var response = await _apiClient.PutAsync(cancelOrderUri, order, token, requestId); if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError) { - throw new Exception("Error creating order, try later."); + throw new Exception("Error cancelling order, try later."); } response.EnsureSuccessStatusCode(); @@ -100,6 +96,25 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services destination.CardSecurityNumber = original.CardSecurityNumber; } + public BasketDTO MapOrderToBasket(Order order) + { + return new BasketDTO() + { + City = order.City, + Street = order.Street, + State = order.State, + Country = order.Country, + ZipCode = order.ZipCode, + CardNumber = order.CardNumber, + CardHolderName = order.CardHolderName, + CardExpiration = order.CardExpiration, + CardSecurityNumber = order.CardSecurityNumber, + CardTypeId = order.CardTypeId, + Buyer = order.Buyer, + RequestId = order.RequestId + }; + } + void SetFakeIdToProducts(Order order) { var id = 1; @@ -111,6 +126,6 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services var context = _httpContextAccesor.HttpContext; return await context.Authentication.GetTokenAsync("access_token"); - } + } } } diff --git a/src/Web/WebMVC/Views/Order/Create.cshtml b/src/Web/WebMVC/Views/Order/Create.cshtml index e05d3a7b7..79ced5b3a 100644 --- a/src/Web/WebMVC/Views/Order/Create.cshtml +++ b/src/Web/WebMVC/Views/Order/Create.cshtml @@ -9,7 +9,7 @@ @Html.Partial("_Header", new Header() { Controller = "Cart", Text = "Back to cart" })
-
+
@foreach (var error in ViewData.ModelState.Values.SelectMany(err => err.Errors)) { diff --git a/test/Services/UnitTest/Basket/Application/BasketWebApiTest.cs b/test/Services/UnitTest/Basket/Application/BasketWebApiTest.cs index b6e45425a..be551115f 100644 --- a/test/Services/UnitTest/Basket/Application/BasketWebApiTest.cs +++ b/test/Services/UnitTest/Basket/Application/BasketWebApiTest.cs @@ -1,4 +1,5 @@ using Basket.API.IntegrationEvents.Events; +using Basket.API.Model; using Microsoft.AspNetCore.Mvc; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; using Microsoft.eShopOnContainers.Services.Basket.API.Controllers; @@ -35,7 +36,7 @@ namespace UnitTest.Basket.Application .Returns(Task.FromResult(fakeCustomerBasket)); _identityServiceMock.Setup(x => x.GetUserIdentity()).Returns(fakeCustomerId); - _serviceBusMock.Setup(x => x.Publish(It.IsAny())); + _serviceBusMock.Setup(x => x.Publish(It.IsAny())); //Act var basketController = new BasketController( _basketRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object); @@ -56,7 +57,7 @@ namespace UnitTest.Basket.Application _basketRepositoryMock.Setup(x => x.UpdateBasketAsync(It.IsAny())) .Returns(Task.FromResult(fakeCustomerBasket)); _identityServiceMock.Setup(x => x.GetUserIdentity()).Returns(fakeCustomerId); - _serviceBusMock.Setup(x => x.Publish(It.IsAny())); + _serviceBusMock.Setup(x => x.Publish(It.IsAny())); //Act var basketController = new BasketController( _basketRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object); @@ -79,7 +80,7 @@ namespace UnitTest.Basket.Application var basketController = new BasketController( _basketRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object); - var result = await basketController.Checkout() as BadRequestResult; + var result = await basketController.Checkout(new BasketCheckout()) as BadRequestResult; Assert.NotNull(result); } @@ -95,8 +96,8 @@ namespace UnitTest.Basket.Application var basketController = new BasketController( _basketRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object); - var result = await basketController.Checkout() as AcceptedResult; - _serviceBusMock.Verify(mock => mock.Publish(It.IsAny()), Times.Once); + var result = await basketController.Checkout(new BasketCheckout()) as AcceptedResult; + _serviceBusMock.Verify(mock => mock.Publish(It.IsAny()), Times.Once); Assert.NotNull(result); } diff --git a/test/Services/UnitTest/Ordering/Application/OrderControllerTest.cs b/test/Services/UnitTest/Ordering/Application/OrderControllerTest.cs index 27c524010..66c42906f 100644 --- a/test/Services/UnitTest/Ordering/Application/OrderControllerTest.cs +++ b/test/Services/UnitTest/Ordering/Application/OrderControllerTest.cs @@ -95,51 +95,51 @@ namespace UnitTest.Ordering.Application Assert.IsAssignableFrom(viewResult.ViewData.Model); } - [Fact] - public async Task Post_create_order_success() - { - //Arrange - var fakeOrder = GetFakeOrder(); - - _basketServiceMock.Setup(x => x.CleanBasket(It.IsAny())) - .Returns(Task.FromResult(1)); - - _orderServiceMock.Setup(x => x.CreateOrder(It.IsAny())) - .Returns(Task.FromResult(1)); - - //Act - var orderController = new OrderController(_orderServiceMock.Object, _basketServiceMock.Object, _identityParserMock.Object); - orderController.ControllerContext.HttpContext = _contextMock.Object; - var actionResult = await orderController.Create(fakeOrder, "fakeAction"); - - //Assert - var redirectToActionResult = Assert.IsType(actionResult); - Assert.Null(redirectToActionResult.ControllerName); - Assert.Equal("Index", redirectToActionResult.ActionName); - } - - [Fact] - public async Task Post_create_order_fail() - { - //Arrange - var fakeOrder = GetFakeOrder(); - - _basketServiceMock.Setup(x => x.CleanBasket(It.IsAny())) - .Returns(Task.FromResult(1)); - - _orderServiceMock.Setup(x => x.CreateOrder(It.IsAny())) - .Returns(Task.FromResult(1)); - - //Act - var orderController = new OrderController(_orderServiceMock.Object, _basketServiceMock.Object, _identityParserMock.Object); - orderController.ControllerContext.HttpContext = _contextMock.Object; - orderController.ModelState.AddModelError("fakeError", "fakeError"); - var actionResult = await orderController.Create(fakeOrder, "action"); - - //Assert - var viewResult = Assert.IsType(actionResult); - Assert.IsAssignableFrom(viewResult.ViewData.Model); - } + //[Fact] + //public async Task Post_create_order_success() + //{ + // //Arrange + // var fakeOrder = GetFakeOrder(); + + // _basketServiceMock.Setup(x => x.CleanBasket(It.IsAny())) + // .Returns(Task.FromResult(1)); + + // _orderServiceMock.Setup(x => x.CreateOrder(It.IsAny())) + // .Returns(Task.FromResult(1)); + + // //Act + // var orderController = new OrderController(_orderServiceMock.Object, _basketServiceMock.Object, _identityParserMock.Object); + // orderController.ControllerContext.HttpContext = _contextMock.Object; + // var actionResult = await orderController.Create(fakeOrder, "fakeAction"); + + // //Assert + // var redirectToActionResult = Assert.IsType(actionResult); + // Assert.Null(redirectToActionResult.ControllerName); + // Assert.Equal("Index", redirectToActionResult.ActionName); + //} + + //[Fact] + //public async Task Post_create_order_fail() + //{ + // //Arrange + // var fakeOrder = GetFakeOrder(); + + // _basketServiceMock.Setup(x => x.CleanBasket(It.IsAny())) + // .Returns(Task.FromResult(1)); + + // _orderServiceMock.Setup(x => x.CreateOrder(It.IsAny())) + // .Returns(Task.FromResult(1)); + + // //Act + // var orderController = new OrderController(_orderServiceMock.Object, _basketServiceMock.Object, _identityParserMock.Object); + // orderController.ControllerContext.HttpContext = _contextMock.Object; + // orderController.ModelState.AddModelError("fakeError", "fakeError"); + // var actionResult = await orderController.Create(fakeOrder, "action"); + + // //Assert + // var viewResult = Assert.IsType(actionResult); + // Assert.IsAssignableFrom(viewResult.ViewData.Model); + //} private BasketModel GetFakeBasket(string buyerId) { diff --git a/test/Services/UnitTest/Ordering/Application/OrdersWebApiTest.cs b/test/Services/UnitTest/Ordering/Application/OrdersWebApiTest.cs index c0656f050..22142dfbf 100644 --- a/test/Services/UnitTest/Ordering/Application/OrdersWebApiTest.cs +++ b/test/Services/UnitTest/Ordering/Application/OrdersWebApiTest.cs @@ -25,36 +25,36 @@ namespace UnitTest.Ordering.Application _identityServiceMock = new Mock(); } - [Fact] - public async Task Create_order_with_requestId_success() - { - //Arrange - _mediatorMock.Setup(x => x.SendAsync(It.IsAny>())) - .Returns(Task.FromResult(true)); - - //Act - var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object); - var actionResult = await orderController.CreateOrder(new CreateOrderCommand(), Guid.NewGuid().ToString()) as OkResult; - - //Assert - Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.OK); - - } - - [Fact] - public async Task Create_order_bad_request() - { - //Arrange - _mediatorMock.Setup(x => x.SendAsync(It.IsAny>())) - .Returns(Task.FromResult(true)); - - //Act - var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object); - var actionResult = await orderController.CreateOrder(new CreateOrderCommand(), String.Empty) as BadRequestResult; - - //Assert - Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.BadRequest); - } + //[Fact] + //public async Task Create_order_with_requestId_success() + //{ + // //Arrange + // _mediatorMock.Setup(x => x.SendAsync(It.IsAny>())) + // .Returns(Task.FromResult(true)); + + // //Act + // var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object); + // var actionResult = await orderController.CreateOrder(new CreateOrderCommand(), Guid.NewGuid().ToString()) as OkResult; + + // //Assert + // Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.OK); + + //} + + //[Fact] + //public async Task Create_order_bad_request() + //{ + // //Arrange + // _mediatorMock.Setup(x => x.SendAsync(It.IsAny>())) + // .Returns(Task.FromResult(true)); + + // //Act + // var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object); + // var actionResult = await orderController.CreateOrder(new CreateOrderCommand(), String.Empty) as BadRequestResult; + + // //Assert + // Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.BadRequest); + //} [Fact] public async Task Get_orders_success()