Exemplo n.º 1
0
        public void ConfigurationIsLoadedCorrectly()
        {
            // arrange
            const bool   requiresExpirationTime = false;
            const string signingUrl             = "https://faketokens.com";
            const string targetAudience         = "Testers";
            const string validIssuer            = "https://valid.com";
            const string authType  = "Token";
            const string userClaim = "Username";
            const string roleClaim = "User";

            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.OAuthRequireExperationTime, requiresExpirationTime.ToString());
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.OAuthSigningKeysUrl, signingUrl);
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.OAuthTargetAudiance, targetAudience);
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.OAuthValidIssuer, validIssuer);
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.OAuthAuthenticationType, authType);
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.OAuthClaimRepresetingUsername, userClaim);
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.OAuthClaimRepresentingRole, roleClaim);
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.OAuthAuthenticationEnabled, true.ToString());

            // act
            var sut = new OAuthTokenValidatorConfiguration();

            // assert
            sut.SigningKeyUrl.Should().Be(signingUrl);
            sut.RequiresExpirationTime.Should().Be(requiresExpirationTime);
            sut.TargetAudience.Should().Be(targetAudience);
            sut.ValidIssuer.Should().Be(validIssuer);
            sut.AuthenticationType.Should().Be(authType);
            sut.ClaimRepresentingUsername.Should().Be(userClaim);
            sut.ClaimRepresentingRole.Should().Be(roleClaim);
            sut.Enabled.Should().BeTrue();
        }
Exemplo n.º 2
0
        public void ConfigureServices(IServiceCollection services)
        {
            IApplicationConfiguration applicationConfiguration = ApplicationConfigurationHelper.GetApplicationConfiguration(Configuration);

            services.AddSingleton(applicationConfiguration);

            DependencyInjectionManager.RegisterServices(services);
            services.AddControllers();
            services.AddApiVersioning();
        }
        public void ConfigurationIsLoadedCorrectly()
        {
            // arrange
            const string agentString = "Kuroyukihime";

            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.UserAgent, agentString);

            // act
            var sut = new HttpClientConfiguration();

            // assert
            sut.UserAgent.Should().Be(agentString);
        }
Exemplo n.º 4
0
        public void ApplyLoggingConfiguration(bool isUsed, bool isActive, bool wasApplied)
        {
            // arrange
            ApplicationConfigurationHelper.AdjustKeys("log.console", isUsed.ToString());
            var serilogConfigurationDummy = new Mock <LoggerConfiguration>();
            var sut = new ConsoleLoggingConfiguration();

            // act
            sut.Apply(serilogConfigurationDummy.Object);

            // assert
            sut.LogToConsole.Should().Be(isUsed);
            sut.IsActive.Should().Be(isActive);
            sut.WasApplied.Should().Be(wasApplied);
        }
Exemplo n.º 5
0
        public void UseMemoryStorage()
        {
            // arrange
            var globalConfigDummy = new Mock <IGlobalConfiguration>();

            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireMemoryStorageEnabled, true.ToString());

            var sut = new HangfireMemoryStorageConfiguration();

            // act
            sut.Apply(globalConfigDummy.Object);

            // assert
            sut.Enabled.Should().BeTrue();
            sut.IsActive.Should().BeTrue();
        }
        public void DoNotUseSqlStorageProvider()
        {
            // arrange
            var globalConfigDummy = new Mock <IGlobalConfiguration>();

            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireSqlStorageEnabled, false.ToString());

            var sut = new HangfireSqlStorageProviderConfiguration();

            // act
            sut.Apply(globalConfigDummy.Object);

            // assert
            sut.Enabled.Should().BeFalse();
            sut.IsActive.Should().BeFalse();
        }
        public void ApplyLoggingConfiguration(bool isUsed, bool isActive, bool wasApplied)
        {
            // arrange
            StringExtensions.ConfigurationLocation = Assembly.GetExecutingAssembly().Location;
            ApplicationConfigurationHelper.AdjustKeys("log.file", isUsed.ToString());
            var serilogConfigurationDummy = new Mock <LoggerConfiguration>();
            var sut = new FileLoggingConfiguration();

            // act
            sut.Apply(serilogConfigurationDummy.Object);

            // assert
            sut.LogFilePath.Should().Be(FilePath);
            sut.LogToFile.Should().Be(isUsed);
            sut.IsActive.Should().Be(isActive);
            sut.WasApplied.Should().Be(wasApplied);
        }
        public void ConfigurationIsLoadedCorrectly()
        {
            // arrange
            const string host = "http://localhost";
            const int    port = 1337;

            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.ServiceHost, host);
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.ServicePort, port.ToString(CultureInfo.InvariantCulture));

            // act
            var sut = new HostConfiguration();

            // assert
            sut.Host.Should().Be(host);
            sut.Port.Should().Be(port);
            sut.HostUrl.Should().Be($"{host}:{port}");
        }
        public void ConfigurationIsLoadedCorrectly()
        {
            // arrange
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireEnabled, true.ToString());
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireEnableDashboard, false.ToString());
            var hangfireConfigDummy = new Mock <HangfireStorageConfigurationBase>();
            var activatorDummy      = new Mock <JobActivator>();

            // act
            var sut = new HangfireConfiguration(new List <HangfireStorageConfigurationBase> {
                hangfireConfigDummy.Object
            }, activatorDummy.Object, new List <HangfireJobBase>());

            // assert
            sut.Enabled.Should().BeTrue();
            sut.EnableDashboard.Should().BeFalse();
        }
        public void UseSqlStorageProviderNegativeProof()
        {
            // arrange
            var          globalConfigDummy    = new Mock <IGlobalConfiguration>();
            const string testConnectionString = "Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;";

            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireSqlStorageEnabled, true.ToString());
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireSqlConnectionString, testConnectionString);

            var sut = new HangfireSqlStorageProviderConfiguration();

            var act = new Action(() => sut.Apply(globalConfigDummy.Object));

            // act
            // assert
            act.ShouldThrow <SqlException>();
            sut.Enabled.Should().BeTrue();
        }
