public void generate_givenClassWithTestMethodWithAssertions() { List <Attribute> givenClassAttributes = new List <Attribute>(); givenClassAttributes.Add(new Attribute(AttributeType.ClassAttribute, "TestFixture")); Document given = new Document(); //given.addToStructure(documentUnit.ClassAttributeWithoutArgs); given.addClass("CodeGeneratorTests", givenClassAttributes); given.addToStructure(documentUnit.TestAttributeWithoutArgs); List <Attribute> givenListOfAttr1 = new List <Attribute>(); givenListOfAttr1.Add(new Attribute(AttributeType.TestAttribute, "Test")); TestMethod test = new TestMethod("void", givenListOfAttr1); test.AddArgs(""); test.SetName("TestMethod1"); given.AddTestMethod(test); Assertion a1 = new Assertion("Assert"); a1.SetMethod("AreEqual"); a1.SetArgs("1, 1"); given.AddAssertion(a1); Assertion a2 = new Assertion("CollectionAssert"); a2.SetMethod("AreEqual"); a2.SetArgs("b, c"); given.AddAssertion(a2); List <string> expected = new List <string>(); expected.Add("using Microsoft.VisualStudio.TestTools.UnitTesting;"); expected.Add(" [TestClass]"); expected.Add(" public class MSCodeGeneratorTests"); expected.Add(" {"); expected.Add(" [TestMethod]"); expected.Add(" public void MSTestMethod1()"); expected.Add(" {"); expected.Add(" Assert.AreEqual(1, 1);"); expected.Add(" CollectionAssert.AreEqual(b, c);"); expected.Add(" }"); expected.Add(" }"); CollectionAssert.AreEqual(expected, codeGenerator.TranslateDocument(given)); }
public void generate_givenClassWithTestMethod() { List <Attribute> givenClassAttributes = new List <Attribute>(); //givenClassAttributes.Add(new Attribute(AttributeType.ClassAttribute, "TestFixture")); Document given = new Document(); //given.addToStructure(documentUnit.ClassAttributeWithoutArgs); given.addClass("CodeGeneratorTests", givenClassAttributes); given.addToStructure(documentUnit.TestAttributeWithoutArgs); List <Attribute> givenListOfAttr = new List <Attribute>(); givenListOfAttr.Add(new Attribute(AttributeType.TestAttribute, "SetUp")); TestMethod setUp = new TestMethod("void", givenListOfAttr); setUp.AddArgs(""); setUp.SetName("SetupMethod"); given.AddTestMethod(setUp); given.addToStructure(documentUnit.TestAttributeWithoutArgs); List <Attribute> givenListOfAttr1 = new List <Attribute>(); givenListOfAttr1.Add(new Attribute(AttributeType.TestAttribute, "Test")); TestMethod test = new TestMethod("void", givenListOfAttr1); test.AddArgs(""); test.SetName("TestMethod1"); given.AddTestMethod(test); List <string> expected = new List <string>(); expected.Add("using Microsoft.VisualStudio.TestTools.UnitTesting;"); expected.Add(" [TestClass]"); expected.Add(" public class MSCodeGeneratorTests"); expected.Add(" {"); expected.Add(" [TestInitialize]"); expected.Add(" public void MSSetupMethod()"); expected.Add(" {"); expected.Add(" }"); expected.Add(" [TestMethod]"); expected.Add(" public void MSTestMethod1()"); expected.Add(" {"); expected.Add(" }"); expected.Add(" }"); CollectionAssert.AreEqual(expected, codeGenerator.TranslateDocument(given)); }
private void doIfFoundReturnTypeExpectedMethodName(string nextToken) { nextMethod.SetName(nextToken); changeState(ParserState.FoundMethodNameExpectedLeftParenthesis); }
public void analize_givenTestMethod_createdTestMethodInDocument() { string[] givenToken = { "[", "SetUp", "]", "public", "void", "SetupMethod","(", ")", "{", "}", "[", "Test", "]", "public", "void", "TestMethod", "(", ")", "{", "}" }; bool[] givenSpace = { false, false, false, false, true, true, false, false, false, false, false, false, false, false, true, true, false, false, false, false }; bool[] givenEndl = { false, false, true, false, false, false,false, true, true, true, false, false, true, false, false, false,false, true, true, true }; parser.changeState(ParserState.ExpectedCodeLineOrTestMethod); for (int i = 0; i < 20; i++) { parser.analize(givenToken[i], givenSpace[i], givenEndl[i]); } Document document = Program.GetDocument(); List <documentUnit> expectedStructure = new List <documentUnit>(); expectedStructure.Add(documentUnit.TestAttributeWithoutArgs); expectedStructure.Add(documentUnit.TestMethodDeclaration); expectedStructure.Add(documentUnit.TestAttributeWithoutArgs); expectedStructure.Add(documentUnit.TestMethodDeclaration); List <TestMethod> result = document.GetTestMethods(); List <Attribute> attr1 = new List <Attribute>(); attr1.Add(new Attribute(AttributeType.TestAttribute, "SetUp")); TestMethod tm1 = new TestMethod("void", attr1); tm1.AddArgs(""); tm1.SetName("SetupMethod"); List <Attribute> attr2 = new List <Attribute>(); attr2.Add(new Attribute(AttributeType.TestAttribute, "Test")); TestMethod tm2 = new TestMethod("void", attr2); tm2.AddArgs(""); tm2.SetName("TestMethod"); List <TestMethod> expected = new List <TestMethod>(); expected.Add(tm1); expected.Add(tm2); CollectionAssert.AreEqual(expectedStructure, document.getDocumentStructure()); Assert.AreEqual("TestInitialize", result[0].getListOfAttributes()[0].getKeyWord()); Assert.AreEqual("TestMethod", result[1].getListOfAttributes()[0].getKeyWord()); // CollectionAssert.AreEqual(attr1, result[0].getListOfAttributes()); //CollectionAssert.AreEqual(attr2, result[1].getListOfAttributes()); //CollectionAssert.AreEqual(expected, result); }