Example #1
0
        public static void BeEquivalentToModel <T>(this ObjectAssertions assertations, T expectation, Func <EquivalencyAssertionOptions <T>, EquivalencyAssertionOptions <T> > config = null)
        {
            assertations.BeEquivalentTo(expectation, x =>
            {
                x.Using <DateTime>(y => y.Subject.Should().BeCloseTo(y.Expectation, 5000)).WhenTypeIs <DateTime>();
                x.Using <DateTime?>(y =>
                {
                    if (y.Expectation.HasValue)
                    {
                        y.Subject.Should().BeCloseTo(y.Expectation.Value, 5000);
                    }
                    else
                    {
                        y.Subject.Should().Be(y.Expectation);
                    }
                }).WhenTypeIs <DateTime?>();

                if (config != null)
                {
                    config.Invoke(x);
                }

                return(x);
            });
        }
 public static void HaveEquivalentMembers <TExpectation>(this ObjectAssertions obj,
                                                         TExpectation expectation,
                                                         Func <EquivalencyAssertionOptions <TExpectation>, EquivalencyAssertionOptions <TExpectation> > config,
                                                         string because = "",
                                                         params object[] becauseArgs)
 {
     obj.BeEquivalentTo(expectation, opt => config.Invoke(opt.ComparingByMembers <TExpectation>()), because, becauseArgs);
 }
 public static void MatchStockistIgnoringIds(this ObjectAssertions assertions, Stockist expected)
 {
     assertions.BeEquivalentTo(expected,
                               o => o.IgnoringCyclicReferences()
                               .Excluding(x => x.StockistId)
                               .Excluding(x => x.Details.StockistId)
                               .Excluding(x => x.Commission.StockistId)
                               .Excluding(x => x.Commission.CommissionId)
                               .Excluding(x => x.Commission.InsertedAt));
 }
Example #4
0
 public static void BeEquivalentToRespectingRuntimeTypes <TExpectation>(
     this ObjectAssertions assertions,
     TExpectation expectation,
     Func <EquivalencyAssertionOptions <TExpectation>, EquivalencyAssertionOptions <TExpectation> > config = null)
 {
     assertions.BeEquivalentTo(expectation, o =>
     {
         if (config is { })
         {
             return(config.Invoke(o).RespectingRuntimeTypes());
         }
Example #5
0
        public static void BeEquivalentToEntity <T>(this ObjectAssertions assertions, T expectation, Func <EquivalencyAssertionOptions <T>, EquivalencyAssertionOptions <T> > config = null)
            where T : class, IEntity
        {
            assertions.BeEquivalentTo(expectation, x =>
            {
                x.Excluding(y => y.SelectedMemberInfo.Name.StartsWith(nameof(IEntity.Id)));

                config?.Invoke(x);

                return(x);
            });
        }
Example #6
0
        private static void BeEquivalentToModel <T>(this ObjectAssertions assertions, T expectation, Func <EquivalencyAssertionOptions <T>, EquivalencyAssertionOptions <T> > config = null)
        {
            assertions.BeEquivalentTo(expectation, x =>
            {
                x.Excluding(y => y.SelectedMemberInfo.Name.StartsWith(nameof(IEntity.Id)));
                x.Excluding(y => y.RuntimeType == typeof(Geometry));
                x.Using <Geometry>(y => y.Subject.Centroid.Should().Be(y.Expectation.Centroid)).WhenTypeIs <Geometry>();

                config?.Invoke(x);

                return(x);
            });
        }
        /// <summary>
        /// Asserts that an object is equivalent to another mapped object.
        /// </summary>
        /// <typeparam name="TMapped"></typeparam>
        /// <param name="assertions"></param>
        /// <param name="expectation"></param>
        /// <param name="mapper"></param>
        public static void BeEquivalentToMapped <TMapped>(this ObjectAssertions assertions, object expectation, IMapper mapper)
        {
            var mappedExpectation = mapper.Map <TMapped>(expectation);

            assertions.BeEquivalentTo(mappedExpectation);
        }
 public static void HaveEquivalentMembers <TExpectation>(this ObjectAssertions obj,
                                                         TExpectation expectation)
 {
     obj.BeEquivalentTo(expectation, opt => opt.ComparingByMembers <TExpectation>());
 }
        public static void BeEquivalentTo <T>(this ObjectAssertions assertion, T expectation, params IEquivalencyOption[] options)
        {
            var ops = new EquivalencyOptions(options);

            assertion.BeEquivalentTo(expectation, ops.ExecuteOptions);
        }
 public static void MatchStockist(this ObjectAssertions assertions, Stockist expected)
 {
     assertions.BeEquivalentTo(expected, o => o.IgnoringCyclicReferences());
 }