Exemplo n.º 1
0
        public void Equals_True_WithDifferentOrder()
        {
            MixinData mixinData1 = new MixinData(new object[] { simpleMixin, otherMixin });
            MixinData mixinData2 = new MixinData(new object[] { otherMixin, simpleMixin });

            Assert.AreEqual(mixinData1, mixinData2);
        }
Exemplo n.º 2
0
		public void GetMixinInterfaceImplementationsAsArray()
		{
			MixinData mixinData = new MixinData(new object[] {simpleMixin});
			object[] mixinsAsArray = mixinData.GetMixinInterfaceImplementationsAsArray();
			Assert.AreEqual(1, mixinsAsArray.Length);
			Assert.AreSame(simpleMixin, mixinsAsArray[0]);
		}
Exemplo n.º 3
0
        public void Equals_false_for_two_instances_having_compatible_delegate_type_mixins()
        {
            MixinData mixinData1 = new MixinData(new object[] { typeof(Func <object, bool>) });
            MixinData mixinData2 = new MixinData(new object[] { typeof(Predicate <object>) });

            Assert.AreNotEqual(mixinData1, mixinData2);
        }
Exemplo n.º 4
0
        public void Equals_False_WithInstanceCount()
        {
            MixinData mixinData1 = new MixinData(new object[] { otherMixin });
            MixinData mixinData2 = new MixinData(new object[] { otherMixin, simpleMixin });

            Assert.AreNotEqual(mixinData1, mixinData2);
        }
Exemplo n.º 5
0
		public void MixinInterfaces()
		{
			MixinData mixinData = new MixinData(new object[] { simpleMixin });
			List<Type> mixinInterfaces = new List<Type>(mixinData.MixinInterfaces);
			Assert.AreEqual(1, mixinInterfaces.Count);
			Assert.AreSame(mixinInterfaces[0], typeof (ISimpleMixin));
		}
Exemplo n.º 6
0
        public void GetHashCode_Equal_WithDifferentInstances()
        {
            MixinData mixinData1 = new MixinData(new object[] { simpleMixin, otherMixin });
            MixinData mixinData2 = new MixinData(new object[] { new SimpleMixin(), new OtherMixin() });

            Assert.AreEqual(mixinData1.GetHashCode(), mixinData2.GetHashCode());
        }
Exemplo n.º 7
0
        public void GetHashCode_Equal_WithDifferentOrder()
        {
            MixinData mixinData1 = new MixinData(new object[] { simpleMixin, otherMixin });
            MixinData mixinData2 = new MixinData(new object[] { otherMixin, simpleMixin });

            Assert.AreEqual(mixinData1.GetHashCode(), mixinData2.GetHashCode());
        }
Exemplo n.º 8
0
        public void ContainsMixinWithInterface()
        {
            MixinData mixinData = new MixinData(new object[] { simpleMixin });

            Assert.IsTrue(mixinData.ContainsMixin(typeof(ISimpleMixin)));
            Assert.IsFalse(mixinData.ContainsMixin(typeof(IOtherMixin)));
        }
Exemplo n.º 9
0
		public void Mixins()
		{
			MixinData mixinData = new MixinData(new object[] {simpleMixin});
			List<object> mixins = new List<object>(mixinData.Mixins);
			Assert.AreEqual(1, mixins.Count);
			Assert.AreSame(simpleMixin, mixins[0]);
		}
Exemplo n.º 10
0
        public void MixinsNotImplementingInterfacesAreIgnored()
        {
            MixinData     mixinData = new MixinData(new object[] { new object() });
            List <object> mixins    = new List <object>(mixinData.Mixins);

            Assert.AreEqual(0, mixins.Count);
        }
Exemplo n.º 11
0
        public void GetHashCode_equal_for_two_instances_having_different_delegate_type_mixins()
        {
            MixinData mixinData1 = new MixinData(new object[] { typeof(Action) });
            MixinData mixinData2 = new MixinData(new object[] { typeof(Action <int>) });

            Assert.AreEqual(mixinData1.GetHashCode(), mixinData2.GetHashCode());
        }
