public async Task DeleteAlbumShouldReturnOkIfTheUserDeletesOwnPicture() { // Arrange var userId = Guid.NewGuid().ToString(); var pictureService = new Mock <IPictureService>(); var userManager = MockManager.GetMockUserManger(); pictureService .Setup(s => s.AlbumOwnerId(It.IsAny <int>())). ReturnsAsync(userId); pictureService .Setup(s => s.DeleteAlbumByIdAsync(It.IsAny <int>())) .ReturnsAsync(true); userManager .Setup(s => s.GetUserId(It.IsAny <ClaimsPrincipal>())) .Returns(userId); var controller = new PhotosController(pictureService.Object, null, userManager.Object); controller.LoginMockUser(); // Act var result = await controller.DeleteAlbum(1); // Assert result .Should() .BeOfType <OkResult>(); }
public async Task DeleteAlbumShouldReturnBadRequestIfUserTriesToDeleteForeignAlbum() { // Arrange var pictureService = new Mock <IPictureService>(); var userManager = MockManager.GetMockUserManger(); pictureService .Setup(s => s.AlbumOwnerId(It.IsAny <int>())). ReturnsAsync(Guid.NewGuid().ToString()); userManager .Setup(s => s.GetUserId(It.IsAny <ClaimsPrincipal>())) .Returns(Guid.NewGuid().ToString()); var controller = new PhotosController(pictureService.Object, null, userManager.Object); controller.LoginMockUser(); // Act var result = await controller.DeleteAlbum(1); // Assert result .Should() .BeOfType <BadRequestObjectResult>(); }
public async Task CreateAlbumShouldReturnOkIfTitleAndDescriptionAreProvided() { // Arrange var pictureService = new Mock <IPictureService>(); var userManager = MockManager.GetMockUserManger(); pictureService .Setup(s => s.CreateAlbumAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(true); userManager .Setup(s => s.GetUserId(It.IsAny <ClaimsPrincipal>())) .Returns(Guid.NewGuid().ToString()); var controller = new PhotosController(pictureService.Object, null, userManager.Object); controller.LoginMockUser(); // Act var result = await controller.CreateAlbum("fakeTitle", "fakeDescription"); // Assert result .Should() .BeOfType <OkResult>(); }
public async Task PostByUserNotInTheFriendListOfOtherNormalUserShouldReturnAccessDeniedView() { // Arrange var firstUserId = "FirstUserId"; var secondUserId = "SecondUserId"; var postService = new Mock <IPostService>(); var userService = new Mock <IUserService>(); var userManager = MockManager.GetMockUserManger(); postService .Setup(s => s.ByIdAsync(It.IsAny <int>())) .ReturnsAsync(new Post { UserId = firstUserId }); userManager .Setup(s => s.GetUserId(It.IsAny <ClaimsPrincipal>())) .Returns(secondUserId); userService .Setup(s => s.CheckFriendshipStatusAsync(firstUserId, secondUserId)) .ReturnsAsync((FriendshipStatus.NotFriend, "")); var controller = new PostsController(postService.Object, userService.Object, userManager.Object); controller.LoginMockUser(); // Act var result = await controller.Details(5); // Assert result.AssertAccessDeniedView(); }