コード例 #1
0
        public async Task GivenExistingProduct_WhenUpdateProductCommandSent_ThenProductUpdated()
        {
            var product = Product.Create(Guid.NewGuid(), "Old name", 10.99m);
            var command = new UpdateProduct(product.Id, "New name", 34.99m);

            repository.GetAsync(command.ProductId).Returns(product);

            await handler.HandleAsync(command);

            await repository.Received().UpdateAsync(product);
        }
コード例 #2
0
        public void AddsProductToRepository_RaisesIntegrationEvent()
        {
            var product    = new Domain.Product(Id, "Product Name", null);
            var repository = new Mock <IProductRepository>(MockBehavior.Strict);

            repository.Setup(r => r.GetAsync(product.Id)).Returns(Task.FromResult(product)).Verifiable();
            repository.Setup(r => r.UpdateAsync(product)).Returns(Task.CompletedTask).Verifiable();
            repository.Setup(r => r.SaveChanges()).Returns(Task.CompletedTask).Verifiable();

            var busPublisher = new Mock <IBusPublisher>(MockBehavior.Strict);

            busPublisher.Setup(p => p.Publish <IProductUpdated>(It.Is <IProductUpdated>(e => ValidateEquality(e)))).Returns(Task.CompletedTask).Verifiable();

            var handler = new UpdateProductHandler(repository.Object, busPublisher.Object);
            var result  = handler.HandleAsync(Cmd, new Mock <ICorrelationContext>().Object).GetAwaiter().GetResult();

            Assert.IsTrue(result.Successful);
            repository.Verify();
            busPublisher.Verify();
            ValidateEquality(product);
        }