A class that represents the configuration used for the Stumps server.
Ejemplo n.º 1
0
        public void SaveConfiguration_CallsDalWithCorrectArgs()
        {
            const int    DataCompatibility = 15;
            const string StoragePath       = @"C:\StoragePath";
            const int    Port = 8000;

            var entity = CreateSampleConfigurationEntity();

            var configurationDal = Substitute.For <IConfigurationDataAccess>();

            var configuration = new StumpsConfiguration(configurationDal)
            {
                DataCompatibilityVersion = DataCompatibility,
                StoragePath = StoragePath,
                WebApiPort  = Port
            };

            configuration.SaveConfiguration();

            configurationDal.Received()
            .SaveConfiguration(
                Arg.Is <ConfigurationEntity>(
                    x =>
                    x.DataCompatibilityVersion == DataCompatibility && x.StoragePath.Equals(StoragePath) &&
                    x.WebApiPort == Port));
        }
Ejemplo n.º 2
0
        public void SaveConfiguration_CallsDalWithCorrectArgs()
        {
            const int DataCompatibility = 15;
            const string StoragePath = @"C:\StoragePath";
            const int Port = 8000;

            var entity = CreateSampleConfigurationEntity();

            var configurationDal = Substitute.For<IConfigurationDataAccess>();

            var configuration = new StumpsConfiguration(configurationDal)
            {
                DataCompatibilityVersion = DataCompatibility,
                StoragePath = StoragePath,
                WebApiPort = Port
            };

            configuration.SaveConfiguration();

            configurationDal.Received()
                            .SaveConfiguration(
                                Arg.Is<ConfigurationEntity>(
                                    x =>
                                    x.DataCompatibilityVersion == DataCompatibility && x.StoragePath.Equals(StoragePath) &&
                                    x.WebApiPort == Port));
        }
Ejemplo n.º 3
0
        public void Constructor_WithValidDataAccess_InitializesUsingDefaults()
        {
            var dal = Substitute.For<IConfigurationDataAccess>();
            var config = new StumpsConfiguration(dal);

            Assert.AreEqual(DefaultConfigurationSettings.DataCompatibilityVersion, config.DataCompatibilityVersion);
            Assert.AreEqual(DefaultConfigurationSettings.StoragePath, config.StoragePath);
            Assert.AreEqual(DefaultConfigurationSettings.WebApiPort, config.WebApiPort);
        }
