コード例 #1
0
ファイル: TestDbGenerator.cs プロジェクト: dyancl1024/Rafy
        public static void GenerateDb()
        {
            if (ConfigurationHelper.GetAppSettingOrDefault("单元测试-生成数据库", false))
            {
                if (ClearDb && ConfigurationHelper.GetAppSettingOrDefault("单元测试-生成数据库-先清空数据库", false))
                {
                    //不想手工去删除数据库,可以使用下面这个方法来在程序中删除所有的表。
                    DropAllTables();

                    ClearDb = false;
                }

                using (var c = new RafyDbMigrationContext(DbSettingNames.DbMigrationHistory))
                {
                    c.RunDataLossOperation = DataLossOperation.All;
                    c.AutoMigrate();
                }
                using (var c = new RafyDbMigrationContext(DbSettingNames.RafyPlugins))
                {
                    c.HistoryRepository    = new DbHistoryRepository();
                    c.RunDataLossOperation = DataLossOperation.All;
                    c.AutoMigrate();
                }
                using (var c = new RafyDbMigrationContext(UnitTestEntityRepositoryDataProvider.DbSettingName))
                {
                    c.HistoryRepository    = new DbHistoryRepository();
                    c.RunDataLossOperation = DataLossOperation.All;
                    c.AutoMigrate();
                }
                UnitTestPlugin.InitailizeSequences();

                using (RdbDataProvider.RedirectDbSetting(
                           UnitTestEntityRepositoryDataProvider.DbSettingName,
                           UnitTestEntityRepositoryDataProvider.DbSettingName_Duplicate
                           ))
                {
                    using (var c = new RafyDbMigrationContext(UnitTestEntityRepositoryDataProvider.DbSettingName_Duplicate))
                    {
                        c.ClassMetaReader.EntityDbSettingName    = UnitTestEntityRepositoryDataProvider.DbSettingName;
                        c.ClassMetaReader.IsGeneratingForeignKey = false;
                        c.HistoryRepository    = new DbHistoryRepository();
                        c.RunDataLossOperation = DataLossOperation.All;
                        c.AutoMigrate();
                    }
                    UnitTestPlugin.InitailizeSequences();
                }
                using (var c = new RafyDbMigrationContext(UnitTest2EntityRepositoryDataProvider.DbSettingName))
                {
                    c.HistoryRepository    = new DbHistoryRepository();
                    c.RunDataLossOperation = DataLossOperation.All;
                    c.AutoMigrate();
                }
                using (var c = new RafyDbMigrationContext(StringTestEntityDataProvider.DbSettingName))
                {
                    c.HistoryRepository    = new DbHistoryRepository();
                    c.RunDataLossOperation = DataLossOperation.All;
                    c.AutoMigrate();
                }
            }
        }
コード例 #2
0
        public void RegisterShouldThrowExceptionIfIncorrectEntityReferenceIsPassedThrough()
        {
            var context    = new XrmFakedContext();
            var orgService = context.GetOrganizationService();

            Assert.Throws <ArgumentException>(
                () => UnitTestPlugin.Register(orgService, new SdkMessageProcessingStep().ToEntityReference()));
        }
コード例 #3
0
 public void NotifyPropertyChangedTest()
 {
     var plugin = new UnitTestPlugin();
     try
     {
         plugin.NotifyPropertyChanged();
     }
     catch (Exception ex)
     {
         Assert.Fail("Expected no exception, but got: " + ex.Message);
     }
 }
コード例 #4
0
 public async Task InitializeTest()
 {
     var plugin = new UnitTestPlugin();
     try
     {
         await plugin.Initialize(new StubIFeedback<LogEntry>(), new StubIEntityContextConnection(), new StubIAdapterManager());
     }
     catch (Exception ex)
     {
         Assert.Fail("Expected no exception, but got: " + ex.Message);
     }
 }
コード例 #5
0
        public void NotifyPropertyChangedTest()
        {
            var plugin = new UnitTestPlugin();

            try
            {
                plugin.NotifyPropertyChanged();
            }
            catch (Exception ex)
            {
                Assert.Fail("Expected no exception, but got: " + ex.Message);
            }
        }
