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();
        }
		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);
		}
Ejemplo n.º 3
0
        public static void MigrateSettings(this SmartObjectContext ctx, Action <SettingsBuilder> fn)
        {
            Guard.NotNull(ctx, nameof(ctx));
            Guard.NotNull(fn, nameof(fn));

            var builder = new SettingsBuilder();

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

            var migrator = new SettingsMigrator(ctx);

            migrator.Migrate(entries);
        }
        public void Can_add_setting_entries()
        {
            var settings = context.Set<Setting>();
            settings.Any().ShouldBeFalse();

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

            ReloadContext();
            settings = context.Set<Setting>();

            settings.ToList().Count.ShouldEqual(8);
            settings.RemoveRange(settings.ToList());
            context.SaveChanges();
        }