Exemplo n.º 12
0
        public void MixinData()
        {
            _options1.Initialize();
            MixinData data = _options1.MixinData;

            Assert.AreEqual(0, new List <object>(data.Mixins).Count);
        }
Exemplo n.º 13
0
        public void Equals_False_WithDifferentInstances()
        {
            MixinData mixinData1 = new MixinData(new object[] { simpleMixin, otherMixin });
            MixinData mixinData2 = new MixinData(new object[] { simpleMixin, complexMixin });

            Assert.AreNotEqual(mixinData1, mixinData2);
        }
Exemplo n.º 14
0
        public void Equals_true_for_two_instances_having_same_delegate_type_mixins()
        {
            MixinData mixinData1 = new MixinData(new object[] { typeof(Action) });
            MixinData mixinData2 = new MixinData(new object[] { typeof(Action) });

            Assert.AreEqual(mixinData1, mixinData2);
        }
Exemplo n.º 15
0
        public void Equals_false_for_two_instances_having_different_delegate_type_mixins()
        {
            MixinData mixinData1 = new MixinData(new object[] { typeof(Action) });
            MixinData mixinData2 = new MixinData(new object[] { typeof(Action <int>) });

            Assert.AreNotEqual(mixinData1, mixinData2);
        }
Exemplo n.º 16
0
        public void Equals_True_WithDifferentInstances()
        {
            MixinData mixinData1 = new MixinData(new object[] { simpleMixin, otherMixin });
            MixinData mixinData2 = new MixinData(new object[] { new SimpleMixin(), new OtherMixin() });

            Assert.AreEqual(mixinData1, mixinData2);
        }
Exemplo n.º 17
0
        public void Mixins()
        {
            MixinData     mixinData = new MixinData(new object[] { simpleMixin });
            List <object> mixins    = new List <object>(mixinData.Mixins);

            Assert.AreEqual(1, mixins.Count);
            Assert.AreSame(simpleMixin, mixins[0]);
        }
Exemplo n.º 18
0
 public void Ctor_succeeds_when_mixing_regular_mixin_instances_with_delegate_type_mixins()
 {
     var mixinData = new MixinData(new object[]
     {
         new NotADelegate(),
         typeof(Action),
     });
 }
        public void MixinData_NeedsInitialize()
        {
            Assert.Throws <InvalidOperationException>(delegate {
#pragma warning disable 219
                MixinData data = _options1.MixinData;
#pragma warning restore 219
            });
        }
Exemplo n.º 20
0
        public void MixinData_WithMixins()
        {
            _options1.AddMixinInstance(new SimpleMixin());
            _options1.Initialize();
            MixinData data = _options1.MixinData;

            Assert.AreEqual(1, new List <object>(data.Mixins).Count);
        }
Exemplo n.º 21
0
        public void MixinInterfaces()
        {
            MixinData   mixinData       = new MixinData(new object[] { simpleMixin });
            List <Type> mixinInterfaces = new List <Type>(mixinData.MixinInterfaces);

            Assert.AreEqual(1, mixinInterfaces.Count);
            Assert.AreSame(mixinInterfaces[0], typeof(ISimpleMixin));
        }
Exemplo n.º 22
0
        public void MixinData_NoReInitializeWhenNothingChanged()
        {
            _options1.AddMixinInstance(new SimpleMixin());
            _options1.Initialize();

            MixinData data1 = _options1.MixinData;

            _options1.Initialize();
            MixinData data2 = _options1.MixinData;

            Assert.AreSame(data1, data2);
        }
