public UsersControllerTests() { _mockUserStore = new Mock <IUserStore <User> >(); _mockUserManager = new Mock <UserManager <User> > (_mockUserStore.Object, null, null, null, null, null, null, null, null); _mockUserManager.Setup(u => u.CreateAsync(It.IsAny <User>(), It.IsAny <string>())).ReturnsAsync(IdentityResult.Success); _mockUserManager.Setup(u => u.AddToRoleAsync(It.IsAny <User>(), It.IsAny <string>())).ReturnsAsync(IdentityResult.Success); _mockUserManager.Setup(u => u.ResetPasswordAsync(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(IdentityResult.Success); _mockUserManager.Setup(u => u.ChangePasswordAsync(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(IdentityResult.Success); _mockUserManager.Setup(u => u.FindByEmailAsync(It.IsAny <string>())).ReturnsAsync(new User()); _mockEmailService = new Mock <IEmailService>(); _mockTokenFactory = new Mock <ITokenFactory>(); _mockUserService = new Mock <IUserService>(); _mockUserService.Setup(u => u.Save()).Returns(Task.FromResult(true)); _mockRazorViewRenderer = new Mock <IRazorViewToStringRenderer>(); _controller = new UsersController(_mockUserService.Object, _mockUserManager.Object, _mockTokenFactory.Object, _mockEmailService.Object, _mapper, _mockRazorViewRenderer.Object); SetupTestController(_controller); SetupAuthentication(_controller); _builder = new UserTestBuilder(); resourceParameters = new UsersResourceParameters(); resourceParameters.Fields = "Id, UserName"; }
public void Constructor_Should_Throw_Exception_When_User_Dosnt_Have_Minimum_Number_Of_Roles() { //Arrange var empty = new List <long>(); var builder = new UserTestBuilder(); //Act Action user = () => builder.WithRoles(empty).Build(); //Assert user.Should().Throw <UserShouldHaveARoleException>(); }
public void Constructor_Should_Construct_User_Properly() { //Arrange var userBuilder = new UserTestBuilder(); //Act var user = userBuilder.Build(); //Assert user.Id.Should().Be(userBuilder.UserId); user.Username.Should().Be(userBuilder.Username); user.Password.Should().Be(userBuilder.Password); user.FullName.Should().Be(userBuilder.Firstname); user.Lastname.Should().Be(userBuilder.Lastname); }
private IEnumerable <User> GetUsersTestData() { var data = new List <User>(); for (int i = 0; i < DefaultValues.ListSize; i++) { var dataBuilder = new UserTestBuilder(); data.Add(dataBuilder .WithId(new Guid()) .WithDefault() .Build()); } data.Add(new User() { Id = UserDefaultValues.DefaultId, Email = UserDefaultValues.DefaultEmail, PasswordHash = UserDefaultValues.DefaultString, RoleId = UserDefaultValues.DefaultRoleId, }); return(data.AsEnumerable()); }
public UserTests() { _builder = new UserTestBuilder(); }