/// <summary>
        /// Asserts that a collection of objects is equivalent to another collection of objects.
        /// </summary>
        /// <remarks>
        /// The two collections are equivalent when they both contain the same strings in any order.
        /// </remarks>
        /// <param name="config">
        /// A reference to the <see cref="EquivalencyAssertionOptions{String}"/> configuration object that can be used
        /// to influence the way the object graphs are compared. You can also provide an alternative instance of the
        /// <see cref="EquivalencyAssertionOptions{String}"/> class. The global defaults are determined by the
        /// <see cref="AssertionOptions"/> class.
        /// </param>
        /// <param name="because">
        /// An optional formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the
        /// assertion is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
        /// </param>
        /// <param name="becauseArgs">
        /// Zero or more objects to format using the placeholders in <see cref="because" />.
        /// </param>
        public AndConstraint <StringCollectionAssertions> BeEquivalentTo(IEnumerable <string> expectation,
                                                                         Func <EquivalencyAssertionOptions <string>, EquivalencyAssertionOptions <string> > config, string because = "",
                                                                         params object[] becauseArgs)
        {
            Guard.ThrowIfArgumentIsNull(config, nameof(config));

            EquivalencyAssertionOptions <IEnumerable <string> > options = config(AssertionOptions.CloneDefaults <string>()).AsCollection();

            var context = new EquivalencyValidationContext
            {
                Subject          = Subject,
                Expectation      = expectation,
                RootIsCollection = true,
                CompileTimeType  = typeof(IEnumerable <string>),
                Because          = because,
                BecauseArgs      = becauseArgs,
                Tracer           = options.TraceWriter
            };

            var equivalencyValidator = new EquivalencyValidator(options);

            equivalencyValidator.AssertEquality(context);

            return(new AndConstraint <StringCollectionAssertions>(this));
        }
        /// <summary>
        /// Applies a step as part of the task to compare two objects for structural equality.
        /// </summary>
        /// <value>
        /// Should return <c>true</c> if the subject matches the expectation or if no additional assertions
        /// have to be executed. Should return <c>false</c> otherwise.
        /// </value>
        /// <remarks>
        /// May throw when preconditions are not met or if it detects mismatching data.
        /// </remarks>
        public bool Handle(EquivalencyValidationContext context, IEquivalencyValidator parent,
            IEquivalencyAssertionOptions config)
        {
            context.Subject.Should().Be(context.Expectation, context.Reason, context.ReasonArgs);

            return true;
        }
        /// <summary>
        /// Applies a step as part of the task to compare two objects for structural equality.
        /// </summary>
        /// <value>
        /// Should return <c>true</c> if the subject matches the expectation or if no additional assertions
        /// have to be executed. Should return <c>false</c> otherwise.
        /// </value>
        /// <remarks>
        /// May throw when preconditions are not met or if it detects mismatching data.
        /// </remarks>
        public bool Handle(EquivalencyValidationContext context, IEquivalencyValidator parent,
                           IEquivalencyAssertionOptions config)
        {
            context.Subject.Should().Be(context.Expectation, context.Reason, context.ReasonArgs);

            return(true);
        }
Beispiel #4
0
        public bool Handle(
            IEquivalencyValidationContext context,
            IEquivalencyValidator parent,
            IEquivalencyAssertionOptions config)
        {
            EquivalencyValidationContext equivalencyValidationContext = CreateAdjustedCopy(context);

            return(equivalencyStep.Handle(equivalencyValidationContext, parent, config));
        }
        public static void ShouldAllBeEquivalentTo <T>(this IEnumerable <T> subject, IEnumerable expectation,
                                                       Func <EquivalencyAssertionOptions <T>, EquivalencyAssertionOptions <T> > config, string reason = "", params object[] reasonArgs)
        {
            var context = new EquivalencyValidationContext()
            {
                Subject         = subject,
                Expectation     = expectation,
                CompileTimeType = typeof(T),
                Reason          = reason,
                ReasonArgs      = reasonArgs
            };

            new EquivalencyValidator(config(EquivalencyAssertionOptions <T> .Default())).AssertEquality(context);
        }
        public static void ShouldAllBeEquivalentTo <T>(this IEnumerable <T> subject, IEnumerable expectation,
                                                       Func <EquivalencyAssertionOptions <T>, EquivalencyAssertionOptions <T> > config, string because = "",
                                                       params object[] becauseArgs)
        {
            var context = new EquivalencyValidationContext()
            {
                Subject         = subject,
                Expectation     = expectation,
                CompileTimeType = typeof(T),
                Because         = because,
                BecauseArgs     = becauseArgs
            };

            new EquivalencyValidator(config(AssertionOptions.CloneDefaults <T>())).AssertEquality(context);
        }
