Exemplo n.º 1
0
        public async Task AddMovie_ForLimitedUser_RedirectsToAccessDeniedPage()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("Title", "New Movie Without Info"),
                new KeyValuePair <string, string>("MovieUri", "https://www.kinopoisk.ru/film/13/"),
                new KeyValuePair <string, string>("PosterUri", String.Empty),
                new KeyValuePair <string, string>("RatingValue", String.Empty),
                new KeyValuePair <string, string>("RatingVotesNumber", String.Empty),
                new KeyValuePair <string, string>("Duration", String.Empty),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.LimitedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/MoviesToSee/AddMovie"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("https://localhost:5001/Identity/Account/AccessDenied?ReturnUrl=%2FMoviesToSee%2FAddMovie"));
        }
Exemplo n.º 2
0
        public async Task UpdateUser_ForLimitedUser_RedirectsToAccessDeniedPage()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("Roles[0].RoleName", "Administrator"),
                new KeyValuePair <string, string>("Roles[1].Assigned", "true"),
                new KeyValuePair <string, string>("Roles[1].RoleName", "Privileged User"),
                new KeyValuePair <string, string>("Roles[2].RoleName", "Limited User"),
                new KeyValuePair <string, string>("UserId", "5eb7eb9f1fdada19f4eb59b1"),
                new KeyValuePair <string, string>("Roles[0].Assigned", "false"),
                new KeyValuePair <string, string>("Roles[1].Assigned", "false"),
                new KeyValuePair <string, string>("Roles[2].Assigned", "false"),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.LimitedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/Users/UpdateUser"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("https://localhost:5001/Identity/Account/AccessDenied?ReturnUrl=%2FUsers%2FUpdateUser"));
        }
        public async Task MoveToMoviesToSee_ForPrivilegedUser_MovesMovieToMoviesToSee()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("id", "5eac4f407a15596e90c09d7b"),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.PrivilegedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/MoviesToGet/MoveToMoviesToSee/5eac4f407a15596e90c09d7b"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("/MoviesToGet", UriKind.Relative));

            using var indexResponse = await client.GetAsync(new Uri ("https://localhost:5001/MoviesToGet"), CancellationToken.None);

            await ResponseAssert.VerifyPageLoaded(indexResponse);

            // The fact, that movie was actually added to movies to see, is checked by ITs for services layer.
        }
        public async Task AddMovie_ForDuplicatedMovie_ReturnsCorrectPage()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("Title", "New Movie Without Info"),
                new KeyValuePair <string, string>("Year", String.Empty),
                new KeyValuePair <string, string>("MovieUri", "https://www.kinopoisk.ru/film/777/"),
                new KeyValuePair <string, string>("PosterUri", String.Empty),
                new KeyValuePair <string, string>("RatingValue", String.Empty),
                new KeyValuePair <string, string>("RatingVotesNumber", String.Empty),
                new KeyValuePair <string, string>("Duration", String.Empty),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.PrivilegedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/MoviesToGet/AddMovie"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("/MoviesToGet", UriKind.Relative));

            using var indexResponse = await client.GetAsync(new Uri ("https://localhost:5001/MoviesToGet"), CancellationToken.None);

            await ResponseAssert.VerifyPageLoaded(indexResponse);
        }
