public Intercept ( IInvocation invocation ) : void | ||
invocation | IInvocation | The invocation. |
Résultat | void |
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); } }
public void Intercept_InterceptsProperties_SetsExpectedPropertyValue() { //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 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, new ModelCounter()) { Parameters = new Dictionary<string, object>() }; var interceptor = new InterfacePropertyInterceptor(args); 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); }