示例#1
0
        public void LoginWithAsSystemUserWithWrongPasswordShouldReturnFalse()
        {
            var user = (LoginCriteria)CreateSystemUser();

            user.Password = "******";
            GenFormPrincipal.Login(user);

            Assert.IsFalse(GenFormPrincipal.GetPrincipal().IsLoggedIn(), "System user should not be able to login with password bar");
        }
示例#2
0
        public void LoginSystemUserResultsInPricipalIdentityBeingSet()
        {
            ILoginCriteria user = CreateSystemUser();

            IsolateGetIdentity();
            GenFormPrincipal.Login(user);

            Assert.IsNotNull(GenFormPrincipal.GetPrincipal().Identity, "Principal identity should be set");
        }
        public JObject GenFormLogOut(string user)
        {
            Session.Remove("user");
            GenFormPrincipal.Logout();

            var     ser  = new JsonSerializer();
            JObject json = JObject.FromObject(new { success = true }, ser);

            return(json);
        }
示例#4
0
        public static void Login(UserLoginDto dto)
        {
            EnvironmentServices.SetEnvironment(dto.Environment);

            var criteria = new LoginCriteria
            {
                UserName = dto.UserName,
                Password = dto.Password
            };

            GenFormPrincipal.Login(criteria);
        }
示例#5
0
        public void Init()
        {
            _principal = Isolate.Fake.Instance <GenFormPrincipal>();
            _identity  = Isolate.Fake.Instance <IGenFormIdentity>();
            Isolate.WhenCalled(() => _principal.Identity).WillReturn(_identity);

            Isolate.WhenCalled(() => GenFormPrincipal.GetPrincipal()).WillReturn(_principal);
            Isolate.WhenCalled(() => GenFormPrincipal.Login(_criteria)).IgnoreCall();

            Isolate.WhenCalled(() => EnvironmentServices.SetEnvironment(string.Empty)).IgnoreCall();

            _dto = GetAdminUserDto();
        }
示例#6
0
        public void UseGenFormPrincipalToLogin()
        {
            try
            {
                LoginServices.Login(_dto);
                _criteria = new LoginCriteria
                {
                    UserName = _dto.UserName,
                    Password = _dto.Password
                };

                Isolate.Verify.WasCalledWithAnyArguments(() => GenFormPrincipal.Login(_criteria));
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }
        }
示例#7
0
        public void LoginCallsSetPrincipalWithIdentity()
        {
            var user     = CreateSystemUser();
            var identity = CreateFakeGenFormIdentity();

            Isolate.WhenCalled(() => GenFormIdentity.GetIdentity(user)).WillReturn(identity);
            Isolate.NonPublic.WhenCalled(typeof(GenFormPrincipal), "SetPrincipal").CallOriginal();

            try
            {
                GenFormPrincipal.Login(user);
                Isolate.Verify.NonPublic.WasCalled(typeof(GenFormPrincipal), "SetPrincipal").WithArguments(identity);
            }
            catch (VerifyException e)
            {
                Assert.Fail("SetPrincipal was not called using a fake identity: " + e);
            }
        }
示例#8
0
 public static bool IsLoggedIn(string userName)
 {
     return(GenFormPrincipal.GetPrincipal().Identity.Name == userName &&
            GenFormPrincipal.GetPrincipal().IsLoggedIn());
 }
示例#9
0
        public void IsLoggedInReturnsFalseForAnonymousUser()
        {
            var principal = GenFormPrincipal.GetPrincipal();

            Assert.IsFalse(principal.IsLoggedIn(), "Principal that is not logged in should return false");
        }