Esempio n. 1
0
        public void AddMixinToClass_WithoutOrigin()
        {
            var mockRepository = new MockRepository();
            var builder        = mockRepository.StrictMock <MixinConfigurationBuilder> ((MixinConfiguration)null);

            var targetType           = typeof(object);
            var mixinType            = typeof(string);
            var explicitDependencies = new[] { typeof(int) };
            var suppressedMixins     = new[] { typeof(double) };

            var expectedOrigin = MixinContextOrigin.CreateForMethod(MethodBase.GetCurrentMethod());

            builder
            .Expect(
                mock => mock.AddMixinToClass(
                    MixinKind.Extending, targetType, mixinType, MemberVisibility.Private, explicitDependencies, suppressedMixins, expectedOrigin))
            .Return(builder);

            mockRepository.ReplayAll();

            var returnedBuilder = builder.AddMixinToClass(
                MixinKind.Extending, targetType, mixinType, MemberVisibility.Private, explicitDependencies, suppressedMixins);

            mockRepository.VerifyAll();
            Assert.That(returnedBuilder, Is.SameAs(builder));
        }
Esempio n. 2
0
        public void CreateForMethod()
        {
            var origin = MixinContextOrigin.CreateForMethod(MethodBase.GetCurrentMethod());

            Assert.That(origin.Kind, Is.EqualTo("Method"));
            Assert.That(origin.Assembly, Is.EqualTo(GetType().Assembly));
            Assert.That(origin.Location, Is.EqualTo("Void CreateForMethod(), declaring type: Remotion.Mixins.UnitTests.Core.Context.MixinContextOriginTest"));
        }
        public void EnsureMixins_Generic3_WithoutOrigin()
        {
            var expectedOrigin = MixinContextOrigin.CreateForMethod(MethodBase.GetCurrentMethod());

            _classBuilderMock.Expect(mock => mock.EnsureMixins <BT2Mixin1, BT3Mixin1, BT3Mixin2> (expectedOrigin)).Return(_classBuilderMock);

            _mockRepository.Replay(_classBuilderMock);
            Assert.That(_classBuilderMock.EnsureMixins <BT2Mixin1, BT3Mixin1, BT3Mixin2> (), Is.SameAs(_classBuilderMock));
            _mockRepository.Verify(_classBuilderMock);
        }
        public void AddMixin_NonGeneric_WithoutOrigin()
        {
            var expectedOrigin = MixinContextOrigin.CreateForMethod(MethodBase.GetCurrentMethod());

            _classBuilderMock.Expect(mock => mock.AddMixin(typeof(BT2Mixin1), expectedOrigin)).Return(_mixinBuilderMock);

            _mockRepository.Replay(_classBuilderMock);
            Assert.That(_classBuilderMock.AddMixin(typeof(BT2Mixin1)), Is.SameAs(_mixinBuilderMock));
            _mockRepository.Verify(_classBuilderMock);
        }
        public void AddOrderedMixins_Generic2_WithoutOrigin()
        {
            var expectedOrigin = MixinContextOrigin.CreateForMethod(MethodBase.GetCurrentMethod());

            _classBuilderMock.Expect(mock => mock.AddOrderedMixins <BT2Mixin1, BT3Mixin1> (expectedOrigin)).Return(_classBuilderMock);

            _mockRepository.ReplayAll();

            var result = _classBuilderMock.AddOrderedMixins <BT2Mixin1, BT3Mixin1>();

            _mockRepository.VerifyAll();
            Assert.That(result, Is.SameAs(_classBuilderMock));
        }
