Пример #1
0
        public async Task F1PutWithSuccess()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestAddresses);

                var client         = testScope.CreateClient();
                var recordToUpdate = testScope.GetDbTableContent <Address>().Last();
                recordToUpdate.City   = "Some new city";
                recordToUpdate.Street = "Some new street";

                var response = await client.PutAsJsonAsync($"/addresses/{recordToUpdate.Id}", recordToUpdate);

                response.EnsureSuccessStatusCode();
                var putResponse = await response.Content.ReadAsAsync <Address>();

                Assert.IsNotNull(putResponse);
                Assert.AreEqual(recordToUpdate.Id, putResponse.Id);
                Assert.AreEqual(recordToUpdate.City, putResponse.City);
                Assert.AreEqual(recordToUpdate.Street, putResponse.Street);

                var updatedRecord = testScope.GetDbTableContent <Address>().SingleOrDefault(x => x.Id == recordToUpdate.Id);
                Assert.IsNotNull(updatedRecord);
                Assert.AreEqual(recordToUpdate.Id, updatedRecord.Id);
                Assert.AreEqual(recordToUpdate.City, updatedRecord.City);
                Assert.AreEqual(recordToUpdate.Street, updatedRecord.Street);
            }
        }
        public async Task F3BadDateFormat()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                var client   = testScope.CreateClient();
                var response = await client.GetAsync($"/transportplans?dateTime={DateTime.Now}");

                Assert.AreEqual(response.StatusCode, System.Net.HttpStatusCode.BadRequest);
            }
        }
Пример #3
0
        public async Task F1PostNewWithInvalidContent()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                var client   = testScope.CreateClient();
                var response = await client.PostAsJsonAsync("/addresses", new Milestone());

                Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, response.StatusCode);
            }
        }
Пример #4
0
        public async Task F1PutDoesNotExist()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestAddresses);
                var client = testScope.CreateClient();

                var response = await client.PutAsJsonAsync("/addresses/1234567", new Address(47.31, 19.05, "HU", "BUDAPEST", "1111", "street1", "2") { Id = 1234567 });

                Assert.AreEqual(System.Net.HttpStatusCode.NotFound, response.StatusCode);
            }
        }
Пример #5
0
        public async Task F1DeleteDoesNotExist()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestAddresses);
                var client = testScope.CreateClient();

                var response = await client.DeleteAsync($"/addresses/{new Random().Next(100, 999999999)}");

                response.EnsureSuccessStatusCode();
            }
        }
Пример #6
0
        public async Task F1GetOneDoesNotExist()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestAddresses);
                var client = testScope.CreateClient();

                var response = await client.GetAsync($"/addresses/{new Random().Next(100, 999999999)}");

                Assert.AreEqual(System.Net.HttpStatusCode.NotFound, response.StatusCode);
            }
        }
Пример #7
0
        public async Task F1PostNewWithMissingProperties()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                var client   = testScope.CreateClient();
                var response = await client.PostAsJsonAsync("/addresses", new Address()
                {
                    City = "Budapest"
                });

                Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, response.StatusCode);
            }
        }
        public async Task F2SearchNoBodyTest()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestAddresses);
                var client = testScope.CreateClient();

                var content  = new StringContent("", Encoding.UTF8, "application/json");;
                var response = await client.PostAsync("/addresses/search", content);

                Assert.AreEqual(response.StatusCode, System.Net.HttpStatusCode.BadRequest);
            }
        }
Пример #9
0
        public async Task F1AddressesListAllWhenNone()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                var client   = testScope.CreateClient();
                var response = await client.GetAsync("/addresses");

                response.EnsureSuccessStatusCode();
                var actual = await response.Content.ReadAsAsync <Address[]>();

                Assert.IsNotNull(actual);
                Assert.AreEqual(0, actual.Length);
            }
        }
Пример #10
0
        public async Task F1DeleteOneWithSuccess()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestAddresses);
                var client = testScope.CreateClient();

                var recordToDelete = testScope.GetDbTableContent <Address>().Last();

                var response = await client.DeleteAsync($"/addresses/{recordToDelete.Id}");

                response.EnsureSuccessStatusCode();
                Assert.IsNull(testScope.GetDbTableContent <Address>().FirstOrDefault(x => x.Id == recordToDelete.Id));
            }
        }
Пример #11
0
        public async Task F1PutWithMissingProperties()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestAddresses);
                var client         = testScope.CreateClient();
                var recordToUpdate = testScope.GetDbTableContent <Address>().Last();

                var response = await client.PutAsJsonAsync($"/addresses/{recordToUpdate.Id}", new Address()
                {
                    City = "Budapest"
                });

                Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, response.StatusCode);
            }
        }
        public async Task F3GetAllTransportPlansTest()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestTransportPlans.ToArray());

                var client   = testScope.CreateClient();
                var response = await client.GetAsync("/transportplans?dateTime=2020-01-01T01-01-01");

                response.EnsureSuccessStatusCode();
                var actual = await response.Content.ReadAsAsync <TransportPlan[]>();

                Assert.IsNotNull(actual);
                CollectionAssert.AreEquivalent(TestTransportPlans, actual);
            }
        }
