Example #1
0
        public async Task Delete_Returns404NotFoundStatusCodeAfterDeleted_WhenDatabaseIsEmpty()
        {
            // Act
            var devicesDeletedResponse = await TestHttpClient.DeleteAsync($"{DeviceApiRoot}/1");

            // Assert
            devicesDeletedResponse.StatusCode.Should().Be(HttpStatusCode.NotFound);
        }
Example #2
0
        public void Delete()
        {
            var id = CreateTimeEntry(new TimeEntry(222, 333, Convert.ToDateTime("01/08/2008"), 24));

            var deleteResponse = TestHttpClient.DeleteAsync($"/time-entries/{id}").Result;
            var getResponse    = TestHttpClient.GetAsync($"/time-entries/{id}").Result;
            var getAllResponse = TestHttpClient.GetAsync("/time-entries").Result;

            Assert.Equal(HttpStatusCode.NoContent, deleteResponse.StatusCode);
            Assert.Equal(HttpStatusCode.NotFound, getResponse.StatusCode);
            Assert.Equal("[]", getAllResponse.Content.ReadAsStringAsync().Result);
        }
Example #3
0
        Delete_Returns200OkStatusCodeWhenDeletes_Returns404NotFoundStatusCodeAfterDeleted_WhenCreatedInDatabase()
        {
            // Arrange
            var gatewayIps = await GenerateGatewayIpsAsync(5);

            var devicesData = DeviceUtilities.GenerateDevicesRequestDataWithUniqueVendors(9, gatewayIps)
                              .OrderBy(x => x.Vendor)
                              .ToArray();
            var createdDevices = (await Task.WhenAll(
                                      devicesData.Select(async x => {
                var message = await TestHttpClient.PostAsJsonAsync(DeviceApiRoot, x);
                return(await message.Content.ReadAsAsync <DeviceResponse>());
            })
                                      ))
                                 .OrderBy(x => x.Vendor)
                                 .ToArray();

            // Act
            var devicesDeletedResponses = await Task.WhenAll(
                createdDevices.Select(x => TestHttpClient.DeleteAsync($"{DeviceApiRoot}/{x.UID}"))
                );

            var devices = (await Task.WhenAll(
                               devicesDeletedResponses.Select(x => x.Content.ReadAsAsync <DeviceResponse>())
                               ))
                          .OrderBy(x => x.Vendor)
                          .ToArray();
            var devicesAfterDeletedResponses = await Task.WhenAll(
                createdDevices.Select(x => TestHttpClient.DeleteAsync($"{DeviceApiRoot}/{x.UID}"))
                );

            // Assert
            devicesDeletedResponses.Select(x => x.StatusCode)
            .Should().AllBeEquivalentTo(HttpStatusCode.OK);
            devicesAfterDeletedResponses.Select(x => x.StatusCode)
            .Should().AllBeEquivalentTo(HttpStatusCode.NotFound);

            var valueTuples = devices
                              .Zip(devicesData)
                              .Zip(createdDevices, (x, cg) => (x.First, x.Second, cg));

            foreach (var(device, data, createdDevice) in valueTuples)
            {
                device.UID.Should().Be(createdDevice.UID);
                device.Vendor.Should().Be(data.Vendor);
                device.Vendor.Should().Be(createdDevice.Vendor);
            }
        }
        Delete_Returns200OkStatusCodeWhenDeletes_Returns404NotFoundStatusCodeAfterDeleted_WhenCreatedInDatabase()
        {
            // Arrange
            var gatewaysData = GatewayUtilities.GenerateGatewaysRequestDataWithUniqueNames(23)
                               .OrderBy(x => x.Name)
                               .ToArray();
            var createdGateways = (await Task.WhenAll(
                                       gatewaysData.Select(async x => {
                var message = await TestHttpClient.PostAsJsonAsync(GatewayApiRoot, x);
                return(await message.Content.ReadAsAsync <GatewayResponse>());
            })
                                       ))
                                  .OrderBy(x => x.Name)
                                  .ToArray();

            // Act
            var gatewaysDeletedResponses = await Task.WhenAll(
                createdGateways.Select(x => TestHttpClient.DeleteAsync($"{GatewayApiRoot}/{x.Id}"))
                );

            var gateways = (await Task.WhenAll(
                                gatewaysDeletedResponses.Select(x => x.Content.ReadAsAsync <GatewayResponse>())
                                ))
                           .OrderBy(x => x.Name)
                           .ToArray();
            var gatewaysAfterDeletedResponses = await Task.WhenAll(
                createdGateways.Select(x => TestHttpClient.DeleteAsync($"{GatewayApiRoot}/{x.Id}"))
                );

            // Assert
            gatewaysDeletedResponses.Select(x => x.StatusCode)
            .Should().AllBeEquivalentTo(HttpStatusCode.OK);
            gatewaysAfterDeletedResponses.Select(x => x.StatusCode)
            .Should().AllBeEquivalentTo(HttpStatusCode.NotFound);

            var valueTuples = gateways
                              .Zip(gatewaysData)
                              .Zip(createdGateways, (x, cg) => (x.First, x.Second, cg));

            foreach (var(gateway, data, createdGateway) in valueTuples)
            {
                gateway.Id.Should().Be(createdGateway.Id);
                gateway.Name.Should().Be(data.Name);
                gateway.Name.Should().Be(createdGateway.Name);
            }
        }
Example #5
0
        public async Task DeleteReturns204NoContentWhenNotFound()
        {
            var statusCode = await client.DeleteAsync(Guid.NewGuid().ToString());

            Assert.StrictEqual(HttpStatusCode.NoContent, statusCode);
        }