Skip to content

Commit

Permalink
Fixed the failing test for invalid attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasohlund committed Aug 7, 2011
1 parent 55bbf40 commit 23e44f6
Showing 1 changed file with 57 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
using System;
using System.Reflection;
using NUnit.Framework;

namespace NServiceBus.MessageInterfaces.Tests
{
[TestFixture]
public class When_mapping_interfaces
{
IMessageMapper mapper;

[SetUp]
public void SetUp()
{
mapper = new MessageMapper.Reflection.MessageMapper();
}

[Test]
public void Interfaces_with_only_properties_should_be_mapped()
{
mapper.Initialize(new[] { typeof(InterfaceWithProperties) });

Assert.NotNull(mapper.GetMappedTypeFor(typeof(InterfaceWithProperties)));
}

[Test]
using NUnit.Framework;

namespace NServiceBus.MessageInterfaces.Tests
{
[TestFixture]
public class When_mapping_interfaces
{
IMessageMapper mapper;

[SetUp]
public void SetUp()
{
mapper = new MessageMapper.Reflection.MessageMapper();
}

[Test]
public void Interfaces_with_only_properties_should_be_mapped()
{
mapper.Initialize(new[] { typeof(InterfaceWithProperties) });

Assert.NotNull(mapper.GetMappedTypeFor(typeof(InterfaceWithProperties)));
}

[Test]
public void Interface_should_be_created()
{
mapper.Initialize(new[] { typeof(InterfaceWithProperties) });

var result = mapper.CreateInstance<InterfaceWithProperties>(null);

Assert.IsNotNull(result);
}

[Test]
public void Interfaces_with_methods_should_be_ignored()
{
mapper.Initialize(new[] {typeof(InterfaceWithMethods)});

Assert.Null(mapper.GetMappedTypeFor(typeof(InterfaceWithMethods)));
}

[Test]
}

[Test]
public void Interfaces_with_methods_should_be_ignored()
{
mapper.Initialize(new[] {typeof(InterfaceWithMethods)});

Assert.Null(mapper.GetMappedTypeFor(typeof(InterfaceWithMethods)));
}

[Test]
public void Attributes_on_properties_should_be_mapped()
{
mapper.Initialize(new[]{typeof(InterfaceWithPropertiesAndAttributes)});
Expand All @@ -52,53 +52,53 @@ public void Attributes_on_properties_should_be_mapped()
}

[Test]
[ExpectedException(typeof(ArgumentException))]
public void Invalid_attributes_should_fail()
public void Attributes_with_no_default_ctor_should_be_ignored()
{
mapper.Initialize(new[] { typeof(InterfaceWithInvalidAttribute) });
Assert.IsFalse(PropertyContainsAttribute("SomeProperty", typeof(InvalidAttribute), mapper.CreateInstance(typeof(InterfaceWithInvalidAttribute))));
}

private bool PropertyContainsAttribute(string propertyName, Type attributeType, object obj)
{
return obj.GetType().GetProperty(propertyName).GetCustomAttributes(attributeType,true).Length > 0;
}
}

public interface InterfaceWithProperties : IMessage
{
string SomeProperty { get; set; }
}

public interface InterfaceWithMethods
{
string SomeProperty { get; set; }
void MethodOnInterface();
}

}

public interface InterfaceWithProperties : IMessage
{
string SomeProperty { get; set; }
}

public interface InterfaceWithMethods
{
string SomeProperty { get; set; }
void MethodOnInterface();
}

public interface InterfaceWithPropertiesAndAttributes
{
[SomeAttribute]
string SomeProperty { get; set; }

string SomeOtherProperty { get; set; }
}

}

public interface InterfaceWithInvalidAttribute
{
[InvalidAttribute("Blah")]
string SomeProperty { get; set; }
}

}

public class SomeAttribute : Attribute
{

}

}

public class InvalidAttribute : Attribute
{
public InvalidAttribute(string requiredArg)
{

}
}
}
}

0 comments on commit 23e44f6

Please sign in to comment.