Ejemplo n.º 4
0
        public void Constructor_WithValidDataAccess_InitializesUsingDefaults()
        {
            var dal    = Substitute.For <IConfigurationDataAccess>();
            var config = new StumpsConfiguration(dal);

            Assert.AreEqual(DefaultConfigurationSettings.DataCompatibilityVersion, config.DataCompatibilityVersion);
            Assert.AreEqual(DefaultConfigurationSettings.StoragePath, config.StoragePath);
            Assert.AreEqual(DefaultConfigurationSettings.WebApiPort, config.WebApiPort);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Stumps.StumpsService"/> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="configuration"/> is <c>null</c>.</exception>
        public StumpsService(StumpsConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            InitializeComponent();
            _server = new StumpsRunner(configuration);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.StumpsServer"/> class.
        /// </summary>
        /// <param name="configuration">The <see cref="T:Stumps.Server.StumpsConfiguration"/> used to initialize the instance.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="configuration"/> is <c>null</c>.</exception>
        public StumpsRunner(StumpsConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            this.Configuration = configuration;
            _syncRoot = new object();
        }
Ejemplo n.º 7
0
        public void ValidConfiguration_WithValidValues_ReturnsTrue()
        {
            var configurationDal = Substitute.For <IConfigurationDataAccess>();
            var configuration    = new StumpsConfiguration(configurationDal)
            {
                DataCompatibilityVersion = 1,
                StoragePath = Path.GetTempPath(),
                WebApiPort  = 8000
            };

            Assert.IsTrue(configuration.ValidateConfigurationSettings());
        }
Ejemplo n.º 8
0
        public void Constructor_WithValidConfiguration_SetsConfigurationProperty()
        {
            var dal = Substitute.For<IConfigurationDataAccess>();
            var config = new StumpsConfiguration(dal);

            using (var server = new StumpsRunner(config))
            {

                Assert.AreSame(config, server.Configuration);

            }
        }
Ejemplo n.º 9
0
        public void LoadConfiguration_CallsDal()
        {
            var entity = CreateSampleConfigurationEntity();

            var configurationDal = Substitute.For<IConfigurationDataAccess>();
            configurationDal.LoadConfiguration().Returns(entity);

            var configuration = new StumpsConfiguration(configurationDal);
            configuration.LoadConfiguration();

            configurationDal.Received(1).LoadConfiguration();
        }
Ejemplo n.º 10
0
        public void LoadConfiguration_CallsDal()
        {
            var entity = CreateSampleConfigurationEntity();

            var configurationDal = Substitute.For <IConfigurationDataAccess>();

            configurationDal.LoadConfiguration().Returns(entity);

            var configuration = new StumpsConfiguration(configurationDal);

            configuration.LoadConfiguration();

            configurationDal.Received(1).LoadConfiguration();
        }
Ejemplo n.º 11
0
        public void LoadConfiguration_UpdatesConfigurationValues()
        {
            var entity = CreateSampleConfigurationEntity();

            var configurationDal = Substitute.For<IConfigurationDataAccess>();
            configurationDal.LoadConfiguration().Returns(entity);

            var configuration = new StumpsConfiguration(configurationDal);
            configuration.LoadConfiguration();

            Assert.AreEqual(entity.DataCompatibilityVersion, configuration.DataCompatibilityVersion);
            Assert.AreEqual(entity.StoragePath, configuration.StoragePath);
            Assert.AreEqual(entity.WebApiPort, configuration.WebApiPort);
        }
Ejemplo n.º 12
0
        public static void Main(string[] args)
        {
            var isRunningAsConsole = IsApplicationRunningAsConsole(args);

            var writer = isRunningAsConsole
                              ? (IMessageWriter)new ConsoleWriter()
                              : (IMessageWriter)new EventLogWriter();

            if (IsApplicationAlreadyRunning())
            {
                writer.WriteError(StartupResources.ApplicationRunning);
                return;
            }

            var configurationFile = Path.Combine(
                DefaultConfigurationSettings.StoragePath, DefaultConfigurationSettings.ConfigurationFileName);

            if (args != null && args.Length > 0)
            {
                configurationFile = DetermineConfigurationFileFromArgs(args);
            }

            if (configurationFile == null)
            {

                writer.WriteError(StartupResources.InvalidArguments + string.Join(@" ", args));

                if (isRunningAsConsole)
                {
                    writer.Information(StartupResources.HelpInformation);
                }

                return;

            }

            var configurationDal = new ConfigurationDataAccess(configurationFile);
            var configuration = new StumpsConfiguration(configurationDal);
            configurationDal.EnsureConfigurationIsInitialized(configuration.SaveConfiguration);

            configuration.LoadConfiguration();

            var startup = isRunningAsConsole ? (IStartup)new ConsoleStartup() : (IStartup)new ServiceStartup();

            startup.Configuration = configuration;
            startup.MessageWriter = writer;

            startup.RunInstance();
        }
Ejemplo n.º 13
0
        public static void Main()
        {
            var configurationFile = Path.Combine(
                DefaultConfigurationSettings.StoragePath, DefaultConfigurationSettings.ConfigurationFileName);

            var configurationDal = new ConfigurationDataAccess(configurationFile);
            var configuration = new StumpsConfiguration(configurationDal);
            configurationDal.EnsureConfigurationIsInitialized(configuration.SaveConfiguration);

            configuration.LoadConfiguration();

            var urlString = string.Format(CultureInfo.InvariantCulture, "http://localhost:{0}/", configuration.WebApiPort);

            Process.Start(urlString);
        }
Ejemplo n.º 14
0
        public void LoadConfiguration_UpdatesConfigurationValues()
        {
            var entity = CreateSampleConfigurationEntity();

            var configurationDal = Substitute.For <IConfigurationDataAccess>();

            configurationDal.LoadConfiguration().Returns(entity);

            var configuration = new StumpsConfiguration(configurationDal);

            configuration.LoadConfiguration();

            Assert.AreEqual(entity.DataCompatibilityVersion, configuration.DataCompatibilityVersion);
            Assert.AreEqual(entity.StoragePath, configuration.StoragePath);
            Assert.AreEqual(entity.WebApiPort, configuration.WebApiPort);
        }
Ejemplo n.º 15
0
        public void ValidConfiguration_WithInvalidDatabaseCompatibility_ReturnsFalse()
        {
            var configurationDal = Substitute.For <IConfigurationDataAccess>();

            var configuration = new StumpsConfiguration(configurationDal)
            {
                DataCompatibilityVersion = StumpsConfiguration.MinimumDataCompatibilityVersion - 1,
                StoragePath = Path.GetTempPath(),
                WebApiPort  = 8000
            };

            Assert.IsFalse(configuration.ValidateConfigurationSettings());

            configuration.DataCompatibilityVersion = StumpsConfiguration.MaximumDataCompatibilityVersion + 1;

            Assert.IsFalse(configuration.ValidateConfigurationSettings());
        }
Ejemplo n.º 16
0
        public void ValidConfiguration_WithInvalidStoragePath_ReturnsFalse()
        {
            var configurationDal = Substitute.For <IConfigurationDataAccess>();

            var configuration = new StumpsConfiguration(configurationDal)
            {
                DataCompatibilityVersion = 1,
                StoragePath = null,
                WebApiPort  = 8000
            };

            Assert.IsFalse(configuration.ValidateConfigurationSettings());

            configuration.StoragePath = "junkstorage";

            Assert.IsFalse(configuration.ValidateConfigurationSettings());

            configuration.StoragePath = "test >> &&& // \\ || bad path";
            Assert.IsFalse(configuration.ValidateConfigurationSettings());
        }
Ejemplo n.º 17
0
        public void ValidConfiguration_WithInvalidDatabaseCompatibility_ReturnsFalse()
        {
            var configurationDal = Substitute.For<IConfigurationDataAccess>();

            var configuration = new StumpsConfiguration(configurationDal)
            {
                DataCompatibilityVersion = StumpsConfiguration.MinimumDataCompatibilityVersion - 1,
                StoragePath = Path.GetTempPath(),
                WebApiPort = 8000
            };

            Assert.IsFalse(configuration.ValidateConfigurationSettings());

            configuration.DataCompatibilityVersion = StumpsConfiguration.MaximumDataCompatibilityVersion + 1;

            Assert.IsFalse(configuration.ValidateConfigurationSettings());
        }
Ejemplo n.º 18
0
        public void ValidConfiguration_WithInvalidStoragePath_ReturnsFalse()
        {
            var configurationDal = Substitute.For<IConfigurationDataAccess>();

            var configuration = new StumpsConfiguration(configurationDal)
            {
                DataCompatibilityVersion = 1,
                StoragePath = null,
                WebApiPort = 8000
            };

            Assert.IsFalse(configuration.ValidateConfigurationSettings());

            configuration.StoragePath = "junkstorage";

            Assert.IsFalse(configuration.ValidateConfigurationSettings());

            configuration.StoragePath = "test >> &&& // \\ || bad path";
            Assert.IsFalse(configuration.ValidateConfigurationSettings());
        }
Ejemplo n.º 19
0
        public void ValidConfiguration_WithValidValues_ReturnsTrue()
        {
            var configurationDal = Substitute.For<IConfigurationDataAccess>();
            var configuration = new StumpsConfiguration(configurationDal)
            {
                DataCompatibilityVersion = 1,
                StoragePath = Path.GetTempPath(),
                WebApiPort = 8000
            };

            Assert.IsTrue(configuration.ValidateConfigurationSettings());
        }