Beispiel #7
0
        /// <summary>
        /// Asserts that an object is equivalent to another object.
        /// </summary>
        /// <remarks>
        /// Objects are equivalent when both object graphs have equally named properties with the same value,
        /// irrespective of the type of those objects. Two properties are also equal if one type can be converted to another and the result is equal.
        /// The type of a collection property is ignored as long as the collection implements <see cref="IEnumerable"/> and all
        /// items in the collection are structurally equal.
        /// </remarks>
        /// <param name="config">
        /// A reference to the <see cref="EquivalencyAssertionOptions{TSubject}"/> configuration object that can be used
        /// to influence the way the object graphs are compared. You can also provide an alternative instance of the
        /// <see cref="EquivalencyAssertionOptions{TSubject}"/> class. The global defaults are determined by the
        /// <see cref="AssertionOptions"/> class.
        /// </param>
        /// <param name="because">
        /// An optional formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the
        /// assertion is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
        /// </param>
        /// <param name="reasonArgs">
        /// Zero or more objects to format using the placeholders in <see cref="reason" />.
        /// </param>
        public static void ShouldBeEquivalentTo <T>(this T subject, object expectation,
                                                    Func <EquivalencyAssertionOptions <T>, EquivalencyAssertionOptions <T> > config, string because = "",
                                                    params object[] reasonArgs)
        {
            var context = new EquivalencyValidationContext
            {
                Subject         = subject,
                Expectation     = expectation,
                CompileTimeType = typeof(T),
                Reason          = because,
                ReasonArgs      = reasonArgs
            };

            new EquivalencyValidator(config(AssertionOptions.CloneDefaults <T>())).AssertEquality(context);
        }
Beispiel #8
0
        public static AndConstraint <GenericCollectionAssertions <T> > NotContainEquivalentOf <T>(
            this GenericCollectionAssertions <T> assert,
            T expectation,
            Func <EquivalencyAssertionOptions <T>, EquivalencyAssertionOptions <T> > config,
            string because = "",
            params object[] becauseArgs)
        {
            if (ReferenceEquals(assert.Subject, null))
            {
                return(new AndConstraint <GenericCollectionAssertions <T> >(assert));
            }

            IEquivalencyAssertionOptions options     = config(AssertionOptions.CloneDefaults <T>());
            IEnumerable <object>         actualItems = assert.Subject.Cast <object>();

            using (var scope = new AssertionScope())
            {
                scope.AddReportable("configuration", options.ToString());

                foreach (var actualItem in actualItems)
                {
                    var context = new EquivalencyValidationContext
                    {
                        Subject         = actualItem,
                        Expectation     = expectation,
                        CompileTimeType = typeof(T),
                        Because         = because,
                        BecauseArgs     = becauseArgs,
                        Tracer          = options.TraceWriter,
                    };

                    var equivalencyValidator = new EquivalencyValidator(options);
                    equivalencyValidator.AssertEquality(context);

                    var failures = scope.Discard();
                    if (!failures.Any())
                    {
                        Execute.Assertion
                        .BecauseOf(because, becauseArgs)
                        .FailWith("Expected {context:collection} {0} to not contain equivalent of {1}.", assert.Subject, expectation);
                        break;
                    }
                }
            }

            return(new AndConstraint <GenericCollectionAssertions <T> >(assert));
        }
        internal static void BeEquivalentTo <TExpectation, TSubject>(TSubject subject, TExpectation expectation,
                                                                     Func <EquivalencyAssertionOptions <TExpectation>, EquivalencyAssertionOptions <TExpectation> > config,
                                                                     string because = "",
                                                                     params object[] becauseArgs)
        {
            var options = config(AssertionOptions.CloneDefaults <TExpectation>());
            var context = new EquivalencyValidationContext
            {
                Subject         = subject,
                Expectation     = expectation,
                CompileTimeType = typeof(TExpectation),
                Because         = because,
                BecauseArgs     = becauseArgs,
                Tracer          = options.TraceWriter
            };

            new EquivalencyValidator(options).AssertEquality(context);
        }
        /// <summary>
        /// Asserts that an object is equivalent to another object.
        /// </summary>
        /// <remarks>
        /// Objects are equivalent when both object graphs have equally named properties with the same value,
        /// irrespective of the type of those objects. Two properties are also equal if one type can be converted to another and the result is equal.
        /// The type of a collection property is ignored as long as the collection implements <see cref="IEnumerable"/> and all
        /// items in the collection are structurally equal.
        /// </remarks>
        /// <param name="config">
        /// A reference to the <see cref="EquivalencyAssertionOptions{TSubject}"/> configuration object that can be used
        /// to influence the way the object graphs are compared. You can also provide an alternative instance of the
        /// <see cref="EquivalencyAssertionOptions{TSubject}"/> class. The global defaults are determined by the
        /// <see cref="AssertionOptions"/> class.
        /// </param>
        /// <param name="because">
        /// An optional formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the
        /// assertion is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
        /// </param>
        /// <param name="becauseArgs">
        /// Zero or more objects to format using the placeholders in <see cref="because" />.
        /// </param>
        public static void ShouldBeEquivalentTo <T>(this T subject, object expectation,
                                                    Func <EquivalencyAssertionOptions <T>, EquivalencyAssertionOptions <T> > config, string because = "",
                                                    params object[] becauseArgs)
        {
            IEquivalencyAssertionOptions options = config(AssertionOptions.CloneDefaults <T>());

            var context = new EquivalencyValidationContext
            {
                Subject         = subject,
                Expectation     = expectation,
                CompileTimeType = typeof(T),
                Because         = because,
                BecauseArgs     = becauseArgs,
                Tracer          = options.TraceWriter
            };

            new EquivalencyValidator(options).AssertEquality(context);
        }