Esempio n. 6
0
        private static ClassContext CreateClassContext(Type classType, Type[] persistentMixins)
        {
            var mixinContexts =
                persistentMixins.Select(
                    t =>
                    new MixinContext(
                        MixinKind.Extending,
                        t,
                        MemberVisibility.Private,
                        Enumerable.Empty <Type>(),
                        MixinContextOrigin.CreateForMethod(MethodBase.GetCurrentMethod())));

            return(new ClassContext(classType, mixinContexts, Enumerable.Empty <Type> ()));
        }
        public void ParentMembers()
        {
            _mockRepository.BackToRecordAll();

            var suppressionRuleStub = MockRepository.GenerateStub <IMixinSuppressionRule> ();
            var r1     = new ClassContextBuilder(new MixinConfigurationBuilder(null), typeof(object));
            var r2     = new MixinConfiguration();
            var r3     = _mockRepository.StrictMock <IDisposable> ();
            var r4     = new MixinContextBuilder(r1, typeof(BT1Mixin1), _origin);
            var r5     = ClassContextObjectMother.Create(typeof(object));
            var origin = MixinContextOriginObjectMother.Create();

            IEnumerable <ClassContext> inheritedContexts = new ClassContext[0];

            var expectedInferredOrigin = MixinContextOrigin.CreateForMethod(MethodBase.GetCurrentMethod());

            using (_mockRepository.Ordered())
            {
                _parentBuilderMock.Expect(mock => mock.Clear()).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddMixin(typeof(object), origin)).Return(r4);
                _parentBuilderMock.Expect(mock => mock.AddMixin(typeof(object), expectedInferredOrigin)).Return(r4);
                _parentBuilderMock.Expect(mock => mock.AddMixin <string> (origin)).Return(r4);
                _parentBuilderMock.Expect(mock => mock.AddMixin <string> (expectedInferredOrigin)).Return(r4);
                _parentBuilderMock.Expect(mock => mock.AddMixins(origin, typeof(BT1Mixin1), typeof(BT1Mixin2))).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddMixins(expectedInferredOrigin, typeof(BT1Mixin1), typeof(BT1Mixin2))).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddMixins <BT1Mixin1, BT1Mixin2> (origin)).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddMixins <BT1Mixin1, BT1Mixin2> (expectedInferredOrigin)).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddMixins <BT1Mixin1, BT1Mixin2, BT3Mixin1> (origin)).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddMixins <BT1Mixin1, BT1Mixin2, BT3Mixin1> (expectedInferredOrigin)).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddOrderedMixins(origin, typeof(BT1Mixin1), typeof(BT1Mixin2))).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddOrderedMixins(expectedInferredOrigin, typeof(BT1Mixin1), typeof(BT1Mixin2))).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddOrderedMixins <BT1Mixin1, BT1Mixin2> (origin)).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddOrderedMixins <BT1Mixin1, BT1Mixin2> (expectedInferredOrigin)).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddOrderedMixins <BT1Mixin1, BT1Mixin2, BT3Mixin1> (origin)).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddOrderedMixins <BT1Mixin1, BT1Mixin2, BT3Mixin1> (expectedInferredOrigin)).Return(r1);
                _parentBuilderMock.Expect(mock => mock.EnsureMixin(typeof(object), origin)).Return(r4);
                _parentBuilderMock.Expect(mock => mock.EnsureMixin(typeof(object), expectedInferredOrigin)).Return(r4);
                _parentBuilderMock.Expect(mock => mock.EnsureMixin <string> (origin)).Return(r4);
                _parentBuilderMock.Expect(mock => mock.EnsureMixin <string> (expectedInferredOrigin)).Return(r4);
                _parentBuilderMock.Expect(mock => mock.EnsureMixins(origin, typeof(BT1Mixin1), typeof(BT1Mixin2))).Return(r1);
                _parentBuilderMock.Expect(mock => mock.EnsureMixins(expectedInferredOrigin, typeof(BT1Mixin1), typeof(BT1Mixin2))).Return(r1);
                _parentBuilderMock.Expect(mock => mock.EnsureMixins <BT1Mixin1, BT1Mixin2> (origin)).Return(r1);
                _parentBuilderMock.Expect(mock => mock.EnsureMixins <BT1Mixin1, BT1Mixin2> (expectedInferredOrigin)).Return(r1);
                _parentBuilderMock.Expect(mock => mock.EnsureMixins <BT1Mixin1, BT1Mixin2, BT3Mixin1> (origin)).Return(r1);
                _parentBuilderMock.Expect(mock => mock.EnsureMixins <BT1Mixin1, BT1Mixin2, BT3Mixin1> (expectedInferredOrigin)).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddComposedInterface(typeof(IBT6Mixin1))).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddComposedInterface <IBT6Mixin1>()).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddComposedInterfaces(typeof(IBT6Mixin1), typeof(IBT6Mixin2))).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddComposedInterfaces <IBT6Mixin1, IBT6Mixin2> ()).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddComposedInterfaces <IBT6Mixin1, IBT6Mixin2, IBT6Mixin3> ()).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddComposedInterfaces <IBT6Mixin1, IBT6Mixin2, IBT6Mixin3> ()).Return(r1);
                _parentBuilderMock.Expect(mock => mock.SuppressMixin(suppressionRuleStub)).Return(r1);
                _parentBuilderMock.Expect(mock => mock.SuppressMixin(typeof(object))).Return(r1);
                _parentBuilderMock.Expect(mock => mock.SuppressMixin <string> ()).Return(r1);
                _parentBuilderMock.Expect(mock => mock.SuppressMixins(typeof(BT1Mixin1), typeof(BT1Mixin2))).Return(r1);
                _parentBuilderMock.Expect(mock => mock.SuppressMixins <BT1Mixin1, BT1Mixin2> ()).Return(r1);
                _parentBuilderMock.Expect(mock => mock.SuppressMixins <BT1Mixin1, BT1Mixin2, BT3Mixin1> ()).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddMixinDependency(typeof(BT1Mixin1), typeof(BT1Mixin2))).Return(r1);
                _parentBuilderMock.Expect(mock => mock.AddMixinDependency <BT1Mixin1, BT1Mixin2> ()).Return(r1);
                _parentBuilderMock.Expect(mock => mock.BuildClassContext(inheritedContexts)).Return(r5);
                _parentBuilderMock.Expect(mock => mock.BuildClassContext()).Return(r5);

                _parentBuilderMock.Expect(mock => mock.ForClass <object> ()).Return(r1);
                _parentBuilderMock.Expect(mock => mock.ForClass <string> ()).Return(r1);
                _parentBuilderMock.Expect(mock => mock.BuildConfiguration()).Return(r2);
                _parentBuilderMock.Expect(mock => mock.EnterScope()).Return(r3);
            }

            _mockRepository.ReplayAll();

            Assert.That(_mixinBuilder.Clear(), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddMixin(typeof(object), origin), Is.SameAs(r4));
            Assert.That(_mixinBuilder.AddMixin(typeof(object)), Is.SameAs(r4));
            Assert.That(_mixinBuilder.AddMixin <string> (origin), Is.SameAs(r4));
            Assert.That(_mixinBuilder.AddMixin <string> (), Is.SameAs(r4));
            Assert.That(_mixinBuilder.AddMixins(origin, typeof(BT1Mixin1), typeof(BT1Mixin2)), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddMixins(typeof(BT1Mixin1), typeof(BT1Mixin2)), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddMixins <BT1Mixin1, BT1Mixin2> (origin), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddMixins <BT1Mixin1, BT1Mixin2> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddMixins <BT1Mixin1, BT1Mixin2, BT3Mixin1> (origin), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddMixins <BT1Mixin1, BT1Mixin2, BT3Mixin1> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddOrderedMixins(origin, typeof(BT1Mixin1), typeof(BT1Mixin2)), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddOrderedMixins(typeof(BT1Mixin1), typeof(BT1Mixin2)), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddOrderedMixins <BT1Mixin1, BT1Mixin2> (origin), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddOrderedMixins <BT1Mixin1, BT1Mixin2> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddOrderedMixins <BT1Mixin1, BT1Mixin2, BT3Mixin1> (origin), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddOrderedMixins <BT1Mixin1, BT1Mixin2, BT3Mixin1> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.EnsureMixin(typeof(object), origin), Is.SameAs(r4));
            Assert.That(_mixinBuilder.EnsureMixin(typeof(object)), Is.SameAs(r4));
            Assert.That(_mixinBuilder.EnsureMixin <string> (origin), Is.SameAs(r4));
            Assert.That(_mixinBuilder.EnsureMixin <string> (), Is.SameAs(r4));
            Assert.That(_mixinBuilder.EnsureMixins(origin, typeof(BT1Mixin1), typeof(BT1Mixin2)), Is.SameAs(r1));
            Assert.That(_mixinBuilder.EnsureMixins(typeof(BT1Mixin1), typeof(BT1Mixin2)), Is.SameAs(r1));
            Assert.That(_mixinBuilder.EnsureMixins <BT1Mixin1, BT1Mixin2> (origin), Is.SameAs(r1));
            Assert.That(_mixinBuilder.EnsureMixins <BT1Mixin1, BT1Mixin2> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.EnsureMixins <BT1Mixin1, BT1Mixin2, BT3Mixin1> (origin), Is.SameAs(r1));
            Assert.That(_mixinBuilder.EnsureMixins <BT1Mixin1, BT1Mixin2, BT3Mixin1> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddComposedInterface(typeof(IBT6Mixin1)), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddComposedInterface <IBT6Mixin1> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddComposedInterfaces(typeof(IBT6Mixin1), typeof(IBT6Mixin2)), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddComposedInterfaces <IBT6Mixin1, IBT6Mixin2> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddComposedInterfaces <IBT6Mixin1, IBT6Mixin2, IBT6Mixin3> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddComposedInterfaces <IBT6Mixin1, IBT6Mixin2, IBT6Mixin3> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.SuppressMixin(suppressionRuleStub), Is.SameAs(r1));
            Assert.That(_mixinBuilder.SuppressMixin(typeof(object)), Is.SameAs(r1));
            Assert.That(_mixinBuilder.SuppressMixin <string> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.SuppressMixins(typeof(BT1Mixin1), typeof(BT1Mixin2)), Is.SameAs(r1));
            Assert.That(_mixinBuilder.SuppressMixins <BT1Mixin1, BT1Mixin2> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.SuppressMixins <BT1Mixin1, BT1Mixin2, BT3Mixin1> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddMixinDependency(typeof(BT1Mixin1), typeof(BT1Mixin2)), Is.SameAs(r1));
            Assert.That(_mixinBuilder.AddMixinDependency <BT1Mixin1, BT1Mixin2> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.BuildClassContext(inheritedContexts), Is.SameAs(r5));
            Assert.That(_mixinBuilder.BuildClassContext(), Is.SameAs(r5));

            Assert.That(_mixinBuilder.ForClass <object> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.ForClass <string> (), Is.SameAs(r1));
            Assert.That(_mixinBuilder.BuildConfiguration(), Is.SameAs(r2));
            Assert.That(_mixinBuilder.EnterScope(), Is.SameAs(r3));

            _mockRepository.VerifyAll();
        }