コード例 #1
0
        public async Task AddSale_Test_With_Valid_Data()
        {
            try {
                var repositoryMock = new Mock <IMainRepository> ();
                repositoryMock.Setup(rm => rm.IsProductExist(It.IsAny <string> (), It.IsAny <string> ())).ReturnsAsync(true);
                repositoryMock.Setup(rm => rm.IsUsertNameExist(It.IsAny <string> ())).ReturnsAsync(true);
                repositoryMock.Setup(rm => rm.GetLastSalePrice(It.IsAny <SaleListFilterModel> ())).ReturnsAsync(110);
                repositoryMock.Setup(rm => rm.IsCityNameExist(It.IsAny <string> ())).ReturnsAsync(10);
                repositoryMock.Setup(rm => rm.AddSale(It.IsAny <Sale> ()));

                var mockMapper = new Mock <IMapper> ();
                mockMapper.Setup(x => x.Map <SaleResource, Sale> (It.IsAny <SaleResource> ()))
                .Returns(new Sale());

                AddSaleCommandHandler handler = new AddSaleCommandHandler(repositoryMock.Object, mockMapper.Object);
                var result = await handler.Handle(request, default);

                Assert.NotNull(result);
            } catch (Exception ex) {
                Assert.False(true, ex.Message);
            }
        }
コード例 #2
0
        public async Task AddSale_Test_With_Invalid_Price()
        {
            try {
                var repositoryMock = new Mock <IMainRepository> ();
                repositoryMock.Setup(rm => rm.IsProductExist(It.IsAny <string> (), It.IsAny <string> ())).ReturnsAsync(true);
                repositoryMock.Setup(rm => rm.IsUsertNameExist(It.IsAny <string> ())).ReturnsAsync(true);
                repositoryMock.Setup(rm => rm.GetLastSalePrice(It.IsAny <SaleListFilterModel> ())).ReturnsAsync(100);

                var mockMapper = new Mock <IMapper> ();

                AddSaleCommandHandler handler = new AddSaleCommandHandler(repositoryMock.Object, mockMapper.Object);
                await Assert.ThrowsAsync <MaximumAmountThresholdException> (async() => await handler.Handle(request, default));
            } catch (Exception ex) {
                Assert.False(true, ex.Message);
            }
        }
コード例 #3
0
        public async Task AddSale_Test_With_Invalid_UserName()
        {
            try {
                var repositoryMock = new Mock <IMainRepository> ();
                repositoryMock.Setup(rm => rm.IsProductExist(It.IsAny <string> (), It.IsAny <string> ())).ReturnsAsync(true);
                repositoryMock.Setup(rm => rm.IsUsertNameExist(It.IsAny <string> ())).ReturnsAsync(false);

                var mockMapper = new Mock <IMapper> ();

                AddSaleCommandHandler handler = new AddSaleCommandHandler(repositoryMock.Object, mockMapper.Object);
                await Assert.ThrowsAsync <UserNameNotFoundException> (async() => await handler.Handle(request, default));
            } catch (Exception ex) {
                Assert.False(true, ex.Message);
            }
        }