private static IInvocation CreateInterceptedProperty(StubAbstractTypeConfiguration config, string propertyName) { var invocation = Substitute.For <IInvocation>(); var property = new StubAbstractPropertyConfiguration(); var mapper = new StubAbstractDataMapper(); var getter = Substitute.For <MethodInfo>(); getter.Attributes.Returns(MethodAttributes.SpecialName); getter.Name.Returns("get_" + propertyName); getter.ReturnType.Returns(typeof(string)); var returnValue = propertyName; var info = Substitute.For <FakePropertyInfo>(typeof(string), propertyName, typeof(IStubTarget)); info.CanWrite.Returns(false); info.DeclaringType.Returns(typeof(IStubTarget)); info.Name.Returns(propertyName); property.Mapper = mapper; property.PropertyInfo = info; config.AddProperty(property); mapper.Value = returnValue; invocation.Method.Returns(getter); return(invocation); }
public void Intercept_InterceptsMultiplePropertiesOnDifferentInterfaces_ReturnsExpectedPropertyValues() { //Arrange var service = Substitute.For<IAbstractService>(); var config1 = new StubAbstractTypeConfiguration(); var config2 = new StubAbstractTypeConfiguration(); var property1 = new StubAbstractPropertyConfiguration(); var property2 = new StubAbstractPropertyConfiguration(); var mapper1 = new StubAbstractDataMapper(); var mapper2 = new StubAbstractDataMapper(); var expected1 = "test random 1"; var expected2 = "some other random"; var propertyName1 = "Property1"; var propertyName2 = "Property2"; var info1 = new FakePropertyInfo(typeof(string), propertyName1, typeof(IStubTarget)); var info2 = new FakePropertyInfo(typeof(string), propertyName2, typeof(IStubTarget2)); config1.AddProperty(property1); config2.AddProperty(property2); property1.Mapper = mapper1; property2.Mapper = mapper2; property1.PropertyInfo = info1; property2.PropertyInfo = info2; mapper1.Value = expected1; mapper2.Value = expected2; var args = new ObjectConstructionArgs(null, null, config1, service); args.Parameters = new Dictionary<string, object>(); args.Parameters[CreateMultiInferaceTask.MultiInterfaceConfigsKey] = new[] {config2}; var interceptor = new MultiInterfacePropertyInterceptor(args); var invocation1 = Substitute.For<IInvocation>(); var invocation2 = Substitute.For<IInvocation>(); invocation1.Method.Returns(typeof(IStubTarget).GetProperty(propertyName1).GetGetMethod()); invocation2.Method.Returns(typeof(IStubTarget2).GetProperty(propertyName2).GetGetMethod()); //Act interceptor.Intercept(invocation1); interceptor.Intercept(invocation2); //Assert Assert.AreEqual(expected1, invocation1.ReturnValue); Assert.AreEqual(expected2, invocation2.ReturnValue); }
public void Intercept_InterceptsMultiplePropertiesOnDifferentInterfaces_ReturnsExpectedPropertyValues() { //Arrange var service = Substitute.For <IAbstractService>(); var config1 = new StubAbstractTypeConfiguration(); var config2 = new StubAbstractTypeConfiguration(); var property1 = new StubAbstractPropertyConfiguration(); var property2 = new StubAbstractPropertyConfiguration(); var mapper1 = new StubAbstractDataMapper(); var mapper2 = new StubAbstractDataMapper(); var expected1 = "test random 1"; var expected2 = "some other random"; var propertyName1 = "Property1"; var propertyName2 = "Property2"; var info1 = new FakePropertyInfo(typeof(string), propertyName1, typeof(IStubTarget)); var info2 = new FakePropertyInfo(typeof(string), propertyName2, typeof(IStubTarget2)); config1.AddProperty(property1); config2.AddProperty(property2); property1.Mapper = mapper1; property2.Mapper = mapper2; property1.PropertyInfo = info1; property2.PropertyInfo = info2; mapper1.Value = expected1; mapper2.Value = expected2; var args = new ObjectConstructionArgs(null, null, config1, service, new ModelCounter()); args.Parameters = new Dictionary <string, object>(); args.Parameters[CreateMultiInferaceTask.MultiInterfaceConfigsKey] = new[] { config2 }; var interceptor = new MultiInterfacePropertyInterceptor(args); var invocation1 = Substitute.For <IInvocation>(); var invocation2 = Substitute.For <IInvocation>(); invocation1.Method.Returns(typeof(IStubTarget).GetProperty(propertyName1).GetGetMethod()); invocation2.Method.Returns(typeof(IStubTarget2).GetProperty(propertyName2).GetGetMethod()); //Act interceptor.Intercept(invocation1); interceptor.Intercept(invocation2); //Assert Assert.AreEqual(expected1, invocation1.ReturnValue); Assert.AreEqual(expected2, invocation2.ReturnValue); }
public void Intercept_InterceptsProperties_SetsExpectedPropertyValue() { //Arrange var service = Substitute.For <IAbstractService>(); var config = new StubAbstractTypeConfiguration(); var context = Substitute.For <AbstractTypeCreationContext>(); context.Options = new GetOptions { Lazy = LazyLoading.Enabled }; var propertyName = "Property1"; var info = typeof(IStubTarget).GetProperty(propertyName); var property = new StubAbstractPropertyConfiguration(); property.PropertyInfo = info; var mapper = new StubAbstractDataMapper(); var expected = "test random 1"; var info1 = new FakePropertyInfo(typeof(string), propertyName, typeof(IStubTarget)); config.AddProperty(property); config.Type = typeof(IStubTarget); property.Mapper = mapper; property.PropertyInfo = info1; var args = new ObjectConstructionArgs(null, context, config, service) { Parameters = new Dictionary <string, object>() }; var interceptor = new InterfacePropertyInterceptor(args, new LazyLoadingHelper()); var setInvocation = Substitute.For <IInvocation>(); setInvocation.Arguments.Returns(new[] { expected }); setInvocation.Method.Returns(typeof(IStubTarget).GetProperty(propertyName).GetSetMethod()); //Act interceptor.Intercept(setInvocation); //Assert var getInvocation = Substitute.For <IInvocation>(); getInvocation.Method.Returns(typeof(IStubTarget).GetProperty(propertyName).GetGetMethod()); interceptor.Intercept(getInvocation); Assert.AreEqual(expected, getInvocation.ReturnValue); }
public void Intercept_InterceptsProperties_ReturnsExpectedPropertyValue() { //Arrange var service = Substitute.For <IAbstractService>(); var config = new StubAbstractTypeConfiguration(); var context = Substitute.For <AbstractTypeCreationContext>(); var property = new StubAbstractPropertyConfiguration(); var mapper = new StubAbstractDataMapper(); var expected = "test random 1"; var propertyName = "Property1"; var info = new FakePropertyInfo(typeof(string), propertyName, typeof(IStubTarget)); config.AddProperty(property); config.Type = typeof(IStubTarget); property.Mapper = mapper; property.PropertyInfo = info; mapper.Value = expected; var args = new ObjectConstructionArgs(null, context, config, service) { Parameters = new Dictionary <string, object>() }; var interceptor = new InterfacePropertyInterceptor(args); var invocation = Substitute.For <IInvocation>(); invocation.Method.Returns(typeof(IStubTarget).GetProperty(propertyName).GetGetMethod()); //Act interceptor.Intercept(invocation); //Assert Assert.AreEqual(expected, invocation.ReturnValue); }
public void Intercept_InterceptsProperties_ReturnsExpectedPropertyValue() { //Arrange var service = Substitute.For<IAbstractService>(); var config = new StubAbstractTypeConfiguration(); var context = Substitute.For<AbstractTypeCreationContext>(); var property = new StubAbstractPropertyConfiguration(); var mapper = new StubAbstractDataMapper(); var expected = "test random 1"; var propertyName = "Property1"; var info = new FakePropertyInfo(typeof(string), propertyName, typeof(IStubTarget)); config.AddProperty(property); config.Type = typeof(IStubTarget); property.Mapper = mapper; property.PropertyInfo = info; mapper.Value = expected; var args = new ObjectConstructionArgs(null, context, config, service, new ModelCounter()) { Parameters = new Dictionary<string, object>() }; var interceptor = new InterfacePropertyInterceptor(args); var invocation = Substitute.For<IInvocation>(); invocation.Method.Returns(typeof(IStubTarget).GetProperty(propertyName).GetGetMethod()); //Act interceptor.Intercept(invocation); //Assert Assert.AreEqual(expected, invocation.ReturnValue); }
private static IInvocation CreateInterceptedProperty(StubAbstractTypeConfiguration config, string propertyName) { var invocation = Substitute.For<IInvocation>(); var property = new StubAbstractPropertyConfiguration(); var mapper = new StubAbstractDataMapper(); var getter = Substitute.For<MethodInfo>(); getter.Attributes.Returns(MethodAttributes.SpecialName); getter.Name.Returns("get_" + propertyName); getter.ReturnType.Returns(typeof(string)); var returnValue = propertyName; var info = Substitute.For<FakePropertyInfo>(typeof(string), propertyName, typeof(IStubTarget)); info.CanWrite.Returns(false); info.DeclaringType.Returns(typeof(IStubTarget)); info.Name.Returns(propertyName); property.Mapper = mapper; property.PropertyInfo = info; config.AddProperty(property); mapper.Value = returnValue; invocation.Method.Returns(getter); return invocation; }