public async void Put_should_return_OK_result() { var basketService = new Mock <IBasketService>(); _sut = new BasketController(basketService.Object); SetupCookies(); var result = await _sut.Put(new BasketItem()); var expectedResult = new SaveBasketResponse(); var okObjectResult = result as OkObjectResult; Assert.Equal(expectedResult, okObjectResult.Value as SaveBasketResponse); }
public async void Post_should_return_created_result() { var basketService = new Mock <IBasketService>(); basketService.Setup(x => x.Save(It.IsAny <Guid>(), It.IsAny <BasketItem>())) .Returns(Task.FromResult(new SaveBasketResponse())); _sut = new BasketController(basketService.Object); SetupCookies(); var result = await _sut.Post(new BasketItem()); var expectedResult = new SaveBasketResponse(); var okObjectResult = result as OkObjectResult; Assert.Equal(expectedResult, okObjectResult.Value as SaveBasketResponse); }
public async Task <SaveBasketResponse> Save(Guid sessionId, BasketItem item) { var policy = _pollyPolicyProvider.BasketStorePolicy(); var result = await policy.ExecuteAndCaptureAsync(async() => { await _basketStore.SaveOrUpdate(new BasketItemModel { ProductId = Guid.Parse(item.ProductId), Quantity = item.Quantity, SessionId = sessionId }); }); if (result.Outcome == OutcomeType.Failure) { //LOG var response = new SaveBasketResponse(); response.AddError(result.FinalException.Message); return(response); } return(new SaveBasketResponse()); }