public void Can_delete_and_add_setting_entries()
        {
            var settings = context.Set <Setting>();

            settings.Any().ShouldBeFalse();

            var entries  = GetDefaultSettingEntries();
            var migrator = new SettingsMigrator(context);

            migrator.Migrate(entries);

            var builder = new SettingsBuilder();

            builder.Delete("type1.setting1", "type2.setting1");
            migrator.Migrate(builder.Build());

            settings.ToList().Count.ShouldEqual(6);

            builder.Reset();
            builder.DeleteGroup("type1");
            migrator.Migrate(builder.Build());
            settings.ToList().Count.ShouldEqual(3);

            builder.Reset();
            builder.Add("type3.Setting1", true);
            builder.Add("type3.Setting2", 20);
            migrator.Migrate(builder.Build());
            var db = settings.ToList();

            db.Count.ShouldEqual(5);

            var st = settings.Where(x => x.Name == "type3.Setting2").FirstOrDefault();

            st.Value.ShouldEqual("20");
        }
        public void Can_delete_and_add_setting_entries()
        {
            var settings = context.Set<Setting>();
            settings.Any().ShouldBeFalse();

            var entries = GetDefaultSettingEntries();
            var migrator = new SettingsMigrator(context);
            migrator.Migrate(entries);

            var builder = new SettingsBuilder();
            builder.Delete("type1.setting1", "type2.setting1");
            migrator.Migrate(builder.Build());

            settings.ToList().Count.ShouldEqual(6);

            builder.Reset();
            builder.DeleteGroup("type1");
            migrator.Migrate(builder.Build());
            settings.ToList().Count.ShouldEqual(3);

            builder.Reset();
            builder.Add("type3.Setting1", true);
            builder.Add("type3.Setting2", 20);
            migrator.Migrate(builder.Build());
            var db = settings.ToList();
            db.Count.ShouldEqual(5);

            var st = settings.Where(x => x.Name == "type3.Setting2").FirstOrDefault();
            st.Value.ShouldEqual("20");

            settings.RemoveRange(db);
            context.SaveChanges();
        }
Beispiel #3
0
        public void MissingPropertyWithoutDefaultFailsValidation()
        {
            var builder = new SettingsBuilder()
                          .UseSettingsDictionary(_settingsDictionary);

            Assert.Throws <ConfigurationException>(() => {
                builder.Build <UnresolvedPropertySettings>();
            });
        }
		public static void MigrateSettings(this SmartObjectContext ctx, Action<SettingsBuilder> fn)
		{
			Guard.ArgumentNotNull(() => ctx);
			Guard.ArgumentNotNull(() => fn);

			var builder = new SettingsBuilder();
			fn(builder);
			var entries = builder.Build();

			var migrator = new SettingsMigrator(ctx);
			migrator.Migrate(entries);
		}
        public void BuildCreatesValidXml()
        {
            // Arrange
            var json    = "[{\"SearchTerm\": \"bob\",\"ReplaceWith\": \"#\"}]";
            var builder = new SettingsBuilder();

            // Act
            var xml = builder.Build(json);

            // Assert
            xml.Should().HaveLength(270);
        }
Beispiel #6
0
        public void ShouldBeWithOnCreateCacheEntry()
        {
            var action  = new Action <MemoryCacheEntryOptions>(m => m.Size = 1024);
            var builder =
                new SettingsBuilder()
                .OnCreateCacheEntry(action);
            var expected = builder.Build();

            expected.OnCreateCacheEntry.Should()
            .NotBeNull();
            expected.OnCreateCacheEntry.Should()
            .Be(action);
        }
