public void Element() { var customAttributeNamedArgumentMock = MockRepository.GenerateStrictMock <ICustomAttributeNamedArgument> (); var input = "test"; var output = "output"; customAttributeNamedArgumentMock .Expect(x => x.MemberType) .Return(typeof(string)); customAttributeNamedArgumentMock .Expect(x => x.Value) .Return(input); Func <Type, object, object> elementConstructor = (type, value) => { Assert.That(type, Is.EqualTo(typeof(string))); Assert.That(value, Is.SameAs(input)); return(output); }; Func <Type, IEnumerable <object>, object> arrayConstructor = (type, enumerable) => { throw new Exception("should not get here"); }; var result = ICustomAttributeDataExtensions.ConvertTo(customAttributeNamedArgumentMock, elementConstructor, arrayConstructor); Assert.That(result, Is.SameAs(output)); customAttributeNamedArgumentMock.VerifyAllExpectations(); }
public void Array() { var customAttributeNamedArgumentMock = MockRepository.GenerateStrictMock <ICustomAttributeNamedArgument> (); var input = new object[] { "str", 7 }; var output = "output"; customAttributeNamedArgumentMock .Expect(x => x.MemberType) .Return(typeof(object[])); customAttributeNamedArgumentMock .Expect(x => x.Value) .Return(input); Func <Type, object, object> elementConstructor = (type, value) => value; Func <Type, IEnumerable <object>, object> arrayConstructor = (type, enumerable) => { Assert.That(type, Is.EqualTo(typeof(object))); Assert.That(enumerable, Is.EquivalentTo(input)); return(output); }; var result = ICustomAttributeDataExtensions.ConvertTo(customAttributeNamedArgumentMock, elementConstructor, arrayConstructor); Assert.That(result, Is.SameAs(output)); customAttributeNamedArgumentMock.VerifyAllExpectations(); }
public void NamedArgument() { var input = new[] { "named" }; var customAttributeDataMock = MockRepository.GenerateStrictMock <ICustomAttributeData> (); var customAttributeNamedArgumentMock = MockRepository.GenerateStrictMock <ICustomAttributeNamedArgument>(); customAttributeNamedArgumentMock .Expect(x => x.MemberInfo) .Return(typeof(DomainAttribute).GetFields().Single()); customAttributeNamedArgumentMock .Expect(x => x.MemberType) .Return(typeof(string[])); customAttributeNamedArgumentMock .Expect(x => x.Value) .Return(input); customAttributeDataMock .Expect(x => x.Constructor) .Return(typeof(DomainAttribute).GetConstructor(Type.EmptyTypes)); customAttributeDataMock .Expect(x => x.ConstructorArguments) .Return(new ReadOnlyCollection <object> (new object[0])); customAttributeDataMock .Expect(x => x.NamedArguments) .Return(new ReadOnlyCollectionDecorator <ICustomAttributeNamedArgument> (new[] { customAttributeNamedArgumentMock })) .Repeat.Twice(); var result = ICustomAttributeDataExtensions.CreateAttribute <DomainAttribute> (customAttributeDataMock); Assert.That(result.Field, Is.Not.SameAs(input)); Assert.That(result.Field, Is.EqualTo(input)); }
public void CompilerGenerated_ReturnsFalse() { var customAttributeDataMock = MockRepository.GenerateStrictMock <ICustomAttributeData> (); customAttributeDataMock .Expect(x => x.Constructor) .Return(typeof(CompilerGeneratedAttribute).GetConstructors().Single()); var result = ICustomAttributeDataExtensions.IsAspectAttribute(customAttributeDataMock); Assert.That(result, Is.False); }
public void AspectAttribute_ReturnsTrue() { var customAttributeDataMock = MockRepository.GenerateStrictMock <ICustomAttributeData> (); customAttributeDataMock .Expect(x => x.Constructor) .Return(typeof(DomainAttribute).GetConstructor(Type.EmptyTypes)); var result = ICustomAttributeDataExtensions.IsAspectAttribute(customAttributeDataMock); Assert.That(result, Is.True); }
public void DefaultConstructor() { var customAttributeDataMock = MockRepository.GenerateStrictMock <ICustomAttributeData>(); customAttributeDataMock .Expect(x => x.Constructor) .Return(typeof(DomainAttribute).GetConstructor(Type.EmptyTypes)); customAttributeDataMock .Expect(x => x.ConstructorArguments) .Return(new ReadOnlyCollection <object>(new object[0])); customAttributeDataMock .Expect(x => x.NamedArguments) .Return(new ReadOnlyCollectionDecorator <ICustomAttributeNamedArgument> (new ICustomAttributeNamedArgument[0])) .Repeat.Twice(); var result = ICustomAttributeDataExtensions.CreateAttribute(customAttributeDataMock); Assert.That(result, Is.TypeOf <DomainAttribute>()); }
public void ConstructorWithArgument() { var input = new[] { "ctor" }; var customAttributeDataMock = MockRepository.GenerateStrictMock <ICustomAttributeData> (); customAttributeDataMock .Expect(x => x.Constructor) .Return(typeof(DomainAttribute).GetConstructor(new[] { typeof(string) })); customAttributeDataMock .Expect(x => x.ConstructorArguments) .Return(new ReadOnlyCollection <object> (input)); customAttributeDataMock .Expect(x => x.NamedArguments) .Return(new ReadOnlyCollectionDecorator <ICustomAttributeNamedArgument> (new ICustomAttributeNamedArgument[0])) .Repeat.Twice(); var result = ICustomAttributeDataExtensions.CreateAttribute <DomainAttribute> (customAttributeDataMock); Assert.That(result, Is.Not.SameAs(input)); Assert.That(result.ConstructorArgument, Is.EqualTo("ctor")); }