Beispiel #11
0
        /// <summary>
        /// Asserts that a collection of objects is equivalent to another collection of objects.
        /// </summary>
        /// <remarks>
        /// Objects within the collections are equivalent when both object graphs have equally named properties with the same
        /// value,  irrespective of the type of those objects. Two properties are also equal if one type can be converted to another
        /// and the result is equal.
        /// The type of a collection property is ignored as long as the collection implements <see cref="IEnumerable"/> and all
        /// items in the collection are structurally equal.
        /// </remarks>
        /// <param name="config">
        /// A reference to the <see cref="EquivalencyAssertionOptions{TSubject}"/> configuration object that can be used
        /// to influence the way the object graphs are compared. You can also provide an alternative instance of the
        /// <see cref="EquivalencyAssertionOptions{TSubject}"/> class. The global defaults are determined by the
        /// <see cref="AssertionOptions"/> class.
        /// </param>
        /// <param name="because">
        /// An optional formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the
        /// assertion is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
        /// </param>
        /// <param name="reasonArgs">
        /// Zero or more objects to format using the placeholders in <see cref="reason" />.
        /// </param>
        public static void ShouldAllBeEquivalentTo <T>(this IEnumerable <T> subject, IEnumerable expectation,
                                                       Func <EquivalencyAssertionOptions <T>, EquivalencyAssertionOptions <T> > config, string because = "",
                                                       params object[] reasonArgs)
        {
            EquivalencyAssertionOptions <IEnumerable <T> > source = config(AssertionOptions.CloneDefaults <T>()).AsCollection();

            var context = new EquivalencyValidationContext
            {
                Subject          = subject,
                Expectation      = expectation,
                RootIsCollection = true,
                CompileTimeType  = typeof(IEnumerable <T>),
                Reason           = because,
                ReasonArgs       = reasonArgs
            };

            new EquivalencyValidator(source).AssertEquality(context);
        }
        /// <summary>
        /// Asserts that a collection of objects is equivalent to another collection of objects.
        /// </summary>
        /// <remarks>
        /// Objects within the collections are equivalent when both object graphs have equally named properties with the same
        /// value,  irrespective of the type of those objects. Two properties are also equal if one type can be converted to another
        /// and the result is equal.
        /// The type of a collection property is ignored as long as the collection implements <see cref="IEnumerable"/> and all
        /// items in the collection are structurally equal.
        /// </remarks>
        /// <param name="config">
        /// A reference to the <see cref="EquivalencyAssertionOptions{TSubject}"/> configuration object that can be used
        /// to influence the way the object graphs are compared. You can also provide an alternative instance of the
        /// <see cref="EquivalencyAssertionOptions{TSubject}"/> class. The global defaults are determined by the
        /// <see cref="AssertionOptions"/> class.
        /// </param>
        /// <param name="because">
        /// An optional formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the
        /// assertion is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
        /// </param>
        /// <param name="becauseArgs">
        /// Zero or more objects to format using the placeholders in <see cref="because" />.
        /// </param>
        public void BeEquivalentTo(IEnumerable expectation,
                                   Func <EquivalencyAssertionOptions <IEnumerable>, EquivalencyAssertionOptions <IEnumerable> > config, string because = "",
                                   params object[] becauseArgs)
        {
            EquivalencyAssertionOptions <IEnumerable> options = config(AssertionOptions.CloneDefaults <IEnumerable>());

            var context = new EquivalencyValidationContext
            {
                Subject          = Subject,
                Expectation      = expectation,
                RootIsCollection = true,
                CompileTimeType  = typeof(IEnumerable),
                Because          = because,
                BecauseArgs      = becauseArgs,
                Tracer           = options.TraceWriter
            };

            new EquivalencyValidator(options).AssertEquality(context);
        }
        public void CannotHandleObjectExpectation()
        {
            // Arrange
            object expectation = new object();

            var context = new EquivalencyValidationContext
            {
                Expectation     = expectation,
                CompileTimeType = expectation.GetType()
            };

            var config = new EquivalencyAssertionOptions <None <int> >();

            var sut = new MaybeEquivalencyStep();

            // Act
            var actual = sut.CanHandle(context, config);

            // Assert
            actual.Should().BeFalse();
        }
        public void CanHandleIMaybeExpectation()
        {
            // Arrange
            IMaybe <Guid> expectation = new Some <Guid>(Guid.NewGuid());

            var context = new EquivalencyValidationContext
            {
                Expectation     = expectation,
                CompileTimeType = expectation.GetType()
            };

            var config = new EquivalencyAssertionOptions <None <int> >();

            var sut = new MaybeEquivalencyStep();

            // Act
            var actual = sut.CanHandle(context, config);

            // Assert
            actual.Should().BeTrue();
        }
        /// <summary>
        /// Applies a step as part of the task to compare two objects for structural equality.
        /// </summary>
        /// <value>
        /// Should return <c>true</c> if the subject matches the expectation or if no additional assertions
        /// have to be executed. Should return <c>false</c> otherwise.
        /// </value>
        /// <remarks>
        /// May throw when preconditions are not met or if it detects mismatching data.
        /// </remarks>
        public bool Handle(EquivalencyValidationContext context, IEquivalencyValidator structuralEqualityValidator)
        {
            if (ReferenceEquals(context.Subject, context.Expectation))
            {
                return true;
            }

            if (ReferenceEquals(context.Expectation, null))
            {
                string propertyPath = context.PropertyDescription;
                if (propertyPath.Length == 0)
                {
                    propertyPath = "subject";
                }

                context.Verification
                    .FailWith("Expected " + propertyPath + " to be {0}{reason}, but found {1}.", context.Expectation,
                        context.Subject);
            }

            return !ReferenceEquals(context.Subject, null) && context.Subject.Equals(context.Expectation);
        }
