Пример #1
0
        public async Task CreatePromotionAsync_ShouldBeOkObjectResult()
        {
            // Arrange
            TestMock.PromotionService
            .Setup(
                promotionService => promotionService.CreatePromotionAsync(
                    It.IsAny <string>(),
                    It.IsAny <Currency>(),
                    It.IsAny <TimeSpan>(),
                    It.IsAny <DateTime>()))
            .ReturnsAsync(DomainValidationResult <Promotion> .Succeeded(GeneratePromotion()))
            .Verifiable();

            var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper);

            var request = new CreatePromotionRequest
            {
                Currency = new CurrencyDto
                {
                    Amount = 50,
                    Type   = EnumCurrencyType.Money
                },
                Duration        = new Duration(),
                ExpiredAt       = DateTime.UtcNow.ToTimestamp(),
                PromotionalCode = TestCode
            };

            // Act
            var result = await controller.CreatePromotionAsync(request);

            // Assert
            result.Should().BeOfType <OkObjectResult>();
            result.As <OkObjectResult>().Value.Should().BeEquivalentTo(TestMapper.Map <PromotionDto>(GeneratePromotion()));

            TestMock.PromotionService.Verify(
                promotionService => promotionService.CreatePromotionAsync(
                    It.IsAny <string>(),
                    It.IsAny <Currency>(),
                    It.IsAny <TimeSpan>(),
                    It.IsAny <DateTime>()),
                Times.Once);
        }
Пример #2
0
        public async Task CreatePromotionAsync_ShouldBeBadRequestObjectResult()
        {
            // Arrange
            TestMock.PromotionService
            .Setup(
                promotionService => promotionService.CreatePromotionAsync(
                    It.IsAny <string>(),
                    It.IsAny <Currency>(),
                    It.IsAny <TimeSpan>(),
                    It.IsAny <DateTime>()))
            .ReturnsAsync(DomainValidationResult <Promotion> .Failure("error message"))
            .Verifiable();

            var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper);

            var request = new CreatePromotionRequest
            {
                Currency = new CurrencyDto
                {
                    Amount = 50,
                    Type   = EnumCurrencyType.Money
                },
                Duration        = new Duration(),
                ExpiredAt       = DateTime.UtcNow.ToTimestamp(),
                PromotionalCode = "code1"
            };

            // Act
            var result = await controller.CreatePromotionAsync(request);

            // Assert
            result.Should().BeOfType <BadRequestObjectResult>();

            TestMock.PromotionService.Verify(
                promotionService => promotionService.CreatePromotionAsync(
                    It.IsAny <string>(),
                    It.IsAny <Currency>(),
                    It.IsAny <TimeSpan>(),
                    It.IsAny <DateTime>()),
                Times.Once);
        }