Example #1
0
        public async Task UpdateSale_Test_With_Invalid_SaleId()
        {
            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.IsCityNameExist(It.IsAny <string> ())).ReturnsAsync(10);
                repositoryMock.Setup(rm => rm.UpdateSale(It.IsAny <Sale> ())).ThrowsAsync(new SaleNotFoundException());

                var mockMapper = new Mock <IMapper> ();
                mockMapper.Setup(x => x.Map <SaleResource, Sale> (It.IsAny <SaleResource> ()))
                .Returns(new Sale());
                UpdateSaleCommandHandler handler = new UpdateSaleCommandHandler(repositoryMock.Object, mockMapper.Object);
                await Assert.ThrowsAsync <SaleNotFoundException> (async() => await handler.Handle(request, default));
            } catch (Exception ex) {
                Assert.False(true, ex.Message);
            }
        }
Example #2
0
        public async Task UpdateSale_Test_With_Invalid_ProductName()
        {
            try {
                var repositoryMock = new Mock <IMainRepository> ();
                repositoryMock.Setup(rm => rm.IsProductExist(It.IsAny <string> (), It.IsAny <string> ())).ReturnsAsync(false);
                var mockMapper = new Mock <IMapper> ();

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