Beispiel #16
0
        /// <summary>
        /// Asserts that an object is equivalent to another object.
        /// </summary>
        /// <remarks>
        /// Objects are equivalent when both object graphs have equally named properties with the same value,
        /// irrespective of the type of those objects. Two properties are also equal if one type can be converted to another and the result is equal.
        /// The type of a collection property is ignored as long as the collection implements <see cref="IEnumerable{T}"/> and all
        /// items in the collection are structurally equal.
        /// </remarks>
        /// <param name="config">
        /// A reference to the <see cref="EquivalencyAssertionOptions{TSubject}"/> configuration object that can be used
        /// to influence the way the object graphs are compared. You can also provide an alternative instance of the
        /// <see cref="EquivalencyAssertionOptions{TSubject}"/> class. The global defaults are determined by the
        /// <see cref="AssertionOptions"/> class.
        /// </param>
        /// <param name="because">
        /// An optional formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the
        /// assertion is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
        /// </param>
        /// <param name="becauseArgs">
        /// Zero or more objects to format using the placeholders in <see cref="because" />.
        /// </param>
        public void BeEquivalentTo <TExpectation>(TExpectation expectation,
                                                  Func <EquivalencyAssertionOptions <TExpectation>, EquivalencyAssertionOptions <TExpectation> > config, string because = "",
                                                  params object[] becauseArgs)
        {
            Guard.ThrowIfArgumentIsNull(config, nameof(config));

            EquivalencyAssertionOptions <TExpectation> options = config(AssertionOptions.CloneDefaults <TExpectation>());

            var context = new EquivalencyValidationContext
            {
                Subject         = Subject,
                Expectation     = expectation,
                CompileTimeType = typeof(TExpectation),
                Because         = because,
                BecauseArgs     = becauseArgs,
                Tracer          = options.TraceWriter
            };

            var equivalencyValidator = new EquivalencyValidator(options);

            equivalencyValidator.AssertEquality(context);
        }
 public static void ShouldNotBeEquivalentToDefault<T>( this T subject, 
     Func<EquivalencyAssertionOptions<T>, EquivalencyAssertionOptions<T>> config, string because = "", params object[] reasonArgs )
 {
     var context = new EquivalencyValidationContext
     {
         Subject = subject,
         Expectation = subject,
         CompileTimeType = typeof( T ),
         Reason = because,
         ReasonArgs = reasonArgs
     };
     var validator = new EquivalencyValidator( 
         config( EquivalencyAssertionOptions<T>.Default()
             .Using<string>( ctx => ctx.Subject.Should().NotBeDefault() ).WhenTypeIs<string>() )
             .WithStrictOrdering()
             );
     validator.Steps.Remove( validator.Steps.Single( _ => typeof( TryConversionEquivalencyStep ) == _.GetType() ) );
     validator.Steps.Remove( validator.Steps.Single( _ => typeof( ReferenceEqualityEquivalencyStep ) == _.GetType() ) );
     validator.Steps.Remove( validator.Steps.Single( _ => typeof( SimpleEqualityEquivalencyStep ) == _.GetType() ) );
     validator.Steps.Add( new SimpleIsNotDefaultEquivalencyStep() );
 
     validator.AssertEquality( context );
 }
