Example #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;
        }
        public void Format_Pick_Best_Formatter()
        {
            ErrorItem itemHelloTxt;
            ErrorItem itemBasicCs;
            ICodeFormatter txtFormatter;
            ICodeFormatter csFormatter;
            FormattedCode exp;

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

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

            return;
        }
Example #3
0
        public void ReadFile()
        {
            ErrorItem item;

            using (TestResource resource = new TestResource("HelloWorld.txt"))
            {
                item = new ErrorItem(resource.Path, 1);

                Assert.That(item.ReadFile(), Is.Not.Null);
                Assert.That(item.ReadFile(), Is.EqualTo("Hello world!"));
            }

            return;
        }
Example #4
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;
        }
Example #5
0
        public void SelectedItemChanged()
        {
            GeneralCodeFormatter formatter = new GeneralCodeFormatter();
            ErrorItem            item;

            // test to pass:
            //
            // handle selection changed event when there
            // is a non null selected item

            using (new TestResource("Basic.cs"))
            {
                item = new ErrorItem("Basic.cs", 2);
                Assert.That(item.ReadFile(), Is.Not.Null);

                _mockStack.ExpectAndReturn("get_SelectedItem", item, null);
                _mockCode.ExpectAndReturn("get_Formatter", formatter, null);
                _mockCode.Expect("set_Text", new object[] { item.ReadFile() });
                _mockCode.Expect("set_Language", new object[] { "C#" });

                // CurrentLine is a based 0 index
                _mockCode.Expect("set_CurrentLine", new object[] { 1 });

                _code.RaiseSelectedItemChanged();
                _mockStack.Verify();
                _mockCode.Verify();
            }

            // test to fail:
            //
            // should handle selection changed event even
            // if selection comes to null

            _mockStack.ExpectAndReturn("get_SelectedItem", null, null);
            _mockCode.Expect("set_Text", new object[] { null });

            _code.RaiseSelectedItemChanged();
            _mockStack.Verify();
            _mockCode.Verify();

            return;
        }
        public void SelectedItemChanged()
        {
            GeneralCodeFormatter formatter = new GeneralCodeFormatter();
            ErrorItem            item;

            // test to pass:
            //
            // handle selection changed event when there
            // is a non null selected item

            using (TestResource resource = new TestResource("Basic.cs"))
            {
                item = new ErrorItem(resource.Path, 2);
                Assert.That(item.ReadFile(), Is.Not.Null);

                _mockStack.SelectedItem.Returns(item);
                _mockCode.Formatter.Returns(formatter);

                _code.RaiseSelectedItemChanged();

                Assert.That(_mockCode.Text, Is.EqualTo(item.ReadFile()));
                Assert.That(_mockCode.Language, Is.EqualTo("C#"));
                // CurrentLine is a based 0 index
                Assert.That(_mockCode.CurrentLine, Is.EqualTo(1));
            }

            // test to fail:
            //
            // should handle selection changed event even
            // if selection comes to null

            _mockStack.SelectedItem.Returns((ErrorItem)null);

            _code.RaiseSelectedItemChanged();

            Assert.That(_mockCode.Text, Is.EqualTo(null));

            return;
        }
        public void SelectedItemChanged()
        {
            GeneralCodeFormatter formatter = new GeneralCodeFormatter();
            ErrorItem item;

            // test to pass:
            //
            // handle selection changed event when there
            // is a non null selected item

            using (TestResource resource = new TestResource("Basic.cs"))
            {
                item = new ErrorItem(resource.Path, 2);
                Assert.That(item.ReadFile(), Is.Not.Null);

                _mockStack.SelectedItem.Returns(item);
                _mockCode.Formatter.Returns(formatter);
                
                _code.RaiseSelectedItemChanged();

                Assert.That(_mockCode.Text, Is.EqualTo(item.ReadFile()));
                Assert.That(_mockCode.Language, Is.EqualTo("C#"));
                // CurrentLine is a based 0 index
                Assert.That(_mockCode.CurrentLine, Is.EqualTo(1));
            }

            // test to fail:
            //
            // should handle selection changed event even
            // if selection comes to null

            _mockStack.SelectedItem.Returns((ErrorItem) null); 

            _code.RaiseSelectedItemChanged();

            Assert.That(_mockCode.Text, Is.EqualTo(null));

            return;
        }
        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;
        }
        public void ReadFile()
        {
            ErrorItem item;

            using (TestResource resource = new TestResource("HelloWorld.txt"))
            {
                item = new ErrorItem(resource.Path, 1);

                Assert.That(item.ReadFile(), Is.Not.Null);
                Assert.That(item.ReadFile(), Is.EqualTo("Hello world!"));
            }

            return;
        }        
 public void ReadFile_Throws_FileNotExistException()
 {
     ErrorItem item = new ErrorItem("C:\\unknown\\unknown.txt", 1);
     item.ReadFile(); // throws exception
 }
        public void ReadFile_Throws_FileNotExistException()
        {
            ErrorItem item = new ErrorItem("C:\\unknown\\unknown.txt", 1);

            item.ReadFile(); // throws exception
        }
        public void SelectedItemChanged()
        {
            GeneralCodeFormatter formatter = new GeneralCodeFormatter();
            ErrorItem item;

            // test to pass:
            //
            // handle selection changed event when there
            // is a non null selected item

            using (new TestResource("Basic.cs"))
            {
                item = new ErrorItem("Basic.cs", 2);
                Assert.That(item.ReadFile(), Is.Not.Null);

                _mockStack.ExpectAndReturn("get_SelectedItem", item, null);
                _mockCode.ExpectAndReturn("get_Formatter", formatter, null);
                _mockCode.Expect("set_Text", new object[] { item.ReadFile() });
                _mockCode.Expect("set_Language", new object[] { "C#" });

                // CurrentLine is a based 0 index
                _mockCode.Expect("set_CurrentLine", new object[] { 1 });
                
                _code.RaiseSelectedItemChanged();
                _mockStack.Verify();
                _mockCode.Verify();
            }

            // test to fail:
            //
            // should handle selection changed event even
            // if selection comes to null

            _mockStack.ExpectAndReturn("get_SelectedItem", null, null);
            _mockCode.Expect("set_Text", new object[] { null });

            _code.RaiseSelectedItemChanged();
            _mockStack.Verify();
            _mockCode.Verify();

            return;
        }