Exemple #1
0
        public void CloneLocalizedResourcesWorksAsExpectedWithOverrideAndDefault()
        {
            // --- Arrange
            SqlScriptHelper.RunScript("InitLocalizedResources.sql");
            SqlScriptHelper.RunScript("SetupCloneScenario.sql");
            var service = ServiceManager.GetService <IConfigurationService>();

            // --- Act
            service.CloneLocalizedResources(new CloneLocalizedResourcesDto
            {
                BaseCode                  = "def",
                TargetCode                = "fr",
                DefaultResourceValue      = "magic",
                OverrideExistingResources = true
            });

            // --- Assert
            var resources = service.GetLocalizedResourcesByCategory("fr", "Message");

            resources.ShouldHaveCountOf(2);
            // ReSharper disable PossibleNullReferenceException
            resources.FirstOrDefault(r => r.ResourceKey == "1").Value.ShouldEqual("magic"); // --- Ez az Override ereménye
            resources.FirstOrDefault(r => r.ResourceKey == "2").Value.ShouldEqual("magic");
            resources = service.GetLocalizedResourcesByCategory("fr", "Error");
            resources.ShouldHaveCountOf(1);
            resources.FirstOrDefault(r => r.ResourceKey == "1").Value.ShouldEqual("magic");
            // ReSharper restore PossibleNullReferenceException
        }
Exemple #2
0
        static void InitDbScheme(IUtHelper utHelper, bool recreateDb = false)
        {
            JsonHelper.JsonSerialize = new NhJsonSerialize();

            NHibernateProfiler.Initialize();

            //FluentNhibernateConvertions.Conventions.Add(new Nb_ForeignKeyConstraintNameConvention());
            //DbSettingHelper.ShowSql = true;
            //DbSettingHelper.ConnString = @"Data Source=.;AttachDbFilename=|DataDirectory|\App_Data\DemoDb.mdf;Integrated Security=True;Connect Timeout=30";

            var dbName     = "DemoDb";
            var connString = string.Format(@"Data Source=.;Initial Catalog={0};Persist Security Info=True;User ID=sa;Password=zqnb_123", dbName);

            DbSettingHelper.ConnString = connString;

            var sqlScriptHelper = new SqlScriptHelper();

            if (recreateDb)
            {
                sqlScriptHelper.ReCreateDbIfExist(connString, dbName);
            }
            else
            {
                sqlScriptHelper.CreateDbIfNotExist(connString, dbName);
            }

            utHelper.SetUpNHibernate(recreateDb, typeof(Program));
            ShowSplit("Setup Done!");
            Console.WriteLine();
        }
Exemple #3
0
        public void GetLocalizedResourcesCategoryWorksAsExpected()
        {
            // --- Arrange
            SqlScriptHelper.RunScript("InitLocalizedResources.sql");
            var service = ServiceManager.GetService <IConfigurationService>();

            // --- Act
            var cat1Def  = service.GetLocalizedResourcesByCategory("def", "Message");
            var cat2EnUs = service.GetLocalizedResourcesByCategory("en-us", "Error");

            // --- Arrange
            cat1Def.ShouldHaveCountOf(3);
            cat1Def.Select(i => i.ResourceKey).ShouldContain("1");
            cat1Def.Select(i => i.ResourceKey).ShouldContain("2");
            cat1Def.Select(i => i.ResourceKey).ShouldContain("3");
            // ReSharper disable PossibleNullReferenceException
            cat1Def.FirstOrDefault(i => i.ResourceKey == "1").Value.ShouldEqual("Value1");
            cat1Def.FirstOrDefault(i => i.ResourceKey == "2").Value.ShouldEqual("Value2");
            cat1Def.FirstOrDefault(i => i.ResourceKey == "3").Value.ShouldEqual("Value3");
            // ReSharper restore PossibleNullReferenceException

            cat2EnUs.ShouldHaveCountOf(2);
            cat2EnUs.Select(i => i.ResourceKey).ShouldContain("1");
            cat2EnUs.Select(i => i.ResourceKey).ShouldContain("2");
            // ReSharper disable PossibleNullReferenceException
            cat2EnUs.FirstOrDefault(i => i.ResourceKey == "1").Value.ShouldEqual("One US");
            cat2EnUs.FirstOrDefault(i => i.ResourceKey == "2").Value.ShouldEqual("Two US");
            // ReSharper restore PossibleNullReferenceException
        }
