Esempio n. 1
0
        public async Task add_parcel_should_succeed()
        {
            var httpClient = _factory.CreateClient();
            var command    = new AddParcel(Guid.Empty, "normal", "Test parcel", "Test address");
            var request    = new StringContent(
                JsonConvert.SerializeObject(command), Encoding.UTF8,
                "application/json");

            var response = await httpClient.PostAsync("api/parcels", request);

            response.EnsureSuccessStatusCode();
            response.StatusCode.ShouldBe(HttpStatusCode.Created);
            var parcelUrl = response.Headers.Location?.ToString();

            parcelUrl.ShouldNotBeEmpty();

            var getResponse = await httpClient.GetAsync(parcelUrl);

            getResponse.EnsureSuccessStatusCode();
            var content = await getResponse.Content.ReadAsStringAsync();

            var parcel = JsonConvert.DeserializeObject <ParcelDetailsDto>(content);

            parcel.ShouldNotBeNull();
            parcel.Size.ShouldBe(command.Size, StringCompareShould.IgnoreCase);
            parcel.Address.ShouldBe(command.Address);
            parcel.Name.ShouldBe(command.Name);
        }
Esempio n. 2
0
        public async Task add_parcel_should_fail_given_invalid_size()
        {
            var command   = new AddParcel(Guid.NewGuid(), "test_size", "test");
            var exception = await Record.ExceptionAsync(async() => await _parcelsService.AddAsync(command));

            exception.ShouldNotBeNull();
            exception.ShouldBeOfType <InvalidParcelSizeException>();
        }
Esempio n. 3
0
        public async Task <ActionResult> Post(AddParcel command)
        {
            await _dispatcher.SendAsync(command);

            Response.Headers.Add("Resource-ID", $"{command.ParcelId:N}");

            return(CreatedAtAction(nameof(Get), new { parcelId = command.ParcelId }, null));
        }
Esempio n. 4
0
 public async Task AddAsync(AddParcel request)
 {
     if (!Enum.TryParse<ParcelSize>(request.Size, true, out var size))
     {
         throw new InvalidParcelSizeException(request.Size);
     }
 
     var parcel = new Parcel(request.Id, size, request.Address);
     await _parcelsRepository.AddAsync(parcel);
 }
        public async Task add_parcel_should_return_location_header()
        {
            var command  = new AddParcel(Guid.NewGuid(), "large", "test");
            var response = await _client.PostAsync("api/parcels", GetContent(command));

            response.EnsureSuccessStatusCode();
            response.StatusCode.ShouldBe(HttpStatusCode.Created);
            response.Headers.Location.ShouldNotBeNull();
            response.Headers.Location.ToString().ShouldBe($"http://localhost/api/Parcels/{command.Id}");
        }
        public async Task add_parcel_should_succeed_given_valid_size_and_address()
        {
            var command = new AddParcel("test", "large");

            await _parcelsService.AddAsync(command);

            await _parcelsRepository.Received().AddAsync(Arg.Is <Parcel>(x =>
                                                                         x.Id == command.Id &&
                                                                         x.Address == command.Address &&
                                                                         x.Size == ParcelSize.Large &&
                                                                         x.State == ParcelState.New));
        }
Esempio n. 7
0
        public async Task <ActionResult> Post(AddParcel command)
        {
            await _parcelsService.AddAsync(command);

            return(CreatedAtAction(nameof(Get), new { parcelId = command.Id }, null));
        }