Пример #13
0
        public async Task F1AddressesListAll()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestAddresses);

                var client   = testScope.CreateClient();
                var response = await client.GetAsync("/addresses");

                response.EnsureSuccessStatusCode();
                var actual = await response.Content.ReadAsAsync <Address[]>();

                Assert.IsNotNull(actual);
                CollectionAssert.AreEquivalent(TestAddresses, actual);
            }
        }
Пример #14
0
        public async Task F1GetOneSuccess()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestAddresses);
                var client = testScope.CreateClient();

                foreach (var expected in testScope.GetDbTableContent <Address>())
                {
                    var response = await client.GetAsync($"/addresses/{expected.Id}");

                    response.EnsureSuccessStatusCode();
                    var actual = await response.Content.ReadAsAsync <Address>();

                    Assert.IsNotNull(actual);
                    Assert.AreEqual(expected, actual);
                }
            }
        }
        public async Task F2SearchWithSizeAndPageSortByStreetDescendingTest()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestAddresses);
                var searchAddress = new Address()
                {
                    Country = "HU"
                };

                var client   = testScope.CreateClient();
                var response = await client.PostAsJsonAsync("/addresses/search?size=4&page=1&sort=street,desc", searchAddress);

                response.EnsureSuccessStatusCode();
                var actual = await response.Content.ReadAsAsync <Address[]>();

                Assert.IsNotNull(actual);
                CollectionAssert.DoesNotContain(actual, TestAddresses[9]);
            }
        }
Пример #16
0
        public async Task F1PostNewWithSuccess()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                var toInsert = new Address(47.29, 19.04, "HU", "Budapest", "1111", "street1", "2");

                var client   = testScope.CreateClient();
                var response = await client.PostAsJsonAsync("/addresses", toInsert);

                response.EnsureSuccessStatusCode();
                var postResponse = await response.Content.ReadAsAsync <IdResponse>();

                Assert.IsNotNull(postResponse);
                var insertedRecord = testScope.GetDbTableContent <Address>().SingleOrDefault(x => x.Id == postResponse.Id);
                Assert.IsNotNull(insertedRecord);
                Assert.AreEqual(toInsert.GeoLatitude, insertedRecord.GeoLatitude);
                Assert.AreEqual(toInsert.City, insertedRecord.City);
                Assert.AreEqual(toInsert.Number, insertedRecord.Number);
            }
        }
        public async Task F2SearchSearchByUnsupportedPropertiesTest()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestAddresses);

                var searchAddress = new Address()
                {
                    GeoLongitude = 47.29, GeoLatitude = 19.04
                };

                var client   = testScope.CreateClient();
                var response = await client.PostAsJsonAsync("/addresses/search", searchAddress);

                response.EnsureSuccessStatusCode();
                var actual = await response.Content.ReadAsAsync <Address[]>();

                Assert.IsNotNull(actual);
                CollectionAssert.AreEquivalent(TestAddresses, actual);
            }
        }
        public async Task F2SearchWithSizeAndLastPageTest()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestAddresses);

                var searchAddress = new Address()
                {
                    Country = "hu"
                };
                var expected = new Address[] { TestAddresses[9], TestAddresses[10] };

                var client   = testScope.CreateClient();
                var response = await client.PostAsJsonAsync("/addresses/search?size=3&page=3", searchAddress);

                response.EnsureSuccessStatusCode();
                var actual = await response.Content.ReadAsAsync <Address[]>();

                Assert.IsNotNull(actual);
                CollectionAssert.AreEquivalent(expected, actual);
            }
        }
        public async Task F2SearchMultiCityTest()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestAddresses);

                var searchAddress = new Address()
                {
                    City = "Buda"
                };
                var expected = new[] { TestAddresses[0], TestAddresses[2] };

                var client   = testScope.CreateClient();
                var response = await client.PostAsJsonAsync("/addresses/search", searchAddress);

                response.EnsureSuccessStatusCode();
                var actual = await response.Content.ReadAsAsync <Address[]>();

                Assert.IsNotNull(actual);
                CollectionAssert.AreEquivalent(expected, actual);
            }
        }
        public async Task F2SearchHeaderTest()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestAddresses);

                var searchAddress = new Address()
                {
                    City = "Budapest"
                };
                var expected = new Address[] { TestAddresses[0], TestAddresses[1], TestAddresses[2], TestAddresses[3], TestAddresses[4] };

                var client   = testScope.CreateClient();
                var response = await client.PostAsJsonAsync("/addresses/search?size=5", searchAddress);

                response.EnsureSuccessStatusCode();
                var actual = await response.Content.ReadAsAsync <Address[]>();

                Assert.IsNotNull(actual);
                CollectionAssert.AreEquivalent(expected, actual);
                Assert.AreEqual(TestAddresses.Count(ta => ta.City == "Budapest").ToString(), response.Headers.GetValues("X-Total-Count").FirstOrDefault());
            }
        }