<commit_before>// Copyright 2005-2010 Gallio Project - http://www.gallio.org/
// Portions Copyright 2000-2004 <NAME>
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Xml;
using Gallio.Common.Markup;
using Gallio.Common.Policies;
using Gallio.Reports;
using Gallio.Runtime.ProgressMonitoring;
using Gallio.Runtime;
using Gallio.Framework;
using Gallio.Common.Reflection;
using Gallio.Runner.Reports;
using Gallio.Tests;
using MbUnit.Framework;
using Rhino.Mocks;
using Rhino.Mocks.Constraints;
using Gallio.Common.Collections;
using Gallio.Runner.Reports.Schema;
using NVelocity.App;
using NVelocity.Runtime;
using System.Reflection;
using Gallio.Reports.Vtl;

namespace Gallio.Tests.Reports
{
    [TestFixture]
    [TestsOn(typeof(VtlReportFormatter))]
    public class VtlReportFormatterTest
    {
        [Test]
        [ExpectedArgumentNullException]
        public void Constructs_with_null_extension_should_throw_exception()
        {
            new VtlReportFormatter(null, MimeTypes.PlainText, new DirectoryInfo("content"), "vm", EmptyArray<string>.Instance);
        }

        [Test]
        [ExpectedArgumentNullException]
        public void Constructs_with_null_contentType_should_throw_exception()
        {
            new VtlReportFormatter("ext", null, new DirectoryInfo("content"), "vm", EmptyArray<string>.Instance);
        }   

        [Test]
        [ExpectedArgumentNullException]
        public void Constructs_with_null_resourceDirectory_should_throw_exception()
        {
            new VtlReportFormatter("ext", MimeTypes.PlainText, null, "vm", EmptyArray<string>.Instance);
        }

        [Test]
        [ExpectedArgumentNullException]
        public void Constructs_with_null_templatePath_should_throw_exception()
        {
            new VtlReportFormatter("ext", MimeTypes.PlainText, new DirectoryInfo("content"), null, EmptyArray<string>.Instance);
        }

        [Test]
        [ExpectedArgumentNullException]
        public void Constructs_with_null_resourcePaths_should_throw_exception()
        {
            new VtlReportFormatter("ext", MimeTypes.PlainText, new DirectoryInfo("content"), "vm", null);
        }

        [Test]
        [ExpectedArgumentNullException]
        public void Constructs_with_null_resource_containing_null_element_should_throw_exception()
        {
            new VtlReportFormatter("ext", MimeTypes.PlainText, new DirectoryInfo("content"), "vm", new string[] { null });
        }

        [Test]
        public void Format()
        {
            var mockReportWriter = MockRepository.GenerateStub<IReportWriter>();
            var mockReportContainer = MockRepository.GenerateStub<IReportContainer>();
            var mockProgressMonitor = NullProgressMonitor.CreateInstance();
            var output = new StringBuilder();
            var stream = new StringStream(output);
            var fakeReport = new Report();
            mockReportWriter.Stub(x => x.Report).Return(fakeReport);
            mockReportWriter.Stub(x => x.ReportContainer).Return(mockReportContainer);
            mockReportContainer.Stub(x => x.ReportName).Return("output");
            mockReportContainer.Stub(x => x.OpenWrite(null, null, null)).IgnoreArguments().Return(stream);
            fakeReport.TestPackageRun = new TestPackageRun();
            fakeReport.TestPackageRun.Statistics.RunCount = 123;
            var formatter = new VtlReportFormatter("ext", MimeTypes.PlainText, new DirectoryInfo("content"), "Gallio.Tests.Reports.SampleTemplate.vm", EmptyArray<string>.Instance);
            formatter.VelocityEngineFactory = new ResourceVelocityEngineFactory();
            formatter.Format(mockReportWriter, new ReportFormatterOptions(), mockProgressMonitor);
            Assert.AreEqual("This is the test report (123)", output.ToString());
        }