Exemplo n.º 5
0
        public async Task PostRegisterUser_ForPrivilegedUser_RegistersUserCorrectly()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("Email", "*****@*****.**"),
                new KeyValuePair <string, string>("Password", "Qwerty123!"),
                new KeyValuePair <string, string>("ConfirmPassword", "Qwerty123!"),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.PrivilegedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/Users/RegisterUser"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("/Users", UriKind.Relative));

            using var indexResponse = await client.GetAsync(new Uri ("https://localhost:5001/Users"), CancellationToken.None);

            await ResponseAssert.VerifyPageLoaded(indexResponse);
        }
        public async Task UpdateRole_ForPrivilegedUser_UpdatesRoleCorrectly()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                // Here we delete permission "Permissions.MoviesToGet.Add" and add permission "Permissions.MoviesToSee.Add".
                new KeyValuePair <string, string>("Permissions[0].PermissionName", "Permissions.MoviesToGet.Add"),
                new KeyValuePair <string, string>("Permissions[1].Assigned", "true"),
                new KeyValuePair <string, string>("Permissions[1].PermissionName", "Permissions.MoviesToGet.Read"),
                new KeyValuePair <string, string>("Permissions[2].PermissionName", "Permissions.MoviesToGet.MoveToMoviesToSee"),
                new KeyValuePair <string, string>("Permissions[3].PermissionName", "Permissions.MoviesToGet.Delete"),
                new KeyValuePair <string, string>("Permissions[4].Assigned", "true"),
                new KeyValuePair <string, string>("Permissions[4].PermissionName", "Permissions.MoviesToSee.Add"),
                new KeyValuePair <string, string>("Permissions[5].Assigned", "true"),
                new KeyValuePair <string, string>("Permissions[5].PermissionName", "Permissions.MoviesToSee.Read"),
                new KeyValuePair <string, string>("Permissions[6].PermissionName", "Permissions.MoviesToSee.MarkAsSeen"),
                new KeyValuePair <string, string>("Permissions[7].PermissionName", "Permissions.MoviesToSee.Delete"),
                new KeyValuePair <string, string>("RoleId", "5eb995ef4083c272a80ca308"),
                new KeyValuePair <string, string>("Permissions[0].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[1].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[2].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[3].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[4].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[5].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[6].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[7].Assigned", "false"),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.PrivilegedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/Roles/UpdateRole"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("/Roles", UriKind.Relative));

            using var indexResponse = await client.GetAsync(new Uri ("https://localhost:5001/Roles"), CancellationToken.None);

            await ResponseAssert.VerifyPageLoaded(indexResponse);

            var expectedPermissions = new[]
            {
                "Permissions.MoviesToGet.Read",
                "Permissions.MoviesToSee.Add",
                "Permissions.MoviesToSee.Read",
            };

            using var scopeServiceProvider = webApplicationFactory.Services.CreateScope();
            var roleService    = scopeServiceProvider.ServiceProvider.GetRequiredService <IRoleService>();
            var newPermissions = (await roleService.GetRolePermissions("5eb995ef4083c272a80ca308", CancellationToken.None)).ToList();

            newPermissions.Should().BeEquivalentTo(expectedPermissions);
        }
Exemplo n.º 7
0
        public async Task Get_ForIdentityAccountRegisterAndUnauthenticatedUser_RedirectsToLoginPage()
        {
            // Arrange

            await using var webApplicationFactory = new CustomWebApplicationFactory(authenticatedUser: null);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.GetAsync(new Uri ("https://localhost:5001/Identity/Account/Register"), CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("https://localhost:5001/Identity/Account/Login?ReturnUrl=%2FIdentity%2FAccount%2FRegister"));
        }
Exemplo n.º 8
0
        public async Task Index_ForLimitedUser_RedirectsToPageWithMoviesToSee()
        {
            // Arrange

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.LimitedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.GetAsync(new Uri ("https://localhost:5001/"), CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("/MoviesToSee", UriKind.Relative));
        }
        public async Task ConfirmMovieDeletion_ForLimitedUser_RedirectsToAccessDeniedPage()
        {
            // Arrange

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.LimitedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.GetAsync(new Uri ("https://localhost:5001/MoviesToGet/ConfirmMovieDeletion/5eac4f407a15596e90c09d7b"), CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("https://localhost:5001/Identity/Account/AccessDenied?ReturnUrl=%2FMoviesToGet%2FConfirmMovieDeletion%2F5eac4f407a15596e90c09d7b"));
        }
        public async Task EditRole_ForLimitedUser_RedirectsToAccessDeniedPage()
        {
            // Arrange

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.LimitedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.GetAsync(new Uri ("https://localhost:5001/Roles/EditRole/5eb995ef4083c272a80ca308"), CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("https://localhost:5001/Identity/Account/AccessDenied?ReturnUrl=%2FRoles%2FEditRole%2F5eb995ef4083c272a80ca308"));
        }
