Exemplo n.º 1
0
        public void Execute_FindsClassContexts()
        {
            var mixedTypeFinderMock = new MockRepository().StrictMock <IMixedTypeFinder> ();

            mixedTypeFinderMock.Expect(mock => mock.FindMixedTypes(_configuration)).Return(new Type[0]);
            mixedTypeFinderMock.Replay();
            _codeManagerDynamicMock.Stub(stub => stub.FlushCodeToDisk()).Return(new string[0]);

            var mixer = new Mixer(mixedTypeFinderMock, _mixerPipelineFactoryStub, _assemblyOutputDirectoy);

            mixer.Execute(_configuration);

            mixedTypeFinderMock.VerifyAllExpectations();
        }
        public void SavesMixedTypes()
        {
            AppDomainRunner.Run(
                delegate
            {
                using (MixinConfiguration.BuildNew()
                       .ForClass <BaseType1>().AddMixins(typeof(BT1Mixin1))
                       .ForClass <Page> ().AddMixin(typeof(NullMixin))
                       .EnterScope())
                {
                    Mixer mixer = Mixer.Create("Assembly", _assemblyOutputDirectory, 1);
                    mixer.PrepareOutputDirectory();
                    mixer.Execute(MixinConfiguration.ActiveConfiguration);

                    Assembly theAssembly = Assembly.LoadFile(mixer.MixerPipelineFactory.GetModulePaths(_assemblyOutputDirectory).Single());
                    var types            = theAssembly.GetTypes();

                    var concreteType = types.SingleOrDefault(t => t.BaseType == typeof(BaseType1));
                    Assert.NotNull(concreteType);
                    Assert.That(
                        MixinTypeUtility.GetClassContextForConcreteType(concreteType),
                        Is.EqualTo(MixinConfiguration.ActiveConfiguration.GetContext(typeof(BaseType1))));

                    object instance = Activator.CreateInstance(concreteType);
                    Assert.That(Mixin.Get <BT1Mixin1> (instance), Is.Not.Null);

                    var concreteTypeFromSystemAssembly = types.SingleOrDefault(t => t.BaseType == typeof(Page));
                    Assert.That(concreteTypeFromSystemAssembly, Is.Not.Null);

                    SafeServiceLocator.Current.GetInstance <IPipelineRegistry>().DefaultPipeline.CodeManager.LoadFlushedCode(theAssembly);

                    Type concreteTypeFromFactory = TypeFactory.GetConcreteType(typeof(BaseType1));
                    Assert.That(concreteTypeFromFactory, Is.SameAs(concreteType));

                    Assert.That(theAssembly.IsDefined(typeof(NonApplicationAssemblyAttribute), false), Is.True);
                }
            });
        }