Example #1
0
        public async Task Delete500InternalServerError()
        {
            using var clientFactory = new TestFaultyClientFactory <BookStoreApi.Code.AppDataSeeder>();
            var exampleDTO = GetUpdateExampleDTO();
            var client     = await clientFactory.GetTestClientAsync((client) => AuthorizeMethods.AutorizeAsync(() => AppDataSeeder.AdminDto, client));

            var postResponse = await client.DeleteAsync($"/api/Books/{exampleDTO.Id}");

            Assert.AreEqual(System.Net.HttpStatusCode.InternalServerError, postResponse.StatusCode);
        }
Example #2
0
        public async Task Create201Created()
        {
            using var clientFactory = new TestInMemoryAuthentificatedDbServerClientFactory <Mocks.MockDataSeeder>();
            var exampleDTO = GetCreateExampleDTO();
            var content    = new StringContent(JsonConvert.SerializeObject(exampleDTO), Encoding.UTF8, MediaTypeNames.Application.Json);
            var client     = await clientFactory.GetTestClientAsync((client) => AuthorizeMethods.AutorizeAsync(() => Mocks.MockDataSeeder.AdminLogin, client));

            var postResponse = await client.PostAsync("api/Books", content);

            Assert.AreEqual(HttpStatusCode.Created, postResponse.StatusCode);
        }
Example #3
0
        public async Task Update500InternalServerError()
        {
            using var clientFactory = new TestFaultyClientFactory <BookStoreApi.Code.AppDataSeeder>();
            var exampleDTO = GetUpdateExampleDTO();
            var content    = new StringContent(JsonConvert.SerializeObject(exampleDTO), Encoding.UTF8, MediaTypeNames.Application.Json);
            var client     = await clientFactory.GetTestClientAsync((client) => AuthorizeMethods.AutorizeAsync(() => AppDataSeeder.AdminDto, client));

            var postResponse = await client.PutAsync($"api/Authors/{exampleDTO.Id}", content);

            Assert.AreEqual(HttpStatusCode.InternalServerError, postResponse.StatusCode);
        }
Example #4
0
        public async Task CreateAndTakeBackAuthor()
        {
            using var clientFactory = new TestInMemoryAuthentificatedDbServerClientFactory <Mocks.MockDataSeeder>();
            var exampleDTO = GetCreateExampleDTO();
            var content    = new StringContent(JsonConvert.SerializeObject(exampleDTO), Encoding.UTF8, MediaTypeNames.Application.Json);
            var client     = await clientFactory.GetTestClientAsync(async (client) =>
                                                                    await AuthorizeMethods.AutorizeAsync(() => Mocks.MockDataSeeder.AdminLogin, client));

            var postResponse = await client.PostAsync("api/Books", content);

            bool assertion = postResponse.IsSuccessStatusCode;

            Assert.IsTrue(assertion, "Save failed");
            var createdBook          = JsonConvert.DeserializeObject <BookDTO>(await postResponse.Content.ReadAsStringAsync());
            var authorFromDbResponce = await client.GetAsync($"api/Books/{createdBook.Id}");

            assertion &= authorFromDbResponce.IsSuccessStatusCode;
            Assert.IsTrue(assertion, "Failed to get author back");
            var authorFromDb = JsonConvert.DeserializeObject <BookDTO>(await authorFromDbResponce.Content.ReadAsStringAsync());

            Assert.AreEqual(exampleDTO.Title, authorFromDb.Title);
        }
Example #5
0
        public async Task Create400BadRequest()
        {
            using var clientFactory = new TestInMemoryAuthentificatedDbServerClientFactory <Mocks.MockDataSeeder>();
            var exampleDTO = GetCreateExampleDTO();

            exampleDTO.Title = default;
            var content = new StringContent(JsonConvert.SerializeObject(exampleDTO), Encoding.UTF8, MediaTypeNames.Application.Json);
            var client  = await clientFactory.GetTestClientAsync(async (client) => await AuthorizeMethods.AutorizeAsync(() => new UserLoginDTO()
            {
                Login    = "******",
                Password = "******"
            }, client));

            var postResponse = await client.PostAsync("api/Books", content);

            Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, postResponse.StatusCode);
        }