        // Simple stream that stored the input UTF8 text into a string builder.
        private class StringStream : Stream <commit_msg>Fixed broken test.<commit_after>// Copyright 2005-2010 Gallio Project - http://www.gallio.org/
// Portions Copyright 2000-2004 <NAME>
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Xml;
using Gallio.Common.Markup;
using Gallio.Common.Policies;
using Gallio.Reports;
using Gallio.Runtime.ProgressMonitoring;
using Gallio.Runtime;
using Gallio.Framework;
using Gallio.Common.Reflection;
using Gallio.Runner.Reports;
using Gallio.Tests;
using MbUnit.Framework;
using Rhino.Mocks;
using Rhino.Mocks.Constraints;
using Gallio.Common.Collections;
using Gallio.Runner.Reports.Schema;
using NVelocity.App;
using NVelocity.Runtime;
using System.Reflection;
using Gallio.Reports.Vtl;
using Gallio.Model.Schema;

namespace Gallio.Tests.Reports
{
    [TestFixture]
    [TestsOn(typeof(VtlReportFormatter))]
    public class VtlReportFormatterTest
    {
        [Test]
        [ExpectedArgumentNullException]
        public void Constructs_with_null_extension_should_throw_exception()
        {
            new VtlReportFormatter(null, MimeTypes.PlainText, new DirectoryInfo("content"), "vm", EmptyArray<string>.Instance);
        }

        [Test]
        [ExpectedArgumentNullException]
        public void Constructs_with_null_contentType_should_throw_exception()
        {
            new VtlReportFormatter("ext", null, new DirectoryInfo("content"), "vm", EmptyArray<string>.Instance);
        }   

        [Test]
        [ExpectedArgumentNullException]
        public void Constructs_with_null_resourceDirectory_should_throw_exception()
        {
            new VtlReportFormatter("ext", MimeTypes.PlainText, null, "vm", EmptyArray<string>.Instance);
        }

        [Test]
        [ExpectedArgumentNullException]
        public void Constructs_with_null_templatePath_should_throw_exception()
        {
            new VtlReportFormatter("ext", MimeTypes.PlainText, new DirectoryInfo("content"), null, EmptyArray<string>.Instance);
        }

        [Test]
        [ExpectedArgumentNullException]
        public void Constructs_with_null_resourcePaths_should_throw_exception()
        {
            new VtlReportFormatter("ext", MimeTypes.PlainText, new DirectoryInfo("content"), "vm", null);
        }

        [Test]
        [ExpectedArgumentNullException]
        public void Constructs_with_null_resource_containing_null_element_should_throw_exception()
        {
            new VtlReportFormatter("ext", MimeTypes.PlainText, new DirectoryInfo("content"), "vm", new string[] { null });
        }

        [Test]
        public void Format()
        {
            var mockReportWriter = MockRepository.GenerateStub<IReportWriter>();
            var mockReportContainer = MockRepository.GenerateStub<IReportContainer>();
            var mockProgressMonitor = NullProgressMonitor.CreateInstance();
            var output = new StringBuilder();
            var stream = new StringStream(output);
            var fakeReport = new Report();
            mockReportWriter.Stub(x => x.Report).Return(fakeReport);
            mockReportWriter.Stub(x => x.ReportContainer).Return(mockReportContainer);
            mockReportContainer.Stub(x => x.ReportName).Return("output");
            mockReportContainer.Stub(x => x.OpenWrite(null, null, null)).IgnoreArguments().Return(stream);
            fakeReport.TestPackageRun = new TestPackageRun();
            fakeReport.TestPackageRun.RootTestStepRun = new TestStepRun(new TestStepData("", "", "", ""));
            fakeReport.TestPackageRun.Statistics.RunCount = 123;
            var formatter = new VtlReportFormatter("ext", MimeTypes.PlainText, new DirectoryInfo("content"), "Gallio.Tests.Reports.SampleTemplate.vm", EmptyArray<string>.Instance);
            formatter.VelocityEngineFactory = new ResourceVelocityEngineFactory();
            formatter.Format(mockReportWriter, new ReportFormatterOptions(), mockProgressMonitor);
            Assert.AreEqual("This is the test report (123)", output.ToString());
        }

        // Simple stream that stored the input UTF8 text into a string builder.
        private class StringStream : Stream 
{'fraction_non_alphanumeric': 0.09610613741775428, 'fraction_numerical': 0.0058246143889548055, 'mean_word_length': 3.3408239700374533, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2493316', 'n_tokens_mistral': 2472, 'n_tokens_neox': 2399, 'n_words': 594}