Exemple #1
0
        public async Task Should_Update_Account_Roles_When_Requesting_By_Administrator_Client()
        {
            var factory = new AdministratorWebApplicationFactory("AdministratorShouldUpdateAccountRolesIntegrationTest");
            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 roleToUpdate = await InsertRoleEntityToUpdateAsync(factory.DbContext);

            var updateAccountRolesRequest = new UpdateAccountRolesRequest
            {
                Roles = new List <Guid> {
                    accountRoleEntity.Id, roleToUpdate.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.NoContent);
            var updatedAccountRoleEntities = await factory.DbContext.AccountRoles.Where(x => x.AccountId == accountEntity.Id)
                                             .ToListAsync();

            var updatedAccountRoleIds = updatedAccountRoleEntities.Select(x => x.RoleId);

            updatedAccountRoleIds.Should().Contain(roleToUpdate.Id);
        }
Exemple #2
0
        public async Task Should_Assign_Password_When_Requesting_By_Administrator_Client()
        {
            var factory = new AdministratorWebApplicationFactory("AdministratorShouldSetPasswordIntegrationTest");
            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 assignPasswordRequestString = JsonConvert.SerializeObject(assignPasswordRequest);
            var requestContent = new StringContent(assignPasswordRequestString, 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();
        }
Exemple #3
0
        public async Task Should_Change_Password_When_Requesting_By_Administrator_Client()
        {
            var factory = new AdministratorWebApplicationFactory("AdministratorShouldChangePasswordIntegrationTest");
            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);
        }
Exemple #4
0
        public async Task Should_Delete_Account_When_Requesting_By_Administrator_Client()
        {
            var factory = new AdministratorWebApplicationFactory("AdministratorShouldDeleteAccountIntegrationTest");
            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);
        }