Exemple #4
0
        public void GetListItemWorksAsExpected()
        {
            // --- Arrange
            SqlScriptHelper.RunScript("InitListItems.sql");
            var service = ServiceManager.GetService <IConfigurationService>();

            // --- Act
            var typesDef = service.GetListItems("Type");
            var catHu    = service.GetListItems("Cat", "hu");
            var catDe    = service.GetListItems("Cat", "de");

            // --- Assert
            typesDef.ShouldHaveCountOf(3);
            typesDef.First(l => l.Id == "1").DisplayName.ShouldEqual("Type.Value1");
            typesDef.First(l => l.Id == "1").Description.ShouldEqual("Type.Des1");
            typesDef.First(l => l.Id == "2").DisplayName.ShouldEqual("Type.Value2");
            typesDef.First(l => l.Id == "2").Description.ShouldEqual("Type.Des2");
            typesDef.First(l => l.Id == "3").DisplayName.ShouldEqual("Type.Value3");
            typesDef.First(l => l.Id == "3").Description.ShouldEqual("Type.Des3");

            catHu.ShouldHaveCountOf(2);
            catHu.First(l => l.Id == "F").DisplayName.ShouldEqual("Cat.1");
            catHu.First(l => l.Id == "F").Description.ShouldEqual("Cat.D1");
            catHu.First(l => l.Id == "S").DisplayName.ShouldEqual("Cat.2");
            catHu.First(l => l.Id == "S").Description.ShouldEqual("Cat.D2");

            catDe.ShouldHaveCountOf(2);
            catDe.First(l => l.Id == "F").DisplayName.ShouldEqual("Cat.Value1");
            catDe.First(l => l.Id == "F").Description.ShouldEqual("Cat.Des1");
            catDe.First(l => l.Id == "S").DisplayName.ShouldEqual("Cat.Value2");
            catDe.First(l => l.Id == "S").Description.ShouldEqual("Cat.Des2");
        }
Exemple #5
0
 public static void InitializeClass(TestContext context)
 {
     ServiceManager.SetRegistry(new DefaultServiceRegistry());
     ServiceManager.Register <IConfigurationDataOperations, ConfigurationDataOperations>(DB_CONN);
     ServiceManager.Register <IConfigurationService, ConfigurationService>();
     DataAccessFactory.SetRegistry(ServiceManager.ServiceRegistry);
     SqlScriptHelper.RunScript("InitMultipleLocales.sql");
 }
Exemple #6
0
        public void GetListItemFailsWithNonExistingList()
        {
            // --- Arrange
            SqlScriptHelper.RunScript("InitListItems.sql");
            var service = ServiceManager.GetService <IConfigurationService>();

            // --- Act
            service.GetListItems("Dummy");
        }
        public void TestInitialize()
        {
            ServiceManager.SetRegistry(new DefaultServiceRegistry());
            ServiceManager.Register <IConfigurationDataOperations, ConfigurationDataOperations>(DB_CONN);
            DataAccessFactory.SetRegistry(ServiceManager.ServiceRegistry);

            SqlScriptHelper.RunScript("InitConfigurationValues.sql");
            MsSqlConfigurationHandler.Reset(TimeSpan.FromSeconds(10));
        }
Exemple #8
0
        public void GetLocalizedResourceCategoriesWorksAsExpected()
        {
            // --- Arrange
            SqlScriptHelper.RunScript("InitLocalizedResources.sql");
            var service = ServiceManager.GetService <IConfigurationService>();

            // --- Act
            var categories = service.GetLocalizedResourceCategories();

            // --- Assert
            categories.ShouldHaveCountOf(2);
            categories.ShouldContain("Message");
            categories.ShouldContain("Error");
        }
Exemple #9
0
        public void RemoveLocaleWorksAsExpected()
        {
            // --- Arrange
            SqlScriptHelper.RunScript("InitLocalizedResources.sql");
            var service = ServiceManager.GetService <IConfigurationService>();

            // --- Act
            var huMessagesBefore = service.GetLocalizedResourcesByCategory("hu", "Message");
            var huErrorsBefore   = service.GetLocalizedResourcesByCategory("hu", "Error");

            service.RemoveLocale("hu");
            var huMessagesAfter = service.GetLocalizedResourcesByCategory("hu", "Message");
            var huErrorsAfter   = service.GetLocalizedResourcesByCategory("hu", "Error");

            // --- Assert
            huMessagesBefore.ShouldHaveCountOf(3);
            huMessagesAfter.ShouldHaveCountOf(0);
            huErrorsBefore.ShouldHaveCountOf(2);
            huErrorsAfter.ShouldHaveCountOf(0);
        }
Exemple #10
0
 public void Initialize()
 {
     SqlScriptHelper.RunScript("InitEmailTemplates.sql");
     EmailSenderTask.ResetCache();
 }
Exemple #11
0
 public void TestInitialize()
 {
     SqlScriptHelper.RunScript("InitLocales.sql");
 }
