Пример #1
0
        /// <summary>
        /// Performs any preparatory tasks that have to be done after a new unit test project has been created.
        /// </summary>
        /// <param name="unitTestProject">The <see cref="Project"/> of the unit test project that has just been created.</param>
        /// <param name="sourceMethod">The <see cref="CodeFunction2"/> of the source method that is to be unit tested.</param>
        protected override void OnUnitTestProjectCreated(Project unitTestProject, CodeFunction2 sourceMethod)
        {
            if (unitTestProject == null)
            {
                throw new ArgumentNullException(nameof(unitTestProject));
            }
            if (sourceMethod == null)
            {
                throw new ArgumentNullException(nameof(sourceMethod));
            }

            TraceLogger.LogInfo("xUnitSolutionManager.OnUnitTestProjectCreated: Adding reference to NUnit assemblies through nuget.");

            base.OnUnitTestProjectCreated(unitTestProject, sourceMethod);

            this.EnsureNuGetReference(unitTestProject, "xunit", "2.4.1");
            this.EnsureNuGetReference(unitTestProject, "xunit.runner.visualstudio", "2.4.1");


            var vsp       = unitTestProject.Object as VSProject2;
            var reference = vsp?.References.Find(GlobalConstants.MSTestAssemblyName);

            if (reference != null)
            {
                TraceLogger.LogInfo("xUnitSolutionManager.OnUnitTestProjectCreated: Removing reference to {0}", reference.Name);
                reference.Remove();
            }
        }
Пример #2
0
        /// <summary>
        /// Performs any preparatory tasks that have to be done after a new unit test project has been created.
        /// </summary>
        /// <param name="unitTestProject">The <see cref="Project"/> of the unit test project that has just been created.</param>
        /// <param name="sourceMethod">The <see cref="CodeFunction2"/> of the source method that is to be unit tested.</param>
        protected override void OnUnitTestProjectCreated(Project unitTestProject, CodeFunction2 sourceMethod)
        {
            if (unitTestProject == null)
            {
                throw new ArgumentNullException("unitTestProject");
            }

            TraceLogger.LogInfo("MSTestv2SolutionManager.OnUnitTestProjectCreated: Adding reference to MSTestv2 assemblies through nuget.");

            base.OnUnitTestProjectCreated(unitTestProject, sourceMethod);

            this.EnsureNuGetReference(unitTestProject, "MSTest.TestAdapter", "1.1.18");
            this.EnsureNuGetReference(unitTestProject, "MSTest.TestFramework", "1.1.18");

            VSProject2 vsp = unitTestProject.Object as VSProject2;

            if (vsp != null)
            {
                Reference reference = vsp.References.Find(GlobalConstants.MSTestAssemblyName);
                if (reference != null)
                {
                    TraceLogger.LogInfo("MSTestv2SolutionManager.OnUnitTestProjectCreated: Removing reference to {0}", reference.Name);
                    reference.Remove();
                }
            }
        }
        protected override void OnUnitTestProjectCreated(Project unitTestProject, CodeFunction2 sourceMethod)
        {
            if (unitTestProject == null)
            {
                throw new ArgumentNullException("unitTestProject");
            }
            if (sourceMethod == null)
            {
                throw new ArgumentNullException("sourceMethod");
            }

            // TODO: Remove references to "MSTestFramework" and "MSTestFramework.Universal"

            // Add package reference for xUnit.net
            TraceLogger.LogInfo("XunitSolutionManager.OnUnitTestProjectCreated: Adding reference to NuGet packages 'xunit' and 'xunit.runner.visualstudion' (version {0})", xunitPackageVersion);
            EnsureNuGetReference(unitTestProject, "xunit", xunitPackageVersion);
            EnsureNuGetReference(unitTestProject, "xunit.runner.visualstudio", visualStudioRunnerPackageVersion);

            // Remove any *.cs/*.vb files from the root of the project (i.e., Class1.cs/Class1.vb)
            foreach (var projectItem in unitTestProject.ProjectItems.AsEnumerable())
            {
                var extension = Path.GetExtension(projectItem.Name).ToLowerInvariant();
                if (extension == ".cs" || extension == ".vb")
                {
                    TraceLogger.LogInfo("XunitSolutionManager.OnUnitTestProjectCreated: Removing project item {0}", projectItem.Name);
                    projectItem.Delete();
                }
            }
        }