public async void it_should_create_product_when_product_name_exceed_max_long()
        {
            var id   = ProductIdMother.Create();
            var name = ProductNameMother.Create(name: "Product name Product name Product name");

            await productCreator.Execute(id, name).ConfigureAwait(false);

            productRepository.Verify(r => r.Save(It.IsAny <Product>()), Times.Once);
            eventBus.Verify(r => r.Publish(It.IsAny <IEnumerable <DomainEvent> >()), Times.Once);
        }
        public void it_should_faild_when_a_product_not_exist()
        {
            var id = ProductIdMother.Create();

            productRepository.Setup(x => x.Search(It.IsAny <ProductId>())).Returns(Task.FromResult <Product>(null));

            var task = Assert.ThrowsAsync <Exception>(async() => await productFinder.Execute(id).ConfigureAwait(false));

            productRepository.Verify(r => r.Search(id), Times.Once);
            Assert.Equal("Product not exist", task.Result.Message);
        }
        public async void it_should_create_product()
        {
            var id   = ProductIdMother.Create();
            var name = ProductNameMother.Create();

            productRepository.Setup(x => x.Save(It.IsAny <Product>()));

            await productCreator.Execute(id, name).ConfigureAwait(false);

            productRepository.Verify(r => r.Save(It.IsAny <Product>()), Times.Once);
            eventBus.Verify(r => r.Publish(It.IsAny <IEnumerable <DomainEvent> >()), Times.Once);
        }
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }