public void SetUp()
        {
            _items = new InternalTraceItemCollection();

            _resourceA = new TestResource("HelloWorld.txt");
            _resourceB = new TestResource("TextCode.txt");

            _itemA = new ErrorItem(_resourceA.Path, 1);
            _itemB = new ErrorItem(_resourceB.Path, 2);

            return;
        }
        public void TearDown()
        {
            if (_resourceA != null)
            {
                _resourceA.Dispose();
                _resourceA = null;
            }

            if (_resourceB != null)
            {
                _resourceB.Dispose();
                _resourceB = null;
            }
        }
        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 Any_Formatter_Should_Format_Any_Text()
        {
            TestResource res;

            using (res = new TestResource("HelloWorld.txt"))
            {
                FormatResource(res);
            }

            using (res = new TestResource("Basic.cs"))
            {
                FormatResource(res);
            }

            using (res = new TestResource("TextCode.txt"))
            {
                FormatResource(res);
            }


            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 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;
        }