예제 #1
0
        public void Execute_Ok_MultipleProjectGenConfig()
        {
            var    projectName = "Test";
            string projectFile = $@"TestProject\{projectName}.csproj";

            DestinationPath = @".\TestData\tmp\TestProject";
            OutputPath      = @".\TestData\tmp\";
            ProjectName     = projectName;

            GenContext.Current = this;

            Directory.CreateDirectory(GenContext.Current.DestinationPath);
            File.Copy(Path.Combine(Environment.CurrentDirectory, $"TestData\\{projectFile}"), Path.Combine(GenContext.Current.OutputPath, projectFile), true);

            Dictionary <string, string> testArgs = new Dictionary <string, string>();

            testArgs.Add("files", "0");
            List <FakeCreationPath> testPrimaryOutputs = new List <FakeCreationPath>();

            testPrimaryOutputs.Add(new FakeCreationPath()
            {
                Path = projectFile
            });
            IPostAction templateDefinedPostAction = new FakeTemplateDefinedPostAction(GenerateTestCertificatePostAction.Id, testArgs, true);

            var postAction = new GenerateTestCertificatePostAction("TestTemplate", "TestUser", templateDefinedPostAction, testPrimaryOutputs as IReadOnlyList <ICreationPath>, new Dictionary <string, string>());

            postAction.Execute();

            var expectedCertFilePath = Path.Combine(GenContext.Current.DestinationPath, $"{projectName}_TemporaryKey.pfx");

            Assert.True(File.Exists(expectedCertFilePath));

            Fs.SafeDeleteDirectory(DestinationPath);
        }
예제 #2
0
        public void AddNugetReferenceToContext_Execute()
        {
            var templateName = "Test";
            var projectName  = "TestProject";
            var destPath     = Path.GetFullPath(@".\DestinationPath\Project");

            var nugetReference = new NugetReference()
            {
                Project   = Path.Combine(destPath, projectName),
                PackageId = "TestPackage",
                Version   = "1.0.0",
            };

            GenContext.Current = new FakeContextProvider()
            {
                DestinationPath      = destPath,
                GenerationOutputPath = destPath,
            };

            var postAction = new FakeTemplateDefinedPostAction(
                new Guid(AddNugetReferenceToContextPostAction.Id),
                new Dictionary <string, string>()
            {
                { "packageId", nugetReference.PackageId },
                { "version", nugetReference.Version },
                { "projectPath", projectName },
            });

            var mergePostAction = new AddNugetReferenceToContextPostAction(templateName, postAction, new Dictionary <string, string>(), destPath);

            mergePostAction.Execute();

            Assert.Equal(nugetReference, GenContext.Current.ProjectInfo.NugetReferences[0]);
        }
예제 #3
0
        public void AddProjectReferenceToContext_Execute()
        {
            var templateName = "Test";
            var projectName  = "MyProject";
            var destPath     = Path.GetFullPath(@".\DestinationPath\Project");
            var projectToAdd = @".\TestProject.csproj";

            GenContext.Current = new FakeContextProvider()
            {
                DestinationPath      = destPath,
                GenerationOutputPath = destPath,
            };

            List <FakeCreationPath> testPrimaryOutputs = new List <FakeCreationPath>();

            testPrimaryOutputs.Add(new FakeCreationPath()
            {
                Path = projectToAdd
            });

            var postAction = new FakeTemplateDefinedPostAction(
                new Guid(AddProjectReferencesToContextPostAction.Id),
                new Dictionary <string, string>()
            {
                { "fileIndex", "0" },
                { "projectPath", projectName },
            });

            var mergePostAction = new AddProjectReferencesToContextPostAction(templateName, postAction, testPrimaryOutputs, new Dictionary <string, string>(), destPath);

            mergePostAction.Execute();

            Assert.True(GenContext.Current.ProjectInfo.ProjectReferences.Any(p => p.Project == Path.Combine(destPath, projectName)));
            Assert.True(GenContext.Current.ProjectInfo.ProjectReferences.Any(p => p.Project == Path.Combine(destPath, projectName) && p.ReferencedProject == Path.GetFullPath(Path.Combine(destPath, projectToAdd))));
        }
예제 #4
0
        public void AddSdkReferenceToContext_Execute()
        {
            var templateName = "Test";
            var projectName  = "TestProject";
            var destPath     = Path.GetFullPath(@".\DestinationPath\Project");

            var sdkReference = new SdkReference()
            {
                Project = Path.Combine(destPath, projectName),
                Name    = "TestName",
                Sdk     = "Test, version=1.0.0",
            };

            GenContext.Current = new FakeContextProvider()
            {
                DestinationPath      = destPath,
                GenerationOutputPath = destPath,
            };

            var postAction = new FakeTemplateDefinedPostAction(
                new Guid(AddSdkReferencesToContextPostAction.Id),
                new Dictionary <string, string>()
            {
                { "name", sdkReference.Name },
                { "sdk", sdkReference.Sdk },
                { "projectPath", projectName },
            });

            var mergePostAction = new AddSdkReferencesToContextPostAction(templateName, postAction, new Dictionary <string, string>(), destPath);

            mergePostAction.Execute();

            Assert.Equal(sdkReference, GenContext.Current.ProjectInfo.SdkReferences[0]);
        }