Exemple #12
0
        private string GenerateScript(SyncDatabaseExecuteConfig executeConfig)
        {
            StringBuilder builder = new StringBuilder();

            using (SqlConnection connection = new SqlConnection(executeConfig.ConnectionString))
            {
                connection.Open();
                // Clear script
                if (executeConfig.ClearSQL != null)
                {
                    builder.AppendLine(executeConfig.ClearSQL);
                }

                foreach (DataTable table in this._dataSet.Tables)
                {
                    string tableName = table.TableName;
                    if (SyncDatabaseConfig.DefaultSheetName.Equals(tableName, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    SqlColumnInfo[] allColumnInfos = SqlDatabaseHelper.GetColumnInfos(connection, tableName);
                    // Filter available columns
                    List <SqlColumnInfo> usedColumnInfos = new List <SqlColumnInfo>();

                    List <int> usedColumnIndices = new List <int>();
                    for (int columnIndex = 0; columnIndex < table.Columns.Count; columnIndex++)
                    {
                        string        columnName = table.Columns[columnIndex].ColumnName;
                        SqlColumnInfo columnInfo = allColumnInfos.FirstOrDefault(p => p.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase));
                        if (columnInfo != null)
                        {
                            usedColumnInfos.Add(columnInfo);
                            usedColumnIndices.Add(columnIndex);
                        }
                    }

                    string template = null;
                    switch (executeConfig.Mode)
                    {
                    case SyncDatabaseMode.Insert:
                        template = SqlScriptHelper.GenerateInsertScript(usedColumnInfos, tableName);
                        break;

                    case SyncDatabaseMode.InsertNotExists:
                        template = SqlScriptHelper.GenerateInsertIfNotExistsScript(usedColumnInfos, tableName);
                        break;

                    case SyncDatabaseMode.Merge:
                        template = SqlScriptHelper.GenerateMergeScript(null, usedColumnInfos, tableName);
                        break;
                    }

                    builder.AppendLine($"-- {tableName}");
                    builder.AppendLine($"IF EXISTS (SELECT 1 FROM sys.identity_columns WHERE object_id = object_id('{tableName}')) SET IDENTITY_INSERT [{tableName}] ON");
                    foreach (DataRow row in table.Rows)
                    {
                        string command = template;
                        for (int i = 0; i < usedColumnIndices.Count; i++)
                        {
                            int           columnIndex = usedColumnIndices[i];
                            string        value       = (string)row[columnIndex];
                            string        text        = string.Empty;
                            SqlColumnInfo columnInfo  = usedColumnInfos[i];
                            if (value == "NULL" || string.IsNullOrEmpty(value))
                            {
                                switch (columnInfo.Type)
                                {
                                case SqlColumnType.@text:
                                case SqlColumnType.@ntext:
                                case SqlColumnType.@varchar:
                                case SqlColumnType.@char:
                                case SqlColumnType.@nvarchar:
                                case SqlColumnType.@nchar:
                                case SqlColumnType.@xml:
                                    if (columnInfo.Nullable)
                                    {
                                        text = "null";
                                    }
                                    else
                                    {
                                        text = "''";
                                    }
                                    break;

                                case SqlColumnType.@tinyint:
                                case SqlColumnType.@smallint:
                                case SqlColumnType.@int:
                                case SqlColumnType.@real:
                                case SqlColumnType.@money:
                                case SqlColumnType.@float:
                                case SqlColumnType.@bit:
                                case SqlColumnType.@decimal:
                                case SqlColumnType.@numeric:
                                case SqlColumnType.@smallmoney:
                                case SqlColumnType.@bigint:
                                    if (columnInfo.Nullable)
                                    {
                                        text = "null";
                                    }
                                    else
                                    {
                                        text = "0";
                                    }
                                    break;

                                case SqlColumnType.@date:
                                case SqlColumnType.@datetime2:
                                case SqlColumnType.@time:
                                case SqlColumnType.@datetimeoffset:
                                case SqlColumnType.@smalldatetime:
                                case SqlColumnType.@datetime:
                                    text = "null";
                                    break;

                                case SqlColumnType.@image:
                                case SqlColumnType.@varbinary:
                                case SqlColumnType.@binary:
                                    if (columnInfo.Nullable)
                                    {
                                        text = "null";
                                    }
                                    else
                                    {
                                        text = "0x";
                                    }
                                    break;

                                case SqlColumnType.@uniqueidentifier:
                                    if (columnInfo.Nullable)
                                    {
                                        text = "null";
                                    }
                                    else
                                    {
                                        text = "'00000000-0000-0000-0000-000000000000'";
                                    }
                                    break;

                                default:
                                    throw new NotSupportedException();
                                }
                            }
                            else
                            {
                                switch (columnInfo.Type)
                                {
                                case SqlColumnType.@text:
                                case SqlColumnType.@varchar:
                                case SqlColumnType.@char:
                                    text = $"'{value}'";
                                    break;

                                case SqlColumnType.@ntext:
                                case SqlColumnType.@nvarchar:
                                case SqlColumnType.@nchar:
                                case SqlColumnType.@xml:
                                    text = $"N'{value}'";
                                    break;

                                case SqlColumnType.@bit:
                                    text = $"{Convert.ToInt32(Convert.ToBoolean(value))}";
                                    break;

                                case SqlColumnType.@tinyint:
                                case SqlColumnType.@smallint:
                                case SqlColumnType.@int:
                                case SqlColumnType.@real:
                                case SqlColumnType.@money:
                                case SqlColumnType.@float:
                                case SqlColumnType.@decimal:
                                case SqlColumnType.@numeric:
                                case SqlColumnType.@smallmoney:
                                case SqlColumnType.@bigint:
                                    text = $"{value}";
                                    break;

                                case SqlColumnType.@date:
                                case SqlColumnType.@datetime2:
                                case SqlColumnType.@time:
                                case SqlColumnType.@datetimeoffset:
                                case SqlColumnType.@smalldatetime:
                                case SqlColumnType.@datetime:
                                    text = $"'{value}'";
                                    break;

                                case SqlColumnType.@image:
                                case SqlColumnType.@varbinary:
                                case SqlColumnType.@binary:
                                    text = $"{value}";
                                    break;

                                case SqlColumnType.@uniqueidentifier:
                                    text = $"'{value}'";
                                    break;

                                default:
                                    throw new NotSupportedException();
                                }
                            }

                            command = Regex.Replace(command, $@"@{columnInfo.Name}\b", (m) =>
                            {
                                return(text);
                            });
                        }
                        builder.AppendLine(command);
                    }
                    builder.AppendLine($"IF EXISTS (SELECT 1 FROM sys.identity_columns WHERE object_id = object_id('{tableName}')) SET IDENTITY_INSERT [{tableName}] OFF");
                }
            }

            return(builder.ToString());
        }
Exemple #13
0
        public virtual void CreateDbIfNotExist(string dbserver, string dbname, string dbuser, string dbpassword)
        {
            SqlScriptHelper helper = new SqlScriptHelper();

            helper.CreateDbIfNotExist(dbserver, dbname, dbuser, dbpassword);
        }
Exemple #14
0
        public string Generate()
        {
            StringBuilder outString = new StringBuilder();

            // 执行依赖任务
            if (!string.IsNullOrEmpty(task.Depends))
            {
                string[] depends = task.Depends.Split(',');

                foreach (string depend in depends)
                {
                    // 任务不能自身依赖 避免发生循环引用
                    if (depend == task.Name)
                    {
                        continue;
                    }

                    DataDumpTask dependTask = DataDumpConfiguration.Instance.Tasks[depend];

                    // 重写依赖任务的参数选项和输出数据库类型
                    dependTask.Options      = task.Options;
                    dependTask.OutputDbType = task.OutputDbType;

                    IDataDumpProvider dependProvider = (IDataDumpProvider)KernelContext.CreateObject(dependTask.DataDumpProvider);

                    dependProvider.Init(dependTask);

                    outString.AppendLine(dependProvider.Generate());
                }
            }

            // 执行任务
            string comment, result;

            foreach (TaskStatement statement in task.Statements)
            {
                comment = null;
                result  = null;

                if (!string.IsNullOrEmpty(statement.Description))
                {
                    string[] descriptionLines = statement.Description.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

                    foreach (string descriptionLine in descriptionLines)
                    {
                        if (!string.IsNullOrEmpty(descriptionLine.Trim()))
                        {
                            comment += "-- " + descriptionLine.Trim() + Environment.NewLine;
                        }
                    }
                }

                GenericSqlCommand command = new GenericSqlCommand(task.DataSourceName);

                string sql = statement.Sql;

                foreach (KeyValuePair <string, string> option in options)
                {
                    sql = sql.Replace("$" + option.Key + "$", option.Value);
                }

                DataTable table = command.ExecuteQueryForDataTable(sql);

                if (table.Rows.Count == 0)
                {
                    continue;
                }

                result = SqlScriptHelper.GenerateDateTableScript(task.OutputDbType, statement.DestTable, table);

                outString.Append(comment);
                outString.AppendLine(result);
            }

            return(outString.ToString());
        }
Exemple #15
0
 public void TestInitialize()
 {
     SqlScriptHelper.RunScript("InitDiveLog.sql");
 }