예제 #1
0
 private void SetupExpectationsForAccessors(IMemberEmitter memberEmitterMock, IEnumerable <MutableMethodInfo> methods)
 {
     foreach (var method in methods)
     {
         var m = method;
         memberEmitterMock.Expect(mock => mock.AddMethod(Arg <CodeGenerationContext> .Is.Anything, Arg.Is(m)));
     }
 }
예제 #2
0
        public void DefineTypeFacets()
        {
            var typeInitializer = _mutableType.AddTypeInitializer(ctx => Expression.Empty());

            var instanceInitialization = ExpressionTreeObjectMother.GetSomeExpression();

            _mutableType.AddInitialization(ctx => instanceInitialization);

            var customAttribute = CustomAttributeDeclarationObjectMother.Create();

            _mutableType.AddCustomAttribute(customAttribute);

            var @interface = typeof(IDisposable);

            _mutableType.AddInterface(@interface);

            var field       = _mutableType.AddField();
            var constructor = _mutableType.AddConstructor();
            var method      = _mutableType.AddMethod();
            var property    = _mutableType.AddProperty();
            var event_      = _mutableType.AddEvent();

            using (_mockRepository.Ordered())
            {
                var context = PopulateContext(_generator, 2);

                _typeBuilderMock.Expect(mock => mock.SetParent(_mutableType.BaseType));

                _memberEmitterMock.Expect(mock => mock.AddConstructor(context, typeInitializer));

                _initializationBuilderMock.Expect(mock => mock.CreateInitializationMembers(_mutableType)).Return(_fakeInitializationMembers);
                _proxySerializationEnablerMock.Expect(mock => mock.MakeSerializable(_mutableType, _fakeInitializationMethod));

                _typeBuilderMock.Expect(mock => mock.SetCustomAttribute(customAttribute));
                _typeBuilderMock.Expect(mock => mock.AddInterfaceImplementation(@interface));
                _memberEmitterMock.Expect(mock => mock.AddField(context, field));
                _initializationBuilderMock.Expect(
                    mock => mock.WireConstructorWithInitialization(constructor, _fakeInitializationMembers, _proxySerializationEnablerMock));
                _memberEmitterMock.Expect(mock => mock.AddConstructor(context, constructor));
                _memberEmitterMock.Expect(mock => mock.AddMethod(context, method));
                SetupExpectationsForAccessors(_memberEmitterMock, _mutableType.AddedMethods.Except(new[] { method }));
                _memberEmitterMock.Expect(mock => mock.AddProperty(context, property));
                _memberEmitterMock.Expect(mock => mock.AddEvent(context, event_));
            }
            _mockRepository.ReplayAll();

            _generator.DefineTypeFacets();

            _mockRepository.VerifyAll();
        }