Exemplo n.º 23
0
		public void MixinInterfacesAndPositions_SortedLikeMixins()
		{
			MixinData mixinData1 = new MixinData(new object[] {simpleMixin, otherMixin});
			Assert.AreEqual(2, mixinData1.MixinInterfacesAndPositions.Count);
			Assert.AreEqual(0, mixinData1.MixinInterfacesAndPositions[typeof (IOtherMixin)]);
			Assert.AreEqual(1, mixinData1.MixinInterfacesAndPositions[typeof (ISimpleMixin)]);

			MixinData mixinData2 = new MixinData(new object[] {otherMixin, simpleMixin});
			Assert.AreEqual(2, mixinData2.MixinInterfacesAndPositions.Count);
			Assert.AreEqual(0, mixinData2.MixinInterfacesAndPositions[typeof (IOtherMixin)]);
			Assert.AreEqual(1, mixinData2.MixinInterfacesAndPositions[typeof (ISimpleMixin)]);
		}
Exemplo n.º 24
0
        public void GetMixinPosition_MatchesMixinInstances()
        {
            MixinData mixinData1 = new MixinData(new object[] { simpleMixin, otherMixin });

            Assert.AreEqual(0, mixinData1.GetMixinPosition(typeof(IOtherMixin)));
            Assert.AreEqual(1, mixinData1.GetMixinPosition(typeof(ISimpleMixin)));

            MixinData mixinData2 = new MixinData(new object[] { otherMixin, simpleMixin });

            Assert.AreEqual(0, mixinData2.GetMixinPosition(typeof(IOtherMixin)));
            Assert.AreEqual(1, mixinData2.GetMixinPosition(typeof(ISimpleMixin)));
        }
Exemplo n.º 25
0
		public void MixinsAreSortedByInterface()
		{
			MixinData mixinData1 = new MixinData(new object[] {simpleMixin, otherMixin});
			List<object> mixins1 = new List<object>(mixinData1.Mixins);
			Assert.AreEqual(2, mixins1.Count);
			Assert.AreSame(otherMixin, mixins1[0]);
			Assert.AreSame(simpleMixin, mixins1[1]);

			MixinData mixinData2 = new MixinData(new object[] {otherMixin, simpleMixin});
			List<object> mixins2 = new List<object>(mixinData2.Mixins);
			Assert.AreEqual(2, mixins2.Count);
			Assert.AreSame(otherMixin, mixins2[0]);
			Assert.AreSame(simpleMixin, mixins2[1]);
		}
Exemplo n.º 26
0
		public void MixinsAreSortedByInterface()
		{
			MixinData mixinData1 = new MixinData(new object[] {simpleMixin, otherMixin});
			object[] mixinsAsArray1 = mixinData1.GetMixinInterfaceImplementationsAsArray();
			Assert.AreEqual(2, mixinsAsArray1.Length);
			Assert.AreSame(otherMixin, mixinsAsArray1[0]);
			Assert.AreSame(simpleMixin, mixinsAsArray1[1]);

			MixinData mixinData2 = new MixinData(new object[] {otherMixin, simpleMixin});
			object[] mixinsAsArray2 = mixinData2.GetMixinInterfaceImplementationsAsArray();
			Assert.AreEqual(2, mixinsAsArray2.Length);
			Assert.AreSame(otherMixin, mixinsAsArray2[0]);
			Assert.AreSame(simpleMixin, mixinsAsArray2[1]);
		}
Exemplo n.º 27
0
        public void MixinData_ReInitializeWhenMixinsChanged()
        {
            _options1.AddMixinInstance(new SimpleMixin());
            _options1.Initialize();

            MixinData data1 = _options1.MixinData;

            _options1.AddMixinInstance(new OtherMixin());
            _options1.Initialize();
            MixinData data2 = _options1.MixinData;

            Assert.AreNotSame(data1, data2);

            Assert.AreEqual(1, new List <object>(data1.Mixins).Count);
            Assert.AreEqual(2, new List <object>(data2.Mixins).Count);
        }
