Ejemplo n.º 1
0
        public void DequeueAll_ReturnsAssemblyContextsFromInnerPool()
        {
            AssemblyContext[] expected = { _assemblyContext };
            _assemblyContextPoolMock.Expect(mock => mock.DequeueAll()).Return(expected);

            var actual = _decorator.DequeueAll();

            Assert.That(actual, Is.SameAs(expected));
        }
        public void CacheMiss_UsesAssemblyContextFromPool()
        {
            var additionalTypeID = new object();
            var additionalType   = ReflectionObjectMother.GetSomeType();
            var assemblyContext  = CreateAssemblyContext();

            bool isDequeued = false;

            _assemblyContextPoolMock
            .Expect(mock => mock.Dequeue())
            .Return(assemblyContext)
            .WhenCalled(mi => { isDequeued = true; });

            _typeAssemblerMock
            .Expect(
                mock => mock.AssembleAdditionalType(
                    additionalTypeID,
                    assemblyContext.ParticipantState,
                    assemblyContext.MutableTypeBatchCodeGenerator))
            .Return(new TypeAssemblyResult(additionalType))
            .WhenCalled(mi => Assert.That(isDequeued, Is.True));

            _assemblyContextPoolMock
            .Expect(mock => mock.Enqueue(assemblyContext))
            .WhenCalled(
                mi =>
            {
                Assert.That(isDequeued, Is.True);
                isDequeued = false;
            });

            var result = _cache.GetOrCreateAdditionalType(additionalTypeID);

            _typeAssemblerMock.VerifyAllExpectations();
            _assemblyContextPoolMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(additionalType));

            Assert.That(_additionalTypes[additionalTypeID].IsValueCreated, Is.True);
            Assert.That(_additionalTypes[additionalTypeID].Value, 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" }));
        }