public async Task <IActionResult> Create([FromBody] CreateRouteCommand command)
        {
            var result = await _mediator.Send(command);

            return(result.Success
                ? Created(result.Value)
                : Error(result.ErrorMessage, result.Code));
        }
        public async Task Handle_GivenInvalidOperationResult()
        {
            //Arrange
            const int createId = 10;
            var       command  = new CreateRouteCommand {
                RouteId = createId
            };

            //Assert
            await Assert.ThrowsAsync <InvalidOperationException>(() => _handler.Handle(command, CancellationToken.None));
        }
Beispiel #3
0
        public void CreateRoute_CallRouteFactory(
            [Frozen] IRouteFactory routeFactory,
            CreateRouteCommand message,
            Route route,
            CreateRouteCommandHandler createRouteCommandHandler)
        {
            //Information
            A.CallTo(() => routeFactory.Create(message.Route)).Returns(route);

            //Act
            createRouteCommandHandler.ExecuteAsync(message);

            //Test
            A.CallTo(() => routeFactory.Create(message.Route)).MustHaveHappened();
        }
        public async Task Handle_GivenValidResult()
        {
            //Arrange
            const int createId = 35;
            var       command  = new CreateRouteCommand {
                RouteId = createId, Enabled = false
            };

            //Act
            await _handler.Handle(command, CancellationToken.None);

            var unit = await Context.Routes.FindAsync(createId);

            //Assert
            Assert.Equal(createId, unit.RouteId);
            Assert.False(unit.Enabled);
        }
        public async Task <DomainResult <ObjectId> > Handle(CreateRouteCommand command, CancellationToken cancellationToken)
        {
            var origin = await _pointRepository.FindAsync(command.OriginPointId);

            var destination = await _pointRepository.FindAsync(command.DestinationPointId);

            if (origin is null || destination is null)
            {
                return(DomainResult.Failure <ObjectId>("Origin or Destination not found"));
            }

            var route = Route.Create(origin, destination);

            if (await _routeRepository.AlreadyExistsAsync(x => route.IsTheSame(x)))
            {
                return(DomainResult.Failure <ObjectId>("Route already exists", HttpStatusCode.Conflict));
            }

            await _routeRepository.CreateAsync(route);

            await _mediator.Publish(new RouteCreatedEvent(route));

            return(DomainResult.Ok(route.Id));
        }
Beispiel #6
0
        public async Task <IActionResult> Create([FromBody] CreateRouteCommand command)
        {
            await Mediator.Send(command);

            return(NoContent());
        }