コード例 #1
0
        private static string[] TestProjectCreation(InitializeSolutionTestInfo context, string key, string newName, string arbitraryFile, string newNameSpace = null)
        {
            newNameSpace = newNameSpace ?? newName;
            context.SolutionInitializer.CreateProject(key, context.Info);
            var framework = context.Info.XrmPackage.Version.Major >= 9 ? "v4.6.2" : "v4.5.2";
            var id        = context.SolutionInitializer.Projects[key].Id;
            var filePath  = Path.Combine(context.SolutionDirectory, newName, newName + ".csproj");

            Assert.IsTrue(File.Exists(filePath), filePath + " was not created!");
            var lines = File.ReadAllLines(filePath);

            // PropertyGroup
            Assert.That.ExistsLineContaining(lines, $"<ProjectGuid>{{{id.ToString().ToUpper()}}}</ProjectGuid>", "The Project Guid should have been replaced!");
            Assert.That.ExistsLineContaining(lines, $"<RootNamespace>{newNameSpace}</RootNamespace>", $"The Root Namespace should have been updated to {newNameSpace}!");
            Assert.That.ExistsLineContaining(lines, $"<AssemblyName>{newName}</AssemblyName>", $"The Assembly Name should have been updated to {newName}!");
            Assert.That.ExistsLineContaining(lines, $"<TargetFrameworkVersion>{framework}</TargetFrameworkVersion>", $"The Target Framework should have been updated to {framework}!");
            Assert.That.NotExistsLineContaining(lines, "CodeAnalysisRuleSet", "The CodeAnalysisRuleSet should have been removed");
            Assert.That.NotExistsLineContaining(lines, "LocalNuget", "LocalNuget should have been removed");

            AssertCsFileNamespaceUpdated(context, newName, arbitraryFile, newNameSpace);

            AssertAssemblyInfoUpdated(context, newName, id);

            return(lines);
        }
コード例 #2
0
        private static string[] TestSharedProjectCreation(InitializeSolutionTestInfo context, string key, string newName, string arbitraryFile, string newNameSpace = null)
        {
            newNameSpace = newNameSpace ?? newName;
            context.SolutionInitializer.CreateProject(key, context.Info);
            var id = context.SolutionInitializer.Projects[key].Id;
            // .shproj
            var filePath = Path.Combine(context.SolutionDirectory, newName, newName + ".shproj");

            Assert.IsTrue(File.Exists(filePath), filePath + " was not created!");
            var lines = File.ReadAllLines(filePath);

            // Line 4
            Assert.That.ExistsLineContaining(lines, $"<ProjectGuid>{id}</ProjectGuid>", "The Project Guid should have been replaced!");
            // Line 11
            Assert.That.ExistsLineContaining(lines, $"<Import Project=\"{newName}.projitems\" Label=\"Shared\" />", "The Project items file should have been added!");

            AssertCsFileNamespaceUpdated(context, newName, arbitraryFile, newNameSpace);

            // .projitems
            filePath = Path.Combine(context.SolutionDirectory, newName, newName + ".projitems");
            Assert.IsTrue(File.Exists(filePath), filePath + " was not created!");
            lines = File.ReadAllLines(filePath);
            // Line 6
            Assert.That.ExistsLineContaining(lines, $"<SharedGUID>{id}</SharedGUID>", "The Shared Guid should have been replaced!");
            // Line 9
            Assert.That.ExistsLineContaining(lines, ($"<Import_RootNamespace>{newNameSpace}</Import_RootNamespace>"), $"The Root Namespace should have been updated to {newNameSpace}!");

            return(lines);
        }
コード例 #3
0
        private static string[] TestTestProjectCreation(InitializeSolutionTestInfo context, string key, string newName, string arbitraryFile, string newNameSpace = null)
        {
            var lines = TestProjectCreation(context, key, newName, arbitraryFile, newNameSpace);

            // Imports
            Assert.That.ExistsLineContaining(lines, @"Project=""..\Abc.Xrm.TestCore\Abc.Xrm.TestCore.projitems"" Label=""Shared"" />", $"The shared test Project should have been updated!");
            return(lines);
        }
コード例 #4
0
        private static void AssertAssemblyInfoUpdated(InitializeSolutionTestInfo context, string newName, Guid projectId)
        {
            var filePath = Path.Combine(context.SolutionDirectory, newName, "Properties", "AssemblyInfo.cs");
            var file     = File.ReadAllLines(filePath);

            Assert.That.ExistsLineContaining(file, $"[assembly: AssemblyTitle(\"{newName}\")]");
            Assert.That.ExistsLineContaining(file, $"[assembly: AssemblyProduct(\"{newName}\")]");
            Assert.That.ExistsLineContaining(file, $"[assembly: AssemblyCopyright(\"Copyright ©  {DateTime.Now.Year}\")]");
            Assert.That.ExistsLineContaining(file, $"[assembly: Guid(\"{projectId}\")]");
        }
