Beispiel #1
0
 /// <summary>
 /// Tests the TypeNameHandling property in a JSON serializer settings object.
 /// </summary>
 /// <param name="typeNameHandling">Expected TypeNameHandling.</param>
 /// <returns>The same JSON serializer settings test builder.</returns>
 public IAndJsonSerializerSettingsTestBuilder WithTypeNameHandling(TypeNameHandling typeNameHandling)
 {
     this.jsonSerializerSettings.TypeNameHandling = typeNameHandling;
     this.validations.Add((expected, actual) =>
     {
         if (!CommonValidator.CheckEquality(expected.TypeNameHandling, actual.TypeNameHandling))
         {
             this.ThrowNewJsonResultAssertionException(
                 string.Format("{0} type name handling", expected.TypeNameHandling),
                 string.Format("in fact found {0}", actual.TypeNameHandling));
         }
     });
     return(this);
 }
Beispiel #2
0
        /// <summary>
        /// Tests the FormatterAssemblyStyle property in a JSON serializer settings object.
        /// </summary>
        /// <param name="typeNameAssemblyFormat">Expected FormatterAssemblyStyle.</param>
        /// <returns>The same JSON serializer settings test builder.</returns>
        public IAndJsonSerializerSettingsTestBuilder WithTypeNameAssemblyFormat(FormatterAssemblyStyle typeNameAssemblyFormat)
        {
            this.jsonSerializerSettings.TypeNameAssemblyFormat = typeNameAssemblyFormat;
            this.validations.Add((expected, actual) =>
            {
                if (!CommonValidator.CheckEquality(expected.TypeNameAssemblyFormat, actual.TypeNameAssemblyFormat))
                {
                    this.ThrowNewJsonResultAssertionException(
                        string.Format("{0} type name assembly format", expected.TypeNameAssemblyFormat),
                        string.Format("in fact found {0}", actual.TypeNameAssemblyFormat));
                }
            });

            return(this);
        }
Beispiel #3
0
        /// <summary>
        /// Tests the ObjectCreationHandling property in a JSON serializer settings object.
        /// </summary>
        /// <param name="objectCreationHandling">Expected ObjectCreationHandling.</param>
        /// <returns>The same JSON serializer settings test builder.</returns>
        public IAndJsonSerializerSettingsTestBuilder WithObjectCreationHandling(ObjectCreationHandling objectCreationHandling)
        {
            this.jsonSerializerSettings.ObjectCreationHandling = objectCreationHandling;
            this.validations.Add((expected, actual) =>
            {
                if (!CommonValidator.CheckEquality(expected.ObjectCreationHandling, actual.ObjectCreationHandling))
                {
                    this.ThrowNewJsonResultAssertionException(
                        string.Format("{0} object creation handling", expected.ObjectCreationHandling),
                        string.Format("in fact found {0}", actual.ObjectCreationHandling));
                }
            });

            return(this);
        }
Beispiel #4
0
        /// <summary>
        /// Tests the ReferenceLoopHandling property in a JSON serializer settings object.
        /// </summary>
        /// <param name="referenceLoopHandling">Expected ReferenceLoopHandling.</param>
        /// <returns>The same JSON serializer settings test builder.</returns>
        public IAndJsonSerializerSettingsTestBuilder WithReferenceLoopHandling(ReferenceLoopHandling referenceLoopHandling)
        {
            this.jsonSerializerSettings.ReferenceLoopHandling = referenceLoopHandling;
            this.validations.Add((expected, actual) =>
            {
                if (!CommonValidator.CheckEquality(expected.ReferenceLoopHandling, actual.ReferenceLoopHandling))
                {
                    this.ThrowNewJsonResultAssertionException(
                        string.Format("{0} reference loop handling", expected.ReferenceLoopHandling),
                        string.Format("in fact found {0}", actual.ReferenceLoopHandling));
                }
            });

            return(this);
        }
