public void SunnyDayPath()
        {
            IObjectFactory objectFactory = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory));
            IConfigurableObjectDefinition configurableObjectDefinition =
                            (IConfigurableObjectDefinition)mocks.CreateMock(typeof(IConfigurableObjectDefinition));

            object expectedLookup = new object();
            const string LookupObjectName = "foo";

            Expect.Call(objectFactory.GetObject(LookupObjectName)).Return(expectedLookup);

            LookupMethodOverride ovr = new LookupMethodOverride("SunnyDayPath", LookupObjectName);
            MethodOverrides overrides = new MethodOverrides();
            overrides.Add(ovr);
            Expect.Call(configurableObjectDefinition.MethodOverrides).Return(overrides);

            LookupMethodReplacer replacer = new LookupMethodReplacer(configurableObjectDefinition, objectFactory);
            mocks.ReplayAll();
            MethodInfo method = (MethodInfo) MethodBase.GetCurrentMethod();

            object lookup = replacer.Implement(this, method, new object[] {});
            Assert.AreSame(expectedLookup, lookup);

            mocks.VerifyAll();
        }
        public void SunnyDayPath()
        {
            IObjectFactory objectFactory = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory));
            IConfigurableObjectDefinition configurableObjectDefinition =
                (IConfigurableObjectDefinition)mocks.CreateMock(typeof(IConfigurableObjectDefinition));

            object       expectedLookup   = new object();
            const string LookupObjectName = "foo";

            Expect.Call(objectFactory.GetObject(LookupObjectName)).Return(expectedLookup);

            LookupMethodOverride ovr       = new LookupMethodOverride("SunnyDayPath", LookupObjectName);
            MethodOverrides      overrides = new MethodOverrides();

            overrides.Add(ovr);
            Expect.Call(configurableObjectDefinition.MethodOverrides).Return(overrides);

            LookupMethodReplacer replacer = new LookupMethodReplacer(configurableObjectDefinition, objectFactory);

            mocks.ReplayAll();
            MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod();

            object lookup = replacer.Implement(this, method, new object[] {});

            Assert.AreSame(expectedLookup, lookup);

            mocks.VerifyAll();
        }
        public void SunnyDayPath()
        {
            var objectFactory = A.Fake <IObjectFactory>();
            var configurableObjectDefinition = A.Fake <IConfigurableObjectDefinition>();

            object       expectedLookup   = new object();
            const string LookupObjectName = "foo";

            A.CallTo(() => objectFactory.GetObject(LookupObjectName)).Returns(expectedLookup);

            LookupMethodOverride ovr       = new LookupMethodOverride("SunnyDayPath", LookupObjectName);
            MethodOverrides      overrides = new MethodOverrides();

            overrides.Add(ovr);
            A.CallTo(() => configurableObjectDefinition.MethodOverrides).Returns(overrides);

            LookupMethodReplacer replacer = new LookupMethodReplacer(configurableObjectDefinition, objectFactory);
            MethodInfo           method   = (MethodInfo)MethodBase.GetCurrentMethod();

            object lookup = replacer.Implement(this, method, new object[] {});

            Assert.AreSame(expectedLookup, lookup);
        }
        public void MatchesWithNullMethod()
        {
            LookupMethodOverride methodOverride = new LookupMethodOverride("Execute", "foo");

            methodOverride.Matches(null);
        }
        public void Matches_MatchingMethodName()
        {
            LookupMethodOverride methodOverride = new LookupMethodOverride("GetGrub", "foo");

            Assert.IsTrue(methodOverride.Matches(typeof(Feeder).GetMethod("GetGrub")));
        }
        public void Matches_TotallyDifferentMethodName()
        {
            LookupMethodOverride methodOverride = new LookupMethodOverride("Bingo", "foo");

            Assert.IsFalse(methodOverride.Matches(typeof(Feeder).GetMethod("GetGrub")));
        }
        public void ToStringWorks()
        {
            LookupMethodOverride methodOverride = new LookupMethodOverride("GetGrub", "foo");

            Assert.AreEqual(typeof(LookupMethodOverride).Name + " for method 'GetGrub'; will return object 'foo'.", methodOverride.ToString());
        }
		public void MatchesWithNullMethod()
		{
			LookupMethodOverride methodOverride = new LookupMethodOverride("Execute", "foo");
			methodOverride.Matches(null);
		}
		public void Matches_MatchingMethodName()
		{
			LookupMethodOverride methodOverride = new LookupMethodOverride("GetGrub", "foo");
			Assert.IsTrue(methodOverride.Matches(typeof (Feeder).GetMethod("GetGrub")));
		}
		public void Matches_TotallyDifferentMethodName()
		{
			LookupMethodOverride methodOverride = new LookupMethodOverride("Bingo", "foo");
			Assert.IsFalse(methodOverride.Matches(typeof (Feeder).GetMethod("GetGrub")));
		}
		public void ToStringWorks()
		{
			LookupMethodOverride methodOverride = new LookupMethodOverride("GetGrub", "foo");
			Assert.AreEqual(typeof (LookupMethodOverride).Name + " for method 'GetGrub'; will return object 'foo'.", methodOverride.ToString());
		}
		public void MatchesWithNullMethod()
		{
			LookupMethodOverride methodOverride = new LookupMethodOverride("Execute", "foo");
            Assert.Throws<ArgumentNullException>(() => methodOverride.Matches(null));
		}
示例#13
0
        public void MatchesWithNullMethod()
        {
            LookupMethodOverride methodOverride = new LookupMethodOverride("Execute", "foo");

            Assert.Throws <ArgumentNullException>(() => methodOverride.Matches(null));
        }