public void CopyAttributes_Ambiguous()
        {
            var builder = new AttributeDefinitionBuilder(DefinitionObjectMother.CreateMixinDefinition(typeof(MixinWithAmbiguousSource)));
            var method  = typeof(MixinWithAmbiguousSource).GetMethod("ToString", BindingFlags.NonPublic | BindingFlags.Instance);
            var data    = CustomAttributeData.GetCustomAttributes(method).Select(d => (ICustomAttributeData) new CustomAttributeDataAdapter(d));

            builder.Apply(method, data, true);
        }
        public void CreateRequiredMethodDefinitions_NoMatch()
        {
            var targetClassDefinition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(object));
            var requiringMixin        = DefinitionObjectMother.CreateMixinDefinition(targetClassDefinition, typeof(string));

            var dependency  = DefinitionObjectMother.CreateTargetCallDependencyDefinition(requiringMixin);
            var requirement = dependency.RequiredType;

            DefinitionObjectMother.AddRequiringDependency(requirement, dependency);

            var builder = new DuckTypingRequiredMethodDefinitionCollector(targetClassDefinition);

            builder.CreateRequiredMethodDefinitions(requirement).ToArray();
        }
        public void GetMixinByConfiguredType_NonNull()
        {
            var targetClassDefinition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(BaseType3));

            var nonGenericMixinType       = typeof(BT3Mixin1);
            var nonGenericMixinDefinition = DefinitionObjectMother.CreateMixinDefinition(targetClassDefinition, nonGenericMixinType);

            var closedMixinType       = targetClassDefinition.MixinTypeCloser.GetClosedMixinType(typeof(BT3Mixin3 <,>));
            var closedMixinDefinition = DefinitionObjectMother.CreateMixinDefinition(targetClassDefinition, closedMixinType);

            Assert.That(targetClassDefinition.GetMixinByConfiguredType(nonGenericMixinType), Is.SameAs(nonGenericMixinDefinition));
            Assert.That(targetClassDefinition.GetMixinByConfiguredType(closedMixinType), Is.SameAs(closedMixinDefinition));
            Assert.That(targetClassDefinition.GetMixinByConfiguredType(closedMixinType.GetGenericTypeDefinition()), Is.SameAs(closedMixinDefinition));
        }
        public void HasMixinWithConfiguredType_True()
        {
            var targetClassDefinition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(BaseType3));

            var nonGenericMixinType = typeof(BT3Mixin1);

            DefinitionObjectMother.CreateMixinDefinition(targetClassDefinition, nonGenericMixinType);

            var closedMixinType = targetClassDefinition.MixinTypeCloser.GetClosedMixinType(typeof(BT3Mixin3 <,>));

            DefinitionObjectMother.CreateMixinDefinition(targetClassDefinition, closedMixinType);

            Assert.That(targetClassDefinition.HasMixinWithConfiguredType(nonGenericMixinType), Is.True);
            Assert.That(targetClassDefinition.HasMixinWithConfiguredType(closedMixinType), Is.True);
            Assert.That(targetClassDefinition.HasMixinWithConfiguredType(closedMixinType.GetGenericTypeDefinition()), Is.True);
        }
        private static TargetClassDefinition CreateTargetClassDefinition(params Tuple <Type, bool, Type[]>[] mixinTypesAndDependencies)
        {
            var targetClassDefinition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(NullTarget));

            foreach (var tuple in mixinTypesAndDependencies)
            {
                DefinitionObjectMother.CreateMixinDefinition(targetClassDefinition, tuple.Item1, tuple.Item2);
            }

            foreach (var tuple in mixinTypesAndDependencies)
            {
                foreach (var dependency in tuple.Item3)
                {
                    DefinitionObjectMother.CreateMixinDependencyDefinition(targetClassDefinition.Mixins[tuple.Item1], targetClassDefinition.Mixins[dependency]);
                }
            }

            return(targetClassDefinition);
        }
 public void SetUp()
 {
     _parentDefinition       = DefinitionObjectMother.CreateTargetClassDefinition(typeof(object));
     _nestedDefinition       = DefinitionObjectMother.CreateMixinDefinition(_parentDefinition, typeof(string));
     _nestedNestedDefinition = DefinitionObjectMother.CreateMethodDefinition(_nestedDefinition, ReflectionObjectMother.GetSomeMethod());
 }