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 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);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #5
0
        public void It_should_rename_an_existing_product()
        {
            var expectedProductName = ProductNameMother.Create();
            var taskpre             = productSQLRepository.GetAll().ConfigureAwait(false);
            var existingProduct     = (taskpre.GetAwaiter().GetResult()).FirstOrDefault();

            existingProduct.Rename(expectedProductName);

            productSQLRepository.Modify(existingProduct).ConfigureAwait(false).GetAwaiter().GetResult();

            var task          = productSQLRepository.Search(existingProduct.Id).ConfigureAwait(false);
            var actualProduct = task.GetAwaiter().GetResult();

            Assert.NotNull(actualProduct);
            Assert.Equal(actualProduct.Name.Value, expectedProductName.Value);
        }