Esempio n. 1
0
        public Type GetOrCreateAdditionalType(object additionalTypeID, IAdditionalTypeAssemblyContext additionalTypeAssemblyContext)
        {
            ArgumentUtility.CheckNotNull("additionalTypeID", additionalTypeID);
            ArgumentUtility.CheckNotNull("additionalTypeAssemblyContext", additionalTypeAssemblyContext);

            var concreteMixinTypeIdentifier = additionalTypeID as ConcreteMixinTypeIdentifier;

            if (concreteMixinTypeIdentifier == null)
            {
                return(null);
            }

            return(_mixinTypeProvider.GetOrGenerateConcreteMixinType(additionalTypeAssemblyContext, concreteMixinTypeIdentifier).GeneratedType);
        }
Esempio n. 2
0
        public void AssembleAdditionalType_ParticipantReturnsMutableType()
        {
            var participantMock1       = new Mock <IParticipant> (MockBehavior.Strict);
            var participantMock2       = new Mock <IParticipant> (MockBehavior.Strict);
            var participantMock3       = new Mock <IParticipant> (MockBehavior.Strict);
            var mutableTypeFactoryMock = new Mock <IMutableTypeFactory> (MockBehavior.Strict);
            var codeGeneratorMock      = new Mock <IMutableTypeBatchCodeGenerator> (MockBehavior.Strict);

            participantMock1.SetupGet(_ => _.PartialTypeIdentifierProvider).Returns(new Mock <ITypeIdentifierProvider>().Object);
            participantMock2.SetupGet(_ => _.PartialTypeIdentifierProvider).Returns(new Mock <ITypeIdentifierProvider>().Object);
            participantMock3.SetupGet(_ => _.PartialTypeIdentifierProvider).Returns(new Mock <ITypeIdentifierProvider>().Object);

            var participantConfigurationID     = "participant configuration ID";
            var additionalTypeID               = new object();
            var generationCompletedEventRaised = false;
            var fakeAdditionalType             = ReflectionObjectMother.GetSomeType();
            var otherAdditionalTypeID          = new object();
            var otherFakeAdditionalType        = ReflectionObjectMother.GetSomeType();

            IAdditionalTypeAssemblyContext additionalTypeAssemblyContextPassedToParticipant1 = null;
            var additionalMutableType = MutableTypeObjectMother.Create();
            var otherAdditionalType   = MutableTypeObjectMother.Create();
            var sequence = new MockSequence();

            participantMock1
            .InSequence(sequence)
            .Setup(mock => mock.GetOrCreateAdditionalType(additionalTypeID, It.IsAny <IAdditionalTypeAssemblyContext>()))
            .Returns((Type)null)
            .Callback(
                (object _, IAdditionalTypeAssemblyContext additionalTypeAssemblyContext) =>
            {
                additionalTypeAssemblyContextPassedToParticipant1 = additionalTypeAssemblyContext;
                Assert.That(additionalTypeAssemblyContext.ParticipantConfigurationID, Is.EqualTo(participantConfigurationID));
                Assert.That(additionalTypeAssemblyContext.ParticipantState, Is.SameAs(_participantStateMock.Object));

                additionalTypeAssemblyContext.CreateAdditionalType(additionalTypeID, "AdditionalType", null, 0, typeof(int));
                additionalTypeAssemblyContext.CreateAdditionalType(otherAdditionalTypeID, "OtherAdditionalType", null, 0, typeof(int));

                additionalTypeAssemblyContext.GenerationCompleted += ctx =>
                {
                    Assert.That(ctx.GetGeneratedType(additionalMutableType), Is.SameAs(fakeAdditionalType));
                    Assert.That(ctx.GetGeneratedType(otherAdditionalType), Is.SameAs(otherFakeAdditionalType));
                    generationCompletedEventRaised = true;
                };
            });
            mutableTypeFactoryMock
            .InSequence(sequence)
            .Setup(mock => mock.CreateType("AdditionalType", null, 0, typeof(int), null)).Returns(additionalMutableType);
            mutableTypeFactoryMock
            .InSequence(sequence)
            .Setup(mock => mock.CreateType("OtherAdditionalType", null, 0, typeof(int), null)).Returns(otherAdditionalType);

            participantMock2
            .InSequence(sequence)
            .Setup(mock => mock.GetOrCreateAdditionalType(additionalTypeID, It.IsAny <IAdditionalTypeAssemblyContext>()))
            .Returns(additionalMutableType)
            .Callback(
                (object _, IAdditionalTypeAssemblyContext additionalTypeAssemblyContextArg) =>
            {
                Assert.That(additionalTypeAssemblyContextArg, Is.SameAs(additionalTypeAssemblyContextPassedToParticipant1));
            });
            // Participant 3 is not invoked.

            codeGeneratorMock
            .InSequence(sequence)
            .Setup(mock => mock.GenerateTypes(new[] { additionalMutableType, otherAdditionalType }))
            .Returns(
                new[]
            {
                new KeyValuePair <MutableType, Type> (additionalMutableType, fakeAdditionalType),
                new KeyValuePair <MutableType, Type> (otherAdditionalType, otherFakeAdditionalType)
            })
            .Callback((IEnumerable <MutableType> mutableTypes) => Assert.That(generationCompletedEventRaised, Is.False));
            var typeAssembler = CreateTypeAssembler(
                mutableTypeFactoryMock.Object,
                configurationId: participantConfigurationID,
                participants: new[] { participantMock1.Object, participantMock2.Object, participantMock3.Object });

            var result = typeAssembler.AssembleAdditionalType(additionalTypeID, _participantStateMock.Object, codeGeneratorMock.Object);

            participantMock1.Verify();
            participantMock2.Verify();
            participantMock3.Verify();
            mutableTypeFactoryMock.Verify();
            codeGeneratorMock.Verify();
            Assert.That(generationCompletedEventRaised, Is.True);
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Type, Is.SameAs(fakeAdditionalType));
            Assert.That(result.AdditionalTypes.Count, Is.EqualTo(2));
            Assert.That(result.AdditionalTypes[additionalTypeID], Is.SameAs(fakeAdditionalType));
            Assert.That(result.AdditionalTypes[otherAdditionalTypeID], Is.SameAs(otherFakeAdditionalType));
        }
