public void ShouldAllowFluentOnNonVirtualReadWriteProperty()
        {
            var target = Mock.Of <Dto>(x => x.Value == "foo");

            Assert.NotNull(Mock.Get(target));
            Assert.Equal("foo", target.Value);
        }
예제 #2
0
        public void ShouldCreateMatcher()
        {
            var attr    = new AdvancedMatcherAttribute(typeof(MockMatcher));
            var matcher = attr.CreateMatcher();

            Assert.NotNull(matcher);
        }
        public void ShouldReturnEmptyArrayTwoDimensionsOnLoose()
        {
            var mock = new Mock <IFoo>(MockBehavior.Loose);

            Assert.NotNull(mock.Object.GetArrayTwoDimensions());
            Assert.Equal(0, mock.Object.GetArrayTwoDimensions().Length);
        }
        public void ShouldOneOfWithPredicateCreateNewMock()
        {
            var target = Mock.Of <IFoo>(x => x.Name == "Foo");

            Assert.NotNull(Mock.Get(target));
            Assert.Equal("Foo", target.Name);
        }
        public void ShouldReturnEmptyEnumerableObjectsOnLoose()
        {
            var mock = new Mock <IFoo>(MockBehavior.Loose);

            Assert.NotNull(mock.Object.GetEnumerableObjects());
            Assert.Equal(0, mock.Object.GetEnumerableObjects().Cast <object>().Count());
        }
예제 #6
0
        public void ReturnsDefaultReferenceValue()
        {
            var mock = new Mock <IFoo>();

            mock.SetReturnsDefault <IList <int> >(new List <int>());

            Assert.NotNull(mock.Object.ReturnIntList());
        }
예제 #7
0
        public void CreatesMockAndExposesInterface()
        {
            var mock = new Mock <IComparable>();

            IComparable comparable = mock.Object;

            Assert.NotNull(comparable);
        }
예제 #8
0
            public void Test()
            {
                var mock = new Mock <IGeneric>();

                mock.Setup(r => r.Get <Foo.Inner>()).Returns(new Object());
                mock.Setup(r => r.Get <Bar.Inner>()).Returns(new Object());

                Assert.NotNull(mock.Object.Get <Foo.Inner>());
                Assert.NotNull(mock.Object.Get <Bar.Inner>());
            }
        public void ReturnsEmptyArrayTwoDimensionsOnLooseWithMockDefaultValue()
        {
            var mock = new Mock <IFoo>(MockBehavior.Loose)
            {
                DefaultValue = DefaultValue.Mock
            };

            Assert.NotNull(mock.Object.GetArrayTwoDimensions());
            Assert.Equal(0, mock.Object.GetArrayTwoDimensions().Length);
        }
예제 #10
0
 public void WhenMockingAnExternalInterface_ThenItWorks()
 {
     Assert.NotNull(new Mock <ClassLibrary1.IFoo>().Object);
     Assert.NotNull(Mock.Of <ClassLibrary1.IFoo>());
     Assert.NotNull(new Mock <ClassLibrary1.Foo>().Object);
     Assert.NotNull(new Mock <ClassLibrary2.IBar>().Object);
     Assert.NotNull(Mock.Of <ClassLibrary2.IBar>());
     Assert.NotNull(new Mock <ClassLibrary2.Bar>().Object);
     Assert.NotNull(new Mock <Baz>().Object);
 }
        public void ReturnsEmptyEnumerableStringOnLooseWithMockDefaultValue()
        {
            var mock = new Mock <IFoo>(MockBehavior.Loose)
            {
                DefaultValue = DefaultValue.Mock
            };

            Assert.NotNull(mock.Object.GetEnumerable());
            Assert.Equal(0, mock.Object.GetEnumerable().Count());
        }
예제 #12
0
        public void ProvidesMockValue()
        {
            var mock     = new Mock <IFoo>();
            var provider = new MockDefaultValueProvider(mock);

            var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod());

            Assert.NotNull(value);
            Assert.True(value is IMocked);
        }
        public void ReturnsEmptyQueryableObjectsOnLooseWithMockDefaultValue()
        {
            var mock = new Mock <IFoo>(MockBehavior.Loose)
            {
                DefaultValue = DefaultValue.Mock
            };

            Assert.NotNull(mock.Object.GetQueryableObjects());
            Assert.Equal(0, mock.Object.GetQueryableObjects().Cast <object>().Count());
        }
        public void ShouldAllowFluentOnReadOnlyGetterProperty()
        {
            var target = Mock.Of <IFoo>(x => x.Bars == new[]
            {
                Mock.Of <IBar>(b => b.Id == "1"),
                Mock.Of <IBar>(b => b.Id == "2"),
            });

            Assert.NotNull(Mock.Get(target));
            Assert.Equal(2, target.Bars.Count());
        }
예제 #15
0
        public void ShouldCreateMocksWithFactoryDefaultValue()
        {
            var repository = new MockRepository(MockBehavior.Loose)
            {
                DefaultValue = DefaultValue.Mock
            };

            var mock = repository.Create <IFoo>();

            Assert.NotNull(mock.Object.Bar());
        }
예제 #16
0
            public void FooTest()
            {
                // Setup
                var fooMock = new Mock <Foo>();

                fooMock.CallBase = true;
                fooMock.Setup(o => o.GetBar()).Returns(new Bar());
                var bar = ((IFoolery)fooMock.Object).DoStuffToBar();

                Assert.NotNull(bar);
            }
        public void CreatesMockForAccessedPropertyWithSetter()
        {
            var mock = new Mock <IFoo>();

            mock.SetupSet(m => m.Bar.Value = It.IsAny <int>());

            Assert.NotNull(mock.Object.Bar);
            Assert.Throws <MockVerificationException>(() => mock.VerifyAll());

            mock.Object.Bar.Value = 5;

            mock.VerifyAll();
        }
