示例#1
0
        public void CanCreate_CanNotCreateWithAlreadyUsedEmail()
        {
            AccountCreateView view = ObjectFactory.CreateAccountCreateView();

            view.Id += "DifferentValue";

            Assert.False(validator.CanCreate(view));
        }
        public void Create_RefreshesAuthorizationProvider()
        {
            AccountCreateView view = ObjectFactory.CreateAccountCreateView(2);

            service.Create(view);

            Authorization.Provider.Received().Refresh();
        }
示例#3
0
        public void CanCreate_CanNotCreateWithAlreadyTakenUsername()
        {
            AccountCreateView view = ObjectFactory.CreateAccountCreateView();

            view.Username = view.Username.ToLower();
            view.Id      += "DifferentValue";

            Assert.False(validator.CanCreate(view));
        }
        public void Create_RefreshesAuthorization()
        {
            AccountCreateView view = ObjectFactory.CreateAccountCreateView(2);

            view.RoleId = null;

            service.Create(view);

            authorizationProvider.Received().Refresh();
        }
示例#5
0
        public void CanCreate_UsedUsername_ReturnsFalse()
        {
            AccountCreateView view = ObjectFactory.CreateAccountCreateView(1);

            view.Username = account.Username.ToLower();

            Boolean canCreate = validator.CanCreate(view);

            Assert.False(canCreate);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validations.UniqueUsername, validator.ModelState["Username"].Errors.Single().ErrorMessage);
        }
示例#6
0
        public void CanCreate_UsedEmail_ReturnsFalse()
        {
            AccountCreateView view = ObjectFactory.CreateAccountCreateView(1);

            view.Email = account.Email.ToUpper();

            Boolean canCreate = validator.CanCreate(view);

            Assert.False(canCreate);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validations.UniqueEmail, validator.ModelState["Email"].Errors.Single().ErrorMessage);
        }
示例#7
0
        public AccountsControllerTests()
        {
            validator = Substitute.For <IAccountValidator>();
            service   = Substitute.For <IAccountService>();

            accountCreate = ObjectFactory.CreateAccountCreateView();
            accountEdit   = ObjectFactory.CreateAccountEditView();
            account       = ObjectFactory.CreateAccountView();

            controller = Substitute.ForPartsOf <AccountsController>(validator, service);
            controller.ActionContext.RouteData = new RouteData();
        }
示例#8
0
        public void Create_RefreshesAuthorization()
        {
            Authorization.Provider = Substitute.For <IAuthorizationProvider>();

            AccountCreateView view = ObjectFactory.CreateAccountCreateView(1);

            view.RoleId = null;

            service.Create(view);

            Authorization.Provider.Received().Refresh();
        }
示例#9
0
        public void CanCreate_AddsErrorMessageThenCanNotCreateWithAlreadyUsedEmail()
        {
            AccountCreateView view = ObjectFactory.CreateAccountCreateView();

            view.Id += "DifferentValue";

            validator.CanCreate(view);

            String actual   = validator.ModelState["Email"].Errors[0].ErrorMessage;
            String expected = Validations.EmailIsAlreadyUsed;

            Assert.Equal(expected, actual);
        }
示例#10
0
        public void CanCreate_AddsErorrMessageThenCanNotCreateWithAlreadyTakenUsername()
        {
            AccountCreateView view = ObjectFactory.CreateAccountCreateView();

            view.Username = view.Username.ToLower();
            view.Id      += "DifferentValue";

            validator.CanCreate(view);

            String actual   = validator.ModelState["Username"].Errors[0].ErrorMessage;
            String expected = Validations.UsernameIsAlreadyTaken;

            Assert.Equal(expected, actual);
        }
        public AccountsControllerTests()
        {
            validator = Substitute.For <IAccountValidator>();
            service   = Substitute.For <IAccountService>();

            accountCreate = ObjectFactory.CreateAccountCreateView();
            accountEdit   = ObjectFactory.CreateAccountEditView();
            account       = ObjectFactory.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>();
        }
示例#12
0
        public AccountsControllerTests()
        {
            validator = Substitute.For <IAccountValidator>();
            service   = Substitute.For <IAccountService>();

            accountCreate = ObjectFactory.CreateAccountCreateView();
            accountEdit   = ObjectFactory.CreateAccountEditView();
            account       = ObjectFactory.CreateAccountView();

            Authorization.Provider       = Substitute.For <IAuthorizationProvider>();
            controller                   = Substitute.ForPartsOf <AccountsController>(validator, service);
            controller.ControllerContext = new ControllerContext {
                RouteData = new RouteData()
            };
        }
示例#13
0
        public void MapAccounts_MapsAccountCreateViewToAccount()
        {
            AccountCreateView expected = ObjectFactory.CreateAccountCreateView();
            Account           actual   = Mapper.Map <Account>(expected);

            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Equal(expected.Username, actual.Username);
            Assert.Null(actual.RecoveryTokenExpirationDate);
            Assert.Equal(expected.RoleId, actual.RoleId);
            Assert.Equal(expected.Email, actual.Email);
            Assert.Equal(expected.Id, actual.Id);
            Assert.Null(actual.RecoveryToken);
            Assert.False(actual.IsLocked);
            Assert.Null(actual.Passhash);
            Assert.Null(actual.Role);
        }
示例#14
0
        public void Create_Account()
        {
            AccountCreateView view = ObjectFactory.CreateAccountCreateView(1);

            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);
        }
示例#15
0
 public void CanCreate_ValidAccount()
 {
     Assert.True(validator.CanCreate(ObjectFactory.CreateAccountCreateView(1)));
     Assert.Empty(validator.ModelState);
     Assert.Empty(validator.Alerts);
 }
示例#16
0
        public void CanCreate_InvalidState_ReturnsFalse()
        {
            validator.ModelState.AddModelError("Test", "Test");

            Assert.False(validator.CanCreate(ObjectFactory.CreateAccountCreateView(1)));
        }
示例#17
0
 public void CanCreate_ValidAccount()
 {
     Assert.True(validator.CanCreate(ObjectFactory.CreateAccountCreateView(2)));
 }
示例#18
0
        public void CanCreate_CanNotCreateWithInvalidModelState()
        {
            validator.ModelState.AddModelError("Key", "Error");

            Assert.False(validator.CanCreate(ObjectFactory.CreateAccountCreateView()));
        }