Example #1
0
        public async Task <IActionResult> AdjustBookPriceCommand([FromBody] AdjustBookPriceCommand command)
        {
            _logger.LogInformation("adjusting book price id: {0}", command.Id);
            await _mediator.DispatchAsync(command);

            _logger.LogInformation("Book id:{0} successfully price adjusted", command.Id);
            return(Ok());
        }
Example #2
0
        public async void AdjustBookPrice_Fail()
        {
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(a => a.SaveAsync());
            var mockDb = _repositoryMock as MockBookRepository <Book>;
            var book   = new Book("test1", "author 1", 100);

            mockDb.Table.Add(book.Id, book);

            var adjustBookPriceCommandHandler = new AdjustBookPriceCommandHandler(_repositoryMock, mockUnitOfWork.Object);
            var command = new AdjustBookPriceCommand
            {
                Id            = book.Id,
                PurchasePrice = -1
            };

            await Assert.ThrowsAsync <ValidateException>(() => adjustBookPriceCommandHandler.HandleAsync(command));
        }
Example #3
0
        public async void AdjustBookPrice_Success()
        {
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(a => a.SaveAsync());
            var mockDb = _repositoryMock as MockBookRepository <Book>;
            var book   = new Book("test1", "author 1", 100);

            mockDb.Table.Add(book.Id, book);

            var adjustBookPriceCommandHandler = new AdjustBookPriceCommandHandler(_repositoryMock, mockUnitOfWork.Object);
            var command = new AdjustBookPriceCommand
            {
                Id            = book.Id,
                PurchasePrice = 150
            };

            await adjustBookPriceCommandHandler.HandleAsync(command);

            var row = mockDb.Table[book.Id];

            Assert.Equal(command.PurchasePrice, row.PurchasePrice);
        }