Esempio n. 3
0
 public Type GetOrCreateAdditionalType(object additionalTypeID, IAdditionalTypeAssemblyContext additionalTypeAssemblyContext)
 {
     return(null); // Does nothing.
 }
Esempio n. 4
0
        public void AssembleAdditionalType_ParticipantReturnsMutableType()
        {
            var mockRepository         = new MockRepository();
            var participantMock1       = mockRepository.StrictMock <IParticipant>();
            var participantMock2       = mockRepository.StrictMock <IParticipant>();
            var participantMock3       = mockRepository.StrictMock <IParticipant>();
            var mutableTypeFactoryMock = mockRepository.StrictMock <IMutableTypeFactory>();
            var codeGeneratorMock      = mockRepository.StrictMock <IMutableTypeBatchCodeGenerator>();

            participantMock1.Stub(_ => _.PartialTypeIdentifierProvider);
            participantMock2.Stub(_ => _.PartialTypeIdentifierProvider);
            participantMock3.Stub(_ => _.PartialTypeIdentifierProvider);

            var  participantConfigurationID     = "participant configuration ID";
            var  additionalTypeID               = new object();
            bool generationCompletedEventRaised = false;
            var  fakeAdditionalType             = ReflectionObjectMother.GetSomeType();
            var  otherAdditionalTypeID          = new object();
            var  otherFakeAdditionalType        = ReflectionObjectMother.GetSomeType();

            using (mockRepository.Ordered())
            {
                IAdditionalTypeAssemblyContext additionalTypeAssemblyContext = null;
                var additionalMutableType = MutableTypeObjectMother.Create();
                var otherAdditionalType   = MutableTypeObjectMother.Create();
                participantMock1
                .Expect(mock => mock.GetOrCreateAdditionalType(Arg.Is(additionalTypeID), Arg <IAdditionalTypeAssemblyContext> .Is.Anything))
                .Return(null)
                .WhenCalled(
                    mi =>
                {
                    additionalTypeAssemblyContext = (IAdditionalTypeAssemblyContext)mi.Arguments[1];
                    Assert.That(additionalTypeAssemblyContext.ParticipantConfigurationID, Is.EqualTo(participantConfigurationID));
                    Assert.That(additionalTypeAssemblyContext.ParticipantState, Is.SameAs(_participantStateMock));

                    additionalTypeAssemblyContext.CreateAdditionalType(additionalTypeID, "AdditionalType", null, 0, typeof(int));
                    additionalTypeAssemblyContext.CreateAdditionalType(otherAdditionalTypeID, "OtherAdditionalType", null, 0, typeof(int));

                    additionalTypeAssemblyContext.GenerationCompleted += ctx =>
                    {
                        Assert.That(ctx.GetGeneratedType(additionalMutableType), Is.SameAs(fakeAdditionalType));
                        Assert.That(ctx.GetGeneratedType(otherAdditionalType), Is.SameAs(otherFakeAdditionalType));
                        generationCompletedEventRaised = true;
                    };
                });
                mutableTypeFactoryMock.Expect(mock => mock.CreateType("AdditionalType", null, 0, typeof(int), null)).Return(additionalMutableType);
                mutableTypeFactoryMock.Expect(mock => mock.CreateType("OtherAdditionalType", null, 0, typeof(int), null)).Return(otherAdditionalType);

                participantMock2
                .Expect(
                    mock => mock.GetOrCreateAdditionalType(
                        Arg.Is(additionalTypeID), Arg <IAdditionalTypeAssemblyContext> .Matches(ctx => ctx == additionalTypeAssemblyContext)))
                .Return(additionalMutableType);
                // Participant 3 is not invoked.

                codeGeneratorMock
                .Expect(mock => mock.GenerateTypes(new[] { additionalMutableType, otherAdditionalType }))
                .Return(
                    new[]
                {
                    new KeyValuePair <MutableType, Type> (additionalMutableType, fakeAdditionalType),
                    new KeyValuePair <MutableType, Type> (otherAdditionalType, otherFakeAdditionalType)
                })
                .WhenCalled(mi => Assert.That(generationCompletedEventRaised, Is.False));
            }
            mockRepository.ReplayAll();
            var typeAssembler = CreateTypeAssembler(
                mutableTypeFactoryMock,
                configurationId: participantConfigurationID,
                participants: new[] { participantMock1, participantMock2, participantMock3 });

            var result = typeAssembler.AssembleAdditionalType(additionalTypeID, _participantStateMock, codeGeneratorMock);

            mockRepository.VerifyAll();
            Assert.That(generationCompletedEventRaised, Is.True);
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Type, Is.SameAs(fakeAdditionalType));
            Assert.That(result.AdditionalTypes.Count, Is.EqualTo(2));
            Assert.That(result.AdditionalTypes[additionalTypeID], Is.SameAs(fakeAdditionalType));
            Assert.That(result.AdditionalTypes[otherAdditionalTypeID], Is.SameAs(otherFakeAdditionalType));
        }
Esempio n. 5
0
 public Type GetOrCreateAdditionalType(object additionalTypeID, IAdditionalTypeAssemblyContext additionalTypeAssemblyContext)
 {
     return(_getOrCreateAdditionalTypeFunc(additionalTypeID, additionalTypeAssemblyContext));
 }