public void AcceptVisitorTest()
        {
            // Arrange
            var proxyDefinition = new InterfaceProxyDefinition(typeof(IOne), new[] { typeof(ITwo), typeof(IOneTwo) });

            // Act
            var proxyDefinitionVisitor = new CollectingProxyDefinitionVisitor();

            proxyDefinition.AcceptVisitor(proxyDefinitionVisitor);

            // Assert
            Assert.That(proxyDefinition.DeclaringType, Is.EqualTo(typeof(IOne)));
            Assert.That(proxyDefinition.ParentType, Is.EqualTo(typeof(object)));
            Assert.That(proxyDefinition.ImplementedInterfaces.Count(), Is.EqualTo(4));
            Assert.That(proxyDefinition.ImplementedInterfaces, Contains.Item(typeof(IBase)));
            Assert.That(proxyDefinition.ImplementedInterfaces, Contains.Item(typeof(IOne)));
            Assert.That(proxyDefinition.ImplementedInterfaces, Contains.Item(typeof(ITwo)));
            Assert.That(proxyDefinition.ImplementedInterfaces, Contains.Item(typeof(IOneTwo)));
            Assert.That(proxyDefinitionVisitor.InterfaceTypes.Count, Is.EqualTo(4));
            Assert.That(proxyDefinitionVisitor.InterfaceTypes, Contains.Item(typeof(IBase)));
            Assert.That(proxyDefinitionVisitor.InterfaceTypes, Contains.Item(typeof(IOne)));
            Assert.That(proxyDefinitionVisitor.InterfaceTypes, Contains.Item(typeof(ITwo)));
            Assert.That(proxyDefinitionVisitor.InterfaceTypes, Contains.Item(typeof(IOneTwo)));

            Assert.That(proxyDefinitionVisitor.ConstructorInfos.Count, Is.EqualTo(1));

            Assert.That(proxyDefinitionVisitor.EventInfos.Count, Is.EqualTo(3));

            Assert.That(proxyDefinitionVisitor.PropertyInfos.Count, Is.EqualTo(6));

            Assert.That(proxyDefinitionVisitor.MethodInfos.Count, Is.EqualTo(7));
        }
        public void EqualsWithDeclaringInterfaceTest()
        {
            // Arrange
            var firstProxyDefinition  = new InterfaceProxyDefinition(typeof(IOne), new[] { typeof(IBase) });
            var secondProxyDefinition = new InterfaceProxyDefinition(typeof(IOne), Type.EmptyTypes);

            // Act
            var equals = firstProxyDefinition.Equals(secondProxyDefinition);

            // Assert
            Assert.That(equals, Is.True);
        }
        public void EqualsWithSwappedInterfacesTest()
        {
            // Arrange
            var firstProxyDefinition  = new InterfaceProxyDefinition(typeof(IBase), new[] { typeof(IOne), typeof(ITwo) });
            var secondProxyDefinition = new InterfaceProxyDefinition(typeof(IBase), new[] { typeof(ITwo), typeof(IOne) });

            // Act
            var equals = firstProxyDefinition.Equals(secondProxyDefinition);

            // Assert
            Assert.That(equals, Is.True);
        }
예제 #4
0
        private void AddInterfaces()
        {
            if (typeDefinition.TypeDefinitionType == TypeDefinitionType.InterfaceProxy)
            {
                InterfaceProxyDefinition interfaceDefinition = typeDefinition as InterfaceProxyDefinition;
                typeBuilder.AddInterfaceImplementation(typeDefinition.Type);
                typeBuilder.AddInterfacesToImplement(interfaceDefinition.Interfaces);
            }

            foreach (var mixinDefinition in typeDefinition.MixinDefinitions)
            {
                typeBuilder.AddInterfacesToImplement(mixinDefinition.Interfaces);
            }
        }