public void Can_delete_resource_entries()
        {
            var resources = context.Set <LocaleStringResource>();

            resources.Any().ShouldBeFalse();

            var entries  = GetDefaultResourceEntries();
            var migrator = new LocaleResourcesMigrator(context);

            migrator.Migrate(entries);

            var builder = new LocaleResourcesBuilder();

            builder.DeleteFor("de", "Res1", "Res2", "Res3");
            builder.DeleteFor("en", "Res1");
            context.DetachEntities <Language>();
            migrator.Migrate(builder.Build());

            resources.ToList().Count.ShouldEqual(2);

            builder.Reset();
            builder.DeleteFor("en", "Res2");
            context.DetachEntities <Language>();
            migrator.Migrate(builder.Build());

            resources.ToList().Count.ShouldEqual(1);
        }
Beispiel #2
0
        public void Can_update_resource_entries()
        {
            var resources = context.Set <LocaleStringResource>();

            resources.Any().ShouldBeFalse();

            var entries  = GetDefaultResourceEntries();
            var migrator = new LocaleResourcesMigrator(context);

            migrator.Migrate(entries);

            var builder = new LocaleResourcesBuilder();

            builder.AddOrUpdate("Res1").Value("NewValue1");
            migrator.Migrate(builder.Build());

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

            var updated = resources.Where(x => x.ResourceName == "Res1").ToList();

            updated.Count.ShouldEqual(2);
            updated.Each(x => x.ResourceValue.ShouldEqual("NewValue1"));

            resources.RemoveRange(resources.ToList());
            context.SaveChanges();
        }
        private IEnumerable <LocaleResourceEntry> GetDefaultResourceEntries()
        {
            var builder = new LocaleResourcesBuilder();

            builder.AddOrUpdate("Res1").Value("en", "Value1");
            builder.AddOrUpdate("Res2").Value("en", "Value2");
            builder.AddOrUpdate("Res3").Value("en", "Value3");
            builder.AddOrUpdate("Res1").Value("de", "Wert1");
            builder.AddOrUpdate("Res2").Value("de", "Wert2");
            builder.AddOrUpdate("Res3").Value("de", "Wert3");

            return(builder.Build());
        }
Beispiel #4
0
        private void ExecutePendingResourceMigrations(string resPath)
        {
            string headPath = Path.Combine(resPath, "head.txt");

            if (!File.Exists(headPath))
            {
                return;
            }

            string resHead = File.ReadAllText(headPath);

            if (!MigratorUtils.IsValidMigrationId(resHead))
            {
                return;
            }

            var migrator   = new DbMigrator(new MigrationsConfiguration());
            var migrations = GetPendingResourceMigrations(migrator, resHead);

            foreach (var id in migrations)
            {
                if (MigratorUtils.IsAutomaticMigration(id))
                {
                    continue;
                }

                if (!MigratorUtils.IsValidMigrationId(id))
                {
                    continue;
                }

                // Resolve and instantiate the DbMigration instance from the assembly
                var migration = MigratorUtils.CreateMigrationInstanceByMigrationId(id, migrator.Configuration);

                var provider = migration as ILocaleResourcesProvider;
                if (provider == null)
                {
                    continue;
                }

                var builder = new LocaleResourcesBuilder();
                provider.MigrateLocaleResources(builder);

                var resEntries  = builder.Build();
                var resMigrator = new LocaleResourcesMigrator(_ctx);
                resMigrator.Migrate(resEntries);
            }
        }