public void Apply_GenericArgumentsAlreadyGiven() { var attribute = new ExtendsAttribute(typeof(object)); attribute.MixinTypeArguments = new[] { typeof(string) }; attribute.Apply(_configurationBuilderMock, typeof(List <string>)); }
public void Apply_WrongKindOfGenericArguments() { var attribute = new ExtendsAttribute(typeof(object)); attribute.MixinTypeArguments = new[] { typeof(string) }; attribute.Apply(_configurationBuilderMock, typeof(Nullable <>)); }
public void Apply_WrongNumberOfGenericArguments_NoneExpected() { var attribute = new ExtendsAttribute(typeof(object)); attribute.MixinTypeArguments = new[] { typeof(double), typeof(string) }; attribute.Apply(_configurationBuilderMock, typeof(object)); }
public void Initialization_Defaults() { ExtendsAttribute attribute = new ExtendsAttribute(typeof(string)); Assert.That(attribute.AdditionalDependencies, Is.Empty); Assert.That(attribute.SuppressedMixins, Is.Empty); Assert.That(attribute.TargetType, Is.EqualTo(typeof(string))); Assert.That(attribute.IntroducedMemberVisibility, Is.EqualTo(MemberVisibility.Private)); }
public void Apply_InvalidOperation() { var attribute = new ExtendsAttribute(typeof(object)); _configurationBuilderMock .Expect(mock => mock.AddMixinToClass(MixinKind.Extending, null, null, MemberVisibility.Private, null, null, null)) .IgnoreArguments() .Throw(new InvalidOperationException("Foofa.")); _mockRepository.ReplayAll(); attribute.Apply(_configurationBuilderMock, _extenderType); }
/// <summary> /// Registers complex type /// </summary> /// <param name="t"></param> /// <param name="isArray"></param> /// <param name="isEnumerable"></param> /// <param name="isEnum"></param> /// <returns>registered type name</returns> protected internal string RegisterComplexType(Type t, bool isArray, bool isEnumerable, bool isEnum) { string registeredName = "any"; ExtendsAttribute extendsAttr = null; TypeNameAttribute typeNameAttr = null; var typeName = isEnum ? t.Name : string.Format("I{0}", t.Name); typeNameAttr = t.GetCustomAttributes(typeof(TypeNameAttribute), false).OfType <TypeNameAttribute>().FirstOrDefault(); if (typeNameAttr != null) { typeName = typeNameAttr.Name; } if (!isEnum) { extendsAttr = t.GetCustomAttributes(typeof(ExtendsAttribute), false).OfType <ExtendsAttribute>().FirstOrDefault(); StringBuilder extendsSb = null; if (extendsAttr != null && extendsAttr.InterfaceNames.Length > 0) { extendsSb = new StringBuilder("extends "); var isFirst = true; foreach (var intfName in extendsAttr.InterfaceNames) { if (!isFirst) { extendsSb.Append(", "); } extendsSb.Append(intfName); isFirst = false; } } registeredName = GetTypeInterface(t, typeName, extendsSb == null ? null : extendsSb.ToString()); } else { registeredName = GetTSEnum(t, typeName); } if (isArray || isEnumerable) { return(string.Format("{0}[]", typeName)); } return(typeName); }
public void Apply() { ExtendsAttribute attribute = new ExtendsAttribute(typeof(object)); _configurationBuilderMock .Expect( mock => mock.AddMixinToClass( MixinKind.Extending, typeof(object), _extenderType, MemberVisibility.Private, attribute.AdditionalDependencies, attribute.SuppressedMixins, CreateExpectedOrigin(attribute))) .Return(null); _mockRepository.ReplayAll(); attribute.Apply(_configurationBuilderMock, _extenderType); _mockRepository.VerifyAll(); }
public void Apply_GenericArgumentsPossible_NoneGiven() { var attribute = new ExtendsAttribute(typeof(object)); _configurationBuilderMock .Expect( mock => mock.AddMixinToClass( MixinKind.Extending, typeof(object), typeof(List <>), MemberVisibility.Private, attribute.AdditionalDependencies, attribute.SuppressedMixins, CreateExpectedOrigin(attribute, typeof(List <>)))) .Return(null); _mockRepository.ReplayAll(); attribute.Apply(_configurationBuilderMock, typeof(List <>)); _mockRepository.VerifyAll(); }
public void Apply_Generic() { ExtendsAttribute attribute = new ExtendsAttribute(typeof(object)); attribute.SuppressedMixins = new[] { typeof(int) }; attribute.AdditionalDependencies = new[] { typeof(string) }; attribute.MixinTypeArguments = new[] { typeof(double) }; _configurationBuilderMock .Expect( mock => mock.AddMixinToClass( MixinKind.Extending, typeof(object), typeof(List <double>), MemberVisibility.Private, attribute.AdditionalDependencies, attribute.SuppressedMixins, CreateExpectedOrigin(attribute))) .Return(null); _mockRepository.ReplayAll(); attribute.Apply(_configurationBuilderMock, _extenderType); _mockRepository.VerifyAll(); }
public void IgnoresDuplicates() { var attribute = new ExtendsAttribute(typeof(string)); Assert.That(attribute.IgnoresDuplicates, Is.False); }
private MixinContextOrigin CreateExpectedOrigin(ExtendsAttribute attribute, Type extenderType = null) { return(MixinContextOrigin.CreateForCustomAttribute(attribute, extenderType ?? _extenderType)); }