示例#1
0
        public async Task Should_Return_Forbidden_Status_Code_When_Requesting_By_User_Client()
        {
            var factory = new UserWebApplicationFactory("UserShouldNotUpdateAccountRolesIntegrationTest");
            var client  = factory.WithWebHostBuilder(builder => builder.ConfigureWebHostBuilderForIntegrationTest())
                          .CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });
            var accountRoleEntity = await InsertUserRoleEntityIfNotExistsAsync(factory.DbContext);

            var accountEntity = await InsertAccountEntityAsync(factory.DbContext, accountRoleEntity.Id);

            var updateAccountRolesRequest = new UpdateAccountRolesRequest
            {
                Roles = new List <Guid> {
                    accountRoleEntity.Id
                }
            };
            var updateAccountRolesRequestString = JsonConvert.SerializeObject(updateAccountRolesRequest);
            var requestContent = new StringContent(updateAccountRolesRequestString, Encoding.UTF8, "application/json");

            client.DefaultRequestHeaders.Add("api-version", "1");

            var response = await client.PutAsync($"api/accounts/{accountEntity.Id}/roles", requestContent);

            response.StatusCode.Should().BeEquivalentTo(HttpStatusCode.Forbidden);
        }
示例#2
0
        public async Task Should_Assign_Password_When_Requesting_By_User_Client()
        {
            var factory = new UserWebApplicationFactory("UserShouldSetPasswordIntegrationTest");
            var client  = factory.WithWebHostBuilder(builder => builder.ConfigureWebHostBuilderForIntegrationTest())
                          .CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });
            var accountEntity = await InsertAccountEntityAsync(factory.DbContext);

            var assignPasswordRequest = new AssignPasswordRequest
            {
                Password        = "******",
                ConfirmPassword = "******"
            };
            var setPasswordRequestString = JsonConvert.SerializeObject(assignPasswordRequest);
            var requestContent           = new StringContent(setPasswordRequestString, Encoding.UTF8, "application/json");

            client.DefaultRequestHeaders.Add("api-version", "1");

            var response = await client.PostAsync($"api/accounts/{accountEntity.Id}/passwords/assignments", requestContent);

            await factory.DbContext.Entry(accountEntity).ReloadAsync();

            response.StatusCode.Should().BeEquivalentTo(HttpStatusCode.NoContent);
            accountEntity.PasswordHash.Should().NotBeNullOrEmpty();
        }
示例#3
0
        public async Task Should_Change_Password_When_Requesting_By_User_Client()
        {
            var factory = new UserWebApplicationFactory("UserShouldChangePasswordIntegrationTest");
            var client  = factory.WithWebHostBuilder(builder => builder.ConfigureWebHostBuilderForIntegrationTest())
                          .CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });
            const string oldPassword   = "******";
            var          accountEntity = await InsertAccountEntityAsync(factory.DbContext, oldPassword);

            var oldPasswordHash       = accountEntity.PasswordHash;
            var changePasswordRequest = new ChangePasswordRequest
            {
                OldPassword        = oldPassword,
                NewPassword        = "******",
                ConfirmNewPassword = "******"
            };
            var changePasswordRequestString = JsonConvert.SerializeObject(changePasswordRequest);
            var requestContent = new StringContent(changePasswordRequestString, Encoding.UTF8, "application/json");

            client.DefaultRequestHeaders.Add("api-version", "1");

            var response = await client.PostAsync($"api/accounts/{accountEntity.Id}/passwords/changes", requestContent);

            response.StatusCode.Should().BeEquivalentTo(HttpStatusCode.NoContent);
            await factory.DbContext.Entry(accountEntity).ReloadAsync();

            accountEntity.PasswordHash.Should().NotBe(oldPasswordHash);
        }
示例#4
0
        public async Task Should_Delete_Account_When_Requesting_By_User_Client()
        {
            var factory = new UserWebApplicationFactory("UserShouldDeleteAccountIntegrationTest");
            var client  = factory.WithWebHostBuilder(builder => builder.ConfigureWebHostBuilderForIntegrationTest())
                          .CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });
            var accountEntity = await InsertAccountEntityAsync(factory.DbContext);

            client.DefaultRequestHeaders.Add("api-version", "1");

            var response = await client.DeleteAsync($"api/accounts/{accountEntity.Id}");

            response.StatusCode.Should().BeEquivalentTo(HttpStatusCode.Accepted);
        }
示例#5
0
        public async Task Should_Return_Account_When_Requesting_By_User_Client()
        {
            var factory = new UserWebApplicationFactory("UserShouldGetAccountIntegrationTest");
            var client  = factory.WithWebHostBuilder(builder => builder.ConfigureWebHostBuilderForIntegrationTest())
                          .CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });
            var accountEntity = await InsertAccountEntityAsync(factory.DbContext);

            var expectedResponse = PrepareExpectedResponse(accountEntity);

            client.DefaultRequestHeaders.Add("api-version", "1");

            var response = await client.GetAsync($"api/accounts/{accountEntity.Id}");

            var responseContentString = await response.Content.ReadAsStringAsync();

            response.StatusCode.Should().BeEquivalentTo(HttpStatusCode.OK);
            responseContentString.Should().BeEquivalentTo(expectedResponse);
        }