コード例 #6
0
        public async Task InitializeTest()
        {
            var plugin = new UnitTestPlugin();

            try
            {
                await plugin.Initialize(new StubIFeedback <LogEntry>(), new UnitTestDbConnection(), new StubIAdapterManager());
            }
            catch (Exception ex)
            {
                Assert.Fail("Expected no exception, but got: " + ex.Message);
            }
        }
コード例 #7
0
        public void RegisterNewPluginShouldBeCreated()
        {
            var context    = new XrmFakedContext();
            var orgService = context.GetOrganizationService();

            context.Initialize(new List <Entity>()
            {
                ExistingPluginAssembly
            });

            UnitTestPlugin.Register(orgService, ExistingPluginAssembly.ToEntityReference());

            var registeredPlugin =
                (from p in context.CreateQuery <PluginType>()
                 where p.Name == UnitTestPlugin.Name
                 select p).ToList();

            Assert.AreEqual(1, registeredPlugin.Count);
            Assert.IsNotNull(registeredPlugin[0].Id);
        }
コード例 #8
0
        public static void GenerateDb()
        {
            if (ConfigurationHelper.GetAppSettingOrDefault("Test_GenerateDb", false))
            {
                //生成数据库时,为简单起见,需要先加载所有的插件。
                //注意,此行代码会导致按需加载的单元测试全部通过。
                //所以平时应该通过配置文件来关闭数据库生成功能。
                RafyEnvironment.EnsureAllPluginsLoaded();
                ForceAllPluginsLoaded = true;

                if (ClearDb && ConfigurationHelper.GetAppSettingOrDefault("Test_GenerateDb_Clear", false))
                {
                    //不想手工去删除数据库,可以使用下面这个方法来在程序中删除所有的表。
                    DropAllTables();

                    ClearDb = false;
                }

                using (var c = new RafyDbMigrationContext(DbSettingNames.DbMigrationHistory))
                {
                    c.RunDataLossOperation = DataLossOperation.All;
                    c.AutoMigrate();
                }
                using (var c = new RafyDbMigrationContext(DbSettingNames.RafyPlugins))
                {
                    if (c.DbSetting.ProviderName != DbSetting.Provider_SQLite)
                    {
                        c.HistoryRepository = new DbHistoryRepository();
                    }
                    c.RunDataLossOperation = DataLossOperation.All;
                    c.AutoMigrate();
                }
                using (var c = new RafyDbMigrationContext(UnitTestEntityRepositoryDataProvider.DbSettingName))
                {
                    if (c.DbSetting.ProviderName != DbSetting.Provider_SQLite)
                    {
                        c.HistoryRepository = new DbHistoryRepository();
                    }
                    c.RunDataLossOperation = DataLossOperation.All;
                    c.AutoMigrate();
                }
                UnitTestPlugin.InitailizeSequences();

                using (RdbDataProvider.RedirectDbSetting(
                           UnitTestEntityRepositoryDataProvider.DbSettingName,
                           UnitTestEntityRepositoryDataProvider.DbSettingName_Duplicate
                           ))
                {
                    using (var c = new RafyDbMigrationContext(UnitTestEntityRepositoryDataProvider.DbSettingName_Duplicate))
                    {
                        c.ClassMetaReader.EntityDbSettingName    = UnitTestEntityRepositoryDataProvider.DbSettingName;
                        c.ClassMetaReader.IsGeneratingForeignKey = false;
                        if (c.DbSetting.ProviderName != DbSetting.Provider_SQLite)
                        {
                            c.HistoryRepository = new DbHistoryRepository();
                        }
                        c.RunDataLossOperation = DataLossOperation.All;
                        c.AutoMigrate();
                    }
                    UnitTestPlugin.InitailizeSequences();
                }
                using (var c = new RafyDbMigrationContext(UnitTest2EntityRepositoryDataProvider.DbSettingName))
                {
                    if (c.DbSetting.ProviderName != DbSetting.Provider_SQLite)
                    {
                        c.HistoryRepository = new DbHistoryRepository();
                    }
                    c.RunDataLossOperation = DataLossOperation.All;
                    c.AutoMigrate();
                }
                using (var c = new RafyDbMigrationContext(StringTestEntityDataProvider.DbSettingName))
                {
                    if (c.DbSetting.ProviderName != DbSetting.Provider_SQLite)
                    {
                        c.HistoryRepository = new DbHistoryRepository();
                    }
                    c.RunDataLossOperation = DataLossOperation.All;
                    c.AutoMigrate();
                }
            }
        }