public void IsValidKeyServiceExceptionUserNotFoundTest() { _rootRepoMock.Setup(x => x.FindConnectionByUserGuid(It.IsAny <Guid>())).Returns(_connection); _settingRepoMock.Setup(x => x.FindSettingAsString(SettingName.EncryptionSalt)).Returns(Salt); _settingRepoMock.Setup(x => x.FindSettingAsString(SettingName.EncryptionKey)).Returns(Key); _customerContextFactoryMock.Setup(x => x.CreateDbContext(It.IsAny <string>())).Returns(_customerDatabaseMock.Object); _isValidKeyRequest = new IsValidKeyRequest(Guid.NewGuid(), new Guid(UserGuid)); var response = _userService.IsValidKey(_isValidKeyRequest); Assert.IsNotNull(response); Assert.AreEqual(ResponseCode.NotFound, response.Code); Assert.IsNotEmpty(response.ErrorMessage); Assert.AreEqual(false, response.Entity); }
public void SetUp() { _rootRepoMock = new Mock <IRootRepository>(); _settingRepoMock = new Mock <ISettingRepository>(); _customerContextFactoryMock = new Mock <IDbCustomerDatabaseFactory>(); _customerDatabaseMock = new Mock <dbCustomerDatabase>(); _userDbSetMock = new Mock <DbSet <User> >(); var user = new User(new Guid(UserGuid), "Name", "Email", "Password"); user.AddPasswordResetRequest(new ForgottenPassword(new Guid(UsedForgottenPasswordGuid)), 1); user.AddPasswordResetRequest(new ForgottenPassword(new Guid(ForgottenPasswordGuid)), 1); //Having to due all of this due to multi-tenency set up, I can't inject UserRepo var data = new List <User> { user } .AsQueryable(); _userDbSetMock.As <IQueryable <User> >().Setup(m => m.Provider).Returns(data.Provider); _userDbSetMock.As <IQueryable <User> >().Setup(m => m.Expression).Returns(data.Expression); _userDbSetMock.As <IQueryable <User> >().Setup(m => m.ElementType).Returns(data.ElementType); _userDbSetMock.As <IQueryable <User> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); _customerDatabaseMock.Setup(c => c.Users).Returns(_userDbSetMock.Object); _userService = new UserService( _rootRepoMock.Object, _settingRepoMock.Object, _customerContextFactoryMock.Object); _isValidKeyRequest = new IsValidKeyRequest(new Guid(ForgottenPasswordGuid), new Guid(UserGuid)); _requestPasswordResetRequest = new RequestPasswordResetRequest("Email"); _resetPasswordRequest = new ResetPasswordRequest(new Guid(ForgottenPasswordGuid), "Password2", new Guid(UserGuid)); var guid = Guid.NewGuid(); var connectionString = new Encryption( Key, Salt, guid.ToByteArray()) .EncryptString("Connection String"); _connection = new RootConnection(guid, connectionString); }
public Response <bool> IsValidKey(IsValidKeyRequest request) { try { SetUserRepositoryByUserGuid(request.UserGuid); var user = _userRepository.FindByKey(request.Key); if (user == null) { throw new ServiceException(ResponseCode.NotFound, "Selected Agent does not exist."); } var expiryLength = _settingRepository.FindSettingAsInt(SettingName.PasswordResetLength); var isvalid = user.IsValidKey(request.Key, expiryLength); return(new Response <bool>(isvalid)); } catch (Exception e) { return(HandleException <bool>(e)); } }