Example #1
0
        public async Task <IActionResult> CreateAsync(CreateDeliveryCommand createDeliveryCommand,
                                                      [FromHeader(Name = "x-requestid")] Guid requestId)
        {
            var commandResult = false;

            if (requestId != Guid.Empty)
            {
                var requestCreateDelivery =
                    new IdentifiedCommand <CreateDeliveryCommand, bool>(createDeliveryCommand, requestId);

                _logger.LogInformation(
                    "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
                    requestCreateDelivery.GetGenericTypeName(),
                    nameof(requestCreateDelivery.Command.ClientId),
                    requestCreateDelivery.Command.ClientId,
                    requestCreateDelivery);

                commandResult = await _mediator.Send(requestCreateDelivery);
            }

            if (!commandResult)
            {
                return(BadRequest());
            }

            return(Ok());
        }
        public async Task <HttpResponseMessage> CreateDelivery(CreateDeliveryCommand command)
        {
            var content = new StringContent(JsonConvert.SerializeObject(command), Encoding.UTF8, "application/json");

            var response = await _httpClient.PostAsync("delivery", content);

            return(response);
        }
Example #3
0
        public async Task <IActionResult> Create(CreateDeliveryCommand command)
        {
            var delivery = new Delivery(command.Barcode, command.Destination);
            await _repository.Add(delivery);

            AddCreatePostJob(command);

            return(this.Created($"/deliveries/{delivery.Id}", delivery));
        }
Example #4
0
 private void AddCreatePostJob(CreateDeliveryCommand command)
 {
     if (command.IsOurCommand())
     {
         FluentScheduler.JobManager.AddJob(
             async() =>
         {
             var userId = await _microService1AntiCorruption.GetUserId();
             await _microService2AntiCorruption.CreatePackage(new RemotePackage(command.Barcode, command.Destination, userId));
         },
             schedule => schedule.ToRunOnceAt(DateTime.Now.AddSeconds(1)));
     }
 }
Example #5
0
 private void  AddSecondaryCallJob(CreateDeliveryCommand command)
 {
     FluentScheduler.JobManager.AddJob(
         async() =>
     {
         await _legacyApiClient.CreatePackage(new CreatePackageCommand
         {
             Barcode     = command.Barcode,
             Destination = command.Destination,
             Source      = command.Source
         });
     },
         schedule => schedule.ToRunOnceAt(DateTime.Now.AddSeconds(1)));
 }
Example #6
0
        public async Task <IActionResult> Post(CreateDeliveryCommand command)
        {
            command.Source = SourceConsts.New;
            var response = await _newApiClient.CreateDelivery(command);

            if (!response.IsSuccessStatusCode)
            {
                return(this.StatusCode((int)response.StatusCode, response.Content));
            }

            AddSecondaryCallJob(command);

            return(this.StatusCode((int)response.StatusCode, response.Content));
        }
Example #7
0
        public int Handle(CreateDeliveryCommand command)
        {
            var delivery = _workUnit.Deliveries.Create();

            delivery.Title            = command.Title;
            delivery.CreationDate     = DateTime.Now;
            delivery.ModificationDate = delivery.CreationDate;
            delivery.ExpirationTime   = command.ExpirationTime;
            delivery.Status           = DeliveySatus.Available;

            _workUnit.SaveChanges();

            return(delivery.Id);
        }
        public void SetUp()
        {
            this.drones = new List <Drone>();

            this.droneRepository = new Mock <IRepository <Drone> >();
            this.generalSettings = new Mock <IGeneralSettings>();

            this.droneRepository.SetupGet(c => c.Items)
            .Returns(() => this.drones.AsQueryable());

            this.generalSettings.SetupGet(c => c.MaxRoutesPerDrone)
            .Returns(() => this.maxRoutes);

            this.validator = new CreateDeliveryCommandValidator(this.droneRepository.Object, this.generalSettings.Object);

            this.model = new CreateDeliveryCommand();
        }
Example #9
0
        public async Task ShouldCreateDelivery()
        {
            var userId = await RunAsDefaultUserAsync();

            var listId = await SendAsync(new CreateZoneCommand { Title = "New Zone" });

            var command = new CreateDeliveryCommand {
                ZoneId = listId,
                Title  = "Delvery1"
            };

            var itemId = await SendAsync(command);

            var item = await FindAsync <Delivery>(itemId);

            item.Should().NotBeNull();
            item.ZoneId.Should().Be(command.ZoneId);
            item.Title.Should().Be(command.Title);
            item.CreatedBy.Should().Be(userId);
            item.Created.Should().BeCloseTo(DateTime.Now, 10000);
            item.LastModifiedBy.Should().BeNull();
            item.LastModified.Should().BeNull();
        }
 public async Task <IActionResult> CreateAsync([FromBody] CreateDeliveryCommand command)
 {
     return(Ok(await HandleAsync(command)));
 }
Example #11
0
 public async Task <ActionResult <int> > Create(CreateDeliveryCommand command)
 {
     return(await Mediator.Send(command));
 }
Example #12
0
        public void ShouldRequireMinimumFields()
        {
            var command = new CreateDeliveryCommand();

            FluentActions.Invoking(() => SendAsync(command)).Should().Throw <ValidationException>();
        }