Exemplo n.º 1
0
        public void Authorization_UserDefinitionThrowsExceptionIfNoUserRetrieveServiceIsRegistered()
        {
            using (new MunqContext())
            {
                var testUser = new TestUserDefinition();
                var registrar = Dependency.Resolve<IDependencyRegistrar>();
                registrar.RegisterInstance<IAuthorizationService>(
                    new TestAuthorizationService(() => testUser));

                var exception = Assert.Throws<KeyNotFoundException>(() => Authorization.UserDefinition);
                Assert.Contains(typeof(IUserRetrieveService).Name, exception.Message);
            }
        }
Exemplo n.º 2
0
        public void Authorization_LoggedInUsesRegisteredAuthorizationService()
        {
            using (new MunqContext())
            {
                TestUserDefinition testUser = null;

                var registrar = Dependency.Resolve<IDependencyRegistrar>();

                registrar.RegisterInstance<IAuthorizationService>(
                    new TestAuthorizationService(() => testUser));

                Assert.Equal(false, Authorization.IsLoggedIn);

                testUser = new TestUserDefinition();

                Assert.Equal(true, Authorization.IsLoggedIn);
            }
        }
Exemplo n.º 3
0
        public void Authorization_UsernameReturnsUsernameFromRegisteredAuthorizationService()
        {
            using (new MunqContext())
            {
                TestUserDefinition testUser = null;

                var registrar = Dependency.Resolve<IDependencyRegistrar>();

                registrar.RegisterInstance<IAuthorizationService>(
                    new TestAuthorizationService(() => testUser));

                Assert.Equal(null, Authorization.Username);

                testUser = new TestUserDefinition();

                Assert.Equal(testUser.Username, Authorization.Username);

                testUser.Username = "******";
                Assert.Equal("x", Authorization.Username);
            }
        }
Exemplo n.º 4
0
        public void Authorization_ValidateLoggedInThrowsExceptionIfNotLoggedIn()
        {
            using (new MunqContext())
            {
                TestUserDefinition testUser = null;

                var registrar = Dependency.Resolve<IDependencyRegistrar>();
                registrar.RegisterInstance<IAuthorizationService>(
                    new TestAuthorizationService(() => testUser));

                var exception = Assert.Throws<ValidationError>(() =>
                    Authorization.ValidateLoggedIn());

                Assert.Equal("NotLoggedIn", exception.ErrorCode);

                testUser = new TestUserDefinition();
                Authorization.ValidateLoggedIn();
            }
        }
Exemplo n.º 5
0
        public void Authorization_UserIdUsesRegisteredUserRetrieveService()
        {
            using (new MunqContext())
            {
                TestUserDefinition testUser = null;

                var registrar = Dependency.Resolve<IDependencyRegistrar>();

                registrar.RegisterInstance<IAuthorizationService>(
                    new TestAuthorizationService(() => testUser));

                registrar.RegisterInstance<IUserRetrieveService>(
                    new TestUserRetrieveService(() => new[] { testUser }));

                Assert.Equal(null, Authorization.UserId);

                testUser = new TestUserDefinition();

                Assert.Equal(testUser.Id, Authorization.UserId);
            }
        }