Ejemplo n.º 1
0
        public void Dequeue_AfterDequeueAllAndEnqueue()
        {
            var assemblyContexts = new[] { CreateAssemblyContext(), CreateAssemblyContext() };

            _assemblyContextPoolMock.Expect(mock => mock.DequeueAll()).Return(assemblyContexts);
            _assemblyContextPoolMock.Expect(mock => mock.Enqueue(assemblyContexts[0]));
            _assemblyContextPoolMock.Expect(mock => mock.Enqueue(assemblyContexts[1]));
            _assemblyContextPoolMock.Expect(mock => mock.Dequeue()).Return(assemblyContexts[0]);

            _decorator.DequeueAll();

            _decorator.Enqueue(assemblyContexts[0]);
            _decorator.Enqueue(assemblyContexts[1]);

            var assemblyContext = _decorator.Dequeue();

            Assert.That(assemblyContext, Is.SameAs(assemblyContexts[0]));

            _assemblyContextPoolMock.VerifyAllExpectations();
        }
        public void CacheHit()
        {
            var additionalTypeID = new object();
            var additionalType   = ReflectionObjectMother.GetSomeType();

            _additionalTypes.Add(additionalTypeID, new Lazy <Type> (() => additionalType, LazyThreadSafetyMode.None));

            var result = _cache.GetOrCreateAdditionalType(additionalTypeID);

            _typeAssemblerMock.VerifyAllExpectations();
            _assemblyContextPoolMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(additionalType));
        }
Ejemplo n.º 3
0
        public void FlushCodeToDisk_FlushesMultipleAssemblies_ReturnsNonNullResultPaths()
        {
            var assemblyAttribute = CustomAttributeDeclarationObjectMother.Create();

            var generatedCodeFlusherMock1 = MockRepository.GenerateStrictMock <IGeneratedCodeFlusher>();
            var assemblyContext1          = new AssemblyContext(MockRepository.GenerateStrictMock <IMutableTypeBatchCodeGenerator>(), generatedCodeFlusherMock1);
            var participantState1         = assemblyContext1.ParticipantState;

            var generatedCodeFlusherMock2 = MockRepository.GenerateStrictMock <IGeneratedCodeFlusher>();
            var assemblyContext2          = new AssemblyContext(MockRepository.GenerateStrictMock <IMutableTypeBatchCodeGenerator>(), generatedCodeFlusherMock2);
            var participantState2         = assemblyContext2.ParticipantState;

            var generatedCodeFlusherMock3 = MockRepository.GenerateStrictMock <IGeneratedCodeFlusher>();
            var assemblyContext3          = new AssemblyContext(MockRepository.GenerateStrictMock <IMutableTypeBatchCodeGenerator>(), generatedCodeFlusherMock3);
            var participantState3         = assemblyContext3.ParticipantState;

            bool isDequeued = false;

            _assemblyContextPool
            .Expect(mock => mock.DequeueAll())
            .Return(new[] { assemblyContext1, assemblyContext2, assemblyContext3 })
            .WhenCalled(mi => { isDequeued = true; });

            bool isFlushed1 = false;

            generatedCodeFlusherMock1
            .Expect(mock => mock.FlushCodeToDisk(Arg <IEnumerable <CustomAttributeDeclaration> > .Is.Anything))
            .Return("path1")
            .WhenCalled(
                mi =>
            {
                Assert.That(isDequeued, Is.True);
                isFlushed1 = true;
            });

            bool isFlushed2 = false;

            generatedCodeFlusherMock2
            .Expect(mock => mock.FlushCodeToDisk(Arg <IEnumerable <CustomAttributeDeclaration> > .Is.Anything))
            .Return(null)
            .WhenCalled(
                mi =>
            {
                Assert.That(isDequeued, Is.True);
                isFlushed2 = true;
            });

            bool isFlushed3 = false;

            generatedCodeFlusherMock3
            .Expect(mock => mock.FlushCodeToDisk(Arg <IEnumerable <CustomAttributeDeclaration> > .Is.Anything))
            .Return("path3")
            .WhenCalled(
                mi =>
            {
                Assert.That(isDequeued, Is.True);
                isFlushed3 = true;
            });

            _assemblyContextPool
            .Expect(mock => mock.Enqueue(assemblyContext1))
            .WhenCalled(
                mi =>
            {
                Assert.That(isFlushed1, Is.True);
                Assert.That(assemblyContext1.ParticipantState, Is.Not.SameAs(participantState1));
            });

            _assemblyContextPool
            .Expect(mock => mock.Enqueue(assemblyContext2))
            .WhenCalled(
                mi =>
            {
                Assert.That(isFlushed2, Is.True);
                Assert.That(assemblyContext2.ParticipantState, Is.Not.SameAs(participantState2));
            });

            _assemblyContextPool
            .Expect(mock => mock.Enqueue(assemblyContext3))
            .WhenCalled(
                mi =>
            {
                Assert.That(isFlushed3, Is.True);
                Assert.That(assemblyContext3.ParticipantState, Is.Not.SameAs(participantState3));
            });

            var result = _manager.FlushCodeToDisk(new[] { assemblyAttribute });

            _assemblyContextPool.VerifyAllExpectations();
            generatedCodeFlusherMock1.VerifyAllExpectations();
            generatedCodeFlusherMock2.VerifyAllExpectations();
            generatedCodeFlusherMock3.VerifyAllExpectations();

            Assert.That(result, Is.EquivalentTo(new[] { "path1", "path3" }));
        }