Ejemplo n.º 1
0
        public void ShouldBeSameAs()
        {
            var aReferenceType       = new object();
            var anotherReferenceType = new object();

            Should.Error(
                () => aReferenceType.ShouldBeSameAs(anotherReferenceType),
                "() => aReferenceType should be same as System.Object but was System.Object"
                );

            var list = new List <int> {
                1, 2, 3
            };
            var equalListWithDifferentRef = new List <int> {
                1, 2, 3
            };

            Should.Error(
                () => list.ShouldBeSameAs(equalListWithDifferentRef),
                "() => list should be same as [1, 2, 3] but was [1, 2, 3] difference [1, 2, 3]"
                );

            const int boxedInt = 1;

            Should.Error(
                () => boxedInt.ShouldBeSameAs(boxedInt),
                "() => boxedInt should be same as 1 but was 1"
                );
        }
Ejemplo n.º 2
0
        public void WhenPropertyGetterFilterIsAddedWithComponentAndSetter_ThenFilterIsApplied(PropertyBehaviorManager manager)
        {
            var list                = Expression.Parameter(typeof(List <string>), "list");
            var comp                = Expression.Parameter(typeof(CustomizedPropertyShouldModel), "comp");
            var setter              = Expression.Parameter(typeof(Action <List <string> >), "setter");
            var newList             = Expression.Parameter(typeof(List <string>), "newList");
            LambdaExpression lambda = Expression.Lambda(
                Expression.Condition(
                    Expression.Equal(list, Expression.Constant(null)),
                    Expression.Block(new [] { newList },
                                     Expression.Assign(newList, Expression.New(typeof(List <string>))),
                                     Expression.Invoke(setter, newList),
                                     newList), list)
                , list, comp, setter);

            manager.Behavior(b => b
                             .SpecifyBackingComponentProperty(m => m.P3)
                             .AddGetterFilter(lambda));

            var model = new CustomizedPropertyShouldModel();

            manager.GetAdapter(model);

            model.P3.ShouldBeNull();

            List <string> result = manager.Value;

            result.ShouldNotBeNull();
            result.ShouldBeSameAs(model.P3);
        }
        public void SameListDifferentInstanceScenarioShouldFail()
        {
            var list = new List <int> {
                1, 2, 3
            };
            var equalListWithDifferentRef = new List <int> {
                1, 2, 3
            };

            Verify.ShouldFail(() =>
                              list.ShouldBeSameAs(equalListWithDifferentRef),

                              errorWithSource:
                              @"list
    should be same as
[1, 2, 3]
    but was
[1, 2, 3]
    difference
[1, 2, 3]",

                              errorWithoutSource:
                              @"[1, 2, 3]
    should be same as
[1, 2, 3]
    but was not
    difference
[1, 2, 3]");
        }
Ejemplo n.º 4
0
        public void ShouldBeSameAs_WhenSameReference()
        {
            var list = new List <int> {
                1, 2, 3
            };
            IList <int> sameReference = list;

            list.ShouldBeSameAs(sameReference);
        }
        protected override void ShouldThrowAWobbly()
        {
            var list = new List <int> {
                1, 2, 3
            };
            var equalListWithDifferentRef = new List <int> {
                1, 2, 3
            };

            list.ShouldBeSameAs(equalListWithDifferentRef);
        }
Ejemplo n.º 6
0
        public void ShouldBeSameAs_WhenSameReference_ShouldNotThrow()
        {
            List <int> list = new List <int> {
                1, 2, 3
            };
            IList <int> sameReference = list;

            list.ShouldBeSameAs(sameReference);

            Should.Error(
                () => list.ShouldNotBeSameAs(sameReference),
                "() => list should not be same as [1, 2, 3] but was [1, 2, 3] difference [1, 2, 3]"
                );
        }
Ejemplo n.º 7
0
        public void ShouldBeSameAs_WhenEqualListsButDifferentReferences_ShouldThrow()
        {
            var list = new List <int> {
                1, 2, 3
            };
            var equalListWithDifferentRef = new List <int> {
                1, 2, 3
            };

            list.ShouldBe(equalListWithDifferentRef);

            Should.Error(
                () => list.ShouldBeSameAs(equalListWithDifferentRef),
                "() => list should be same as [1, 2, 3] but was [1, 2, 3] difference [1, 2, 3]"
                );

            list.ShouldNotBeSameAs(equalListWithDifferentRef);
        }
        public void SameListDifferentInstanceScenarioShouldFail()
        {
            var list = new List<int> { 1, 2, 3 };
            var equalListWithDifferentRef = new List<int> { 1, 2, 3 };
            Verify.ShouldFail(() =>
list.ShouldBeSameAs(equalListWithDifferentRef),

errorWithSource:
@"list
    should be same as
[1, 2, 3]
    but was
[1, 2, 3]
    difference
[1, 2, 3]",

errorWithoutSource:
@"[1, 2, 3]
    should be same as
[1, 2, 3]
    but was not
    difference
[1, 2, 3]");
        }
 protected override void ShouldThrowAWobbly()
 {
     var list = new List<int> { 1, 2, 3 };
     var equalListWithDifferentRef = new List<int> { 1, 2, 3 };
     list.ShouldBeSameAs(equalListWithDifferentRef);
 }