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);
        }
        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);
        }
		public void ProvidesEmptyValueIfNotMockeable()
		{
			var mock = new Mock<IFoo>();
			var provider = new MockDefaultValueProvider(mock);

			var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Value").GetGetMethod());
			Assert.Equal(default(string), value);

			value = provider.ProvideDefault(typeof(IFoo).GetProperty("Value").GetGetMethod());
			Assert.Equal(default(string), value);

			value = provider.ProvideDefault(typeof(IFoo).GetProperty("Indexes").GetGetMethod());
			Assert.True(value is IEnumerable<int> && ((IEnumerable<int>)value).Count() == 0);

			value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bars").GetGetMethod());
			Assert.True(value is IBar[] && ((IBar[])value).Length == 0);
		}
        public void ProvidesEmptyValueIfNotMockeable()
        {
            var mock     = new Mock <IFoo>();
            var provider = new MockDefaultValueProvider(mock);

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

            Assert.Equal(default(string), value);

            value = provider.ProvideDefault(typeof(IFoo).GetProperty("Value").GetGetMethod());
            Assert.Equal(default(string), value);

            value = provider.ProvideDefault(typeof(IFoo).GetProperty("Indexes").GetGetMethod());
            Assert.True(value is IEnumerable <int> && ((IEnumerable <int>)value).Count() == 0);

            value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bars").GetGetMethod());
            Assert.True(value is IBar[] && ((IBar[])value).Length == 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 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 NewMocksHaveSameCallBaseAsOwner()
		{
			var mock = new Mock<IFoo> { CallBase = true };
			var provider = new MockDefaultValueProvider(mock);

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

			var barMock = Mock.Get((IBar)value);

			Assert.Equal(mock.CallBase, barMock.CallBase);
		}
        public void NewMocksHaveSameBehaviorAndDefaultValueAsOwner()
        {
            var mock     = new Mock <IFoo>();
            var provider = new MockDefaultValueProvider(mock);

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

            var barMock = Mock.Get((IBar)value);

            Assert.Equal(mock.Behavior, barMock.Behavior);
            Assert.Equal(mock.DefaultValue, barMock.DefaultValue);
        }
        public void NewMocksHaveSameBehaviorAndDefaultValueAsOwner()
        {
            var mock = new Mock<IFoo>();
            var provider = new MockDefaultValueProvider(mock);

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

            var barMock = Mock.Get((IBar)value);

            Assert.Equal(mock.Behavior, barMock.Behavior);
            Assert.Equal(mock.DefaultValue, barMock.DefaultValue);
        }
        public void CreatedMockIsVerifiedWithOwner()
        {
            var mock = new Mock<IFoo>();
            var provider = new MockDefaultValueProvider(mock);

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

            var barMock = Mock.Get((IBar)value);
            barMock.Setup(b => b.Do()).Verifiable();

            Assert.Throws<MockVerificationException>(() => mock.Verify());
        }
        public void CreatedMockIsVerifiedWithOwner()
        {
            var mock     = new Mock <IFoo>();
            var provider = new MockDefaultValueProvider(mock);

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

            var barMock = Mock.Get((IBar)value);

            barMock.Setup(b => b.Do()).Verifiable();

            Assert.Throws <MockVerificationException>(() => mock.Verify());
        }
        public void NewMocksHaveSameCallBaseAsOwner()
        {
            var mock = new Mock <IFoo> {
                CallBase = true
            };
            var provider = new MockDefaultValueProvider(mock);

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

            var barMock = Mock.Get((IBar)value);

            Assert.Equal(mock.CallBase, barMock.CallBase);
        }
Exemplo n.º 13
0
        public void ProvidesEmptyValueIfHasForceEmptyDefaultValueAttribute()
        {
            var mock = new Mock<IFoo>();
            var provider = new MockDefaultValueProvider(mock);

            var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Legacy").GetGetMethod());
            Assert.Equal(default(ILegacy), value);

            value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod());
            Assert.NotEqual(default(IBar), value);
        }