Пример #1
0
        public void GetReturnsMockForAMockedAbstract()
        {
            var mock   = new Mock <FooBase>();
            var mocked = mock.Object;

            Assert.Same(mock, Mock.Get(mocked));
        }
Пример #2
0
        public void GetReturnsMockForAMocked()
        {
            var mock   = new Mock <IFoo>();
            var mocked = mock.Object;

            Assert.Same(mock, Mock.Get(mocked));
        }
Пример #3
0
        public void MockOfMockedClassWithCtorShouldReturnSame()
        {
            Mock <FooWithCtor>    mock   = new Mock <FooWithCtor>(5);
            IMocked <FooWithCtor> mocked = mock.Object as IMocked <FooWithCtor>;

            Assert.Same(mock, mocked.Mock);
        }
Пример #4
0
        public void MockOfMockedClassShouldReturnSame()
        {
            Mock <Foo>    mock   = new Mock <Foo>();
            IMocked <Foo> mocked = mock.Object as IMocked <Foo>;

            Assert.Same(mock, mocked.Mock);
        }
Пример #5
0
        public void MockOfMockedInterfaceShouldReturnSame()
        {
            Mock <IFoo>    mock   = new Mock <IFoo>();
            IMocked <IFoo> mocked = mock.Object as IMocked <IFoo>;

            Assert.Same(mock, mocked.Mock);
        }
Пример #6
0
        public void CachesProvidedValue()
        {
            var mock     = new Mock <IFoo>();
            var provider = new MockDefaultValueProvider(mock);

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

            Assert.Same(value1, value2);
        }
Пример #7
0
            public void Test()
            {
                var mock = new Mock <IDisposable>().As <IComponent>();

                mock.SetupAllProperties();

                ISite site = new FooSite();

                mock.Object.Site = site;
                Assert.Same(site, mock.Object.Site);
            }
        public void RetrievesSameMockForProperty()
        {
            var mock = new Mock <IFoo> {
                DefaultValue = DefaultValue.Mock
            };

            var b1 = mock.Object.Bar;
            var b2 = mock.Object.Bar;

            Assert.Same(b1, b2);
        }
        public void DoesNotRaiseEventOnSubObject()
        {
            var mock = new Mock <IParent> {
                DefaultValue = DefaultValue.Mock
            };

            bool raised = false;

            mock.Object.Adder.Added += (sender, args) => raised = true;

            Assert.Same(mock.Object.Adder, mock.Object.Adder);

            mock.Raise(p => p.Adder.Added += null, EventArgs.Empty);

            Assert.False(raised);
        }
        public void StubsAllProperties()
        {
            var mock = new Mock <IFoo>();

            mock.SetupAllProperties();

            mock.Object.ValueProperty = 5;
            Assert.Equal(5, mock.Object.ValueProperty);

            var obj = new object();

            mock.Object.Object = obj;
            Assert.Same(obj, mock.Object.Object);

            var bar = new Mock <IBar>();

            mock.Object.Bar = bar.Object;
            Assert.Same(bar.Object, mock.Object.Bar);
        }