public void TestTypeCachingWithMultipleMixins() { ProxyGenerationOptions options = new ProxyGenerationOptions(); SimpleMixin mixin_instance1 = new SimpleMixin(); ComplexMixin mixin_instance2 = new ComplexMixin(); options.AddMixinInstance(mixin_instance1); options.AddMixinInstance(mixin_instance2); AssertInvocationInterceptor interceptor = new AssertInvocationInterceptor(); object proxy1 = generator.CreateClassProxy(typeof(SimpleClass), options, interceptor); options = new ProxyGenerationOptions(); mixin_instance1 = new SimpleMixin(); mixin_instance2 = new ComplexMixin(); options.AddMixinInstance(mixin_instance2); options.AddMixinInstance(mixin_instance1); interceptor = new AssertInvocationInterceptor(); object proxy2 = generator.CreateClassProxy(typeof(SimpleClass), options, interceptor); Assert.IsTrue(proxy1.GetType().Equals(proxy2.GetType())); }
public void SimpleMixin_ClassProxy() { ProxyGenerationOptions options = new ProxyGenerationOptions(); SimpleMixin mixin_instance = new SimpleMixin(); options.AddMixinInstance(mixin_instance); AssertInvocationInterceptor interceptor = new AssertInvocationInterceptor(); object proxy = generator.CreateClassProxy(typeof(SimpleClass), options, interceptor); Assert.IsNotNull(proxy); Assert.IsTrue(typeof(SimpleClass).IsAssignableFrom(proxy.GetType())); Assert.IsFalse(interceptor.Invoked); ISimpleMixin mixin = proxy as ISimpleMixin; Assert.IsNotNull(mixin); Assert.AreEqual(1, mixin.DoSomething()); Assert.IsTrue(interceptor.Invoked); Assert.AreSame(proxy, interceptor.proxy); Assert.AreSame(mixin_instance, interceptor.mixin); }
public void TwoMixinsWithSameInterfaces() { SimpleMixin mixin1 = new SimpleMixin(); OtherMixinImplementingISimpleMixin mixin2 = new OtherMixinImplementingISimpleMixin(); Assert.Throws <ArgumentException>(() => new MixinData(new object[] { mixin1, mixin2 })); }
public void SimpleMixin_ClassProxy() { var options = new ProxyGenerationOptions(); var mixin_instance = new SimpleMixin(); options.AddMixinInstance(mixin_instance); var interceptor = new AssertInvocationInterceptor(); var proxy = generator.CreateClassProxy(typeof(SimpleClass), options, interceptor); Assert.IsNotNull(proxy); Assert.IsTrue(proxy is SimpleClass); Assert.IsFalse(interceptor.Invoked); var mixin = proxy as ISimpleMixin; Assert.IsNotNull(mixin); Assert.AreEqual(1, mixin.DoSomething()); Assert.IsTrue(interceptor.Invoked); Assert.AreSame(proxy, interceptor.proxy); Assert.AreSame(mixin_instance, interceptor.mixin); }
public void SetUp() #endif { simpleMixin = new SimpleMixin(); otherMixin = new OtherMixin(); complexMixin = new ComplexMixin(); }
public void SimpleMixin_InterfaceProxy_WithtTargetInterface() { var options = new ProxyGenerationOptions(); var mixin_instance = new SimpleMixin(); options.AddMixinInstance(mixin_instance); var interceptor = new AssertInvocationInterceptor(); var proxy = generator.CreateInterfaceProxyWithTargetInterface(typeof(IService), new ServiceImpl(), options, interceptor); Assert.IsNotNull(proxy); Assert.IsTrue(proxy is IService); Assert.IsFalse(interceptor.Invoked); var mixin = proxy as ISimpleMixin; Assert.IsNotNull(mixin); Assert.AreEqual(1, mixin.DoSomething()); Assert.IsTrue(interceptor.Invoked); Assert.AreSame(proxy, interceptor.proxy); Assert.AreSame(mixin_instance, interceptor.mixin); }
public void XmlSerialization() { ProxyObjectReference.ResetScope(); GeneratorContext context = new GeneratorContext(); SimpleMixin mixin1 = new SimpleMixin(); OtherMixin mixin2 = new OtherMixin(); context.AddMixinInstance(mixin1); context.AddMixinInstance(mixin2); object proxy = generator.CreateCustomClassProxy( typeof(SimpleClass), new StandardInterceptor(), context); System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(SimpleClass)); MemoryStream stream = new MemoryStream(); serializer.Serialize(stream, proxy); stream.Position = 0; SimpleClass otherProxy = (SimpleClass)serializer.Deserialize(stream); ISimpleMixin mixin = otherProxy as ISimpleMixin; Assert.AreEqual(1, mixin.DoSomething()); IOtherMixin other = otherProxy as IOtherMixin; Assert.AreEqual(3, other.Sum(1, 2)); }
public void GetHashCode_EqualNonEmptyOptions() { _options1 = new ProxyGenerationOptions(); _options2 = new ProxyGenerationOptions(); _options1.BaseTypeForInterfaceProxy = typeof(IConvertible); _options2.BaseTypeForInterfaceProxy = typeof(IConvertible); SimpleMixin mixin = new SimpleMixin(); _options1.AddMixinInstance(mixin); _options2.AddMixinInstance(mixin); IProxyGenerationHook hook = new AllMethodsHook(); _options1.Hook = hook; _options2.Hook = hook; IInterceptorSelector selector = new AllInterceptorSelector(); _options1.Selector = selector; _options2.Selector = selector; Assert.AreEqual(_options1.GetHashCode(), _options2.GetHashCode()); }
public void SimpleMixin() { GeneratorContext context = new GeneratorContext(); SimpleMixin mixin_instance = new SimpleMixin(); context.AddMixinInstance(mixin_instance); AssertInvocationInterceptor interceptor = new AssertInvocationInterceptor(); object proxy = _generator.CreateCustomClassProxy( typeof(SimpleClass), interceptor, context); Assert.IsNotNull(proxy); Assert.IsTrue(typeof(SimpleClass).IsAssignableFrom(proxy.GetType())); Assert.IsFalse(interceptor.Invoked); ISimpleMixin mixin = proxy as ISimpleMixin; Assert.IsNotNull(mixin); Assert.AreEqual(1, mixin.DoSomething()); Assert.IsTrue(interceptor.Invoked); Assert.AreSame(proxy, interceptor.proxy); Assert.AreSame(mixin_instance, interceptor.mixin); }
public void MixinForInterfaces() { ProxyGenerationOptions proxyGenerationOptions = new ProxyGenerationOptions(); SimpleMixin mixin_instance = new SimpleMixin(); proxyGenerationOptions.AddMixinInstance(mixin_instance); AssertInvocationInterceptor interceptor = new AssertInvocationInterceptor(); MyInterfaceImpl target = new MyInterfaceImpl(); object proxy = generator.CreateInterfaceProxyWithTarget( typeof(IMyInterface), target, proxyGenerationOptions, interceptor); Assert.IsNotNull(proxy); Assert.IsTrue(typeof(IMyInterface).IsAssignableFrom(proxy.GetType())); Assert.IsFalse(interceptor.Invoked); ISimpleMixin mixin = proxy as ISimpleMixin; Assert.IsNotNull(mixin); Assert.AreEqual(1, mixin.DoSomething()); Assert.IsTrue(interceptor.Invoked); Assert.AreSame(proxy, interceptor.proxy); Assert.AreSame(mixin_instance, interceptor.mixin); }
public void TwoMixinsWithSameInterfaces() { SimpleMixin mixin1 = new SimpleMixin(); OtherMixinImplementingISimpleMixin mixin2 = new OtherMixinImplementingISimpleMixin(); new MixinData(new object[] { mixin1, mixin2 }); }
public void Equals_DifferentOptions_AddMixinInstance() { SimpleMixin mixin = new SimpleMixin(); _options1.AddMixinInstance(mixin); Assert.AreNotEqual(_options1, _options2); }
public void GetHashCode_DifferentOptions_AddMixinInstance() { SimpleMixin mixin = new SimpleMixin(); _options1.AddMixinInstance(mixin); Assert.AreNotEqual(_options1.GetHashCode(), _options2.GetHashCode()); }
public void Mixin_and_target_implement_additionalInterface_forwards_to_target() { var mixin = new SimpleMixin(); object proxy = generator.CreateInterfaceProxyWithTarget(typeof(ISimpleMixin), new[] { typeof(IDerivedSimpleMixin) }, new ClassImplementingIDerivedSimpleMixin(), MixIn(mixin)); Assert.AreEqual(3, (proxy as ISimpleMixin).DoSomething()); Assert.AreEqual(2, (proxy as IDerivedSimpleMixin).DoSomethingDerived()); }
public void MixinWithSameInterface_InterfaceWithTarget_AdditionalInterfaces_Derived() { ProxyGenerationOptions options = new ProxyGenerationOptions(); SimpleMixin mixin1 = new SimpleMixin(); options.AddMixinInstance(mixin1); StandardInterceptor interceptor = new StandardInterceptor(); var proxy = generator.CreateInterfaceProxyWithTarget(typeof(IService), new Type[] { typeof(IDerivedSimpleMixin) }, new ServiceImpl(), options, interceptor); Assert.AreEqual(1, (proxy as ISimpleMixin).DoSomething()); }
public void TwoMixinsWithSameInterface() { ProxyGenerationOptions options = new ProxyGenerationOptions(); SimpleMixin mixin1 = new SimpleMixin(); OtherMixinImplementingISimpleMixin mixin2 = new OtherMixinImplementingISimpleMixin(); options.AddMixinInstance(mixin1); options.AddMixinInstance(mixin2); StandardInterceptor interceptor = new StandardInterceptor(); generator.CreateClassProxy(typeof(SimpleClass), options, interceptor); }
public void TwoMixinsWithSameInterface() { ProxyGenerationOptions options = new ProxyGenerationOptions(); SimpleMixin mixin1 = new SimpleMixin(); OtherMixinImplementingISimpleMixin mixin2 = new OtherMixinImplementingISimpleMixin(); options.AddMixinInstance(mixin1); options.AddMixinInstance(mixin2); StandardInterceptor interceptor = new StandardInterceptor(); Assert.Throws <InvalidMixinConfigurationException>(() => generator.CreateClassProxy(typeof(SimpleClass), options, interceptor) ); }
public void TestTypeCachingWithMixins() { var options = new ProxyGenerationOptions(); var mixin_instance = new SimpleMixin(); options.AddMixinInstance(mixin_instance); var interceptor = new AssertInvocationInterceptor(); var proxy1 = generator.CreateClassProxy(typeof(SimpleClass), options, interceptor); options = new ProxyGenerationOptions(); mixin_instance = new SimpleMixin(); options.AddMixinInstance(mixin_instance); interceptor = new AssertInvocationInterceptor(); var proxy2 = generator.CreateClassProxy(typeof(SimpleClass), options, interceptor); Assert.IsTrue(proxy1.GetType().Equals(proxy2.GetType())); }
public void TwoMixins() { ProxyGenerationOptions proxyGenerationOptions = new ProxyGenerationOptions(); SimpleMixin mixin1 = new SimpleMixin(); OtherMixin mixin2 = new OtherMixin(); proxyGenerationOptions.AddMixinInstance(mixin1); proxyGenerationOptions.AddMixinInstance(mixin2); AssertInvocationInterceptor interceptor = new AssertInvocationInterceptor(); object proxy = generator.CreateClassProxy( typeof(SimpleClass), proxyGenerationOptions, interceptor ); Assert.IsFalse(interceptor.Invoked); Assert.IsNotNull(proxy); Assert.IsTrue(typeof(SimpleClass).IsAssignableFrom(proxy.GetType())); ISimpleMixin mixin = proxy as ISimpleMixin; Assert.IsNotNull(mixin); Assert.AreEqual(1, mixin.DoSomething()); Assert.IsTrue(interceptor.Invoked); Assert.AreSame(proxy, interceptor.proxy); Assert.AreSame(mixin1, interceptor.mixin); IOtherMixin other = proxy as IOtherMixin; Assert.IsNotNull(other); Assert.AreEqual(3, other.Sum(1, 2)); Assert.IsTrue(interceptor.Invoked); Assert.AreSame(proxy, interceptor.proxy); Assert.AreSame(mixin2, interceptor.mixin); }
public void MixinSerialization() { ProxyObjectReference.ResetScope(); GeneratorContext context = new GeneratorContext(); SimpleMixin mixin1 = new SimpleMixin(); OtherMixin mixin2 = new OtherMixin(); context.AddMixinInstance(mixin1); context.AddMixinInstance(mixin2); object proxy = generator.CreateCustomClassProxy( typeof(SimpleClass), new StandardInterceptor(), context); Assert.IsTrue(typeof(SimpleClass).IsAssignableFrom(proxy.GetType())); (proxy as SimpleClass).DoSome(); ISimpleMixin mixin = proxy as ISimpleMixin; Assert.AreEqual(1, mixin.DoSomething()); IOtherMixin other = proxy as IOtherMixin; Assert.AreEqual(3, other.Sum(1, 2)); SimpleClass otherProxy = (SimpleClass)SerializeAndDeserialize(proxy); otherProxy.DoSome(); mixin = otherProxy as ISimpleMixin; Assert.AreEqual(1, mixin.DoSomething()); other = otherProxy as IOtherMixin; Assert.AreEqual(3, other.Sum(1, 2)); }
public void Mixin_and_target_implement_additionalInterface_forwards_to_target() { var mixin = new SimpleMixin(); object proxy = generator.CreateInterfaceProxyWithTarget(typeof (ISimpleMixin), new[] {typeof (IDerivedSimpleMixin)}, new ClassImplementingIDerivedSimpleMixin(), MixIn(mixin)); Assert.AreEqual(3, (proxy as ISimpleMixin).DoSomething()); Assert.AreEqual(2, (proxy as IDerivedSimpleMixin).DoSomethingDerived()); }