public void format__correct_json_from_file_write_back_with_formatting()
        {
            // arrange
            var context = new FormatAction
            {
                InputPath    = "mypath",
                UseFormatted = true,
                UseNone      = false
            };

            var obj      = new { name = "ryan r", today = new DateTime(2017, 10, 8) };
            var mockJson = JsonConvert.SerializeObject(obj);

            Isolate.WhenCalled(() => File.Exists(Any.String)).WillReturn(true);
            Isolate.WhenCalled(() => File.ReadAllText(Any.String)).WillReturn(mockJson);
            Isolate.WhenCalled(() => File.WriteAllText(Any.String, Any.String)).IgnoreCall();

            // act
            var dpa = new DefaultProgramActions();

            dpa.Format(context);

            // assert
            // typemock verify api does not allow putting in properties or method calls
            string inputPath    = context.InputPath;
            string expectedJson = JsonConvert.SerializeObject(obj, Formatting.Indented);

            Isolate.Verify.WasCalledWithExactArguments(() => File.Exists(inputPath));
            Isolate.Verify.WasCalledWithExactArguments(() => File.ReadAllText(inputPath));
            Isolate.Verify.WasCalledWithExactArguments(() => File.WriteAllText(inputPath, expectedJson));
        }
        public void format__empty_data_from_file_results_in_no_action_getting_called(string fileContents)
        {
            // arrange
            var context = new FormatAction
            {
                InputPath    = "mypath",
                UseFormatted = true,
                UseNone      = false
            };

            Isolate.WhenCalled(() => File.Exists(Any.String)).WillReturn(true);
            Isolate.WhenCalled(() => File.ReadAllText(Any.String)).WillReturn(fileContents);
            Isolate.WhenCalled(() => Console.WriteLine(Any.String)).IgnoreCall();

            // act
            var dpa = new DefaultProgramActions();

            dpa.Format(context);

            // assert
            // typemock verify api does not allow putting in properties or method calls
            string inputPath = context.InputPath;

            Isolate.Verify.WasCalledWithExactArguments(() => File.Exists(inputPath));
            Isolate.Verify.WasCalledWithExactArguments(() => File.ReadAllText(inputPath));
            Isolate.Verify.WasCalledWithExactArguments(() => Console.WriteLine("File contents are empty. No operation performed."));
        }
        public void format__file_does_not_exist_message_is_printed_to_console()
        {
            // arrange
            var context = new FormatAction
            {
                InputPath    = "mypath",
                UseFormatted = true,
                UseNone      = false
            };

            Isolate.WhenCalled(() => File.Exists(Any.String)).WillReturn(false);
            Isolate.WhenCalled(() => Console.WriteLine(Any.String)).IgnoreCall();

            // act
            var dpa = new DefaultProgramActions();

            dpa.Format(context);

            // assert
            // typemock verify api does not allow putting in properties or method calls
            string inputPath       = context.InputPath;
            string expectedMessage = $"{context.InputPath} does not exist.";

            Isolate.Verify.WasCalledWithExactArguments(() => File.Exists(inputPath));
            Isolate.Verify.WasCalledWithExactArguments(() => Console.WriteLine(expectedMessage));
        }
        public void format__invalid_json_in_file_parse_throws_exception(string fileContents)
        {
            // arrange
            var context = new FormatAction
            {
                InputPath    = "mypath",
                UseFormatted = false,
                UseNone      = true
            };

            Isolate.WhenCalled(() => File.Exists(Any.String)).WillReturn(true);
            Isolate.WhenCalled(() => File.ReadAllText(Any.String)).WillReturn(fileContents);
            Isolate.WhenCalled(() => File.WriteAllText(Any.String, Any.String)).IgnoreCall();

            // act
            var dpa = new DefaultProgramActions();
            var jre = Assert.Throws <JsonReaderException>(() => dpa.Format(context));

            // assert
            // typemock verify api does not allow putting in properties or method calls
            string inputPath = context.InputPath;

            Isolate.Verify.WasCalledWithExactArguments(() => File.Exists(inputPath));
            Isolate.Verify.WasCalledWithExactArguments(() => File.ReadAllText(inputPath));
            Isolate.Verify.WasNotCalled(() => File.WriteAllText(Any.String, Any.String));
        }
Example #5
0
        public void create_default_instance()
        {
            var fa = new FormatAction();

            Assert.IsNotNull(fa);
        }
Example #6
0
 private void InsertFormatTag(FormatAction action)
 {
 }