Ejemplo n.º 1
0
        public void GetIdentityOfNonExistentUserReturnsAnonymousIdentity()
        {
            const String name = "foo";
            var          user = CreateFakeIuser();

            IsolateGetUserByName(user, name);

            var result = GenFormIdentity.GetIdentity(name);

            Assert.IsInstanceOfType(result, typeof(IAnonymousIdentity), "Getidentity with nonexisting user did not return AnonymousIdentity");
            Assert.IsFalse(result.IsAuthenticated, "AnonymousIdentity should not be authenticated");
        }
Ejemplo n.º 2
0
        public void GetIdentityOfSystemUserWithWrongPasswordShouldReturnAnonymousIdentity()
        {
            const String name = "Admin";
            var          user = CreateFakeIuser();

            Isolate.WhenCalled(() => user.Name).WillReturn("Admin");
            Isolate.WhenCalled(() => user.Password).WillReturn("lkjlj");
            IsolateGetUserByName(user, name);

            var result = GenFormIdentity.GetIdentity(name);

            Assert.IsInstanceOfType(result, typeof(AnonymousIdentity), "When passwords do not match an anonymous identity should be returned");
            Assert.IsFalse(result.IsAuthenticated, "If passwords do not match, IsAuthenticated should return false");
        }
Ejemplo n.º 3
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);
            }
        }