Beispiel #1
0
        public async Task Consume(ConsumeContext <IDeleteProductCommand> context)
        {
            try
            {
                var connectionStringSettings = new ConnectionStringSettings();
                var blobStorageSettings      = new BlobStorageSettings();

                _configurationRoot.GetSection("ConnectionStrings").Bind(connectionStringSettings);
                _configurationRoot.GetSection("BlobStorage").Bind(blobStorageSettings);

                var dbContext  = ProductDbContext.GetProductDbContext(connectionStringSettings.DefaultConnection);
                var repository = new RepositoryWrapper(dbContext);

                var product = repository.Product.GetProductById(Guid.Parse(context.Message.ProductId));
                if (product != null)
                {
                    var deleteblob = new PhotoBlob(blobStorageSettings);
                    await deleteblob.DeleteBlob(product.BlobName);
                }

                var productService = new ProductCatalogService(repository);
                var result         = await productService.DeleteProduct(context.Message.ProductId);

                var deletedEvent = new ProductDeletedEvent(result);
                await context.RespondAsync(deletedEvent);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public void DeleteProduct_ReturnsNotFound()
        {
            // Arrange
            var code    = "123";
            var product = new Product()
            {
                Code = code
            };

            var httpClient = new TestHelper().CreateMockHttpClient(JsonConvert.SerializeObject(product), HttpStatusCode.Created);

            var service = new ProductCatalogService(httpClient);

            // Act
            async Task Action() => await service.DeleteProduct(Guid.NewGuid());

            // Assert
            Assert.Null(Action().Exception);
        }
        public void DeleteProduct_Deleted()
        {
            // Arrange
            var code    = "123";
            var product = new Product()
            {
                Code = code
            };

            var httpClient = new TestHelper().CreateMockHttpClient("", HttpStatusCode.OK);

            var service = new ProductCatalogService(httpClient);

            // Act
            async Task Action() => await service.DeleteProduct(Guid.NewGuid());

            // Assert
            Assert.Null(Action().Exception);
        }
        public async Task Remove(string id)
        {
            await productCatalogService.DeleteProduct(id);

            await LoadData();
        }