public void AddEvent_Simple_NoRaiseBodyProvider() { var handlerType = ReflectionObjectMother.GetSomeType(); Func <MethodBodyCreationContext, Expression> addBodyProvider = ctx => null; Func <MethodBodyCreationContext, Expression> removeBodyProvider = ctx => null; var addRemoveParameters = new[] { new ParameterDeclaration(typeof(Func <int, string>), "handler") }; var addMethod = MutableMethodInfoObjectMother.Create(returnType: typeof(void), parameters: addRemoveParameters); var removeMethod = MutableMethodInfoObjectMother.Create(returnType: typeof(void), parameters: addRemoveParameters); var fakeEvent = MutableEventInfoObjectMother.Create(addMethod: addMethod, removeMethod: removeMethod); Assert.That(fakeEvent.MutableRaiseMethod, Is.Null); _mutableMemberFactoryMock .Setup( stub => stub.CreateEvent( It.IsAny <MutableType>(), It.IsAny <string>(), It.IsAny <Type>(), It.IsAny <MethodAttributes>(), It.IsAny <Func <MethodBodyCreationContext, Expression> >(), It.IsAny <Func <MethodBodyCreationContext, Expression> >(), It.IsAny <Func <MethodBodyCreationContext, Expression> >())) .Returns(fakeEvent); var result = _mutableType.AddEvent("Event", handlerType, addBodyProvider: addBodyProvider, removeBodyProvider: removeBodyProvider); Assert.That(_mutableType.AddedMethods, Is.EqualTo(new[] { result.MutableAddMethod, result.MutableRemoveMethod })); }
public void AddEvent() { var name = "Event"; var attributes = (EventAttributes)7; var handlerType = typeof(Func <int, string>); var addMethod = MutableMethodInfoObjectMother.Create(parameters: new[] { ParameterDeclarationObjectMother.Create(handlerType) }); var removeMethod = MutableMethodInfoObjectMother.Create(parameters: new[] { ParameterDeclarationObjectMother.Create(handlerType) }); var raiseMethod = MutableMethodInfoObjectMother.Create( returnType: typeof(string), parameters: new[] { ParameterDeclarationObjectMother.Create(typeof(int)) }); var event_ = MutableEventInfoObjectMother.Create( name: name, attributes: attributes, addMethod: addMethod, removeMethod: removeMethod, raiseMethod: raiseMethod); var addMethodBuilder = MockRepository.GenerateStub <IMethodBuilder>(); var removeMethodBuilder = MockRepository.GenerateStub <IMethodBuilder>(); var raiseMethodBuilder = MockRepository.GenerateStub <IMethodBuilder>(); _context.MethodBuilders.Add(addMethod, addMethodBuilder); _context.MethodBuilders.Add(removeMethod, removeMethodBuilder); _context.MethodBuilders.Add(raiseMethod, raiseMethodBuilder); var eventBuilderMock = MockRepository.GenerateStrictMock <IEventBuilder>(); _typeBuilderMock.Expect(mock => mock.DefineEvent(name, attributes, handlerType)).Return(eventBuilderMock); SetupDefineCustomAttribute(eventBuilderMock, event_); eventBuilderMock.Expect(mock => mock.SetAddOnMethod(addMethodBuilder)); eventBuilderMock.Expect(mock => mock.SetRemoveOnMethod(removeMethodBuilder)); eventBuilderMock.Expect(mock => mock.SetRaiseMethod(raiseMethodBuilder)); _emitter.AddEvent(_context, event_); _typeBuilderMock.VerifyAllExpectations(); eventBuilderMock.VerifyAllExpectations(); }