public void It_should_save_a_new_product() { var expectedProduct = ProductMother.Create(); productSQLRepository.Save(expectedProduct).ConfigureAwait(false).GetAwaiter().GetResult(); var task = productSQLRepository.Search(expectedProduct.Id).ConfigureAwait(false); var actualProduct = task.GetAwaiter().GetResult(); Assert.NotNull(actualProduct); Assert.Equal(actualProduct.Id.Value, expectedProduct.Id.Value); }
public async void It_should_return_a_product() { var id = ProductIdMother.Create(); var expectedProduct = ProductMother.Create(); productRepository.Setup(x => x.Search(It.IsAny <ProductId>())).Returns(Task.FromResult(expectedProduct)); var actualProduct = await productFinder.Execute(id).ConfigureAwait(false); productRepository.Verify(r => r.Search(id), Times.Once); Assert.Same(expectedProduct, actualProduct); }
public async void It_should_delete_product() { var product = ProductMother.Create(); var id = ProductIdMother.Create(); productRepository.Setup(x => x.Search(It.IsAny <ProductId>())).Returns(Task.FromResult(product)); productRepository.Setup(x => x.Remove(It.IsAny <Product>())); await productDeleter.Execute(id).ConfigureAwait(false); productRepository.Verify(r => r.Search(id), Times.Once); productRepository.Verify(r => r.Remove(product), Times.Once); }
public void It_should_faild_when_product_not_exist() { var product = ProductMother.Create(); var id = ProductIdMother.Create(); productRepository.Setup(x => x.Search(It.IsAny <ProductId>())).Returns(Task.FromResult <Product>(null)); productRepository.Setup(x => x.Remove(It.IsAny <Product>())); var task = Assert.ThrowsAsync <Exception>(async() => await productDeleter.Execute(id).ConfigureAwait(false)); Assert.Equal("Product not exist", task.Result.Message); productRepository.Verify(r => r.Search(id), Times.Once); productRepository.Verify(r => r.Remove(product), Times.Never); }
public void it_should_fail_when_the_product_no_exist() { var id = ProductIdMother.Create(); var product = ProductMother.Create(); var name_new = ProductNameMother.Create(name: "Rename product"); productRepository.Setup(x => x.Search(It.IsAny <ProductId>())).Returns(Task.FromResult <Product>(null)); productRepository.Setup(x => x.Modify(It.IsAny <Product>())); var task = Assert.ThrowsAsync <Exception>(async() => await productRenamer.Execute(id, name_new).ConfigureAwait(false)); productRepository.Verify(r => r.Search(id), Times.Once); productRepository.Verify(r => r.Modify(product), Times.Never); Assert.Equal("Product not exist", task.Result.Message); }
public async void it_should_rename_product() { var id = ProductIdMother.Create(); var product = ProductMother.Create(); var name_new = ProductNameMother.Create(name: "Rename product"); productRepository.Setup(x => x.Search(It.IsAny <ProductId>())).Returns(Task.FromResult <Product>(product)); productRepository.Setup(x => x.Modify(It.IsAny <Product>())); await productRenamer.Execute(id, name_new).ConfigureAwait(false); productRepository.Verify(r => r.Search(id), Times.Once); productRepository.Verify(r => r.Modify(product), Times.Once); Assert.Equal(name_new, product.Name); }