Beispiel #5
0
        /// <summary>
        /// Tests the MaxDepth property in a JSON serializer settings object.
        /// </summary>
        /// <param name="maxDepth">Expected max depth.</param>
        /// <returns>The same JSON serializer settings test builder.</returns>
        public IAndJsonSerializerSettingsTestBuilder WithMaxDepth(int?maxDepth)
        {
            this.jsonSerializerSettings.MaxDepth = maxDepth;
            this.validations.Add((expected, actual) =>
            {
                if (!CommonValidator.CheckEquality(expected.MaxDepth, actual.MaxDepth))
                {
                    this.ThrowNewJsonResultAssertionException(
                        string.Format("{0} max depth", expected.MaxDepth),
                        string.Format("in fact found {0}", actual.MaxDepth));
                }
            });

            return(this);
        }
Beispiel #6
0
        /// <summary>
        /// Tests the MissingMemberHandling property in a JSON serializer settings object.
        /// </summary>
        /// <param name="missingMemberHandling">Expected MissingMemberHandling.</param>
        /// <returns>The same JSON serializer settings test builder.</returns>
        public IAndJsonSerializerSettingsTestBuilder WithMissingMemberHandling(MissingMemberHandling missingMemberHandling)
        {
            this.jsonSerializerSettings.MissingMemberHandling = missingMemberHandling;
            this.validations.Add((expected, actual) =>
            {
                if (!CommonValidator.CheckEquality(expected.MissingMemberHandling, actual.MissingMemberHandling))
                {
                    this.ThrowNewJsonResultAssertionException(
                        string.Format("{0} missing member handling", expected.MissingMemberHandling),
                        string.Format("in fact found {0}", actual.MissingMemberHandling));
                }
            });

            return(this);
        }
        /// <inheritdoc />
        public IAndJsonSerializerSettingsTestBuilder WithNullValueHandling(NullValueHandling nullValueHandling)
        {
            this.jsonSerializerSettings.NullValueHandling = nullValueHandling;
            this.validations.Add((expected, actual) =>
            {
                if (!CommonValidator.CheckEquality(expected.NullValueHandling, actual.NullValueHandling))
                {
                    this.ThrowNewJsonResultAssertionException(
                        $"{expected.NullValueHandling} null value handling",
                        $"in fact found {actual.NullValueHandling}");
                }
            });

            return(this);
        }
