コード例 #1
0
        void IPartBuilder.GenerateAssertAreEqualPart(GenAssertAreEqualContext context)
        {
            var g = context.Generator;

            var method = typeof(Assert).ResolveMethod("AreEqual", typeof(object), typeof(object), typeof(string));

            g.BeginCall(method);
            {
                g.Load(context.Expected, LoadOptions.ValueAsAddress);
                g.LoadMember("HasValue");
                g.Box();
                g.Load(context.Actual, LoadOptions.ValueAsAddress);
                g.LoadMember("HasValue");
                g.Box();
                g.Load(context.Part.FullName);
            }
            g.EndCall();

            g.If(() =>
            {
                g.Load(context.Expected, LoadOptions.ValueAsAddress);
                g.LoadMember("HasValue");
                return(BinaryOperator.IsTrue);
            });
            {
                var expected = context.Expected.Copy().AddMember("Value");
                var actual   = context.Actual.Copy().AddMember("Value");

                context.GenerateInnerAssert(_innerBuilder, expected, actual);
            }
            g.EndIf();
        }
コード例 #2
0
        void IPartBuilder.GenerateAssertAreEqualPart(GenAssertAreEqualContext context)
        {
            var g = context.Generator;

            var assertEqual    = typeof(Assert).ResolveMethod("AreEqual", typeof(object), typeof(object), typeof(string));
            var assertNotEqual = typeof(Assert).ResolveMethod("AreNotEqual", typeof(object), typeof(object), typeof(string));

            g.If(() =>
            {
                g.Load(context.Expected);
                return(BinaryOperator.IsNull);
            });
            {
                g.BeginCall(assertEqual);
                {
                    g.LoadNull();
                    g.Load(context.Actual);
                    g.Load(context.Part.FullName);
                }
                g.EndCall();
            }
            g.Else();
            {
                g.BeginCall(assertNotEqual);
                {
                    g.LoadNull();
                    g.Load(context.Actual);
                    g.Load(context.Part.FullName);
                }
                g.EndCall();

                g.BeginCall(assertEqual);
                {
                    g.Load(context.Expected);
                    g.LoadMember("Length");
                    g.Box();
                    g.Load(context.Actual);
                    g.LoadMember("Length");
                    g.Box();
                    g.Load(context.Part.FullName);
                }
                g.EndCall();

                var i = g.DeclareLocal(typeof(int));
                i.Initialize();

                g.While(() =>
                {
                    g.Load(i);
                    g.Load(context.Expected);
                    g.LoadMember("Length");
                    return(BinaryOperator.LessThan);
                }, () =>
                {
                    var expected = g.DeclareLocal(_elementType);
                    var actual   = g.DeclareLocal(_elementType);

                    g.BeginAssign(expected);
                    {
                        g.Load(context.Expected);
                        g.BeginLoadElement();
                        {
                            g.Load(i);
                        }
                        g.EndLoadElement();
                    }
                    g.EndAssign();

                    g.BeginAssign(actual);
                    {
                        g.Load(context.Actual);
                        g.BeginLoadElement();
                        {
                            g.Load(i);
                        }
                        g.EndLoadElement();
                    }
                    g.EndAssign();

                    context.GenerateInnerAssert(_elementBuilder, g.CreateExpression(expected), g.CreateExpression(actual));

                    g.BeginAssign(i);
                    {
                        g.Load(i);
                        g.Increment();
                    }
                    g.EndAssign();
                });
            }
            g.EndIf();
        }
コード例 #3
0
        public void GenerateAssertAreEqualPart(GenAssertAreEqualContext context)
        {
            var g = context.Generator;

            var assertEqual    = typeof(Assert).ResolveMethod("AreEqual", typeof(object), typeof(object), typeof(string));
            var assertNotEqual = typeof(Assert).ResolveMethod("AreNotEqual", typeof(object), typeof(object), typeof(string));

            g.If(() =>
            {
                g.Load(context.Expected);
                return(BinaryOperator.IsNull);
            });
            {
                g.BeginCall(assertEqual);
                {
                    g.LoadNull();
                    g.Load(context.Actual);
                    g.Load(context.Part.FullName);
                }
                g.EndCall();
            }
            g.Else();
            {
                g.BeginCall(assertNotEqual);
                {
                    g.LoadNull();
                    g.Load(context.Actual);
                    g.Load(context.Part.FullName);
                }
                g.EndCall();

                g.BeginCall(assertEqual);
                {
                    g.Load(context.Expected);
                    g.Call(_getCount);
                    g.Box();
                    g.Load(context.Actual);
                    g.Call(_getCount);
                    g.Box();
                    g.Load(context.Part.FullName);
                }
                g.EndCall();

                // todo - make this method resolution better
                var joinPairs = typeof(Algorithm).GetMethod("JoinPairs", BindingFlags.Public | BindingFlags.Static);
                joinPairs = joinPairs.MakeGenericMethod(_elementType, _elementType);
                g.BeginCall(joinPairs);
                {
                    g.Load(context.Expected);
                    g.Load(context.Actual);
                }
                g.EndCall();
                var pair = g.BeginForEach(typeof(KeyValuePair <,>).MakeGenericType(_elementType, _elementType));
                {
                    context.GenerateInnerAssert(
                        _innerBuilder,
                        g.CreateExpression(pair).AddMember("Key"),
                        g.CreateExpression(pair).AddMember("Value"));
                }
                g.EndForEach();
            }
            g.EndIf();
        }
コード例 #4
0
 public void GenerateAssertAreEqualPart(GenAssertAreEqualContext context)
 {
     context.GenerateInnerAssert(_keyBuilder, context.Expected.Copy().AddMember("Key"), context.Actual.Copy().AddMember("Key"));
     context.GenerateInnerAssert(_valueBuilder, context.Expected.Copy().AddMember("Value"), context.Actual.Copy().AddMember("Value"));
 }