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() { IObjectFactory mockFactory = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory)); IConfigurableObjectDefinition mockDefinition = (IConfigurableObjectDefinition)mocks.CreateMock(typeof(IConfigurableObjectDefinition)); IMethodReplacer mockReplacer = (IMethodReplacer)mocks.CreateMock(typeof(IMethodReplacer)); const string ReplacerObjectName = "replacer"; Expect.Call(mockFactory.GetObject(ReplacerObjectName)).Return(mockReplacer); ReplacedMethodOverride ovr = new ReplacedMethodOverride("SunnyDayPath", ReplacerObjectName); MethodOverrides overrides = new MethodOverrides(); overrides.Add(ovr); Expect.Call(mockDefinition.MethodOverrides).Return(overrides); Expect.Call(mockReplacer.Implement(null, null, null)).IgnoreArguments().Return(null); mocks.ReplayAll(); DelegatingMethodReplacer replacer = new DelegatingMethodReplacer(mockDefinition, mockFactory); MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod(); replacer.Implement(this, method, new object[] {}); 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 SunnyDayPath() { IObjectFactory mockFactory = (IObjectFactory) mocks.CreateMock(typeof(IObjectFactory)); IConfigurableObjectDefinition mockDefinition = (IConfigurableObjectDefinition) mocks.CreateMock(typeof(IConfigurableObjectDefinition)); IMethodReplacer mockReplacer = (IMethodReplacer) mocks.CreateMock(typeof(IMethodReplacer)); const string ReplacerObjectName = "replacer"; Expect.Call(mockFactory.GetObject(ReplacerObjectName)).Return(mockReplacer); ReplacedMethodOverride ovr = new ReplacedMethodOverride("SunnyDayPath", ReplacerObjectName); MethodOverrides overrides = new MethodOverrides(); overrides.Add(ovr); Expect.Call(mockDefinition.MethodOverrides).Return(overrides); Expect.Call(mockReplacer.Implement(null, null, null)).IgnoreArguments().Return(null); mocks.ReplayAll(); DelegatingMethodReplacer replacer = new DelegatingMethodReplacer(mockDefinition, mockFactory); MethodInfo method = (MethodInfo) MethodBase.GetCurrentMethod(); replacer.Implement(this, method, new object[] {}); mocks.VerifyAll(); }
public void SunnyDayPath() { IObjectFactory mockFactory = A.Fake <IObjectFactory>(); IConfigurableObjectDefinition mockDefinition = A.Fake <IConfigurableObjectDefinition>(); IMethodReplacer mockReplacer = A.Fake <IMethodReplacer>(); const string ReplacerObjectName = "replacer"; A.CallTo(() => mockFactory.GetObject(ReplacerObjectName)).Returns(mockReplacer); ReplacedMethodOverride ovr = new ReplacedMethodOverride("SunnyDayPath", ReplacerObjectName); MethodOverrides overrides = new MethodOverrides(); overrides.Add(ovr); A.CallTo(() => mockDefinition.MethodOverrides).Returns(overrides); A.CallTo(() => mockReplacer.Implement(null, null, null)).WithAnyArguments().Returns(null); DelegatingMethodReplacer replacer = new DelegatingMethodReplacer(mockDefinition, mockFactory); MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod(); replacer.Implement(this, method, new object[] {}); }
/// <summary> /// Parse <see cref="ObjectDefinitionConstants.ReplacedMethodElement"/> element and add parsed element to <paramref name="overrides"/> /// </summary> protected void ParseReplacedMethodElement( string name, MethodOverrides overrides, XmlElement element, ParserContext parserContext) { string methodName = GetAttributeValue(element, ObjectDefinitionConstants.ReplacedMethodNameAttribute); string targetReplacerObjectName = GetAttributeValue(element, ObjectDefinitionConstants.ReplacedMethodReplacerNameAttribute); if (StringUtils.IsNullOrEmpty(methodName)) { throw new ObjectDefinitionStoreException( parserContext.ReaderContext.Resource, name, string.Format("The '{0}' attribute is required for the '{1}' element.", ObjectDefinitionConstants.ReplacedMethodNameAttribute, ObjectDefinitionConstants.ReplacedMethodElement)); } if (StringUtils.IsNullOrEmpty(targetReplacerObjectName)) { throw new ObjectDefinitionStoreException( parserContext.ReaderContext.Resource, name, string.Format("The '{0}' attribute is required for the '{1}' element.", ObjectDefinitionConstants.ReplacedMethodReplacerNameAttribute, ObjectDefinitionConstants.ReplacedMethodElement)); } ReplacedMethodOverride theOverride = new ReplacedMethodOverride(methodName, targetReplacerObjectName); foreach (XmlNode node in this.SelectNodes(element, ObjectDefinitionConstants.ReplacedMethodArgumentTypeElement)) { XmlElement argElement = (XmlElement)node; string match = GetAttributeValue(argElement, ObjectDefinitionConstants.ReplacedMethodArgumentTypeMatchAttribute); if (StringUtils.IsNullOrEmpty(match)) { throw new ObjectDefinitionStoreException( parserContext.ReaderContext.Resource, name, string.Format("The '{0}' attribute is required for the '{1}' element.", ObjectDefinitionConstants.ReplacedMethodArgumentTypeMatchAttribute, ObjectDefinitionConstants.ReplacedMethodArgumentTypeElement)); } theOverride.AddTypeIdentifier(match); } overrides.Add(theOverride); }
/// <summary> /// Parse <see cref="ObjectDefinitionConstants.LookupMethodElement"/> element and add parsed element to <paramref name="overrides"/> /// </summary> protected void ParseLookupMethodElement( string name, MethodOverrides overrides, XmlElement element, ParserContext parserContext) { string methodName = GetAttributeValue(element, ObjectDefinitionConstants.LookupMethodNameAttribute); string targetObjectName = GetAttributeValue(element, ObjectDefinitionConstants.LookupMethodObjectNameAttribute); if (StringUtils.IsNullOrEmpty(methodName)) { throw new ObjectDefinitionStoreException( parserContext.ReaderContext.Resource, name, string.Format("The '{0}' attribute is required for the '{1}' element.", ObjectDefinitionConstants.LookupMethodNameAttribute, ObjectDefinitionConstants.LookupMethodElement)); } if (StringUtils.IsNullOrEmpty(targetObjectName)) { throw new ObjectDefinitionStoreException( parserContext.ReaderContext.Resource, name, string.Format("The '{0}' attribute is required for the '{1}' element.", ObjectDefinitionConstants.LookupMethodObjectNameAttribute, ObjectDefinitionConstants.LookupMethodElement)); } overrides.Add(new LookupMethodOverride(methodName, targetObjectName)); }