<commit_before>// Copyright 2005-2008 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.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Threading;
using Gallio.Concurrency;
using Gallio.Icarus.Controllers;
using Gallio.Icarus.Controllers.Interfaces;
using Gallio.Icarus.Models;
using Gallio.Icarus.Models.Interfaces;
using Gallio.Model;
using Gallio.Model.Logging;
using Gallio.Model.Serialization;
using Gallio.Runner.Events;
using Gallio.Runner.Reports;
using MbUnit.Framework;
using Rhino.Mocks;
using Rhino.Mocks.Interfaces;

namespace Gallio.Icarus.Tests.Controllers
{
    [MbUnit.Framework.Category("Controllers"), Author("<NAME>")]
    class ExecutionLogControllerTest : MockTest
    {
        private IEventRaiser testRunStartedEventRaiser;
        private IEventRaiser testRunFinishedEventRaiser;

        private BindingList<TestTreeNode> selectedTests;

        [SetUp]
        public void SetUp()
        {
            selectedTests = new BindingList<TestTreeNode>(new List<TestTreeNode>());
        }

        [Test]
        public void TestStepFinished_Test()
        {
            TestStepRun testStepRun = new TestStepRun(new TestStepData("rootStep", "name", "fullName", "root"));
            testStepRun.TestLog = new StructuredTestLog();
            testStepRun.TestLog.Attachments.Add(new TextAttachment("name", "contentType", "text").ToAttachmentData());
            TestStepFinishedEventArgs e = new TestStepFinishedEventArgs(new Report(), new TestData("root", "name", "fullName"), testStepRun);
            ITestController testController = SetupTestController();
            Report report = new Report();
            report.TestPackageRun = new TestPackageRun();
            report.TestModel = new TestModelData(new TestData(new RootTest()));
            report.TestPackageRun.RootTestStepRun = testStepRun;

            SetupResult.For(testController.Report).Return(new LockBox<Report>(report));
            ITestTreeModel testTreeModel = mocks.CreateMock<ITestTreeModel>();
            SetupResult.For(testController.Model).Return(testTreeModel);
            TestTreeNode root = new TestTreeNode("root", "root", "root");
            SetupResult.For(testTreeModel.Root).Return(root);
            mocks.ReplayAll();

            ExecutionLogController executionLogController = new ExecutionLogController(testController);
            bool updated = false;
            executionLogController.ExecutionLogUpdated += delegate { updated = true; };

            selectedTests.Add(root);
            testRunStartedEventRaiser.Raise(testController, System.EventArgs.Empty);
            testRunFinishedEventRaiser.Raise(testController, e);

            Assert.AreEqual(true, updated);
            Assert.AreSame(report.TestModel, executionLogController.TestModelData);
            Assert.AreElementsEqual(new[] { testStepRun }, executionLogController.TestStepRuns);
        }

        ITestController SetupTestController()
        {
            ITestController testController = mocks.CreateMock<ITestController>();
            SetupResult.For(testController.SelectedTests).Return(selectedTests);

            testController.TestStepFinished += null;
            testRunFinishedEventRaiser = LastCall.IgnoreArguments().GetEventRaiser();

            testController.RunStarted += null;
            testRunStartedEventRaiser = LastCall.IgnoreArguments().GetEventRaiser();

            return testController;
        }
    }
}
<commit_msg>Workaround timing issue in test.<commit_after>// Copyright 2005-2008 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.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Threading;
using Gallio.Concurrency;
using Gallio.Icarus.Controllers;
using Gallio.Icarus.Controllers.Interfaces;
using Gallio.Icarus.Models;
using Gallio.Icarus.Models.Interfaces;
using Gallio.Model;
using Gallio.Model.Logging;
using Gallio.Model.Serialization;
using Gallio.Runner.Events;
using Gallio.Runner.Reports;
using MbUnit.Framework;
using Rhino.Mocks;
using Rhino.Mocks.Interfaces;

namespace Gallio.Icarus.Tests.Controllers
{
    [MbUnit.Framework.Category("Controllers"), Author("<NAME>")]
    class ExecutionLogControllerTest : MockTest
    {
        private IEventRaiser testRunStartedEventRaiser;
        private IEventRaiser testRunFinishedEventRaiser;

        private BindingList<TestTreeNode> selectedTests;

        [SetUp]
        public void SetUp()
        {
            selectedTests = new BindingList<TestTreeNode>(new List<TestTreeNode>());
        }

        [Test]
        public void TestStepFinished_Test()
        {
            TestStepRun testStepRun = new TestStepRun(new TestStepData("rootStep", "name", "fullName", "root"));
            testStepRun.TestLog = new StructuredTestLog();
            testStepRun.TestLog.Attachments.Add(new TextAttachment("name", "contentType", "text").ToAttachmentData());
            TestStepFinishedEventArgs e = new TestStepFinishedEventArgs(new Report(), new TestData("root", "name", "fullName"), testStepRun);
            ITestController testController = SetupTestController();
            Report report = new Report();
            report.TestPackageRun = new TestPackageRun();
            report.TestModel = new TestModelData(new TestData(new RootTest()));
            report.TestPackageRun.RootTestStepRun = testStepRun;

            SetupResult.For(testController.Report).Return(new LockBox<Report>(report));
            ITestTreeModel testTreeModel = mocks.CreateMock<ITestTreeModel>();
            SetupResult.For(testController.Model).Return(testTreeModel);
            TestTreeNode root = new TestTreeNode("root", "root", "root");
            SetupResult.For(testTreeModel.Root).Return(root);
            mocks.ReplayAll();

            ExecutionLogController executionLogController = new ExecutionLogController(testController);
            bool updated = false;
            executionLogController.ExecutionLogUpdated += delegate { updated = true; };

            selectedTests.Add(root);
            testRunStartedEventRaiser.Raise(testController, System.EventArgs.Empty);
            testRunFinishedEventRaiser.Raise(testController, e);

            Thread.Sleep(200); // wait for threadpool to run task

            Assert.AreEqual(true, updated);
            Assert.AreSame(report.TestModel, executionLogController.TestModelData);
            Assert.AreElementsEqual(new[] { testStepRun }, executionLogController.TestStepRuns);
        }

        ITestController SetupTestController()
        {
            ITestController testController = mocks.CreateMock<ITestController>();
            SetupResult.For(testController.SelectedTests).Return(selectedTests);

            testController.TestStepFinished += null;
            testRunFinishedEventRaiser = LastCall.IgnoreArguments().GetEventRaiser();

            testController.RunStarted += null;
            testRunStartedEventRaiser = LastCall.IgnoreArguments().GetEventRaiser();

            return testController;
        }
    }
}

{'fraction_non_alphanumeric': 0.0940828402366864, 'fraction_numerical': 0.005088757396449704, 'mean_word_length': 2.9750705550329255, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '3876632', 'n_tokens_mistral': 2238, 'n_tokens_neox': 2192, 'n_words': 501}