public async Task Get_ReturnsGatewayResponse_WhenCreatedInDatabase() { // Arrange var gatewaysData = GatewayUtilities.GenerateGatewaysRequestDataWithUniqueNames(23) .OrderBy(x => x.Name) .ToArray(); var createdGateways = (await GatewayUtilities.CreateGatewaysAsync(TestHttpClient, gatewaysData)) .OrderBy(x => x.Name) .ToArray(); // Act var gatewaysResponses = await Task.WhenAll( createdGateways.Select(x => TestHttpClient.GetAsync($"{GatewayApiRoot}/{x.Id}")) ); var gateways = (await Task.WhenAll( gatewaysResponses.Select(x => x.Content.ReadAsAsync <GatewayResponse>()) )) .OrderBy(x => x.Name) .ToArray(); // Assert gatewaysResponses.Select(x => x.StatusCode) .Should().AllBeEquivalentTo(HttpStatusCode.OK); 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).And.Be(createdGateway.Name); } }
public async Task Update_Returns204NoContentStatusCode_WhenCreatedInDatabase() { // Arrange var gatewaysData = GatewayUtilities.GenerateGatewaysRequestDataWithUniqueNames(23) .OrderBy(x => x.Name) .ToArray(); var createdGateways = (await GatewayUtilities.CreateGatewaysAsync(TestHttpClient, gatewaysData)) .OrderBy(x => x.Name) .ToArray(); foreach (var data in gatewaysData) { data.Name = data.Name.Replace("gateway", "changed gateway"); } // Act var gatewaysResponses = await Task.WhenAll( createdGateways .Zip(gatewaysData) .Select(x => TestHttpClient.PutAsJsonAsync($"{GatewayApiRoot}/{x.First.Id}", x.Second)) ); // Assert gatewaysResponses.Select(x => x.StatusCode) .Should().AllBeEquivalentTo(HttpStatusCode.NoContent); }
public static async Task <DeviceResponse[]> CreateDevicesAsync(HttpClient client, int devicesCount, int gatewaysCount = 5) { var gatewayIps = (await GatewayUtilities.CreateGatewaysAsync(client, gatewaysCount)) .Select(x => x.Id) .ToArray(); var devicesData = GenerateDevicesRequestDataWithUniqueVendors(devicesCount, gatewayIps); return(await CreateDevicesAsync(client, devicesData)); }
public async Task Update_Returns404NotFound_WhenDatabaseIsEmpty() { // Act var gatewaysResponse = await TestHttpClient.PutAsJsonAsync($"{GatewayApiRoot}/1", new GatewayRequest { Ip = GatewayUtilities.GenerateIpv4(), Name = "Awesome gateway" }); // Assert gatewaysResponse.StatusCode.Should().Be(HttpStatusCode.NoContent); }
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); } }
public async Task GetAll_ReturnsPagedData_WhenCreatedInDatabase() { // Arrange var gatewaysData = GatewayUtilities.GenerateGatewaysRequestDataWithUniqueNames(23) .OrderBy(x => x.Name) .ToArray(); await GatewayUtilities.CreateGatewaysAsync(TestHttpClient, gatewaysData); // Act var response = await TestHttpClient.GetAsync(GatewayApiRoot); // Assert var pagedData = await response.Content.ReadAsAsync <PagedData <GatewayListItemResponse> >(); response.StatusCode.Should().Be(HttpStatusCode.OK); pagedData.Should().NotBeNull(); pagedData.Items.Should().HaveCount(10); pagedData.TotalCount.Should().Be(23); pagedData.PageSize.Should().Be(10); pagedData.CurrentPage.Should().Be(1); }
private async Task <int[]> GenerateGatewayIpsAsync(int count) { return((await GatewayUtilities.CreateGatewaysAsync(TestHttpClient, count)) .Select(x => x.Id) .ToArray()); }