예제 #1
0
        public async Task Get_Couriers()
        {
            var courier1 = new Courier {
                Name = "Posti", APIKey = "posti-api-key", BussinessId = "1234-56"
            };
            var courier2 = new Courier {
                Name = "DHL", APIKey = "dhl-api-key", BussinessId = "1234-57"
            };

            await _context.Couriers.AddAsync(courier1);

            await _context.Couriers.AddAsync(courier2);

            await _context.SaveChangesAsync();

            var client = _webApplicationFactory.CreateClient();

            var response = await client.GetAsync(COURIER_URL);

            response.EnsureSuccessStatusCode();
            Expect.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType.ToString());

            var responseString = await response.Content.ReadAsStringAsync();

            var expectedResult = _mapper.Map <IEnumerable <Courier>, IEnumerable <CourierResource> >(new List <Courier> {
                courier1, courier2
            });

            Expect.DeepEqualLowerCaseFields(expectedResult, responseString);
        }
예제 #2
0
        public async Task Get_Sensors()
        {
            var client = _webApplicationFactory.CreateClient();

            var response = await client.GetAsync("https://localhost:44338/api/summary");

            var expectedResult = new SummaryResponse("Success", await _sensorService.GetSummaryAsync());

            response.EnsureSuccessStatusCode();
            Expect.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType.ToString());

            var responseString = await response.Content.ReadAsStringAsync();

            Expect.DeepEqualLowerCaseFields(expectedResult, responseString);
        }
예제 #3
0
        public async Task Get_Valid_Diff()
        {
            double difference = await _sensorService.GetDifferenceAsync("000D6F0003141E14");

            var expectedResult = new DiffResponse("Success", difference);

            var client = _webApplicationFactory.CreateClient();

            var response = await client.GetAsync(@"https://localhost:44338/api/diff/000D6F0003141E14");

            response.EnsureSuccessStatusCode();
            Expect.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType.ToString());

            var responseString = await response.Content.ReadAsStringAsync();

            Expect.DeepEqualLowerCaseFields(expectedResult, responseString);
        }
예제 #4
0
        public async Task Get_Invalid_Diff()
        {
            string id = "THIS_IS_NOT_A_VALID_ID_FOR_SURE";

            var expectedResult = new NotFoundObjectResult(new DiffResponse(id)).Value;

            var client = _webApplicationFactory.CreateClient();

            var response = await client.GetAsync($"https://localhost:44338/api/diff/{id}");

            Expect.Equal(System.Net.HttpStatusCode.NotFound, response.StatusCode);
            Expect.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType.ToString());

            var responseString = await response.Content.ReadAsStringAsync();

            // TODO someone is formatting my decimals
            Expect.DeepEqualLowerCaseFields(expectedResult, responseString);
        }