<commit_before>﻿//----------------------------------------------------------------------- 
// <copyright file="VisualStudioEventTestBase.cs" company="Copacetic Software"> 
// Copyright (c) Copacetic Software.  
// <author><NAME></author> 
// <date>Wednesday, May 7, 2014 2:07:06 PM</date> 
// Licensed under the Apache License, Version 2.0,
// you may not use this file except in compliance with this 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.
// </copyright> 
//-----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using CopaceticSoftware.CodeGenerator.StarterKit.Infrastructure;
using CopaceticSoftware.CodeGenerator.StarterKit.Infrastructure.IO;
using CopaceticSoftware.CodeGenerator.StarterKit.Infrastructure.VisualStudioSolution;
using CopaceticSoftware.pMixins.Tests.Common;
using CopaceticSoftware.pMixins.VisualStudio;
using Microsoft.Build.Evaluation;
using Ninject;
using Rhino.Mocks;

namespace CopaceticSoftware.CodeGenerator.StarterKit.Tests.IntegrationTests.VisualStudioEvents
{
    public abstract class VisualStudioEventTestBase : IntegrationTestBase
    {
        protected TestVisualStudioEventProxy EventProxy;
        /// <summary>
        /// <see cref="IKernel"/> specific to the test class.
        /// It's ok to rebind this Kernel without side effects.
        /// </summary>
        protected IKernel TestSpecificKernel;

        protected IFileWrapper MockFileWrapper;

        protected IMicrosoftBuildProjectLoader MockMicrosoftBuildProjectLoader;

        /*
        protected readonly Dictionary<string, string> MockFileWrapperBackingStore = 
            new Dictionary<string, string>(); */

        protected MockSolution _MockSolution;

        /// <summary>
        /// Got tired fo forgetting to use TestSpecificKernel, need a reminder.
        /// </summary>
        protected static new IKernel Kernel
        {
            get { throw new Exception("Don't call Kernel.  Call TestSpecificKernel"); }
        }

        public override void MainSetup()
        {
            TestSpecificKernel = KernelFactory.BuildDefaultKernelForTests();

            EventProxy = TestSpecificKernel.Get<IVisualStudioEventProxy>()
                //This is important, if the casting isn't done, then EventProxy isn't returned via IoC
                as TestVisualStudioEventProxy;

            MockFileWrapper = BuildMockFileReader();
            TestSpecificKernel.Rebind<IFileWrapper>().ToMethod(c => MockFileWrapper);

            MockMicrosoftBuildProjectLoader = BuildMockMicrosoftBuildProjectLoader();
            TestSpecificKernel.Rebind<IMicrosoftBuildProjectLoader>().ToMethod(c => MockMicrosoftBuildProjectLoader);

            _MockSolution = new MockSolution();

            //Set solution context
            TestSpecificKernel.Get<ISolutionContext>().SolutionFileName =
                _MockSolution.FileName;
        }

        protected virtual IFileWrapper BuildMockFileReader()
        {<commit_msg>Fire Solution Closing on CleanUp to clear Caches<commit_after>﻿//----------------------------------------------------------------------- 
// <copyright file="VisualStudioEventTestBase.cs" company="Copacetic Software"> 
// Copyright (c) Copacetic Software.  
// <author><NAME></author> 
// <date>Wednesday, May 7, 2014 2:07:06 PM</date> 
// Licensed under the Apache License, Version 2.0,
// you may not use this file except in compliance with this 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.
// </copyright> 
//-----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using CopaceticSoftware.CodeGenerator.StarterKit.Infrastructure;
using CopaceticSoftware.CodeGenerator.StarterKit.Infrastructure.IO;
using CopaceticSoftware.CodeGenerator.StarterKit.Infrastructure.VisualStudioSolution;
using CopaceticSoftware.pMixins.Tests.Common;
using CopaceticSoftware.pMixins.VisualStudio;
using Microsoft.Build.Evaluation;
using Ninject;
using Rhino.Mocks;

namespace CopaceticSoftware.CodeGenerator.StarterKit.Tests.IntegrationTests.VisualStudioEvents
{
    public abstract class VisualStudioEventTestBase : IntegrationTestBase
    {
        protected TestVisualStudioEventProxy EventProxy;
        /// <summary>
        /// <see cref="IKernel"/> specific to the test class.
        /// It's ok to rebind this Kernel without side effects.
        /// </summary>
        protected IKernel TestSpecificKernel;

        protected IFileWrapper MockFileWrapper;

        protected IMicrosoftBuildProjectLoader MockMicrosoftBuildProjectLoader;

        /*
        protected readonly Dictionary<string, string> MockFileWrapperBackingStore = 
            new Dictionary<string, string>(); */

        protected MockSolution _MockSolution;

        /// <summary>
        /// Got tired fo forgetting to use TestSpecificKernel, need a reminder.
        /// </summary>
        protected static new IKernel Kernel
        {
            get { throw new Exception("Don't call Kernel.  Call TestSpecificKernel"); }
        }

        public override void MainSetup()
        {
            TestSpecificKernel = KernelFactory.BuildDefaultKernelForTests();

            EventProxy = TestSpecificKernel.Get<IVisualStudioEventProxy>()
                //This is important, if the casting isn't done, then EventProxy isn't returned via IoC
                as TestVisualStudioEventProxy;

            MockFileWrapper = BuildMockFileReader();
            TestSpecificKernel.Rebind<IFileWrapper>().ToMethod(c => MockFileWrapper);

            MockMicrosoftBuildProjectLoader = BuildMockMicrosoftBuildProjectLoader();
            TestSpecificKernel.Rebind<IMicrosoftBuildProjectLoader>().ToMethod(c => MockMicrosoftBuildProjectLoader);

            _MockSolution = new MockSolution();

            //Set solution context
            TestSpecificKernel.Get<ISolutionContext>().SolutionFileName =
                _MockSolution.FileName;
        }

        protected override void Cleanup()
        {
            base.Cleanup();

            //Simulate a Solution Closing event so Cache classes clear their cache
            EventProxy.FireOnSolutionClosing(this, new EventArgs());
        }

        protected virtual IFileWrapper BuildMockFileReader()
        {
{'fraction_non_alphanumeric': 0.11905094207955338, 'fraction_numerical': 0.003907885554780182, 'mean_word_length': 2.6542580316165223, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '836756', 'n_tokens_mistral': 1778, 'n_tokens_neox': 1636, 'n_words': 498}