Esempio n. 1
0
        public static string ConvertTestBase(TestMetaData testMetaData)
        {
            var result = string.IsNullOrEmpty(testMetaData.CleanupBody.Name) ? _testBaseClassTemplate : _testBaseClassWithCleanupTemplate;

            result = ReplacePart(result, "[CLASSNAME]", testMetaData.ClassName);
            result = ReplacePart(result, "[BASECLASSNAME]", testMetaData.GetBaseClassAsString());
            result = ReplacePart(result, "[CLASSATTRIBUTES]", testMetaData.GetClassAttributesAsString());
            result = ReplacePart(result, "[FIELDS]", string.Join("\n", testMetaData.Fields));
            result = ReplacePart(result, "[BECAUSE]", testMetaData.BecauseBody.Body);
            result = ReplacePart(result, "[ESTABLISH]", testMetaData.EstablishBody.Body);
            result = ReplacePart(result, "[METHODS]", string.Join("\n", testMetaData.Methods));
            result = ReplacePart(result, "[INNERCLASSES]", string.Join("\n", testMetaData.Classes));
            result = ReplacePart(result, "[DISPOSE]", testMetaData.CleanupBody.Body);
            result = ReplacePart(result, "[CLASSNAME]", testMetaData.ClassName);

            return(Prettify(result));
        }
Esempio n. 2
0
        public static TestMetaData ParseClass(ClassDeclarationSyntax syntax)
        {
            var testMetaData = new TestMetaData();

            testMetaData.Syntax          = syntax;
            testMetaData.ClassName       = syntax.Identifier.Text;
            testMetaData.ClassModifiers  = syntax.Modifiers.ToString();
            testMetaData.BaseClassName   = ParseBaseClass(syntax);
            testMetaData.ClassAttributes = ParseClassAttributes(syntax);
            testMetaData.Ignore          = ParseIgnoreAttribute(syntax);
            testMetaData.Tags            = ParseTagsAttributes(syntax);
            testMetaData.Tags.AddRange(ParseSubjectAttributes(syntax).ToList());
            testMetaData.EstablishBody = ParseFieldDeclaration(syntax, "Establish");
            testMetaData.BecauseBody   = ParseFieldDeclaration(syntax, "Because");
            testMetaData.CleanupBody   = ParseFieldDeclaration(syntax, "Cleanup");
            testMetaData.Asserts       = ParseAsserts(syntax, "It");
            testMetaData.Fields        = ParseFields(syntax);
            testMetaData.Methods       = ParseMethods(syntax);
            testMetaData.Classes       = ParseInnerClasses(syntax);

            return(testMetaData);
        }