예제 #1
0
        private void ExecuteTemplateApiTests(TableInfo tableInfo, Context configContext, IEnumerable <Info> infos)
        {
            var pathOutput = PathOutput.PathOutputApiTest(tableInfo, configContext);

            if (!tableInfo.MakeTest)
            {
                return;
            }

            if (!tableInfo.MakeApi)
            {
                return;
            }


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

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

            var pathTemplateMoqValues = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), DefineTemplateName.ApiTestMoqValues(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#>", item.Type == "string" ? item.Length : string.Empty).
                                Replace("<#moqMethod#>", DefineMoqMethd(item.Type));

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

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


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