예제 #1
0
        public bool Execute()
        {
            const string fullPath = "FullPath";
            string       src      = SourceFile.GetMetadata(fullPath);
            string       dest     = (DestinationFile?.GetMetadata(fullPath) ?? Path.Combine(Path.GetDirectoryName(BuildEngine.ProjectFileOfTaskNode), "appsettings.json"));

            foreach (string path in JPath.Split(new char[] { ';', ',' }, System.StringSplitOptions.RemoveEmptyEntries))
            {
                JsonEditor.CopyProperty(src, dest, path);
                BuildEngine.LogMessageEvent(new BuildMessageEventArgs(
                                                $"Copied  '{Path.GetFileName(src)}':'{path}' property to '{Path.GetFileName(dest)}'", null, nameof(CopyJsonProperties), MessageImportance.Normal));
            }

            return(true);
        }
예제 #2
0
파일: JsonTest.cs 프로젝트: Ackara/Cecrets
        public void Can_copy_json_property(string jpath)
        {
            // Arrange
            string sourceFilePath = TestData.GetFile("config1.json");
            string resultFilePath = Path.Combine(_currentWorkingDirectory, $"cecret-copy-test.{jpath}.json".Replace('*', '_'));

            using var approver = ApprovalTests.Namers.ApprovalResults.ForScenario(jpath);

            // Act
            if (File.Exists(resultFilePath))
            {
                File.Delete(resultFilePath);
            }
            JsonEditor.CopyProperty(sourceFilePath, resultFilePath, jpath);
            JsonEditor.CopyProperty(sourceFilePath, resultFilePath, jpath);

            // Assert
            File.Exists(resultFilePath).ShouldBeTrue();
            Approvals.Verify(File.ReadAllText(resultFilePath));
        }