Exemple #1
0
        public async Task ThrowExceptionWhenApiUrlInvalid()
        {
            var sut = new PetsRepository();

            await Assert.ThrowsAsync <ArgumentNullException>(() => sut.GetPetOwnerAsync(null, null));

            await Assert.ThrowsAsync <ArgumentNullException>(() => sut.GetPetOwnerAsync(null, "people.json"));

            await Assert.ThrowsAsync <UriFormatException>(() => sut.GetPetOwnerAsync(string.Empty, "people.json"));
        }
        public async Task ThrowExceptionWhenApiUrlInvalid()
        {
            var client = new HttpClient()
            {
                BaseAddress = new Uri("http://agl-developer-test.azurewebsites.net/")
            };

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var sut = new PetsRepository(client);
            //sut.RequestUri = "people.json";
            var petOwnersViewModel = await sut.GetPetOwnerAsync();

            Assert.True(petOwnersViewModel.Exception == null);
            Assert.True(petOwnersViewModel.StatusCode != HttpStatusCode.OK);
        }
        public async Task ValidatePetsFromOwnersInternalServerError()
        {
            var fakeHttpMessageHandler = new FakeHttpMessageHandler(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.InternalServerError,
                Content    = new StringContent(string.Empty)
            });

            var client = new HttpClient(fakeHttpMessageHandler)
            {
                BaseAddress = new Uri("http://agl-developer-test.azurewebsites.net/")
            };

            var sut = new PetsRepository(client);
            var petOwnersViewModel = await sut.GetPetOwnerAsync();

            Assert.True(petOwnersViewModel.Exception == null);
            Assert.True(petOwnersViewModel.StatusCode == HttpStatusCode.InternalServerError);
            Assert.True(petOwnersViewModel.PetOwners != null && petOwnersViewModel.PetOwners.Count == 0);
        }