Example #1
0
        public void Should_create_new_configuration_instance()
        {
            // Arrange
            var configuration = MockRepository.GenerateMock <ISecurityConfiguration>();

            SecurityConfigurator.SetConfiguration(configuration);

            // Act
            SecurityConfigurator.Reset();

            // Assert
            var exception = Assert.Throws <InvalidOperationException>(() => {
                var x = SecurityConfiguration.Current;
            });

            Assert.That(exception.Message, Is.EqualTo("Security has not been configured!"));
        }
Example #2
0
        public void Should_return_the_current_configuration()
        {
            var baseDirectory  = AppDomain.CurrentDomain.BaseDirectory;
            var fullFilePath   = Path.Combine(baseDirectory, "TestData", "DiagnosticsOutputExample.txt");
            var expectedOutput = File.ReadAllText(fullFilePath);

            var securityConfiguration = new SecurityConfiguration(configuration =>
            {
                configuration.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsFalse);
                configuration.IgnoreMissingConfiguration();
                configuration.For <BlogController>(x => x.DeletePost(0)).DenyAnonymousAccess().RequireRole(UserRole.Owner, UserRole.Publisher);
                configuration.For <BlogController>(x => x.Index()).DenyAnonymousAccess();
            });

            SecurityConfigurator.SetConfiguration(securityConfiguration);

            // Act
            var whatIHave = securityConfiguration.WhatDoIHave();

            // Assert
            Assert.That(whatIHave, Is.EqualTo(expectedOutput));
        }