public void CreateModuleBuilder() { var assemblyName = "assembly name"; var assemblyDirectoryOrNull = "directory"; var strongNamed = BooleanObjectMother.GetRandomBoolean(); var keyFilePathOrNull = "key file path"; var moduleBuilderMock = MockRepository.GenerateStrictMock <IModuleBuilder>(); var assemblyBuilderMock = MockRepository.GenerateStrictMock <IAssemblyBuilder>(); _innerFactoryMock .Expect(mock => mock.CreateModuleBuilder(assemblyName, assemblyDirectoryOrNull, strongNamed, keyFilePathOrNull)) .Return(moduleBuilderMock); moduleBuilderMock.Expect(mock => mock.AssemblyBuilder).Return(assemblyBuilderMock); assemblyBuilderMock .Expect(mock => mock.SetCustomAttribute(Arg <CustomAttributeDeclaration> .Is.Anything)) .WhenCalled( mi => { var declaration = (CustomAttributeDeclaration)mi.Arguments.Single(); Assert.That(declaration.Type, Is.SameAs(typeof(NonApplicationAssemblyAttribute))); Assert.That(declaration.ConstructorArguments, Is.Empty); }); var result = _factory.CreateModuleBuilder(assemblyName, assemblyDirectoryOrNull, strongNamed, keyFilePathOrNull); _innerFactoryMock.VerifyAllExpectations(); moduleBuilderMock.VerifyAllExpectations(); assemblyBuilderMock.VerifyAllExpectations(); Assert.That(result, Is.SameAs(moduleBuilderMock)); }
public void DefineType() { var name = "DomainType"; var attributes = (TypeAttributes)7; var forceStrongNaming = BooleanObjectMother.GetRandomBoolean(); var keyFilePath = "key file path"; _flusher.SetAssemblyNamePattern("custom assembly name pattern"); _configurationProviderMock.Expect(mock => mock.ForceStrongNaming).Return(forceStrongNaming); _configurationProviderMock.Expect(mock => mock.KeyFilePath).Return(keyFilePath); _moduleBuilderFactoryMock .Expect(mock => mock.CreateModuleBuilder("custom assembly name pattern", null, forceStrongNaming, keyFilePath)) .Return(_moduleBuilderMock); var fakeTypeBuilder1 = MockRepository.GenerateStub <ITypeBuilder>(); var fakeTypeBuilder2 = MockRepository.GenerateStub <ITypeBuilder>(); _moduleBuilderMock.Expect(mock => mock.DefineType(name, attributes)).Return(fakeTypeBuilder1); _moduleBuilderMock.Expect(mock => mock.DefineType("OtherType", 0)).Return(fakeTypeBuilder2); var result1 = _flusher.DefineType(name, attributes, _emittableOperandProviderMock); var result2 = _flusher.DefineType("OtherType", 0, _emittableOperandProviderMock); _moduleBuilderFactoryMock.VerifyAllExpectations(); _moduleBuilderMock.VerifyAllExpectations(); _configurationProviderMock.VerifyAllExpectations(); Assert.That(result1.As <TypeBuilderDecorator>().DecoratedTypeBuilder, Is.SameAs(fakeTypeBuilder1)); Assert.That(result2.As <TypeBuilderDecorator>().DecoratedTypeBuilder, Is.SameAs(fakeTypeBuilder2)); Assert.That(PrivateInvoke.GetNonPublicField(result1, "EmittableOperandProvider"), Is.SameAs(_emittableOperandProviderMock)); Assert.That(PrivateInvoke.GetNonPublicField(result2, "EmittableOperandProvider"), Is.SameAs(_emittableOperandProviderMock)); }