Beispiel #18
0
        /// <summary>
        /// Asserts that an instance of <see cref="DataTable"/> is equivalent to another.
        /// </summary>
        /// <remarks>
        /// Data tables are equivalent when the following members have the same values:
        ///
        /// <list type="bullet">
        ///   <item><description>TableName</description></item>
        ///   <item><description>CaseSensitive</description></item>
        ///   <item><description>DisplayExpression</description></item>
        ///   <item><description>HasErrors</description></item>
        ///   <item><description>Locale</description></item>
        ///   <item><description>Namespace</description></item>
        ///   <item><description>Prefix</description></item>
        ///   <item><description>RemotingFormat</description></item>
        /// </list>
        ///
        /// In addition, the following collections must contain equivalent data:
        ///
        /// <list type="type=bullet">
        ///   <item><description>ChildRelations</description></item>
        ///   <item><description>Columns</description></item>
        ///   <item><description>Constraints</description></item>
        ///   <item><description>ExtendedProperties</description></item>
        ///   <item><description>ParentRelations</description></item>
        ///   <item><description>PrimaryKey</description></item>
        ///   <item><description>Rows</description></item>
        /// </list>
        ///
        /// The <see cref="DataTable"/> objects must be of the same type; if two <see cref="DataTable"/> objects
        /// are equivalent in all ways, except that one is a typed <see cref="DataTable"/> that is a subclass
        /// of <see cref="DataTable"/>, then by default, they will not be considered equivalent.
        ///
        /// This, as well as testing of any property can be overridden using the <paramref name="config"/> callback.
        /// By calling <see cref="IDataEquivalencyAssertionOptions{T}.AllowingMismatchedTypes"/>, two <see cref="DataTable"/>
        /// objects of differing types can be considered equivalent. Exclude specific properties using
        /// <see cref="IDataEquivalencyAssertionOptions{T}.Excluding(System.Linq.Expressions.Expression{Func{T, object}})"/>.
        /// Exclude columns of the data table using <see cref="IDataEquivalencyAssertionOptions{T}.ExcludingColumn(DataColumn)"/>
        /// or a related function -- this excludes both the <see cref="DataColumn"/> objects in <see cref="DataTable.Columns"/>
        /// and associated field data in <see cref="DataRow"/> objects within the <see cref="DataTable"/>.
        ///
        /// You can use <see cref="IDataEquivalencyAssertionOptions{T}.ExcludingRelated(System.Linq.Expressions.Expression{Func{DataTable, object}})"/>
        /// and related functions to exclude properties on other related System.Data types.
        /// </remarks>
        /// <param name="expectation">A <see cref="DataColumn"/> with the expected configuration.</param>
        /// <param name="config">
        /// A reference to the <see cref="IDataEquivalencyAssertionOptions{DataTable}"/> configuration object that can be used
        /// to influence the way the object graphs are compared. You can also provide an alternative instance of the
        /// <see cref="IDataEquivalencyAssertionOptions{DataTable}"/> class. The global defaults are determined by the
        /// <see cref="AssertionOptions"/> class.
        /// </param>
        /// <param name="because">
        /// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
        /// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
        /// </param>
        /// <param name="becauseArgs">
        /// Zero or more objects to format using the placeholders in <paramref name="because"/>.
        /// </param>
        public AndConstraint <DataTableAssertions <TDataTable> > BeEquivalentTo(DataTable expectation, Func <IDataEquivalencyAssertionOptions <DataTable>, IDataEquivalencyAssertionOptions <DataTable> > config, string because = "", params object[] becauseArgs)
        {
            Guard.ThrowIfArgumentIsNull(config, nameof(config));

            IDataEquivalencyAssertionOptions <DataTable> options = config(AssertionOptions.CloneDefaults <DataTable, DataEquivalencyAssertionOptions <DataTable> >(e => new(e)));

            var context = new EquivalencyValidationContext(Node.From <DataTable>(() => AssertionScope.Current.CallerIdentity), options)
            {
                Reason      = new Reason(because, becauseArgs),
                TraceWriter = options.TraceWriter
            };

            var comparands = new Comparands
            {
                Subject         = Subject,
                Expectation     = expectation,
                CompileTimeType = typeof(TDataTable),
            };

            new EquivalencyValidator().AssertEquality(comparands, context);

            return(new AndConstraint <DataTableAssertions <TDataTable> >(this));
        }