Beispiel #7
0
        public void ShouldBeWithQueryCache()
        {
            var cacheMemory = new MemoryCache(new MemoryCacheOptions());
            var builder     =
                new SettingsBuilder()
                .QueryCache(cacheMemory);
            var expected = builder.Build();

            expected.QueryCache.Should()
            .NotBeNull();

            expected.QueryCache.Should()
            .Be(cacheMemory);
        }
        private IEnumerable <SettingEntry> GetDefaultSettingEntries()
        {
            var builder = new SettingsBuilder();

            builder.Add("Type1.Setting1", true);
            builder.Add("Type1.Setting2", 10);
            builder.Add("Type1.Setting3", "SomeString");
            builder.Add("Type1.Setting4", DateTime.Now);
            builder.Add("Type2.Setting1", false);
            builder.Add("Type2.Setting2", 5);
            builder.Add("Type2.Setting3", "SomeString2");
            builder.Add("Type2.Setting4", DateTime.UtcNow);

            return(builder.Build());
        }
Beispiel #9
0
        /// <summary>
        /// Provides a way to retrieve settings through an sql connection.
        /// </summary>
        /// <param name="settingsBuilder"></param>
        /// <param name="dbConnection"></param>
        /// <param name="dbCommand"></param>
        /// <param name="connectionStringKey"></param>
        /// <returns></returns>
        public static SettingsBuilder UseSql(this SettingsBuilder settingsBuilder, IDbConnection dbConnection,
                                             string connectionStringKey = null, string query = null, bool disposeConnection = true)
        {
            if (connectionStringKey != null)
            {
                var settings         = settingsBuilder.Build();
                var connectionString = settings.Get(connectionStringKey);
                dbConnection.ConnectionString = connectionString ??
                                                throw new Exception($"ConnectionString with key '{connectionStringKey}' was not found in the settings.");
            }

            IDbCommand dbCommand = dbConnection.CreateCommand();

            dbCommand.CommandText = query ?? "SELECT key,value FROM FigSettings";
            var settingsDictionary = new SqlSettingsSource(dbConnection, dbCommand, disposeConnection).ToSettingsDictionary();

            return(settingsBuilder.UseSettingsDictionary(settingsDictionary));
        }
Beispiel #10
0
        /// <summary>
        ///     Adds the RS ql.
        /// </summary>
        /// <returns>The RS ql.</returns>
        /// <param name="mvcBuilder">Services.</param>
        /// <param name="optionsAction">options action.</param>
        public static IMvcBuilder AddRSql(this IMvcBuilder mvcBuilder,
                                          Action <SettingsBuilder> optionsAction = null)
        {
            if (mvcBuilder == null)
            {
                throw new ArgumentNullException(nameof(mvcBuilder));
            }

            var builder = new SettingsBuilder();

            optionsAction?.Invoke(builder);
            var settings = builder.Build();

            mvcBuilder.Services.AddSingleton(settings);
            mvcBuilder.AddMvcOptions(c =>
            {
                c.ModelBinderProviders.Insert(0,
                                              new RSqlPageableModelBinderProvider());
                c.ModelBinderProviders.Insert(1,
                                              new RSqlQueryModelBinderProvider());
            });
            return(mvcBuilder);
        }
Beispiel #11
0
        public void ShouldBeCustomValidBuilder()
        {
            var builder = new SettingsBuilder();

            builder
            .PageNumberFieldName("a")
            .PageSize(2)
            .PageSizeFieldName("b")
            .QueryFieldName("c")
            .SortFieldName("d");

            var expected = builder.Build();

            expected
            .PageNumberField.Should().Be("a");
            expected
            .PageSize.Should().Be(2);
            expected
            .PageSizeField.Should().Be("b");
            expected
            .QueryField.Should().Be("c");
            expected
            .SortField.Should().Be("d");
        }
        private IEnumerable<SettingEntry> GetDefaultSettingEntries()
        {
            var builder = new SettingsBuilder();
            builder.Add("Type1.Setting1", true);
            builder.Add("Type1.Setting2", 10);
            builder.Add("Type1.Setting3", "SomeString");
            builder.Add("Type1.Setting4", DateTime.Now);
            builder.Add("Type2.Setting1", false);
            builder.Add("Type2.Setting2", 5);
            builder.Add("Type2.Setting3", "SomeString2");
            builder.Add("Type2.Setting4", DateTime.UtcNow);

            return builder.Build();
        }