Exemplo n.º 11
0
        public async Task GetRegisterUser_ForLimitedUser_RedirectsToAccessDeniedPage()
        {
            // Arrange

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.LimitedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.GetAsync(new Uri ("https://localhost:5001/Users/RegisterUser"), CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("https://localhost:5001/Identity/Account/AccessDenied?ReturnUrl=%2FUsers%2FRegisterUser"));
        }
Exemplo n.º 12
0
        public async Task ConfirmMarkingAsSeen_ForLimitedUser_RedirectsToAccessDeniedPage()
        {
            // Arrange

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.LimitedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.GetAsync(new Uri ("https://localhost:5001/MoviesToSee/ConfirmMarkingAsSeen/5ead62d14be68246b45bba82"), CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("https://localhost:5001/Identity/Account/AccessDenied?ReturnUrl=%2FMoviesToSee%2FConfirmMarkingAsSeen%2F5ead62d14be68246b45bba82"));
        }
        public async Task AddMovie_ForLimitedUser_AddsMovieCorrectly()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("Title", "Темный рыцарь"),
                new KeyValuePair <string, string>("Year", "2008"),
                new KeyValuePair <string, string>("MovieUri", "https://www.kinopoisk.ru/film/111543/"),
                new KeyValuePair <string, string>("PosterUri", "https://st.kp.yandex.net/images/film_iphone/iphone360_111543.jpg"),
                new KeyValuePair <string, string>("Directors[0]", "Кристофер Нолан"),
                new KeyValuePair <string, string>("Cast[0]", "Кристиан Бэйл"),
                new KeyValuePair <string, string>("Cast[1]", "Хит Леджер"),
                new KeyValuePair <string, string>("Cast[2]", "Аарон Экхарт"),
                new KeyValuePair <string, string>("Cast[3]", "Мэгги Джилленхол"),
                new KeyValuePair <string, string>("Cast[4]", "Гари Олдман"),
                new KeyValuePair <string, string>("Cast[5]", "Майкл Кейн"),
                new KeyValuePair <string, string>("Cast[6]", "Морган Фриман"),
                new KeyValuePair <string, string>("Cast[7]", "Чинь Хань"),
                new KeyValuePair <string, string>("Cast[8]", "Нестор Карбонелл"),
                new KeyValuePair <string, string>("Cast[9]", "Эрик Робертс"),
                new KeyValuePair <string, string>("RatingValue", "8.499"),
                new KeyValuePair <string, string>("RatingVotesNumber", "467272"),
                new KeyValuePair <string, string>("Duration", "02:32:00"),
                new KeyValuePair <string, string>("Genres[0]", "фантастика"),
                new KeyValuePair <string, string>("Genres[1]", "боевик"),
                new KeyValuePair <string, string>("Genres[2]", "триллер"),
                new KeyValuePair <string, string>("Genres[3]", "криминал"),
                new KeyValuePair <string, string>("Genres[4]", "драма"),
                new KeyValuePair <string, string>("SummaryParagraphs[0]", "Бэтмен поднимает ставки в войне с криминалом."),
                new KeyValuePair <string, string>("SummaryParagraphs[1]", "С помощью лейтенанта Джима Гордона и прокурора Харви Дента он намерен очистить улицы Готэма от преступности."),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.LimitedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/MoviesToGet/AddMovie"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("/MoviesToGet", UriKind.Relative));

            using var indexResponse = await client.GetAsync(new Uri ("https://localhost:5001/MoviesToGet"), CancellationToken.None);

            await ResponseAssert.VerifyPageLoaded(indexResponse);
        }
