Beispiel #1
0
        private async Task <HttpClient> CreateClient()
        {
            var client   = _factory.CreateClient();
            var email    = AccountOperations.GenerateUserEmail();
            var password = "******";

            var token = await client.GetUserTokenAsync(email, password);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            return(client);
        }
Beispiel #2
0
        public async Task When_RegisterWithValidParameters_Then_SuccessResponse()
        {
            // Arrange
            var client   = _factory.CreateClient();
            var email    = AccountOperations.GenerateUserEmail();
            var password = "******";

            // Act
            var response = await client.RegisterUserAsync(email, password);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.NoContent);
        }
Beispiel #3
0
        public async Task When_RegisterWithSmallPassword_Then_BadRequestResponse()
        {
            // Arrange
            var client   = _factory.CreateClient();
            var email    = AccountOperations.GenerateUserEmail();
            var password = "******";

            // Act
            var response = await client.RegisterUserAsync(email, password);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);

            var error = await response.AsTypeAsync <ErrorResponse>();

            error.Errors.Count.Should().Be(1);
            error.Errors.First().Should().Be("Passwords must be at least 6 characters.");
        }
Beispiel #4
0
        public async Task When_LoginWithValidParameters_Then_SuccessResponse()
        {
            // Arrange
            var client   = _factory.CreateClient();
            var email    = AccountOperations.GenerateUserEmail();
            var password = "******";

            await client.RegisterUserAsync(email, password);

            // Act
            var response = await client.LoginUserAsync(email, password);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);

            var loginResponse = await response.AsTypeAsync <LoginResponse>();

            loginResponse.Token.Should().NotBeNullOrEmpty();
            loginResponse.Expires.Should().BeAfter(DateTime.UtcNow);
        }