Exemplo n.º 28
0
        public void GetMixinPosition_MatchesMixinInstances_WithMultipleInterfacesPerMixin()
        {
            MixinData mixinData = new MixinData(new object[] { complexMixin, simpleMixin });

            Assert.AreEqual(0, mixinData.GetMixinPosition(typeof(IFirst)));
            Assert.AreEqual(1, mixinData.GetMixinPosition(typeof(ISecond)));
            Assert.AreEqual(2, mixinData.GetMixinPosition(typeof(ISimpleMixin)));
            Assert.AreEqual(3, mixinData.GetMixinPosition(typeof(IThird)));

            List <object> mixins = new List <object>(mixinData.Mixins);

            Assert.AreSame(complexMixin, mixins[0]);
            Assert.AreSame(complexMixin, mixins[1]);
            Assert.AreSame(simpleMixin, mixins[2]);
            Assert.AreSame(complexMixin, mixins[3]);
        }
Exemplo n.º 29
0
        public void MixinsAreSortedByInterface()
        {
            MixinData     mixinData1 = new MixinData(new object[] { simpleMixin, otherMixin });
            List <object> mixins1    = new List <object>(mixinData1.Mixins);

            Assert.AreEqual(2, mixins1.Count);
            Assert.AreSame(otherMixin, mixins1[0]);
            Assert.AreSame(simpleMixin, mixins1[1]);

            MixinData     mixinData2 = new MixinData(new object[] { otherMixin, simpleMixin });
            List <object> mixins2    = new List <object>(mixinData2.Mixins);

            Assert.AreEqual(2, mixins2.Count);
            Assert.AreSame(otherMixin, mixins2[0]);
            Assert.AreSame(simpleMixin, mixins2[1]);
        }
Exemplo n.º 30
0
        public void MixinInterfaces_SortedLikeMixins()
        {
            MixinData   mixinData1       = new MixinData(new object[] { simpleMixin, otherMixin });
            List <Type> mixinInterfaces1 = new List <Type>(mixinData1.MixinInterfaces);

            Assert.AreEqual(2, mixinInterfaces1.Count);
            Assert.AreSame(typeof(IOtherMixin), mixinInterfaces1[0]);
            Assert.AreSame(typeof(ISimpleMixin), mixinInterfaces1[1]);

            MixinData   mixinData2       = new MixinData(new object[] { otherMixin, simpleMixin });
            List <Type> mixinInterfaces2 = new List <Type>(mixinData2.MixinInterfaces);

            Assert.AreEqual(2, mixinInterfaces2.Count);
            Assert.AreSame(typeof(IOtherMixin), mixinInterfaces2[0]);
            Assert.AreSame(typeof(ISimpleMixin), mixinInterfaces2[1]);
        }
Exemplo n.º 31
0
		public void GetMixinPosition_MatchesMixinInstances()
		{
			MixinData mixinData1 = new MixinData(new object[] {simpleMixin, otherMixin});
			Assert.AreEqual(0, mixinData1.GetMixinPosition(typeof(IOtherMixin)));
			Assert.AreEqual(1, mixinData1.GetMixinPosition(typeof(ISimpleMixin)));

			MixinData mixinData2 = new MixinData(new object[] {otherMixin, simpleMixin});
			Assert.AreEqual(0, mixinData2.GetMixinPosition(typeof(IOtherMixin)));
			Assert.AreEqual(1, mixinData2.GetMixinPosition(typeof(ISimpleMixin)));
		}
Exemplo n.º 32
0
		public void GetMixinPosition_MatchesMixinInstances_WithMultipleInterfacesPerMixin()
		{
			MixinData mixinData = new MixinData(new object[] { complexMixin, simpleMixin });
			Assert.AreEqual(0, mixinData.GetMixinPosition(typeof(IFirst)));
			Assert.AreEqual(1, mixinData.GetMixinPosition(typeof(ISecond)));
			Assert.AreEqual(2, mixinData.GetMixinPosition(typeof(ISimpleMixin)));
			Assert.AreEqual(3, mixinData.GetMixinPosition(typeof(IThird)));

			List<object> mixins = new List<object>(mixinData.Mixins);
			Assert.AreSame(complexMixin, mixins[0]);
			Assert.AreSame(complexMixin, mixins[1]);
			Assert.AreSame(simpleMixin, mixins[2]);
			Assert.AreSame(complexMixin, mixins[3]);
		}
