Ejemplo n.º 1
0
        private void ExecuteTemplateAppTestsMoq(TableInfo tableInfo, Context configContext, IEnumerable <Info> infos)
        {
            if (!tableInfo.MakeApp)
            {
                return;
            }


            var pathOutput        = PathOutput.PathOutputApplicationTestMoq(tableInfo, configContext);
            var pathTemplateClass = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), DefineTemplateName.AppTestMoq(tableInfo));

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

            var pathTemplateMoqValues = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), DefineTemplateName.AppTestMoqValues(tableInfo));

            var textTemplateClass     = Read.AllText(tableInfo, pathTemplateClass, this._defineTemplateFolder);
            var TextTemplateMoqValues = Read.AllText(tableInfo, pathTemplateMoqValues, this._defineTemplateFolder);

            var classBuilder = GenericTagsTransformer(tableInfo, configContext, textTemplateClass);

            var classBuilderMoqValues = string.Empty;

            foreach (var item in infos)
            {
                if (item.IsKey == 1)
                {
                    continue;
                }

                if (Audit.IsAuditField(item.PropertyName))
                {
                    continue;
                }

                var itemvalue = TextTemplateMoqValues.
                                Replace("<#propertyName#>", item.PropertyName).
                                Replace("<#length#>", IsString(item) && IsNotVarcharMax(item) ? item.Length : string.Empty).
                                Replace("<#moqMethod#>", DefineMoqMethd(item.Type));

                classBuilderMoqValues += string.Format("{0}{1}", itemvalue, System.Environment.NewLine);
            }

            classBuilder = classBuilder.Replace("<#moqValuesinsert#>", classBuilderMoqValues);

            using (var stream = new HelperStream(pathOutput).GetInstance())
            {
                stream.Write(classBuilder);
            }
        }