Beispiel #1
0
        public async Task CanCreateCategory()
        {
            var category = new CategoryDto()
            {
                Title = "New Title", Description = "New Description"
            };
            var response = await client.PostAsync("/api/categories", HttpClientUtils.CreateContent(category));

            var createdCategory = await response.Content.ReadFromJsonAsync <CategoryDto>();

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            Assert.AreEqual("New Title", createdCategory.Title);
            Assert.AreEqual("New Description", createdCategory.Description);
        }
Beispiel #2
0
        public async Task CanGetToken()
        {
            var loginRequest = new Login.Request()
            {
                Email = UserEmail, Password = Password
            };
            var response = await client.PostAsync("/api/auth/login", HttpClientUtils.CreateContent(loginRequest));

            var data = await response.Content.ReadFromJsonAsync <AuthData>();

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotNull(data);
            Assert.IsTrue(!string.IsNullOrEmpty(data.Token));
        }
Beispiel #3
0
        public async Task CanRegister()
        {
            var registerRequest = new Register.Request()
            {
                Email = "*****@*****.**", Password = Password, ConfirmPassword = Password
            };
            var response = await client.PostAsync("/api/auth/register", HttpClientUtils.CreateContent(registerRequest));

            var data = await response.Content.ReadFromJsonAsync <AuthData>();

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotNull(data);
            Assert.IsTrue(!string.IsNullOrEmpty(data.Token));
        }
Beispiel #4
0
        public async Task CanUpdateCategory()
        {
            var count    = categories.Count;
            var id       = categories[count - 1].Id ?? null;
            var category = new CategoryDto()
            {
                Title = "Updated Title", Description = "Updated Description"
            };

            var response = await client.PutAsync(@$ "/api/categories/{id}", HttpClientUtils.CreateContent(category));

            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);

            response = await client.GetAsync(@$ "/api/categories/{id}");

            var updatedCategory = await response.Content.ReadFromJsonAsync <CategoryDto>();

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual("Updated Title", updatedCategory.Title);
            Assert.AreEqual("Updated Description", updatedCategory.Description);
        }
Beispiel #5
0
        public async Task Initialize()
        {
            factory = new CustomWebApplicationFactory <Startup>();
            client  = factory.CreateClient(new WebApplicationFactoryClientOptions
            {
                BaseAddress = new Uri(BaseURL)
            });

            var loginRequest = new Login.Request()
            {
                Email = UserEmail, Password = Password
            };
            var response = await client.PostAsync("/api/auth/login", HttpClientUtils.CreateContent(loginRequest));

            var data = await response.Content.ReadFromJsonAsync <AuthData>();

            clientUser = factory.CreateClient(new WebApplicationFactoryClientOptions
            {
                BaseAddress = new Uri(BaseURL)
            });

            clientUser.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", data.Token);
        }