コード例 #5
0
        private static string[] TestPluginProjectCreation(InitializeSolutionTestInfo context, string key, string newName, string arbitraryFile, string newNameSpace = null)
        {
            var lines = TestProjectCreation(context, key, newName, arbitraryFile, newNameSpace);

            // PropertyGroup
            Assert.That.ExistsLineContaining(lines, $"<AssemblyOriginatorKeyFile>{newName}.Key.snk</AssemblyOriginatorKeyFile>", $"The Assembly Key File should have been updated to {newName}.Key.snk!");

            // ItemGroup
            Assert.That.ExistsLineContaining(lines, $"<None Include=\"{newName}.Key.snk\" />", $"The Assembly Key File Item Group Value should have been updated to {newName}.Key.snk!");

            // Imports
            Assert.That.ExistsLineContaining(lines, @"Project=""..\Abc.Xrm\Abc.Xrm.projitems"" Label=""Shared"" />", $"The shared Common Project should have been updated!");

            return(lines);
        }
コード例 #6
0
        private static void AssertCsFileNamespaceUpdated(InitializeSolutionTestInfo context, string newName, string arbitraryFile, string newNameSpace)
        {
            if (arbitraryFile == null)
            {
                return;
            }
            //Check for Namespace Update
            var filePath = Path.Combine(context.SolutionDirectory, newName, arbitraryFile);

            Assert.IsTrue(File.Exists(filePath), filePath + " was not created!");
            var lines = File.ReadAllLines(filePath);

            Assert.That.ExistsLineContaining(lines, $"namespace {newNameSpace}", $"The namespace should have been updated to {newNameSpace}!");
            Assert.That.NotExistsLineContaining(lines, "using Xyz.Xrm", "Using Namespaces should have been updated!");
        }
コード例 #7
0
        private InitializeSolutionTestInfo InitializeTest(Action <InitializeSolutionInfo> setCustomSettings = null, string tempDirectoryName = null)
        {
            var tempDir = tempDirectoryName == null
                ? TempDir.Create()
                : new TempDir(tempDirectoryName);

            TestBase.ClearDirectory(tempDir.Name);
            var solutionPath             = Path.Combine(tempDir.Name, @"Abc.Xrm\Abc.Xrm.sln");
            var solutionDirectory        = Path.GetDirectoryName(solutionPath) ?? "";
            var ebgPath                  = Path.Combine(solutionDirectory + @"DLaB.EBG.Settings.xml");
            var testSolutionTemplatePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            Directory.CreateDirectory(solutionDirectory);
            // Copy Solution and EarlyBoundSettings Xml to Temp Folder
            File.Copy(Path.Combine(testSolutionTemplatePath ?? "", @"SolutionTemplate\Abc.Xrm.sln"), solutionPath, true);
            File.Copy(Path.Combine(testSolutionTemplatePath ?? "", @"SolutionTemplate\DLaB.EBG.Settings.xml"), ebgPath, true);

            var results = new object[]
            {
                new List <string> {
                    "Y", solutionPath
                },
                "Abc.Xrm",
                new NuGetPackage
                {
                    Id               = "Microsoft.CrmSdk.CoreAssemblies",
                    LicenseUrl       = "http://download.microsoft.com/download/E/1/8/E18C0FAD-FEC8-44CD-9A16-98EDC4DAC7A2/LicenseTerms.docx",
                    Name             = "Microsoft Dynamics 365 SDK core assemblies",
                    Version          = new Version("9.0.2.5"),
                    VersionText      = "9.0.2.5",
                    XrmToolingClient = false
                },
                "Y",
                "Abc.Xrm",
                "Abc.Xrm.WorkflowCore",
                new List <string> {
                    "Y", "Abc.Xrm.Test", "Abc.Xrm.TestCore"
                },
                new List <string> {
                    "Y", "Abc.Xrm.Plugin", "0"
                },
                "Abc.Xrm.Plugin.Tests",
                new List <string> {
                    "Y", "Abc.Xrm.Workflow", "0"
                },
                "Abc.Xrm.Workflow.Tests",
                new List <string> {
                    "0", "0"
                },
            };
            var info = InitializeSolutionInfo.InitializeSolution(results);

            setCustomSettings?.Invoke(info);

            var templatePath = TestBase.GetTemplatePath();
            var context      = new InitializeSolutionTestInfo
            {
                Info              = info,
                TempDir           = tempDir,
                TemplatePath      = templatePath,
                SolutionDirectory = solutionDirectory
            };

            var logic = new SolutionInitializer(context.Info.SolutionPath, context.TemplatePath);

            logic.Projects = logic.GetProjectInfos(context.Info);
            context.SolutionInitializer = logic;
            return(context);
        }