예제 #1
0
        public int Execute()
        {
            if (!File.Exists(SourceFile))
            {
                File.WriteAllText(SourceFile, "{}");
            }

            JsonEditor.SetProperty(SourceFile, Key, Value);
            return(0);
        }
예제 #2
0
파일: JsonTest.cs 프로젝트: Ackara/Cecrets
        public void Can_set_json_property(string[] keys)
        {
            // Arrange
            using var approver = ApprovalTests.Namers.ApprovalResults.ForScenario(string.Join("__", keys));
            var line = string.Concat(Enumerable.Repeat('-', 50));

            var sourceFile = Path.Combine(_currentWorkingDirectory, $"secrets-set-test({string.Join(" ", keys)}).json");

            // Act
            foreach (var item in keys)
            {
                JsonEditor.SetProperty(sourceFile, item, 123);

                System.Diagnostics.Debug.WriteLine($"arg: {item}");
                var result = File.ReadAllText(sourceFile);
                System.Diagnostics.Debug.WriteLine(result);
                System.Diagnostics.Debug.WriteLine(line);
                System.Diagnostics.Debug.WriteLine(string.Empty);
                System.Diagnostics.Debug.WriteLine(string.Empty);
            }

            // Assert
            Approvals.VerifyFile(sourceFile);
        }