public void CanCreate_InvalidState_ReturnsFalse() { validator.ModelState.AddModelError("Test", "Test"); Assert.False(validator.CanCreate(ObjectsFactory.CreateAccountCreateView(account.Id + 1))); Assert.Single(validator.ModelState); }
public void CanCreate_UsedEmail_ReturnsFalse() { AccountCreateView view = ObjectsFactory.CreateAccountCreateView(2); view.Email = account.Email.ToUpper(); Boolean canCreate = validator.CanCreate(view); Assert.False(canCreate); Assert.Single(validator.ModelState); Assert.Equal(Validation.For <AccountView>("UniqueEmail"), validator.ModelState[nameof(AccountCreateView.Email)].Errors.Single().ErrorMessage); }
public void CanCreate_UsedUsername_ReturnsFalse() { AccountCreateView view = ObjectsFactory.CreateAccountCreateView(1); view.Username = account.Username.ToLower(); Boolean canCreate = validator.CanCreate(view); Assert.False(canCreate); Assert.Single(validator.ModelState); Assert.Equal(Validation.For <AccountView>("UniqueUsername"), validator.ModelState["Username"].Errors.Single().ErrorMessage); }
public AccountsTests() { service = Substitute.For <IAccountService>(); account = ObjectsFactory.CreateAccountView(0); validator = Substitute.For <IAccountValidator>(); accountEdit = ObjectsFactory.CreateAccountEditView(0); accountCreate = ObjectsFactory.CreateAccountCreateView(0); controller = Substitute.ForPartsOf <Accounts>(validator, service); controller.ControllerContext.HttpContext = new DefaultHttpContext(); controller.Authorization.Returns(Substitute.For <IAuthorization>()); controller.ControllerContext.RouteData = new RouteData(); }
public AccountsControllerTests() { validator = Substitute.For <IAccountValidator>(); service = Substitute.For <IAccountService>(); accountCreate = ObjectsFactory.CreateAccountCreateView(); accountEdit = ObjectsFactory.CreateAccountEditView(); account = ObjectsFactory.CreateAccountView(); controller = Substitute.ForPartsOf <AccountsController>(validator, service); controller.ControllerContext.HttpContext = Substitute.For <HttpContext>(); controller.TempData = Substitute.For <ITempDataDictionary>(); controller.ControllerContext.RouteData = new RouteData(); controller.Url = Substitute.For <IUrlHelper>(); }
public void Create_Account() { AccountCreateView view = ObjectsFactory.CreateAccountCreateView(2); view.Email = view.Email?.ToUpper(); view.RoleId = account.RoleId; service.Create(view); Account actual = context.Set <Account>().AsNoTracking().Single(model => model.Id != account.Id); AccountCreateView expected = view; Assert.Equal(hasher.HashPassword(expected.Password !), actual.Passhash); Assert.Equal(expected.CreationDate, actual.CreationDate); Assert.Equal(expected.Email?.ToLower(), actual.Email); Assert.Equal(expected.Username, actual.Username); Assert.Null(actual.RecoveryTokenExpirationDate); Assert.Equal(expected.RoleId, actual.RoleId); Assert.Null(actual.RecoveryToken); Assert.False(actual.IsLocked); }
public void CanCreate_ValidAccount() { Assert.True(validator.CanCreate(ObjectsFactory.CreateAccountCreateView(account.Id + 1))); Assert.Empty(validator.ModelState); Assert.Empty(validator.Alerts); }