예제 #18
0
        public void GetMockFromAddedInterfaceWorks()
        {
            var bag = new Mock <IBag>();
            var foo = bag.As <IFoo>();

            foo.SetupGet(x => x.Value).Returns(25);

            IFoo f = bag.Object as IFoo;

            var foomock = Mock.Get(f);

            Assert.NotNull(foomock);
        }
        public void ReturnsMockListOnLooseWithMockDefaultValue()
        {
            var mock = new Mock <IFoo>(MockBehavior.Loose)
            {
                DefaultValue = DefaultValue.Mock
            };

            Assert.NotNull(mock.Object.GetList());

            var list = mock.Object.GetList();

            list.Add("foo");

            Assert.Equal("foo", list[0]);
        }
        public void CreatesMockForAccessedPropertyWithVoidMethod()
        {
            var mock = new Mock <IFoo>();

            mock.Setup(m => m.Bar.Baz.Do());

            //Assert.Throws<MockVerificationException>(() => mock.VerifyAll());

            Assert.NotNull(mock.Object.Bar);
            Assert.NotNull(mock.Object.Bar.Baz);

            mock.Object.Bar.Baz.Do();

            mock.Verify(m => m.Bar.Baz.Do());
        }
        public void RaisesEventWithActionLambdaOneArg()
        {
            var mock = new Mock <IAdder <int> >();

            mock.Setup(m => m.Do("foo")).Raises <string>(m => m.Done += null, s => new DoneArgs {
                Value = s
            });

            DoneArgs args = null;

            mock.Object.Done += (sender, e) => args = e;

            mock.Object.Do("foo");

            Assert.NotNull(args);
            Assert.Equal("foo", args.Value);
        }
예제 #22
0
        public void TestPresenterSelection()
        {
            var mockView  = new Mock <IOrdersView>();
            var presenter = new OrdersPresenter(mockView.Object);

            // Check that the presenter has no selection by default
            Assert.Null(presenter.SelectedOrder);

            // Finally raise the event with a specific arguments data
            mockView.Raise(mv => mv.OrderSelected += null, new OrderEventArgs {
                Order = new Order("moq", 500)
            });

            // Now the presenter reacted to the event, and we have a selected order
            Assert.NotNull(presenter.SelectedOrder);
            Assert.Equal("moq", presenter.SelectedOrder.ProductName);
        }
        public void RaisesEventWithActionLambdaTwoArgs()
        {
            var mock = new Mock <IAdder <int> >();

            mock.Setup(m => m.Do("foo", 5))
            .Raises(m => m.Done += null, (string s, int i) => new DoneArgs {
                Value = s + i
            });

            DoneArgs args = null;

            mock.Object.Done += (sender, e) => args = e;

            mock.Object.Do("foo", 5);

            Assert.NotNull(args);
            Assert.Equal("foo5", args.Value);
        }
        public void RaisesEventWithActionLambdaEightArgs()
        {
            var mock = new Mock <IAdder <int> >();

            mock.Setup(m => m.Do("foo", 5, true, "bar", 5, 6, 7, 8))
            .Raises(m => m.Done += null, (string s, int i, bool b, string s1, int arg5, int arg6, int arg7, int arg8) => new DoneArgs {
                Value = s + i + b + s1 + arg5 + arg6 + arg7 + arg8
            });

            DoneArgs args = null;

            mock.Object.Done += (sender, e) => args = e;

            mock.Object.Do("foo", 5, true, "bar", 5, 6, 7, 8);

            Assert.NotNull(args);
            Assert.Equal("foo5Truebar5678", args.Value);
        }
        public void RaisesEventWithActionLambdaFourArgs()
        {
            var mock = new Mock <IAdder <int> >();

            mock.Setup(m => m.Do("foo", 5, true, "bar"))
            .Raises(m => m.Done += null, (string s, int i, bool b, string s1) => new DoneArgs {
                Value = s + i + b + s1
            });

            DoneArgs args = null;

            mock.Object.Done += (sender, e) => args = e;

            mock.Object.Do("foo", 5, true, "bar");

            Assert.NotNull(args);
            Assert.Equal("foo5Truebar", args.Value);
        }
        //[ExpectedException] not used so IsMagicStringCalled can be verified
        public void ShouldTranslateToUseMatcherImplementation2()
        {
            var mock = new Mock <IFoo>(MockBehavior.Strict);

            mock.Setup(x => x.Bar(IsMagicString()));
            IsMagicStringCalled = false;
            Exception expectedException = null;

            try
            {
                mock.Object.Bar("no-magic");
            }
            catch (Exception e)
            {
                expectedException = e;
            }

            Assert.True(IsMagicStringCalled);
            Assert.NotNull(expectedException);
        }
예제 #27
0
        public void ShouldCreateFactoryWithMockBehaviorAndVerificationBehavior()
        {
            var repository = new MockRepository(MockBehavior.Loose);

            Assert.NotNull(repository);
        }
예제 #28
0
            public void Test()
            {
                var target = new Mock <MethodInfo>();

                Assert.NotNull(target.Object);
            }
예제 #29
0
            public void Test()
            {
                var mock = new Mock <IMyInterface>();

                Assert.NotNull(mock.Object);
            }
예제 #30
0
            public void ShouldMockInteropDTE()
            {
                var dte = new Mock <EnvDTE.DTE>();

                Assert.NotNull(dte.Object);
            }