Ejemplo n.º 1
0
        public void Format_Pick_Best_Formatter()
        {
            ErrorItem      itemHelloTxt;
            ErrorItem      itemBasicCs;
            ICodeFormatter txtFormatter;
            ICodeFormatter csFormatter;
            FormattedCode  exp;

            using (TestResource resource = new TestResource("HelloWorld.txt"))
            {
                itemHelloTxt = new ErrorItem(resource.Path, 1);
                txtFormatter = new PlainTextCodeFormatter();
                exp          = txtFormatter.Format(itemHelloTxt.ReadFile());
                Assert.That(
                    _formatter.FormatFromExtension(itemHelloTxt.ReadFile(), itemHelloTxt.FileExtension),
                    Is.EqualTo(exp));
                FormattedCode.CheckData(exp);
            }

            using (TestResource resource = new TestResource("Basic.cs"))
            {
                itemBasicCs = new ErrorItem(resource.Path, 1);
                csFormatter = new CSharpCodeFormatter();
                exp         = csFormatter.Format(itemBasicCs.ReadFile());
                Assert.That(
                    _formatter.FormatFromExtension(itemBasicCs.ReadFile(), itemBasicCs.FileExtension),
                    Is.EqualTo(exp));
                FormattedCode.CheckData(exp);
            }

            return;
        }
Ejemplo n.º 2
0
        //[Test]
        //[ExpectedException(typeof(ArgumentNullException),
        //    ExpectedMessage = "code",
        //    MatchType = MessageMatch.Contains)]
        //public void FormatFromExtension_Can_Throw_CodeNullException()
        //{
        //    _formatter.FormatFromExtension(null, "cs"); // throws exception
        //}

        //[Test]
        //[ExpectedException(typeof(ArgumentNullException),
        //    ExpectedMessage = "extension",
        //    MatchType = MessageMatch.Contains)]
        //public void FormatFromExtension_Can_Throw_ExtensionNullException()
        //{
        //    _formatter.FormatFromExtension("test", null); // throws exception
        //}

        //[Test]
        //[ExpectedException(typeof(ArgumentNullException),
        //    ExpectedMessage = "code",
        //    MatchType = MessageMatch.Contains)]
        //public void Format_Can_Throw_CodeNullException()
        //{
        //    _formatter.Format(null, "C#"); // throws exception
        //}

        //[Test]
        //[ExpectedException(typeof(ArgumentNullException),
        //    ExpectedMessage = "language",
        //    MatchType = MessageMatch.Contains)]
        //public void Format_Can_Throw_LanguageNameNullException()
        //{
        //    _formatter.Format("test", null); // throws exception
        //}

        public void FormatResource(TestResource res)
        {
            ErrorItem             error;
            FormattedCode         code;
            List <ICodeFormatter> array = GetAllFormatters();

            foreach (ICodeFormatter item in array)
            {
                error = new ErrorItem(res.Path, 1);
                code  = item.Format(error.ReadFile());

                Assert.That(code, Is.Not.Null,
                            "Formatter: " + item + " failed to format resource.");

                try
                {
                    FormattedCode.CheckData(code);
                }
                catch (Exception e)
                {
                    Assert.Fail("Formatter: " + item + " has created an ill-formed data. Error: " + e.Message);
                }
            }

            return;
        }
Ejemplo n.º 3
0
 public void CheckData_LineArray_Values_Must_Always_Grow_Up()
 {
     FormattedCode.CheckData(
         new FormattedCode("hi\r\nthere\r\n",
                           new int[] { 0, 3 },
                           new byte[] { 0, 0 },
                           new int[] { 0, 0 })); // throws exception
 }
Ejemplo n.º 4
0
 public void CheckData_LineArray_Values_Must_Be_In_IndexArray_Count()
 {
     FormattedCode.CheckData(
         new FormattedCode("hi there!", new int[] { 0 }, new byte[] { 0 }, new int[] { 1 })); // throws exception
 }
Ejemplo n.º 5
0
 public void CheckData_IndexArray_And_TagArray_Count_Must_Match()
 {
     FormattedCode.CheckData(
         new FormattedCode("hello", new int[] { 0 }, new byte[0], new int[] { 0 })); // throws exception
 }
Ejemplo n.º 6
0
 public void CheckData_Can_Throw_NullDataException()
 {
     FormattedCode.CheckData(null); // throws exception
 }
Ejemplo n.º 7
0
 public void CheckData_Can_Throw_NullDataException()
 {
     Assert.Throws <ArgumentNullException>(() => FormattedCode.CheckData(null)); // throws exception
 }