public void GetOverrideInterfaceMethodsByMixinMethod() { var importer = new AttributeBasedMetadataImporter(); var identifier = new ConcreteMixinTypeIdentifier(typeof(MixinWithAbstractMembers), new HashSet <MethodInfo> (), new HashSet <MethodInfo> ()); var interfaceType = typeof(LoadableConcreteMixinTypeForMixinWithAbstractMembers.IOverriddenMethods); var result = importer.GetOverrideInterfaceMethodsByMixinMethod(interfaceType, identifier); var ifcMethod1 = interfaceType.GetMethod("AbstractMethod"); var mixinMethod1 = identifier.MixinType.GetMethod("AbstractMethod", BindingFlags.NonPublic | BindingFlags.Instance); var ifcMethod2 = interfaceType.GetMethod("get_AbstractProperty"); var mixinMethod2 = identifier.MixinType.GetMethod("get_AbstractProperty", BindingFlags.NonPublic | BindingFlags.Instance); var ifcMethod3 = interfaceType.GetMethod("add_AbstractEvent"); var mixinMethod3 = identifier.MixinType.GetMethod("add_AbstractEvent", BindingFlags.NonPublic | BindingFlags.Instance); var ifcMethod4 = interfaceType.GetMethod("remove_AbstractEvent"); var mixinMethod4 = identifier.MixinType.GetMethod("remove_AbstractEvent", BindingFlags.NonPublic | BindingFlags.Instance); var ifcMethod5 = interfaceType.GetMethod("RaiseEvent"); var mixinMethod5 = identifier.MixinType.GetMethod("RaiseEvent", BindingFlags.NonPublic | BindingFlags.Instance); var expected = new Dictionary <MethodInfo, MethodInfo> { { mixinMethod1, ifcMethod1 }, { mixinMethod2, ifcMethod2 }, { mixinMethod3, ifcMethod3 }, { mixinMethod4, ifcMethod4 }, { mixinMethod5, ifcMethod5 }, }; Assert.That(result, Is.EquivalentTo(expected)); }
public void GetWrapperAttribute_WithoutResult() { var importer = new AttributeBasedMetadataImporter(); var method = GetType().GetMethod("FakeNonWrapperMethod"); var attribute = (GeneratedMethodWrapperAttribute)PrivateInvoke.InvokeNonPublicMethod(importer, "GetWrapperAttribute", method); Assert.That(attribute, Is.Null); }
public void GetWrapperAttribute_WithResult() { var importer = new AttributeBasedMetadataImporter(); var method = GetType().GetMethod("FakeWrapperMethod"); var attribute = (GeneratedMethodWrapperAttribute)PrivateInvoke.InvokeNonPublicMethod(importer, "GetWrapperAttribute", method); Assert.That(attribute, Is.Not.Null); Assert.That(attribute.DeclaringType, Is.EqualTo(typeof(DateTime))); Assert.That(attribute.MethodName, Is.EqualTo("get_Now")); Assert.That(attribute.MethodSignature, Is.EqualTo("System.DateTime get_Now()")); }
public void GetIdentifierForMixinType_NoAttribute() { var typeMock = MockRepository.GenerateMock <_Type> (); typeMock.Expect(mock => mock.GetCustomAttributes(typeof(ConcreteMixinTypeAttribute), false)).Return(new ConcreteMixinTypeAttribute[0]); typeMock.Replay(); var importer = new AttributeBasedMetadataImporter(); var result = importer.GetIdentifierForMixinType(typeMock); Assert.That(result, Is.Null); typeMock.VerifyAllExpectations(); }
public void GetIdentifierForMixinType() { var typeMock = MockRepository.GenerateMock <_Type> (); var identifier = new ConcreteMixinTypeIdentifier(typeof(object), new HashSet <MethodInfo>(), new HashSet <MethodInfo>()); var attribute = ConcreteMixinTypeAttribute.Create(identifier); typeMock.Expect(mock => mock.GetCustomAttributes(typeof(ConcreteMixinTypeAttribute), false)).Return(new[] { attribute }); typeMock.Replay(); var importer = new AttributeBasedMetadataImporter(); var result = importer.GetIdentifierForMixinType(typeMock); Assert.That(result, Is.EqualTo(identifier)); typeMock.VerifyAllExpectations(); }
private void SetupImporterMock( AttributeBasedMetadataImporter importerMock, ConcreteMixinTypeIdentifier expectedIdentifier, Dictionary <MethodInfo, MethodInfo> overrideInterfaceMethods, Dictionary <MethodInfo, MethodInfo> methodWrappers) { importerMock .Expect(mock => mock.GetIdentifierForMixinType(typeof(LoadableConcreteMixinTypeForMixinWithAbstractMembers))) .Return(expectedIdentifier); importerMock .Expect(mock => mock.GetOverrideInterfaceMethodsByMixinMethod( typeof(LoadableConcreteMixinTypeForMixinWithAbstractMembers.IOverriddenMethods), expectedIdentifier)) .Return(overrideInterfaceMethods); importerMock .Expect(mock => mock.GetMethodWrappersForMixinType(typeof(LoadableConcreteMixinTypeForMixinWithAbstractMembers))) .Return(methodWrappers); }
public void GetMetadataForMixedType() { var classContext1 = ClassContextObjectMother.Create(typeof(object)); var attribute1 = ConcreteMixedTypeAttribute.FromClassContext(classContext1, new Type[0]); var typeMock = MockRepository.GenerateMock <_Type> (); typeMock.Expect(mock => mock.GetCustomAttributes(typeof(ConcreteMixedTypeAttribute), false)).Return(new[] { attribute1 }); typeMock.Replay(); var importer = new AttributeBasedMetadataImporter(); var result = importer.GetMetadataForMixedType(typeMock); Assert.That(result, Is.EqualTo(classContext1)); typeMock.VerifyAllExpectations(); }