Exemplo n.º 1
0
        public async void SetPartnerPromoCodeLimitAsync_PartnerIsNotFound_ReturnsNotFound()
        {
            // Arrange
            var partnerId = Guid.Parse("def47943-7aaf-44a1-ae21-05aa4948b165");
            var request   = new Fixture().Create <SetPartnerPromoCodeLimitRequest>();

            Partner partner = null;

            _partnersRepositoryMock.Setup(repo => repo.GetByIdAsync(partnerId)).ReturnsAsync(partner);

            // Act
            var result = await _partnersController.SetPartnerPromoCodeLimitAsync(partnerId, request);

            // Assert
            result.Should().BeAssignableTo <NotFoundResult>();
        }
Exemplo n.º 2
0
        public async void SetPartnerPromoCodeLimitAsync_PartnerSetLimit_ZeroingNumberIssuedPromoCodes()
        {
            //Arrange
            var partner   = GetBasePartner().WithActiveLimit();
            var partnerId = partner.Id;
            var request   = new Fixture().Create <SetPartnerPromoCodeLimitRequest>();
            var expected  = GetBasePartner().WithActiveLimit().ResetNumberIssuedPromoCodes();

            var mock = new Mock <IRepository <Partner> >();

            mock.Setup(x => x.GetByIdAsync(partnerId)).ReturnsAsync(partner);

            var mockCurrentDateTimeProvider = new Mock <ICurrentDateTimeProvider>();

            mockCurrentDateTimeProvider.Setup(x => x.CurrentDateTime)
            .Returns(DateTime.Now);

            var controller = new PartnersController(mock.Object, mockCurrentDateTimeProvider.Object);

            //Act
            await controller.SetPartnerPromoCodeLimitAsync(partnerId, request);

            //Assert
            partner.NumberIssuedPromoCodes.Should().Be(expected.NumberIssuedPromoCodes);
        }
Exemplo n.º 3
0
        public async void SetPartnerPromoCodeLimitAsync_HasActiveLimit_ShouldSetCancelDateNow()
        {
            //Arrange
            var partner     = GetBasePartner().WithActiveLimit();
            var targetLimit = partner.PartnerLimits.First();
            var partnerId   = partner.Id;
            var request     = new Fixture().Create <SetPartnerPromoCodeLimitRequest>();
            var now         = new DateTime(2020, 10, 14);
            var expected    =
                new PartnerPromoCodeLimit()
            {
                Id         = Guid.Parse("c9bef066-3c5a-4e5d-9cff-bd54479f075e"),
                CreateDate = new DateTime(2020, 07, 9),
                CancelDate = now,
                EndDate    = new DateTime(2020, 10, 9),
                Limit      = 100
            };

            var mock = new Mock <IRepository <Partner> >();

            mock.Setup(x => x.GetByIdAsync(partnerId)).ReturnsAsync(partner);
            var mockCurrentDateTimeProvider = new Mock <ICurrentDateTimeProvider>();

            mockCurrentDateTimeProvider.Setup(x => x.CurrentDateTime)
            .Returns(now);

            //Act
            var controller = new PartnersController(mock.Object, mockCurrentDateTimeProvider.Object);

            await controller.SetPartnerPromoCodeLimitAsync(partnerId, request);

            //Assert
            targetLimit.Should().BeEquivalentTo(expected);
        }
        public async Task SetPartnerPromoCodeLimitAsync_PartnerNotFound_ReturnsNotFound()
        {
            //Arrange
            var partnerId = _fixture.Create <Guid>();
            var partner   = default(Partner);

            _partnerRepositoryMock
            .Setup(x => x.GetByIdAsync(partnerId))
            .ReturnsAsync(partner);
            var request = _fixture.Create <SetPartnerPromoCodeLimitRequest>();


            //Act
            var result = await _partnersController.SetPartnerPromoCodeLimitAsync(partnerId, request);

            //Assert
            result.Should().BeAssignableTo <NotFoundResult>();
        }
Exemplo n.º 5
0
        public async void SetPartnerPromoCodeLimitAsync_ValidModel_SuccessUpdate()
        {
            //Arrange
            var partner   = GetBasePartner();
            var partnerId = partner.Id;
            var request   = new Fixture().Create <SetPartnerPromoCodeLimitRequest>();

            var mock = new Mock <IRepository <Partner> >();

            mock.Setup(x => x.GetByIdAsync(partnerId)).ReturnsAsync(partner);

            var mockCurrentDateTimeProvider = new Mock <ICurrentDateTimeProvider>();

            mockCurrentDateTimeProvider.Setup(x => x.CurrentDateTime)
            .Returns(DateTime.Now);

            var controller = new PartnersController(mock.Object, mockCurrentDateTimeProvider.Object);

            //Act
            await controller.SetPartnerPromoCodeLimitAsync(partnerId, request);

            //Assert
            mock.Verify(x => x.UpdateAsync(partner), Times.Once);
        }