public void SavePromoCode_Update()
        {
            var repo = CreateRepo(100, new PromoCodeEntity
            {
                Id = 100
            });
            var service = new PromoCodeManagerService(repo.Object);

            PromoCodeDto result = service.SavePromoCode(new PromoCodeSaveDto
            {
                Id          = 100,
                Code        = "CODE",
                Description = "description",
                Discount    = 90,
                From        = DateTime.Today,
                To          = DateTime.Today
            });

            repo.Verify(x => x.Save(It.IsAny <PromoCodeEntity>()));
            Assert.AreEqual(100, result.Id);
            Assert.AreEqual("code", result.Code);
            Assert.AreEqual("description", result.Description);
            Assert.AreEqual(90, result.Discount);
            Assert.AreEqual(DateTime.Today, result.From);
            Assert.AreEqual(DateTime.Today, result.To);
        }
        public void GetTotalPriceAsync_ProductsAndPromoCodeExist_TotalPriceWithPromoCode()
        {
            // Arrange
            var productDtos = new List <ProductDto>
            {
                new ProductDto
                {
                    Price = 2M,
                },
                new ProductDto
                {
                    Price = 4M,
                }
            };

            var promoCodeDto = new PromoCodeDto
            {
                Value = 50M
            };

            // Act
            var result = _calcService
                         .GetTotalPriceAsync(
                productDtos,
                promoCodeDto.Value)
                         .GetAwaiter()
                         .GetResult();

            // Assert
            Assert.Equal(3M, result);
        }
Exemple #3
0
        public ActionResult AddPromoCode([FromBody] PromoCodeDto data)
        {
            var result = this.cartRepository.AddPromoCode(data.PromoCode);

            if (result.Success)
            {
                return(this.JsonOk(result.Data));
            }

            return(this.JsonError(result.Errors?.ToArray(), HttpStatusCode.InternalServerError, tempData: result.Data));
        }
        public void IsValidPromoCodeAsync_ZeroValue_IsNotValid()
        {
            // Arrange
            var promoCodeDto = new PromoCodeDto();

            // Act
            var result = _calcService
                         .IsValidPromoCodeAsync(promoCodeDto.Value)
                         .GetAwaiter()
                         .GetResult();

            // Assert
            Assert.False(result);
        }
        public MovieDto AddPromoCode(PromoCodeDto promoCodeDto)
        {
            var movie = moviesRepository.FindById(promoCodeDto.MovieId);

            if (movie == null)
            {
                throw new HttpException("Movie not found.", HttpStatusCode.NotFound);
            }

            var promoCode = PromoCode.Create(movie, promoCodeDto.PromoEnd, promoCodeDto.Percentage);

            moviesRepository.AddPromoCode(promoCode);

            return(mapper.Map <MovieDto>(movie));
        }
        public void IsValidPromoCodeAsync_PositiveValue_IsValid()
        {
            // Arrange
            var promoCodeDto = new PromoCodeDto
            {
                Value = 5M
            };

            // Act
            var result = _calcService
                         .IsValidPromoCodeAsync(promoCodeDto.Value)
                         .GetAwaiter()
                         .GetResult();

            // Assert
            Assert.True(result);
        }
Exemple #7
0
 public MovieDto AddPromoCode([FromBody] PromoCodeDto promoCodeDto)
 {
     return(moviesService.AddPromoCode(promoCodeDto));
 }