Exemplo n.º 14
0
        public async Task UpdateUser_ForPrivilegedUser_UpdatesUserCorrectly()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                // Here we delete role "Limited User" and add role "Privileged User".
                new KeyValuePair <string, string>("Roles[0].RoleName", "Administrator"),
                new KeyValuePair <string, string>("Roles[1].Assigned", "true"),
                new KeyValuePair <string, string>("Roles[1].RoleName", "Privileged User"),
                new KeyValuePair <string, string>("Roles[2].RoleName", "Limited User"),
                new KeyValuePair <string, string>("UserId", "5eb7eb9f1fdada19f4eb59b1"),
                new KeyValuePair <string, string>("Roles[0].Assigned", "false"),
                new KeyValuePair <string, string>("Roles[1].Assigned", "false"),
                new KeyValuePair <string, string>("Roles[2].Assigned", "false"),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.PrivilegedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/Users/UpdateUser"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("/Users", UriKind.Relative));

            using var indexResponse = await client.GetAsync(new Uri ("https://localhost:5001/Users"), CancellationToken.None);

            await ResponseAssert.VerifyPageLoaded(indexResponse);

            var expectedRoles = new[]
            {
                "Privileged User",
            };

            using var scopeServiceProvider = webApplicationFactory.Services.CreateScope();
            var userService  = scopeServiceProvider.ServiceProvider.GetRequiredService <IUserService>();
            var newUserRoles = await userService.GetUserRoles("5eb7eb9f1fdada19f4eb59b1", CancellationToken.None);

            newUserRoles.Select(r => r.RoleName).Should().BeEquivalentTo(expectedRoles, x => x.WithStrictOrdering());
        }
        public async Task PostCreateRole_ForPrivilegedUser_CreatesRoleCorrectly()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("Name", "Some New Role"),
                new KeyValuePair <string, string>("Permissions[0].Assigned", "true"),
                new KeyValuePair <string, string>("Permissions[0].PermissionName", "Permissions.MoviesToGet.Add"),
                new KeyValuePair <string, string>("Permissions[1].Assigned", "true"),
                new KeyValuePair <string, string>("Permissions[1].PermissionName", "Permissions.MoviesToGet.Read"),
                new KeyValuePair <string, string>("Permissions[2].PermissionName", "Permissions.MoviesToGet.MoveToMoviesToSee"),
                new KeyValuePair <string, string>("Permissions[3].PermissionName", "Permissions.MoviesToGet.Delete"),
                new KeyValuePair <string, string>("Permissions[4].PermissionName", "Permissions.MoviesToSee.Add"),
                new KeyValuePair <string, string>("Permissions[5].Assigned", "true"),
                new KeyValuePair <string, string>("Permissions[5].PermissionName", "Permissions.MoviesToSee.Read"),
                new KeyValuePair <string, string>("Permissions[6].PermissionName", "Permissions.MoviesToSee.MarkAsSeen"),
                new KeyValuePair <string, string>("Permissions[7].PermissionName", "Permissions.MoviesToSee.Delete"),
                new KeyValuePair <string, string>("Permissions[0].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[1].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[2].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[3].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[4].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[5].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[6].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[7].Assigned", "false"),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.PrivilegedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/Roles/CreateRole"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("/Roles", UriKind.Relative));

            using var indexResponse = await client.GetAsync(new Uri ("https://localhost:5001/Roles"), CancellationToken.None);

            await ResponseAssert.VerifyPageLoaded(indexResponse);
        }
Exemplo n.º 16
0
        public async Task ConfirmMovieAdding_ForLimitedUser_RedirectsToAccessDeniedPage()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("NewMovieToSee.MovieUri", "https://www.kinopoisk.ru/film/111543/"),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.LimitedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/MoviesToSee/ConfirmMovieAdding"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("https://localhost:5001/Identity/Account/AccessDenied?ReturnUrl=%2FMoviesToSee%2FConfirmMovieAdding"));
        }
Exemplo n.º 17
0
        public async Task MoveToMoviesToSee_ForLimitedUser_RedirectsToAccessDeniedPage()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("id", "5ead62d14be68246b45bba82"),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.LimitedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/MoviesToSee/MarkMovieAsSeen/5ead62d14be68246b45bba82"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("https://localhost:5001/Identity/Account/AccessDenied?ReturnUrl=%2FMoviesToSee%2FMarkMovieAsSeen%2F5ead62d14be68246b45bba82"));
        }
        public async Task DeleteMovie_ForLimitedUser_RedirectsToAccessDeniedPage()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("id", "5eac4f407a15596e90c09d7b"),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.LimitedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/MoviesToGet/DeleteMovie"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("https://localhost:5001/Identity/Account/AccessDenied?ReturnUrl=%2FMoviesToGet%2FDeleteMovie"));
        }