Exemplo n.º 33
0
		public void Equals_True_WithDifferentOrder()
		{
			MixinData mixinData1 = new MixinData(new object[] {simpleMixin, otherMixin});
			MixinData mixinData2 = new MixinData(new object[] {otherMixin, simpleMixin});
			Assert.AreEqual(mixinData1, mixinData2);
		}
Exemplo n.º 34
0
        Expression <Action <object> > MakeInitExpression(Type proxyType, IInterceptorSelector selector, MixinData mixins)
        {
            var fields      = proxyType.GetFields().ToDictionary(f => f.Name);
            var parameter   = Expression.Parameter(typeof(object));
            var variable    = Expression.Variable(proxyType);
            var expressions = new List <Expression>();

            expressions.Add(Expression.Assign(variable, Expression.Convert(parameter, proxyType)));
            expressions.Add(Expression.Assign(
                                Expression.MakeMemberAccess(variable, fields["__selector"]),
                                Expression.Constant(selector)
                                ));
            expressions.AddRange(mixins.MixinInterfaces.Zip(mixins.Mixins, (t, o) =>
                                                            Expression.Assign(
                                                                Expression.MakeMemberAccess(variable, fields["__mixin_" + t.FullName.Replace(".", "_")]),
                                                                Expression.New(o.GetType())
                                                                )
                                                            ));
            return(Expression.Lambda <Action <object> >(Expression.Block(new[] { variable }, expressions), parameter));
        }
Exemplo n.º 35
0
		public void MixinsNotImplementingInterfacesAreIgnored()
		{
			MixinData mixinData = new MixinData(new object[] {new object()});
			object[] mixinsAsArray = mixinData.GetMixinInterfaceImplementationsAsArray();
			Assert.AreEqual(0, mixinsAsArray.Length);
		}
Exemplo n.º 36
0
		public void GetMixinPosition()
		{
			MixinData mixinData = new MixinData(new object[] { simpleMixin });
			Assert.AreEqual(0, mixinData.GetMixinPosition(typeof(ISimpleMixin)));
		}
Exemplo n.º 37
0
		public void GetHashCode_Equal_WithDifferentOrder()
		{
			MixinData mixinData1 = new MixinData(new object[] {simpleMixin, otherMixin});
			MixinData mixinData2 = new MixinData(new object[] {otherMixin, simpleMixin});
			Assert.AreEqual(mixinData1.GetHashCode(), mixinData2.GetHashCode());
		}
Exemplo n.º 38
0
		public void GetHashCode_Equal_WithDifferentInstances()
		{
			MixinData mixinData1 = new MixinData(new object[] {simpleMixin, otherMixin});
			MixinData mixinData2 = new MixinData(new object[] {new SimpleMixin(), new OtherMixin()});
			Assert.AreEqual(mixinData1.GetHashCode(), mixinData2.GetHashCode());
		}
Exemplo n.º 39
0
		public void ContainsMixinWithInterface()
		{
			MixinData mixinData = new MixinData(new object[] { simpleMixin });
			Assert.IsTrue(mixinData.ContainsMixin(typeof(ISimpleMixin)));
			Assert.IsFalse(mixinData.ContainsMixin(typeof(IOtherMixin)));
		}
Exemplo n.º 40
0
		public void MixinsNotImplementingInterfacesAreIgnored()
		{
			MixinData mixinData = new MixinData(new object[] {new object()});
			List<object> mixins = new List<object>(mixinData.Mixins);
			Assert.AreEqual(0, mixins.Count);
		}
