A class that represents the persisted form of the configuration information.
        public void SaveConfiguration_WithValidEntity_CreateExpectedFile()
        {
            var tempFile = Path.GetTempFileName();

            try
            {
                var dal = new ConfigurationDataAccess(tempFile);
                var entity = new ConfigurationEntity
                {
                    DataCompatibilityVersion = 100,
                    StoragePath = "C:\\SomeValue\\",
                    WebApiPort = 8000
                };

                dal.SaveConfiguration(entity);

                var savedText = File.ReadAllText(tempFile);

                StringAssert.AreEqualIgnoringCase(TestData.SampleConfiguration, savedText);
            }
            finally
            {
                File.Delete(tempFile);
            }
        }
Пример #2
0
        public void SaveConfiguration_WithValidEntity_CreateExpectedFile()
        {
            var tempFile = Path.GetTempFileName();

            try
            {
                var dal    = new ConfigurationDataAccess(tempFile);
                var entity = new ConfigurationEntity
                {
                    DataCompatibilityVersion = 100,
                    StoragePath = "C:\\SomeValue\\",
                    WebApiPort  = 8000
                };

                dal.SaveConfiguration(entity);

                var savedText = File.ReadAllText(tempFile);

                StringAssert.AreEqualIgnoringCase(TestData.SampleConfiguration, savedText);
            }
            finally
            {
                File.Delete(tempFile);
            }
        }
Пример #3
0
        /// <summary>
        /// Persists the specified <see cref="T:Stumps.Server.Data.ConfigurationEntity" /> to the data store.
        /// </summary>
        /// <param name="value">The <see cref="T:Stumps.Server.Data.ConfigurationEntity" /> to persist in the store.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="value"/> is <c>null</c>.</exception>
        public void SaveConfiguration(ConfigurationEntity value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            JsonUtility.SerializeToFile(value, _configurationFile);
        }
Пример #4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Server.StumpsConfiguration"/> class.
        /// </summary>
        /// <param name="dataAccess">The data access.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="dataAccess"/> is <c>null</c>.</exception>
        public StumpsConfiguration(IConfigurationDataAccess dataAccess)
        {
            if (dataAccess == null)
            {
                throw new ArgumentNullException("dataAccess");
            }

            _dataAccess = dataAccess;
            _configurationEntity = CreateDefaultConfigurationEntity();
        }
Пример #5
0
        private ConfigurationEntity CreateSampleConfigurationEntity()
        {
            var entity = new ConfigurationEntity
            {
                DataCompatibilityVersion = 15,
                StoragePath = @"C:\temp\",
                WebApiPort = 8000
            };

            return entity;
        }
        /// <summary>
        /// Persists the specified <see cref="ConfigurationEntity" /> to the data store.
        /// </summary>
        /// <param name="value">The <see cref="ConfigurationEntity" /> to persist in the store.</param>
        /// <exception cref="ArgumentNullException"><paramref name="value"/> is <c>null</c>.</exception>
        public void SaveConfiguration(ConfigurationEntity value)
        {
            value = value ?? throw new ArgumentNullException(nameof(value));

            JsonUtility.SerializeToFile(value, _configurationFile);
        }
Пример #7
0
 /// <summary>
 ///     Loads the configuration from the data store.
 /// </summary>
 public void LoadConfiguration()
 {
     _configurationEntity = _dataAccess.LoadConfiguration();
 }
Пример #8
0
        /// <summary>
        ///     Creates a default configuration entity.
        /// </summary>
        /// <returns>
        ///     A <see cref="T:Stumps.Server.Data.ConfigurationEntity"/> initalized with the default values.
        /// </returns>
        private static ConfigurationEntity CreateDefaultConfigurationEntity()
        {
            var entity = new ConfigurationEntity
            {
                DataCompatibilityVersion = DefaultConfigurationSettings.DataCompatibilityVersion,
                StoragePath = DefaultConfigurationSettings.StoragePath,
                WebApiPort = DefaultConfigurationSettings.WebApiPort
            };

            return entity;
        }