public async Task <DiscountResult> CreateDiscountAsync(DiscountRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var availableProduct = await _paymentRepository.GetById(request.ProductIds); Discount discount = Create <Discount>(request); DiscountResult discountResult = Create <DiscountResult>(request); if (availableProduct != null) { discount.ProductIds = availableProduct.SKU; discount.Id = Guid.NewGuid().ToString(); var result = await _discountRepository.Add(discount); discountResult.Id = discount.Id; discountResult.ProductIds = discount.ProductIds; discountResult.Code = DiscountResultCode.Success; } else { discountResult.ProductIds = ""; discountResult.Code = DiscountResultCode.NoProductAvailable; } return(discountResult); }
public async Task ShouldReturnDiscountCreatedWithResultValuesAsync() { //Act DiscountResult result = await _discount.CreateDiscountAsync(_request); //Assert Assert.NotNull(result); Assert.Equal(_request.Percentage, result.Percentage); Assert.Equal(_request.Description, result.Description); Assert.Equal(_request.ValidDate, result.ValidDate); }