Ejemplo n.º 1
0
        public static string GetSnapResultMessage(SnapResult result)
        {
            switch (result.Status)
            {
            case SnapResultStatus.SnapshotDoesNotExist:
                var attributeName = nameof(UpdateSnapshotsAttribute).Replace("Attribute", string.Empty);
                var message       = new StringBuilder();
                message.AppendLine($"A snapshot does not exist.{Environment.NewLine}");
                message.AppendLine($"Apply the [{attributeName}] attribute on the " +
                                   $"test method or class and then run the test again to " +
                                   $"create a snapshot.");
                return(message.ToString());

            case SnapResultStatus.SnapshotsMatch:
                return("Snapshots Match.");

            case SnapResultStatus.SnapshotsDoNotMatch:
                return(JsonDiffGenerator.GetDiffMessage(result.OldSnapshot, result.NewSnapshot));

            case SnapResultStatus.SnapshotUpdated:
                return("Snapshot was updated.");

            default:
                return(string.Empty);
            }
        }
Ejemplo n.º 2
0
        public void ValueAddedTest_LargeObject()
        {
            var currentSnapshot = new
            {
                Key  = "Value",
                Key1 = "Value",
                Key2 = "Value",
                Key3 = "Value",
                Key4 = "Value",
                Key5 = "Value",
            };

            var newSnapshot = new
            {
                Key    = "Value",
                Key1   = "Value",
                Key2   = "Value",
                Key3   = "Value",
                NewKey = "Value",
                Key4   = "Value",
                Key5   = "Value",
            };

            var result = JsonDiffGenerator.GetDiffMessage(currentSnapshot, newSnapshot);

            result.Should().Be(DiffMaker(builder =>
            {
                builder.AppendLine("  \"Key2\": \"Value\",");
                builder.AppendLine("  \"Key3\": \"Value\",");
                builder.AppendLine("+    \"NewKey\": \"Value\",");
                builder.AppendLine("  \"Key4\": \"Value\",");
                builder.AppendLine("  \"Key5\": \"Value\"");
            }));
        }
Ejemplo n.º 3
0
        public void ValueChangedTest()
        {
            var currentSnapshot = new
            {
                Key = "Value"
            };

            var newSnapshot = new
            {
                Key = "Value2"
            };

            var result = JsonDiffGenerator.GetDiffMessage(currentSnapshot, newSnapshot);

            result.Should().Be(DiffMaker(builder =>
            {
                builder.AppendLine("{");
                builder.AppendLine("-    \"Key\": \"Value\"");
                builder.AppendLine("+    \"Key\": \"Value2\"");
                builder.AppendLine("}");
            }));
        }
Ejemplo n.º 4
0
        public static string GetSnapResultMessage(SnapResult result)
        {
            switch (result.Status)
            {
            case SnapResultStatus.SnapshotDoesNotExist:
                var message = new StringBuilder();
                message.AppendLine($"A snapshot does not exist.{Environment.NewLine}");
                message.AppendLine("Run the test outside of a CI environment to create a snapshot.");
                return(message.ToString());

            case SnapResultStatus.SnapshotsMatch:
                return("Snapshots Match.");

            case SnapResultStatus.SnapshotsDoNotMatch:
                return(JsonDiffGenerator.GetDiffMessage(result.OldSnapshot, result.NewSnapshot));

            case SnapResultStatus.SnapshotUpdated:
                return("Snapshot was updated.");

            default:
                return(string.Empty);
            }
        }