Exemplo n.º 19
0
        public async Task PostRegisterUser_ForLimitedUser_RedirectsToAccessDeniedPage()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("Email", "*****@*****.**"),
                new KeyValuePair <string, string>("Password", "Qwerty123!"),
                new KeyValuePair <string, string>("ConfirmPassword", "Qwerty123!"),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.LimitedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/Users/RegisterUser"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("https://localhost:5001/Identity/Account/AccessDenied?ReturnUrl=%2FUsers%2FRegisterUser"));
        }
        public async Task UpdateRole_ForLimitedUser_RedirectsToAccessDeniedPage()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("Permissions[0].PermissionName", "Permissions.MoviesToGet.Add"),
                new KeyValuePair <string, string>("Permissions[1].Assigned", "true"),
                new KeyValuePair <string, string>("Permissions[1].PermissionName", "Permissions.MoviesToGet.Read"),
                new KeyValuePair <string, string>("Permissions[2].PermissionName", "Permissions.MoviesToGet.MoveToMoviesToSee"),
                new KeyValuePair <string, string>("Permissions[3].PermissionName", "Permissions.MoviesToGet.Delete"),
                new KeyValuePair <string, string>("Permissions[4].Assigned", "true"),
                new KeyValuePair <string, string>("Permissions[4].PermissionName", "Permissions.MoviesToSee.Add"),
                new KeyValuePair <string, string>("Permissions[5].Assigned", "true"),
                new KeyValuePair <string, string>("Permissions[5].PermissionName", "Permissions.MoviesToSee.Read"),
                new KeyValuePair <string, string>("Permissions[6].PermissionName", "Permissions.MoviesToSee.MarkAsSeen"),
                new KeyValuePair <string, string>("Permissions[7].PermissionName", "Permissions.MoviesToSee.Delete"),
                new KeyValuePair <string, string>("RoleId", "5eb995ef4083c272a80ca308"),
                new KeyValuePair <string, string>("Permissions[0].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[1].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[2].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[3].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[4].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[5].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[6].Assigned", "false"),
                new KeyValuePair <string, string>("Permissions[7].Assigned", "false"),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.LimitedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/Roles/UpdateRole"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("https://localhost:5001/Identity/Account/AccessDenied?ReturnUrl=%2FRoles%2FUpdateRole"));
        }
Exemplo n.º 21
0
        public async Task MarkMovieAsSeen_ForPrivilegedUser_DeletesMovie()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("id", "5ead62d14be68246b45bba82"),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.PrivilegedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/MoviesToSee/MarkMovieAsSeen/5ead62d14be68246b45bba82"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("/MoviesToSee", UriKind.Relative));

            using var indexResponse = await client.GetAsync(new Uri ("https://localhost:5001/MoviesToSee"), CancellationToken.None);

            await ResponseAssert.VerifyPageLoaded(indexResponse);
        }
Exemplo n.º 22
0
        public async Task DeleteUser_ForPrivilegedUser_ReturnsCorrectPage()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("id", "5eb7eb9f1fdada19f4eb59b1"),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.PrivilegedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/Users/DeleteUser"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("/Users", UriKind.Relative));

            using var indexResponse = await client.GetAsync(new Uri ("https://localhost:5001/Users"), CancellationToken.None);

            await ResponseAssert.VerifyPageLoaded(indexResponse);
        }
        public async Task DeleteMovie_ForPrivilegedUser_DeletesMovieCorrectly()
        {
            // Arrange

            using var formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("id", "5eac4f407a15596e90c09d7b"),
            });

            await using var webApplicationFactory = new CustomWebApplicationFactory(ApplicationUser.PrivilegedUser);
            using var client = webApplicationFactory.CreateDefaultHttpClient();

            // Act

            using var response = await client.PostAsync(new Uri ("https://localhost:5001/MoviesToGet/DeleteMovie"), formContent, CancellationToken.None);

            // Assert

            ResponseAssert.VerifyRedirect(response, new Uri("/MoviesToGet", UriKind.Relative));

            using var indexResponse = await client.GetAsync(new Uri ("https://localhost:5001/MoviesToGet"), CancellationToken.None);

            await ResponseAssert.VerifyPageLoaded(indexResponse);
        }