public async Task <IActionResult> Post([FromBody] AddShipRequest request)
        {
            var addShipCommand = new AddShipCommand(
                type: (ShipType)Enum.Parse <ShipType>(request.Type),
                name: new ShipName(request.Name),
                capacity: new Capacity(request.Capacity),
                shippingLine: new Id(request.ShippingLine)
                );

            await _commandProcessor.SendAsync(addShipCommand);

            var addedShip = await _queryProcessor.ExecuteAsync(new ShipByIdQuery(new Id(addShipCommand.Id)));

            return(Ok(addedShip));
        }
        public async Task When_registering_a_new_ship()
        {
            //arrange
            using (var contextFactory = new FakeShipRegistryContextFactory(_options))
            {
                var uow = contextFactory.Create();

                var lineRepo = new ShippingLineRepositoryAsync(uow);

                var shippingLine = lineRepo.AddAsync(new ShippingLine(new Id(), new LineName("Maersk"))).Result;

                var commandProcessor = new FakeCommandProcessor();

                var handler = new NewShipRegistrationHandlerAsync(contextFactory, commandProcessor);

                var newShipCommand = new AddShipCommand(
                    type: ShipType.Tanker,
                    name: new ShipName("MV Toronto Star"),
                    capacity: new Capacity(30000),
                    shippingLine: shippingLine.Id);

                //act
                await handler.HandleAsync(newShipCommand);

                //assert
                var ship = uow.Ships.SingleOrDefault(s => s.Id == new Id(newShipCommand.Id));
                Assert.That(ship, Is.Not.Null);
                Assert.That(ship.ShipType, Is.EqualTo(newShipCommand.Type));
                Assert.That(ship.ShipName, Is.EqualTo(newShipCommand.Name));
                Assert.That(ship.Capacity, Is.EqualTo(newShipCommand.Capacity));
                Assert.That(ship.Id, Is.EqualTo(new Id(newShipCommand.Id)));
                Assert.That(ship.ShippingLineId, Is.EqualTo(newShipCommand.ShippingLine));
                Assert.That(ship.Version, Is.EqualTo(0));

                var domainEvent = commandProcessor.Messages.SingleOrDefault(m => m.Action == Action.Post);
                Assert.That(domainEvent, Is.Not.Null);

                var addedMessage = (NewShipAddedEvent)domainEvent.Message;
                Assert.That(addedMessage.Id, Is.EqualTo(newShipCommand.Id));
                Assert.That(addedMessage.Capacity, Is.EqualTo(newShipCommand.Capacity));
                Assert.That(addedMessage.Name, Is.EqualTo(newShipCommand.Name));
                Assert.That(addedMessage.Type, Is.EqualTo(newShipCommand.Type));
                Assert.That(addedMessage.ShipId, Is.EqualTo(new Id(newShipCommand.Id)));
                Assert.That(addedMessage.ShippingLine, Is.EqualTo(newShipCommand.ShippingLine));
            }
        }