Exemplo n.º 41
0
		public void MixinInterfaces_SortedLikeMixins()
		{
			MixinData mixinData1 = new MixinData(new object[] { simpleMixin, otherMixin });
			List<Type> mixinInterfaces1 = new List<Type>(mixinData1.MixinInterfaces);
			Assert.AreEqual(2, mixinInterfaces1.Count);
			Assert.AreSame(typeof(IOtherMixin), mixinInterfaces1[0]);
			Assert.AreSame(typeof(ISimpleMixin), mixinInterfaces1[1]);

			MixinData mixinData2 = new MixinData(new object[] { otherMixin, simpleMixin });
			List<Type> mixinInterfaces2 = new List<Type>(mixinData2.MixinInterfaces);
			Assert.AreEqual(2, mixinInterfaces2.Count);
			Assert.AreSame(typeof (IOtherMixin), mixinInterfaces2[0]);
			Assert.AreSame(typeof (ISimpleMixin), mixinInterfaces2[1]);
		}
Exemplo n.º 42
0
        public void GetMixinPosition()
        {
            MixinData mixinData = new MixinData(new object[] { simpleMixin });

            Assert.AreEqual(0, mixinData.GetMixinPosition(typeof(ISimpleMixin)));
        }
Exemplo n.º 43
0
		public void Equals_False_WithInstanceCount()
		{
			MixinData mixinData1 = new MixinData(new object[] {otherMixin});
			MixinData mixinData2 = new MixinData(new object[] {otherMixin, simpleMixin});
			Assert.AreNotEqual(mixinData1, mixinData2);
		}
Exemplo n.º 44
0
        public void MixinData_NeedsInitialize()
        {
#pragma warning disable 219
            MixinData data = _options1.MixinData;
#pragma warning restore 219
        }
Exemplo n.º 45
0
		public void Equals_False_WithDifferentInstances()
		{
			MixinData mixinData1 = new MixinData(new object[] {simpleMixin, otherMixin});
			MixinData mixinData2 = new MixinData(new object[] {simpleMixin, complexMixin});
			Assert.AreNotEqual(mixinData1, mixinData2);
		}
Exemplo n.º 46
0
		public void MixinInterfacesAndPositions()
		{
			MixinData mixinData = new MixinData(new object[] {simpleMixin});
			Assert.AreEqual(1, mixinData.MixinInterfacesAndPositions.Count);
			Assert.AreEqual(0, mixinData.MixinInterfacesAndPositions[typeof (ISimpleMixin)]);
		}
Exemplo n.º 47
0
		public void Equals_True_WithDifferentInstances()
		{
			MixinData mixinData1 = new MixinData(new object[] {simpleMixin, otherMixin});
			MixinData mixinData2 = new MixinData(new object[] {new SimpleMixin(), new OtherMixin()});
			Assert.AreEqual(mixinData1, mixinData2);
		}
 public void MixinData_NeedsInitialize()
 {
     MixinData data = _options1.MixinData;
 }
Exemplo n.º 49
0
        Tuple <string, Expression <Func <object[], object> > > MakeCreateExpression(Type proxyType, IInterceptorSelector selector, MixinData mixins, ConstructorInfo ctor, ParameterInfo[] ctorArgs)
        {
            var key = new StringBuilder();
            var ctorArgsParameter = Expression.Parameter(typeof(object[]));
            var arguments         = mixins.Mixins.Select(m => Expression.New(m.GetType())).Cast <Expression>().ToList();

            arguments.Add(Expression.Convert(Expression.Constant(null), typeof(IInterceptor[])));
            arguments.Add(Expression.Constant(selector));
            for (int i = arguments.Count, j = 0; i < ctorArgs.Length; i++, j++)
            {
                key.Append(ctorArgs[i].ParameterType.ToString());
                var argExpr = Expression.ArrayIndex(ctorArgsParameter, Expression.Constant(j));
                arguments.Add(Expression.ConvertChecked(argExpr, ctorArgs[i].ParameterType));
            }
            var body   = Expression.New(ctor, arguments);
            var method = Expression.Lambda <Func <object[], object> >(body, ctorArgsParameter);

            return(Tuple.Create(key.ToString(), method));
        }