public void TestIfItCanBuildSetterRedirections() { // Arrange IMoreProperties target; string expectedName = "expected"; int expectedAge = 1; int expectedExtraProperty = 5; string expectedUnmappedProperty = "5"; MoreProperties source = new MoreProperties { Name = expectedName, Age = expectedAge, UnmappedProperty = expectedExtraProperty.ToString() }; // Act target = source.Proxify() .Redirect(subject => subject.UnmappedProperty) .Into <IMoreProperties>() .Property(proxy => proxy.ExtraGetSetProperty) .WithSetter((int proxyArgument) => proxyArgument.ToString()) .Proxy; target.ExtraGetSetProperty = expectedExtraProperty; // Assert Assert.That(target, Is.Not.Null); Assert.That(source.UnmappedProperty, Is.EqualTo(expectedUnmappedProperty)); }
public void TestIfANotFoundPropertyCanBeRedirected() { // Arrange var generator = new ProxyGenerator(); InterfaceMap map = new InterfaceMap() { Subject = new MoreProperties() { UnmappedProperty = "5" } }; MethodMapping mapping = new MethodMapping() { Subject = (proxied, parameters) => { MoreProperties subject = (MoreProperties)proxied; return(int.Parse(subject.UnmappedProperty)); }, Name = "get_ExtraGetProperty", ArgumentTypes = Type.EmptyTypes, GenericArgumentTypes = Type.EmptyTypes }; map.Add(mapping); MatchingInterceptor <IMoreProperties> interceptor = new MatchingInterceptor <IMoreProperties>(map); int expected = 5; int actual = 0; // Act IMoreProperties proxy = generator.CreateInterfaceProxyWithoutTarget <IMoreProperties>(interceptor); TestDelegate getter = () => { actual = proxy.ExtraGetProperty; }; // Assert Assert.That(proxy, Is.Not.Null); Assert.That(getter, Throws.Nothing); Assert.That(actual, Is.EqualTo(expected)); }