Beispiel #19
0
        private static void AssertDictionaryEquivalence <TSubjectKey, TSubjectValue, TExpectedKey, TExpectedValue>(
            EquivalencyValidationContext context,
            IEquivalencyValidator parent,
            IEquivalencyAssertionOptions options,
            IDictionary <TSubjectKey, TSubjectValue> subject,
            IDictionary <TExpectedKey, TExpectedValue> expectation)
            where TExpectedKey : TSubjectKey
        {
            foreach (TExpectedKey key in expectation.Keys)
            {
                if (subject.TryGetValue(key, out TSubjectValue subjectValue))
                {
                    if (options.IsRecursive)
                    {
                        // Run the child assertion without affecting the current context
                        using (new AssertionScope())
                        {
                            var nestedComparands = new Comparands(subject[key], expectation[key], typeof(TExpectedValue));

                            parent.RecursivelyAssertEquality(nestedComparands,
                                                             context.AsDictionaryItem <TExpectedKey, TExpectedValue>(key));
                        }
                    }
                    else
                    {
                        subjectValue.Should().Be(expectation[key], context.Reason.FormattedMessage, context.Reason.Arguments);
                    }
                }
                else
                {
                    AssertionScope.Current
                    .BecauseOf(context.Reason)
                    .FailWith("Expected {context:subject} to contain key {0}{reason}.", key);
                }
            }
        }
        /// <summary>
        /// Applies a step as part of the task to compare two objects for structural equality.
        /// </summary>
        /// <value>
        /// Should return <c>true</c> if the subject matches the expectation or if no additional assertions
        /// have to be executed. Should return <c>false</c> otherwise.
        /// </value>
        /// <remarks>
        /// May throw when preconditions are not met or if it detects mismatching data.
        /// </remarks>
        public bool Handle(EquivalencyValidationContext context, IEquivalencyValidator structuralEqualityValidator)
        {
            context.Subject.Should().Be(context.Expectation, context.Reason, context.ReasonArgs);

            return true;
        }
 /// <summary>
 /// Gets a value indicating whether this step can handle the current subject and/or expectation.
 /// </summary>
 public bool CanHandle(EquivalencyValidationContext context, IEquivalencyAssertionOptions config)
 {
     return !config.IsRecursive && !context.IsRoot;
 }
        /// <summary>
        /// Applies a step as part of the task to compare two objects for structural equality.
        /// </summary>
        /// <value>
        /// Should return <c>true</c> if the subject matches the expectation or if no additional assertions
        /// have to be executed. Should return <c>false</c> otherwise.
        /// </value>
        /// <remarks>
        /// May throw when preconditions are not met or if it detects mismatching data.
        /// </remarks>
        public virtual bool Handle(EquivalencyValidationContext context, IEquivalencyValidator structuralEqualityValidator, IEquivalencyAssertionOptions config)
        {
            context.Subject.Should().Be(context.Expectation, context.Reason, context.ReasonArgs);

            return(true);
        }
 /// <summary>
 /// Gets a value indicating whether this step can handle the current subject and/or expectation.
 /// </summary>
 public bool CanHandle(EquivalencyValidationContext context, IEquivalencyAssertionOptions config)
 {
     return(true);
 }
