public void CreateRequiredMethodDefinitions_BaseWithSameMembers() { var targetClassDefinition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(ClassImplementingInterfaceWithDuckTypingWithBaseWithSameMembers)); DefinitionObjectMother.CreateMethodDefinition( targetClassDefinition, typeof(ClassImplementingInterfaceWithDuckTyping).GetMethod("Method1")); DefinitionObjectMother.CreateMethodDefinition( targetClassDefinition, typeof(ClassImplementingInterfaceWithDuckTyping).GetMethod("Method2")); var m1b = DefinitionObjectMother.CreateMethodDefinition( targetClassDefinition, typeof(ClassImplementingInterfaceWithDuckTypingWithBaseWithSameMembers).GetMethod("Method1")); var m2b = DefinitionObjectMother.CreateMethodDefinition( targetClassDefinition, typeof(ClassImplementingInterfaceWithDuckTypingWithBaseWithSameMembers).GetMethod("Method2")); var requirement = DefinitionObjectMother.CreateRequiredTargetCallTypeDefinition(targetClassDefinition, typeof(IInterface)); var builder = new DuckTypingRequiredMethodDefinitionCollector(targetClassDefinition); var definitions = builder.CreateRequiredMethodDefinitions(requirement).OrderBy(def => def.FullName).ToArray(); Assert.That(definitions.Length, Is.EqualTo(2)); Assert.That(definitions[0].DeclaringRequirement, Is.SameAs(requirement)); Assert.That(definitions[0].InterfaceMethod, Is.EqualTo(typeof(IInterface).GetMethod("Method1"))); Assert.That(definitions[0].ImplementingMethod, Is.SameAs(m1b)); Assert.That(definitions[1].DeclaringRequirement, Is.SameAs(requirement)); Assert.That(definitions[1].InterfaceMethod, Is.EqualTo(typeof(IInterface).GetMethod("Method2"))); Assert.That(definitions[1].ImplementingMethod, Is.SameAs(m2b)); }
public void GetAllMethods_FindsMethods() { var methodDefinition1 = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo1); var methodDefinition2 = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo2); Assert.That(_classDefinition1.GetAllMethods().ToArray(), Is.EquivalentTo(new[] { methodDefinition1, methodDefinition2 })); }
public void GetAllOverrides() { var definition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(BaseType1), typeof(BT1Mixin1)).Mixins[0]; var methodOverride = DefinitionObjectMother.CreateMethodDefinition(definition, definition.Type.GetMethod("ToString")); var overriddenMethod = DefinitionObjectMother.CreateMethodDefinition(definition.TargetClass, definition.Type.GetMethod("ToString")); DefinitionObjectMother.DeclareOverride(methodOverride, overriddenMethod); var propertyOverride = DefinitionObjectMother.CreatePropertyDefinition(definition, typeof(DateTime).GetProperty("Now")); var overriddenProperty = DefinitionObjectMother.CreatePropertyDefinition(definition.TargetClass, typeof(DateTime).GetProperty("Now")); DefinitionObjectMother.DeclareOverride(propertyOverride, overriddenProperty); var eventOverride = DefinitionObjectMother.CreateEventDefinition(definition, typeof(AppDomain).GetEvent("ProcessExit")); var overriddenEvent = DefinitionObjectMother.CreateEventDefinition(definition.TargetClass, typeof(AppDomain).GetEvent("ProcessExit")); DefinitionObjectMother.DeclareOverride(eventOverride, overriddenEvent); var nonOverride = DefinitionObjectMother.CreateMethodDefinition(definition, definition.Type.GetMethod("GetHashCode")); var overrides = definition.GetAllOverrides().ToArray(); Assert.That(overrides, Is.EquivalentTo(new MemberDefinitionBase[] { methodOverride, propertyOverride, eventOverride })); Assert.That(overrides, Has.No.Member(nonOverride)); }
public void GetProtectedOverriders_False() { var overrider = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo1); var overridden = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo2); DefinitionObjectMother.DeclareOverride(overrider, overridden); Assert.That(_classDefinition1.GetProtectedOverriders().ToArray(), Is.Empty); }
public void GetProtectedOverriders_True_ProtectedInternal() { var overrider = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfoProtectedInternal); var overridden = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo2); DefinitionObjectMother.DeclareOverride(overrider, overridden); Assert.That(_classDefinition1.GetProtectedOverriders().ToArray(), Is.EqualTo(new[] { overrider })); }
public void HasProtectedOverriders_True_ProtectedInternal() { var overrider = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfoProtectedInternal); var overridden = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo2); DefinitionObjectMother.DeclareOverride(overrider, overridden); Assert.That(_classDefinition1.HasProtectedOverriders(), Is.True); }
public void HasOverriddenMembers_True() { var overriddenMember = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo1); var overriderMember = DefinitionObjectMother.CreateMethodDefinition(_classDefinition2, _methodInfo2); DefinitionObjectMother.DeclareOverride(overriderMember, overriddenMember); Assert.That(_classDefinition1.HasOverriddenMembers(), Is.True); }
public void GetAllMembers() { var methodDefinition1 = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo1); var propertyDefinition1 = DefinitionObjectMother.CreatePropertyDefinition(_classDefinition1, _propertyInfoWithGetAndSet); var eventDefinition1 = DefinitionObjectMother.CreateEventDefinition(_classDefinition1, _eventInfo1); Assert.That(_classDefinition1.GetAllMembers().ToArray(), Is.EquivalentTo(new MemberDefinitionBase[] { methodDefinition1, propertyDefinition1, eventDefinition1 })); }
public void GetProtectedOverriders_True() { var overrider1 = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfoProtected); var overrider2 = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo1); var overridden1 = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo2); var overridden2 = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo3); DefinitionObjectMother.DeclareOverride(overrider1, overridden1); DefinitionObjectMother.DeclareOverride(overrider2, overridden2); Assert.That(_classDefinition1.GetProtectedOverriders().ToArray(), Is.EqualTo(new[] { overrider1 })); }
private void AddOverride(TargetClassDefinition targetClassDefinition, Type mixinType, string methodName) { var baseMember = targetClassDefinition.GetAllMethods().SingleOrDefault(m => m.Name == methodName); if (baseMember == null) { baseMember = DefinitionObjectMother.CreateMethodDefinition(targetClassDefinition, targetClassDefinition.Type.GetMethod(methodName)); } var mixinDefinition = targetClassDefinition.Mixins.Single(m => m.Type == mixinType); var overridingMember = DefinitionObjectMother.CreateMethodDefinition(mixinDefinition, mixinType.GetMethod(methodName)); DefinitionObjectMother.DeclareOverride(overridingMember, baseMember); }
public void CreateRequiredMethodDefinitions_WithOverloads() { var targetClassDefinition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(ClassImplementingInterfaceWithDuckTypingWithOverloads)); DefinitionObjectMother.CreateMethodDefinition( targetClassDefinition, typeof(ClassImplementingInterfaceWithDuckTypingWithOverloads).GetMethod("Method1", new[] { typeof(string) })); var m1b = DefinitionObjectMother.CreateMethodDefinition( targetClassDefinition, typeof(ClassImplementingInterfaceWithDuckTypingWithOverloads).GetMethod("Method1", Type.EmptyTypes)); DefinitionObjectMother.CreateMethodDefinition( targetClassDefinition, typeof(ClassImplementingInterfaceWithDuckTypingWithOverloads).GetMethod("Method2")); var requirement = DefinitionObjectMother.CreateRequiredTargetCallTypeDefinition(targetClassDefinition, typeof(IInterface)); var builder = new DuckTypingRequiredMethodDefinitionCollector(targetClassDefinition); var definitions = builder.CreateRequiredMethodDefinitions(requirement).OrderBy(def => def.FullName).ToArray(); Assert.That(definitions[0].DeclaringRequirement, Is.SameAs(requirement)); Assert.That(definitions[0].InterfaceMethod, Is.EqualTo(typeof(IInterface).GetMethod("Method1"))); Assert.That(definitions[0].ImplementingMethod, Is.SameAs(m1b)); }
public void Accept() { var methodDefinition = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo1); var propertyDefinition = DefinitionObjectMother.CreatePropertyDefinition(_classDefinition1, _propertyInfoWithGetAndSet); var eventDefinition = DefinitionObjectMother.CreateEventDefinition(_classDefinition1, _eventInfo1); var attributeDefinition = DefinitionObjectMother.CreateAttributeDefinition(_classDefinition1); var visitorMock = MockRepository.GenerateMock <IDefinitionVisitor> (); using (visitorMock.GetMockRepository().Ordered()) { visitorMock.Expect(mock => mock.Visit(methodDefinition)); visitorMock.Expect(mock => mock.Visit(propertyDefinition)); visitorMock.Expect(mock => mock.Visit(eventDefinition)); visitorMock.Expect(mock => mock.Visit(attributeDefinition)); } visitorMock.Replay(); _classDefinition1.Accept(visitorMock); Assert.That(_classDefinition1.ChildSpecificAcceptCalled, Is.True); visitorMock.VerifyAllExpectations(); }
public void SetUp() { _parentDefinition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(object)); _nestedDefinition = DefinitionObjectMother.CreateMixinDefinition(_parentDefinition, typeof(string)); _nestedNestedDefinition = DefinitionObjectMother.CreateMethodDefinition(_nestedDefinition, ReflectionObjectMother.GetSomeMethod()); }
public void HasOverriddenMembers_False_NoOverrides() { DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo1); Assert.That(_classDefinition1.HasOverriddenMembers(), Is.False); }