Beispiel #8
0
        /// <summary>
        /// Tests the WithDateTimeZoneHandling property in a JSON serializer settings object.
        /// </summary>
        /// <param name="dateTimeZoneHandling">Expected WithDateTimeZoneHandling.</param>
        /// <returns>The same JSON serializer settings test builder.</returns>
        public IAndJsonSerializerSettingsTestBuilder WithDateTimeZoneHandling(DateTimeZoneHandling dateTimeZoneHandling)
        {
            this.jsonSerializerSettings.DateTimeZoneHandling = dateTimeZoneHandling;
            this.validations.Add((expected, actual) =>
            {
                if (!CommonValidator.CheckEquality(expected.DateTimeZoneHandling, actual.DateTimeZoneHandling))
                {
                    this.ThrowNewJsonResultAssertionException(
                        string.Format("{0} date time zone handling", expected.DateTimeZoneHandling),
                        string.Format("in fact found {0}", actual.DateTimeZoneHandling));
                }
            });

            return(this);
        }
        /// <inheritdoc />
        public IAndJsonSerializerSettingsTestBuilder WithStringEscapeHandling(StringEscapeHandling stringEscapeHandling)
        {
            this.jsonSerializerSettings.StringEscapeHandling = stringEscapeHandling;
            this.validations.Add((expected, actual) =>
            {
                if (!CommonValidator.CheckEquality(expected.StringEscapeHandling, actual.StringEscapeHandling))
                {
                    this.ThrowNewJsonResultAssertionException(
                        $"{expected.StringEscapeHandling} string escape handling",
                        $"in fact found {actual.StringEscapeHandling}");
                }
            });

            return(this);
        }
        /// <inheritdoc />
        public IAndJsonSerializerSettingsTestBuilder WithMetadataPropertyHandling(MetadataPropertyHandling metadataPropertyHandling)
        {
            this.jsonSerializerSettings.MetadataPropertyHandling = metadataPropertyHandling;
            this.validations.Add((expected, actual) =>
            {
                if (!CommonValidator.CheckEquality(expected.MetadataPropertyHandling, actual.MetadataPropertyHandling))
                {
                    this.ThrowNewJsonResultAssertionException(
                        $"{expected.MetadataPropertyHandling} metadata property handling",
                        $"in fact found {actual.MetadataPropertyHandling}");
                }
            });

            return(this);
        }
        /// <inheritdoc />
        public IAndJsonSerializerSettingsTestBuilder WithFormatting(Formatting formatting)
        {
            this.jsonSerializerSettings.Formatting = formatting;
            this.validations.Add((expected, actual) =>
            {
                if (!CommonValidator.CheckEquality(expected.Formatting, actual.Formatting))
                {
                    this.ThrowNewJsonResultAssertionException(
                        $"{expected.Formatting} formatting",
                        $"in fact found {actual.Formatting}");
                }
            });

            return(this);
        }
        /// <inheritdoc />
        public IAndJsonSerializerSettingsTestBuilder WithConstructorHandling(ConstructorHandling constructorHandling)
        {
            this.jsonSerializerSettings.ConstructorHandling = constructorHandling;
            this.validations.Add((expected, actual) =>
            {
                if (!CommonValidator.CheckEquality(expected.ConstructorHandling, actual.ConstructorHandling))
                {
                    this.ThrowNewJsonResultAssertionException(
                        $"{expected.ConstructorHandling} constructor handling",
                        $"in fact found {actual.ConstructorHandling}");
                }
            });

            return(this);
        }
        /// <inheritdoc />
        public IAndJsonSerializerSettingsTestBuilder WithTypeNameAssemblyFormatHandling(
            TypeNameAssemblyFormatHandling typeNameAssemblyFormatHandling)
        {
            this.jsonSerializerSettings.TypeNameAssemblyFormatHandling = typeNameAssemblyFormatHandling;
            this.validations.Add((expected, actual) =>
            {
                if (!CommonValidator.CheckEquality(expected.TypeNameAssemblyFormatHandling, actual.TypeNameAssemblyFormatHandling))
                {
                    this.ThrowNewJsonResultAssertionException(
                        $"{expected.TypeNameAssemblyFormatHandling} type name assembly format handling",
                        $"in fact found {actual.TypeNameAssemblyFormatHandling}");
                }
            });

            return(this);
        }
        /// <inheritdoc />
        public IAndJsonSerializerSettingsTestBuilder WithPreserveReferencesHandling(PreserveReferencesHandling preserveReferencesHandling)
        {
            this.jsonSerializerSettings.PreserveReferencesHandling = preserveReferencesHandling;
            this.validations.Add((expected, actual) =>
            {
                if (!CommonValidator.CheckEquality(
                        expected.PreserveReferencesHandling,
                        actual.PreserveReferencesHandling))
                {
                    this.ThrowNewJsonResultAssertionException(
                        $"{expected.PreserveReferencesHandling} preserve references handling",
                        $"in fact found {actual.PreserveReferencesHandling}");
                }
            });

            return(this);
        }
        /// <inheritdoc />
        public IAndJsonSerializerSettingsTestBuilder WithMaxDepth(int?maxDepth)
        {
            this.jsonSerializerSettings.MaxDepth = maxDepth;
            this.validations.Add((expected, actual) =>
            {
                var expectedMaxDepth = expected.MaxDepth;
                var actualMaxDepth   = actual.MaxDepth;

                if (!CommonValidator.CheckEquality(expectedMaxDepth, actualMaxDepth))
                {
                    this.ThrowNewJsonResultAssertionException(
                        $"{expectedMaxDepth.GetErrorMessageName(false, "no")} max depth",
                        $"in fact found {actualMaxDepth.GetErrorMessageName(false, "none")}");
                }
            });

            return(this);
        }