public async Task AddPlastDegreeForUser_403Forbidden(int id) { //Arrange string userId = "2"; var user = new UserDTO() { Id = userId, CityMembers = new List <CityMembers>(), ClubMembers = new List <ClubMembers>(), RegionAdministrations = new List <RegionAdministration>(), }; _userManager.Setup(x => x.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(new User() { Id = userId }); _userService.Setup(x => x.GetUserAsync(It.IsAny <string>())).ReturnsAsync(user); _userManager.Setup(x => x.GetRolesAsync(It.IsAny <User>())).ReturnsAsync(new List <string>()); ActiveMembershipController activeMembershipController = _activeMembershipController; var expected = StatusCodes.Status403Forbidden; // Act var result = await activeMembershipController.AddPlastDegreeForUser(new UserPlastDegreePostDTO() { PlastDegreeId = id, UserId = userId }); var actual = (result as StatusCodeResult).StatusCode; // Assert _loggerService.Verify((x) => x.LogError(It.IsAny <string>())); _userManager.Verify(); Assert.AreEqual(expected, actual); }
public async Task AddPlastDegreeForUser_InValid_Test(int id) { //Arrange string userId = "1"; var user = new UserDTO() { Id = userId, CityMembers = new List <CityMembers>(), ClubMembers = new List <ClubMembers>(), RegionAdministrations = new List <RegionAdministration>(), }; bool successfulAdded = false; _userManager.Setup(x => x.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(new User() { Id = userId }); _userService.Setup(x => x.GetUserAsync(It.IsAny <string>())).ReturnsAsync(user); _userManager.Setup(x => x.GetRolesAsync(It.IsAny <User>())).ReturnsAsync(new List <string>() { Roles.Admin }); _plastDegreeService.Setup(cs => cs.AddPlastDegreeForUserAsync(It.IsAny <UserPlastDegreePostDTO>())).ReturnsAsync(successfulAdded); ActiveMembershipController activeMembershipController = _activeMembershipController; //Act var result = await activeMembershipController.AddPlastDegreeForUser(new UserPlastDegreePostDTO() { PlastDegreeId = id }); //Assert Assert.IsInstanceOf <BadRequestResult>(result); }
public async Task AddPlastDegreeForUser_InValid_Test(int id) { //Arrange bool successfulAdded = false; _plastDegreeService.Setup(cs => cs.AddPlastDegreeForUserAsync(It.IsAny <UserPlastDegreePostDTO>())).ReturnsAsync(successfulAdded); ActiveMembershipController activeMembershipController = _activeMembershipController; //Act var result = await activeMembershipController.AddPlastDegreeForUser(new UserPlastDegreePostDTO() { PlastDegreeId = id }); //Assert Assert.IsInstanceOf <BadRequestResult>(result); }
public async Task AddPlastDegreeForUser_Valid_Test(int id) { //Arrange bool successfulAdded = true; _plastDegreeService.Setup(cs => cs.AddPlastDegreeForUserAsync(It.IsAny <UserPlastDegreePostDTO>())).ReturnsAsync(successfulAdded); ActiveMembershipController activeMembershipController = _activeMembershipController; //Act var result = await activeMembershipController.AddPlastDegreeForUser(new UserPlastDegreePostDTO() { PlastDegreeId = id }); //Assert Assert.IsInstanceOf <CreatedResult>(result); var cr = (CreatedResult)result; Assert.NotNull(cr.Value); Assert.IsInstanceOf <int>(cr.Value); Assert.AreEqual(id, cr.Value); }