Пример #1
0
            public void IgnoringAnEnumerableDoesNotCauseError()
            {
                var mapper = new TestMapper <Foo>();

                mapper.Map(m => m.List).Ignore();
                Assert.AreEqual(2, mapper.Properties.Count);
            }
Пример #2
0
        public async Task ChangePhoneAsync_ShouldBeOkObjectResult()
        {
            // Arrange
            var user = TestData.FileStorage.GetUsers().First();

            TestMock.UserService.Setup(userService => userService.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(user).Verifiable();

            TestMock.UserService.Setup(userService => userService.UpdatePhoneNumberAsync(It.IsAny <User>(), It.IsAny <string>()))
            .ReturnsAsync(IdentityResult.Success)
            .Verifiable();

            var controller = new PhoneController(TestMock.UserService.Object, TestMapper);

            var request = new ChangePhoneRequest
            {
                Number = user.PhoneNumber
            };

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

            // Assert
            result.Should().BeOfType <OkObjectResult>();
            result.As <OkObjectResult>().Value.Should().BeEquivalentTo(TestMapper.Map <PhoneDto>(user));
            TestMock.UserService.Verify(userService => userService.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once);
            TestMock.UserService.Verify(userService => userService.UpdatePhoneNumberAsync(It.IsAny <User>(), It.IsAny <string>()), Times.Once);
        }
Пример #3
0
            public void IgnoringAnEnumerableDoesNotCauseError()
            {
                var mapper = new TestMapper <Foo>();

                mapper.Map(m => m.List).Ignore();
                mapper.TestProtected().RunMethod("AutoMap");
                Assert.Equal(2, mapper.Properties.Count);
            }
Пример #4
0
        public void SimpleMapWithContext()
        {
            var mapper = new TestMapper();

            var result = mapper.Map(new Source());

            Assert.That(result.Foo, Is.EqualTo("Foo value"));
            Assert.That(result.Bar, Is.EqualTo(11));
        }
Пример #5
0
        public async Task FetchPromotionsAsync_ShouldBeOkObjectResult()
        {
            // Arrange
            TestMock.PromotionService.Setup(promotionService => promotionService.FetchPromotionsAsync()).ReturnsAsync(GeneratePromotions()).Verifiable();

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

            // Act
            var result = await controller.FetchPromotionsAsync();

            // Assert
            result.Should().BeOfType <OkObjectResult>();
            result.As <OkObjectResult>().Value.Should().BeEquivalentTo(TestMapper.Map <PromotionDto[]>(GeneratePromotions()));
            TestMock.PromotionService.Verify(promotionService => promotionService.FetchPromotionsAsync(), Times.Once);
        }
Пример #6
0
        public async Task CancelPromotionAsync_ShouldBeOkObjectResult()
        {
            // Arrange
            var promotion = GeneratePromotion();

            TestMock.PromotionService
            .Setup(
                promotionService => promotionService.FindPromotionOrNullAsync(
                    It.IsAny <string>()))
            .ReturnsAsync(promotion)
            .Verifiable();

            TestMock.PromotionService
            .Setup(
                promotionService => promotionService.CancelPromotionAsync(
                    It.IsAny <Promotion>(), It.IsAny <IDateTimeProvider>()))
            .ReturnsAsync(DomainValidationResult <Promotion> .Succeeded(promotion))
            .Verifiable();

            var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await controller.CancelPromotionAsync(TestCode);

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

            TestMock.PromotionService.Verify(
                promotionService => promotionService.FindPromotionOrNullAsync(
                    It.IsAny <string>()),
                Times.Once);

            TestMock.PromotionService.Verify(
                promotionService => promotionService.CancelPromotionAsync(
                    It.IsAny <Promotion>(), It.IsAny <IDateTimeProvider>()),
                Times.Once);
        }
Пример #7
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);
        }
Пример #8
0
        public async Task FetchAddressBookAsync_ShouldBeOkObjectResult()
        {
            // Arrange
            var user = new User
            {
                Id = Guid.NewGuid()
            };

            var address = new Address(
                UserId.FromGuid(user.Id),
                Country.Canada,
                "Line1",
                null,
                "City",
                "State",
                "PostalCode");

            var addressBook = new List <Address>
            {
                address
            };

            TestMock.UserService.Setup(userManager => userManager.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(user).Verifiable();

            TestMock.AddressService.Setup(addressService => addressService.FetchAddressBookAsync(It.IsAny <User>())).ReturnsAsync(addressBook).Verifiable();

            var controller = new AddressBookController(TestMock.UserService.Object, TestMock.AddressService.Object, TestMapper);

            // Act
            var result = await controller.FetchAddressBookAsync();

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

            result.As <OkObjectResult>().Value.Should().BeEquivalentTo(TestMapper.Map <ICollection <AddressDto> >(addressBook));

            TestMock.UserService.Verify(userManager => userManager.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once);

            TestMock.AddressService.Verify(addressService => addressService.FetchAddressBookAsync(It.IsAny <User>()), Times.Once);
        }
        public async Task FetchDoxatagHistoryAsync_ShouldBeOkObjectResult()
        {
            // Arrange
            var user = new User
            {
                Id = Guid.NewGuid()
            };

            var doxatag = new Doxatag(
                UserId.FromGuid(user.Id),
                "Name",
                1000,
                new UtcNowDateTimeProvider());

            var doxatagHistory = new List <Doxatag>
            {
                doxatag
            };

            TestMock.UserService.Setup(userManager => userManager.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(user).Verifiable();

            TestMock.DoxatagService.Setup(doxatagService => doxatagService.FetchDoxatagHistoryAsync(It.IsAny <User>())).ReturnsAsync(doxatagHistory).Verifiable();

            var controller = new DoxatagHistoryController(TestMock.UserService.Object, TestMock.DoxatagService.Object, TestMapper);

            // Act
            var result = await controller.FetchDoxatagHistoryAsync();

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

            result.As <OkObjectResult>().Value.Should().BeEquivalentTo(TestMapper.Map <IEnumerable <DoxatagDto> >(doxatagHistory));

            TestMock.UserService.Verify(userManager => userManager.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once);

            TestMock.DoxatagService.Verify(doxatagService => doxatagService.FetchDoxatagHistoryAsync(It.IsAny <User>()), Times.Once);
        }