Beispiel #24
0
 /// <summary>
 /// Applies a step as part of the task to compare two objects for structural equality.
 /// </summary>
 /// <value>
 /// Should return <c>true</c> if the subject matches the expectation or if no additional assertions
 /// have to be executed. Should return <c>false</c> otherwise.
 /// </value>
 /// <remarks>
 /// May throw when preconditions are not met or if it detects mismatching data.
 /// </remarks>
 public virtual bool Handle(EquivalencyValidationContext context, IEquivalencyValidator structuralEqualityValidator,
                            IEquivalencyAssertionOptions config)
 {
     return(ReferenceEquals(context.Subject, context.Expectation));
 }
 /// <summary>
 /// Gets a value indicating whether this step can handle the current subject and/or expectation.
 /// </summary>
 public bool CanHandle(EquivalencyValidationContext context)
 {
     return true;
 }
 /// <summary>
 /// Gets a value indicating whether this step can handle the current subject and/or expectation.
 /// </summary>
 public bool CanHandle(EquivalencyValidationContext context,
                       IEquivalencyAssertionOptions config)
 {
     return(context.RuntimeType != null && context.RuntimeType.IsEnum);
 }
 /// <summary>
 /// Gets a value indicating whether this step can handle the current subject and/or expectation.
 /// </summary>
 public bool CanHandle(EquivalencyValidationContext context,
     IEquivalencyAssertionOptions config)
 {
     return context.RuntimeType != null && context.RuntimeType.IsEnum;
 }
 /// <summary>
 /// Gets a value indicating whether this step can handle the current subject and/or expectation.
 /// </summary>
 public bool CanHandle(EquivalencyValidationContext context, IEquivalencyAssertionOptions config)
 {
     return(!config.IsRecursive && !context.IsRoot);
 }
        /// <summary>
        /// Applies a step as part of the task to compare two objects for structural equality.
        /// </summary>
        /// <value>
        /// Should return <c>true</c> if the subject matches the expectation or if no additional assertions
        /// have to be executed. Should return <c>false</c> otherwise.
        /// </value>
        /// <remarks>
        /// May throw when preconditions are not met or if it detects mismatching data.
        /// </remarks>
        public virtual bool Handle(EquivalencyValidationContext context, IEquivalencyValidator structuralEqualityValidator, IEquivalencyAssertionOptions config)
        {
            context.Subject.Should().Be(context.Expectation, context.Reason, context.ReasonArgs);

            return true;
        }
 /// <summary>
 /// Gets a value indicating whether this step can handle the current subject and/or expectation.
 /// </summary>
 public bool CanHandle(EquivalencyValidationContext context, IEquivalencyAssertionOptions config)
 {
     return true;
 }
 /// <summary>
 /// Applies a step as part of the task to compare two objects for structural equality.
 /// </summary>
 /// <value>
 /// Should return <c>true</c> if the subject matches the expectation or if no additional assertions
 /// have to be executed. Should return <c>false</c> otherwise.
 /// </value>
 /// <remarks>
 /// May throw when preconditions are not met or if it detects mismatching data.
 /// </remarks>
 public virtual bool Handle(EquivalencyValidationContext context, IEquivalencyValidator structuralEqualityValidator,
     IEquivalencyAssertionOptions config)
 {
     return ReferenceEquals(context.Subject, context.Expectation);
 }
 public virtual bool Handle(EquivalencyValidationContext context, IEquivalencyValidator structuralEqualityValidator, IEquivalencyAssertionOptions config)
 {
     context.Subject.Should().NotBeDefault( context.Reason, context.ReasonArgs );
     return true;
 }