Exemplo n.º 11
0
        public void ConfigurationIsLoadedCorrectly()
        {
            // arrange
            const string apiToken       = "testToken";
            const string defaultSendKey = "sendKey";
            const bool   isEnabled      = true;

            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.PushoverApiToken, apiToken);
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.PushoverDefaultSendKey, defaultSendKey);
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.PushoverEnabled, isEnabled.ToString(CultureInfo.InvariantCulture));

            // act
            var sut = new PushoverConfiguration();

            // assert
            sut.ApiToken.Should().Be(apiToken);
            sut.DefaultSendKey.Should().Be(defaultSendKey);
            sut.IsEnabled.Should().Be(isEnabled);
        }
        public void DisabledHangfireIsNoSetUp()
        {
            // arrange
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireEnabled, false.ToString());
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireEnableDashboard, false.ToString());
            var activatorDummy = new Mock <JobActivator>();

            var hangfireConfigDummy = new HangfireStorageProviderFixture();

            var appBuilderDummy = new AppBuilderFixture();
            var sut             = new HangfireConfiguration(new List <HangfireStorageConfigurationBase> {
                hangfireConfigDummy
            }, activatorDummy.Object, new List <HangfireJobBase>());

            // act
            sut.SetupHangfire(appBuilderDummy);

            // assert
            hangfireConfigDummy.IsActive.Should().BeFalse();
        }
        public void ConfigurationIsLoadedCorrectly()
        {
            // arrange
            const string        serviceName        = "Test";
            const string        serviceDisplayName = "Test Display";
            const string        serviceDescription = "Test Description";
            const HostStartMode startMode          = HostStartMode.Automatic;

            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.ServiceName, serviceName);
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.ServiceDisplayName, serviceDisplayName);
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.ServiceDescription, serviceDescription);
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.ServiceStartMode, startMode.ToString());

            // act
            var sut = new TopShelfConfiguration();

            // assert
            sut.Name.Should().Be(serviceName);
            sut.DisplayName.Should().Be(serviceDisplayName);
            sut.Description.Should().Be(serviceDescription);
            sut.StartMode.Should().Be(startMode);
        }
        public void JobsAreNotConfiguredIfHangfireIsNotUsed()
        {
            // arrange
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireEnabled, true.ToString());
            ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireEnableDashboard, false.ToString());
            var activatorDummy = new Mock <JobActivator>();
            var jobDummy       = new JobFixture();

            var hangfireConfigDummy = new HangfireStorageProviderFixture();

            var appBuilderDummy = new AppBuilderFixture();
            var sut             = new HangfireConfiguration(new List <HangfireStorageConfigurationBase> {
                hangfireConfigDummy
            }, activatorDummy.Object, new List <HangfireJobBase> {
                jobDummy
            });

            // act
            sut.SetupHangfire(appBuilderDummy);

            // assert
            jobDummy.WasSetUp.Should().BeTrue();
        }
Exemplo n.º 15
0
 protected BaseController()
 {
     ConfigurationHelper = new ApplicationConfigurationHelper();
 }
Exemplo n.º 16
0
 protected AbstractService()
 {
     Factory = new ConnectionProviderFactory(ApplicationConfigurationHelper.GetOracleConnectionString());
     Ninject = new StandardKernel();
     Ninject.Bind <ConnectionProvider>().ToMethod(context => Factory.Get());
 }