public void Intercept_WithMultiplePropertiesAndLazyLoading_ReturnsExpectedPropertyValues() { //Arrange var service = Substitute.For<IAbstractService>(); var config = new StubAbstractTypeConfiguration(); var context = Substitute.For<AbstractTypeCreationContext>(); config.Type = typeof(IStubTarget); context.IsLazy = true; var args = new ObjectConstructionArgs(null, context, config, service, new ModelCounter()) { Parameters = new Dictionary<string, object>() }; var interceptor = new InterfacePropertyInterceptor(args); var invocations = new List<IInvocation>(); for (var i = 0; i < 100; i++) { invocations.Add(CreateInterceptedProperty(config, i.ToString())); } //Act foreach (var invocation in invocations) { interceptor.Intercept(invocation); // Assert Assert.AreEqual(invocation.Method.Name.Substring(4), invocation.ReturnValue); } }
/// <summary> /// Executes the specified args. /// </summary> /// <param name="args">The args.</param> public override void Execute(ObjectConstructionArgs args) { if (args.Result == null && args.Configuration.Type.IsInterface) { var interceptor = new InterfacePropertyInterceptor( args, _lazyLoadingHelper ); args.Result = _generator.CreateInterfaceProxyWithoutTarget( args.Configuration.Type, interceptor ); ModelCounter.Instance.ProxyModelsCreated++; } base.Execute(args); }
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); }