예제 #5
0
 public void BadInstantiation_NoContinueOnError()
 {
     ProjectName = "test4";
     Assert.Throws <Exception>(() =>
     {
         Dictionary <string, string> testArgs = new Dictionary <string, string>();
         testArgs.Add("myArg", "myValue");
         IPostAction inventedIdPostAction = new FakeTemplateDefinedPostAction(Guid.NewGuid(), testArgs, false);
         var postAction = new GenerateTestCertificatePostAction("TestTemplate", "TestUser", inventedIdPostAction, null, new Dictionary <string, string>());
     });
 }
예제 #6
0
        public void BadInstantiation_ContinueOnError()
        {
            ProjectName = "test3";
            Dictionary <string, string> testArgs = new Dictionary <string, string>();

            testArgs.Add("myArg", "myValue");
            IPostAction inventedIdPostAction = new FakeTemplateDefinedPostAction(Guid.NewGuid(), testArgs, true);

            var postAction = new GenerateTestCertificatePostAction("TestTemplate", "TestUser", inventedIdPostAction, null, new Dictionary <string, string>());

            Assert.True(postAction.ContinueOnError);
            Assert.NotEqual(inventedIdPostAction.ActionId, GenerateTestCertificatePostAction.Id);
            Assert.Null(postAction.Args);
        }
예제 #7
0
        public void GenerateTestCertificate_Execute_Ok_SingleProjectGenConfigs()
        {
            var projectName          = "Test";
            var projectFile          = $"{projectName}.csproj";
            var destinationPath      = @".\TestData\temp\TestProject";
            var generationOutputPath = @".\TestData\temp\TestProject";

            GenContext.Bootstrap(new LocalTemplatesSource(), new FakeGenShell(Platforms.Uwp, ProgrammingLanguages.CSharp), Platforms.Uwp, ProgrammingLanguages.CSharp);

            GenContext.Current = new FakeContextProvider
            {
                DestinationPath      = destinationPath,
                GenerationOutputPath = generationOutputPath,
            };

            Directory.CreateDirectory(generationOutputPath);
            var sourceFile = Path.Combine(Environment.CurrentDirectory, $"TestData\\TestProject\\{projectFile}");
            var destFile   = Path.Combine(generationOutputPath, projectFile);

            File.Copy(sourceFile, destFile, true);

            var testArgs = new Dictionary <string, string>
            {
                { "files", "0" },
            };

            var testPrimaryOutputs = new List <FakeCreationPath>()
            {
                new FakeCreationPath()
                {
                    Path = projectFile
                },
            };

            var templateDefinedPostAction = new FakeTemplateDefinedPostAction(new Guid(GenerateTestCertificatePostAction.Id), testArgs, true);
            var postAction = new GenerateTestCertificatePostAction("TestTemplate", "TestUser", templateDefinedPostAction, testPrimaryOutputs as IReadOnlyList <ICreationPath>, new Dictionary <string, string>(), destinationPath);

            postAction.Execute();

            var expectedCertFilePath = Path.Combine(generationOutputPath, $"{projectName}_TemporaryKey.pfx");

            Assert.True(File.Exists(expectedCertFilePath));

            Fs.SafeDeleteDirectory(generationOutputPath);
        }
        public void AddJsonDictionaryItem_Execute()
        {
            var templateName     = "Test";
            var destPath         = Path.GetFullPath(@".\TestData\TestJson");
            var expectedJsonPath = "TestJson_expected.json";
            var jsonPath         = "TestJson.json";
            var key = "TestKey";

            var dictItemsToAdd = new Dictionary <string, string>()
            {
                { "abc", "123" },
                { "def", "456" },
                { "ghi", "789" },
                { "jkl", "111" },
            };

            string dictItemsToAddSerialized = JsonConvert.SerializeObject(dictItemsToAdd);

            GenContext.Current = new TestContextProvider()
            {
                DestinationPath      = destPath,
                GenerationOutputPath = destPath,
            };

            var postAction = new FakeTemplateDefinedPostAction(
                new Guid(AddJsonDictionaryItemPostAction.Id),
                new Dictionary <string, string>()
            {
                { "dict", dictItemsToAddSerialized },
                { "jsonPath", jsonPath },
                { "key", key },
            });

            var mergePostAction = new AddJsonDictionaryItemPostAction(templateName, postAction, new Dictionary <string, string>(), destPath);

            mergePostAction.Execute();

            var combinedPathOfResult   = Path.Combine(destPath, jsonPath);
            var combinedPathOfExpected = Path.Combine(destPath, expectedJsonPath);

            Assert.Equal(File.ReadAllText(combinedPathOfExpected), File.ReadAllText(combinedPathOfResult));
        }