public UserControllerTests(TestApplicationFactory <Startup> factory)
 {
     _factory = factory;
     _client  = factory.CreateClient(new WebApplicationFactoryClientOptions
     {
         AllowAutoRedirect = false,
     });
 }
Example #2
0
        private async Task <HttpResponseMessage> ChangeLogLevel(string levelToSet,
                                                                TestApplicationFactory <StartupForIntegration> fixture)
        {
            var responseForLevelChange =
                await fixture.CreateClient().PostAsync("diagnostics/logs", new JsonContent(new
            {
                LoggingLevel = levelToSet
            }));

            return(responseForLevelChange);
        }
Example #3
0
        public async Task NavigateWithEmptyUrlThrowsException()
        {
            var factory = new TestApplicationFactory();
            var client  = factory.CreateClient();

            var navigator = new Navigator(client);

            await Assert.ThrowsAsync <ArgumentNullException>(async() => await navigator.NavigateToAsync <SamplePageObject>(""));

            await Assert.ThrowsAsync <ArgumentNullException>(async() => await navigator.NavigateToAsync <SamplePageObject>(null));
        }
Example #4
0
        public async Task CanNavigateToPages()
        {
            var factory = new TestApplicationFactory();
            var client  = factory.CreateClient();

            var navigator = new Navigator(client);

            var(response, pageObject) = await navigator.NavigateToAsync <SamplePageObject>("/");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
Example #5
0
        public async Task NavigateToNonExistingPageReturnsOnlyResponse()
        {
            var factory = new TestApplicationFactory();
            var client  = factory.CreateClient();

            var navigator = new Navigator(client);

            var(response, page) = await navigator.NavigateToAsync <SamplePageObject>("/SomeSillyUrl");

            Assert.NotNull(response);
            Assert.Null(page);
        }
Example #6
0
        public async Task CanSubmitUsingFormActionAttributeOnSubmit()
        {
            var factory   = new TestApplicationFactory();
            var client    = factory.CreateClient();
            var navigator = new Navigator(client);

            var(_, page) = await navigator.NavigateToAsync <SamplePageObject>("/");

            var response = await page.SubmitWithOtherFormAction();

            Assert.Equal("Received on other: ", await response.Content.ReadAsStringAsync());
        }
Example #7
0
        public async Task CantSubmitWithoutSpecifyingSubmitButton()
        {
            var factory   = new TestApplicationFactory();
            var client    = factory.CreateClient();
            var navigator = new Navigator(client);

            var(_, page) = await navigator.NavigateToAsync <SamplePageObject>("/");

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await page.SubmitWithoutSubmitButton();
            });
        }
        public async Task UpdateUser_WithValidPassword_ReturnsOK()
        {
            using (var client = _factory.CreateClient())
            {
                // Arrange
                CreateUser user = new CreateUser()
                {
                    FirstName = "Test",
                    LastName  = "User",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };
                UpdateUserInfo updateUserInfo = new UpdateUserInfo();

                var requestContent = new StringContent(
                    JsonConvert.SerializeObject(user),
                    Encoding.UTF8, "application/json");

                // Act
                HttpResponseMessage createUserResponse = await client.PutAsync("api/user", requestContent);

                string createdUserSerialized = await createUserResponse.Content.ReadAsStringAsync();

                User createdUser = JsonConvert.DeserializeObject <User>(createdUserSerialized);

                updateUserInfo.FirstName       = "New User Name";
                updateUserInfo.LastName        = "New User Last Name";
                updateUserInfo.CurrentPassword = "******";
                updateUserInfo.NewPassword     = "******";
                updateUserInfo.UserId          = createdUser.Id;


                var updateUserContent = new StringContent(
                    JsonConvert.SerializeObject(updateUserInfo),
                    Encoding.UTF8, "application/json");

                HttpResponseMessage updateUserResponse = await client.PostAsync("api/user", updateUserContent);

                // Assert
                updateUserResponse.StatusCode.Should().Be(HttpStatusCode.OK);
            }
        }