// this method returns an action to generate assert statements for later use
        private Action GenerateTestCodeForField(TestCodeGeneratorContext context, TSLStruct struct_, TSLField field, string writerVarName)
        {
            Action assertAction = null;

            switch (field.Type.FieldType)
            {
            case TSLFieldTypes.Enum:
                assertAction = GenerateTestCodeForEnumField(context, struct_, field, writerVarName);
                break;

            case TSLFieldTypes.Array:
                //assertAction = GenerateTestCodeForArrayField(context, struct_, field, writerVarName);
                break;

            case TSLFieldTypes.Atom:
                //assertAction = GenerateTestCodeForAtomField(context, struct_, field, writerVarName);
                break;

            case TSLFieldTypes.List:
                //assertAction = GenerateTestCodeForListField(context, struct_, field, writerVarName);
                break;

            case TSLFieldTypes.Struct:
                //assertAction = GenerateTestCodeForStructField(context, struct_, field, writerVarName);
                break;

            default:
                throw new NotImplementedException();
            }
            assertAction?.Invoke();
            return(assertAction);
        }
 public NetcoreProjectFileTemplate(TestCodeGeneratorContext context)
 {
     TestName = context.TestName;
 }
Пример #3
0
 public NetfxProjectFileTemplate(TestCodeGeneratorContext context, IEnumerable <string> csFileList)
 {
     TestName   = context.TestName;
     CsFileList = csFileList.ToArray();
 }
        private Action GenerateTestCodeForEnumField(TestCodeGeneratorContext context, TSLStruct struct_, TSLField field, string writerVarName)
        {
            var fieldType    = (TSLEnum)field.Type;
            var randomMember = fieldType.Members.Choice(context.MasterRandom);
            var enumMember   = $"{fieldType.Name}.{randomMember.Item1}";
            var structMember = $"{writerVarName}.{field.Name}";


        #line default
        #line hidden

        #line 46 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write("\r\n            ");


        #line default
        #line hidden

        #line 48 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture($"{structMember} = {enumMember};"));


        #line default
        #line hidden

        #line 48 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write("\r\n");


        #line default
        #line hidden

        #line 49 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            return(() =>
            {
        #line default
        #line hidden

        #line 51 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write("            Assert.That(");


        #line default
        #line hidden

        #line 52 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(structMember));


        #line default
        #line hidden

        #line 52 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(", Is.EqualTo(");


        #line default
        #line hidden

        #line 52 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(enumMember));


        #line default
        #line hidden

        #line 52 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write("));\r\n            Assert.That(");


        #line default
        #line hidden

        #line 53 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture($"(({struct_.Name}){writerVarName}).{field.Name}"));


        #line default
        #line hidden

        #line 53 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(", Is.EqualTo(");


        #line default
        #line hidden

        #line 53 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(enumMember));


        #line default
        #line hidden

        #line 53 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write("));\r\n            Assert.That(");


        #line default
        #line hidden

        #line 54 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture($"(new {struct_.Name}Reader({writerVarName}.CellPtr, 0)).{field.Name}"));


        #line default
        #line hidden

        #line 54 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(", Is.EqualTo(");


        #line default
        #line hidden

        #line 54 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(enumMember));


        #line default
        #line hidden

        #line 54 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write("));\r\n");


        #line default
        #line hidden

        #line 55 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            });
        }
 private Action GenerateTestCodeForStructField(TestCodeGeneratorContext context, TSLStruct struct_, TSLField field, string writerVarName)
 {
     return(() => {});
 }
        private Action GenerateTestCodeForListField(TestCodeGeneratorContext context, TSLStruct struct_, TSLField field, string writerVarName)
        {
            var fieldType    = (ListType)field.Type;
            var randomValue  = fieldType.GetRandomValue(context.MasterRandom);
            var parentMember = $"{writerVarName}.{field.Name}";
            var tempVarName  = $"structFieldTestValue{++context.GeneratedCount}";

            // TODO(leasunhy): support struct lists
            if (fieldType.ElementType.FieldType == TSLFieldTypes.Struct)
            {
                return(null);
            }


        #line default
        #line hidden

        #line 117 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write("        var ");


        #line default
        #line hidden

        #line 118 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(tempVarName));


        #line default
        #line hidden

        #line 118 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(" = ");


        #line default
        #line hidden

        #line 118 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(randomValue));


        #line default
        #line hidden

        #line 118 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(";\r\n        ");


        #line default
        #line hidden

        #line 119 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(parentMember));


        #line default
        #line hidden

        #line 119 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(" = ");


        #line default
        #line hidden

        #line 119 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(tempVarName));


        #line default
        #line hidden

        #line 119 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(";\r\n");


        #line default
        #line hidden

        #line 120 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"

            return(() =>
            {
        #line default
        #line hidden

        #line 123 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write("        Assert.That(");


        #line default
        #line hidden

        #line 124 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(parentMember));


        #line default
        #line hidden

        #line 124 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(", Is.EqualTo(");


        #line default
        #line hidden

        #line 124 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(tempVarName));


        #line default
        #line hidden

        #line 124 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write("));\r\n        Assert.That(");


        #line default
        #line hidden

        #line 125 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture($"(({struct_.Name}){writerVarName}).{field.Name}"));


        #line default
        #line hidden

        #line 125 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(", Is.EqualTo(");


        #line default
        #line hidden

        #line 125 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(tempVarName));


        #line default
        #line hidden

        #line 125 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write("));\r\n        Assert.That(");


        #line default
        #line hidden

        #line 126 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture($"(new {struct_.Name}Reader({writerVarName}.CellPtr, 0)).{field.Name}"));


        #line default
        #line hidden

        #line 126 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(", Is.EqualTo(");


        #line default
        #line hidden

        #line 126 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(tempVarName));


        #line default
        #line hidden

        #line 126 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write("));\r\n");


        #line default
        #line hidden

        #line 127 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            });
        }
        private Action GenerateTestCodeForAtomField(TestCodeGeneratorContext context, TSLStruct struct_, TSLField field, string writerVarName)
        {
            var fieldType    = (AtomType)field.Type;
            var randomValue  = fieldType.GetRandomValue(context.MasterRandom);
            var parentMember = $"{writerVarName}.{field.Name}";
            var tempVarName  = $"structFieldTestValue{++context.GeneratedCount}";


        #line default
        #line hidden

        #line 92 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write("        var ");


        #line default
        #line hidden

        #line 93 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(tempVarName));


        #line default
        #line hidden

        #line 93 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(" = ");


        #line default
        #line hidden

        #line 93 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(randomValue));


        #line default
        #line hidden

        #line 93 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(";\r\n        ");


        #line default
        #line hidden

        #line 94 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(parentMember));


        #line default
        #line hidden

        #line 94 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(" = ");


        #line default
        #line hidden

        #line 94 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(tempVarName));


        #line default
        #line hidden

        #line 94 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            this.Write(";\r\n");


        #line default
        #line hidden

        #line 95 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"

            return(() =>
            {
        #line default
        #line hidden

        #line 98 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write("        Assert.That(");


        #line default
        #line hidden

        #line 99 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(parentMember));


        #line default
        #line hidden

        #line 99 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(", Is.EqualTo(");


        #line default
        #line hidden

        #line 99 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(tempVarName));


        #line default
        #line hidden

        #line 99 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write("));\r\n        Assert.That(");


        #line default
        #line hidden

        #line 100 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture($"(({struct_.Name}){writerVarName}).{field.Name}"));


        #line default
        #line hidden

        #line 100 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(", Is.EqualTo(");


        #line default
        #line hidden

        #line 100 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(tempVarName));


        #line default
        #line hidden

        #line 100 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write("));\r\n        Assert.That(");


        #line default
        #line hidden

        #line 101 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture($"(new {struct_.Name}Reader({writerVarName}.CellPtr, 0)).{field.Name}"));


        #line default
        #line hidden

        #line 101 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(", Is.EqualTo(");


        #line default
        #line hidden

        #line 101 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(tempVarName));


        #line default
        #line hidden

        #line 101 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
                this.Write("));\r\n");


        #line default
        #line hidden

        #line 102 "C:\Users\v-siyul.FAREAST\documents\visual studio 2017\Projects\TSLTestGenerator\TSLTestGenerator\Templates\FieldTestCodeTemplate.tt"
            });
        }
 public TestCodeTemplate(TestCodeGeneratorContext context, ITSLTopLevelElement element)
 {
     Context = context;
     Element = element;
 }