public interface IMyServer
{
[OperationContract]
[DynamicResponseType]
[WebGet(UriTemplate = "info")]
string ServerInfo();
}
How do I write an NUnit test to prove that the C# interface method has the [DynamicResponseType]
attribute set on it?
The same you would normally check for an attribute on a class. Here's some sample code. typeof(ScheduleController) . IsDefined(typeof(SubControllerActionToViewDataAttribute), false);
The Test attribute is one way of marking a method inside a TestFixture class as a test. It is normally used for simple (non-parameterized) tests but may also be applied to parameterized tests without causing any extra test cases to be generated.
This attribute is used inside a TestFixture to provide a common set of functions that are performed just before each test method is called.
Action Attributes allow the user to create custom attributes to encapsulate specific actions for use before or after any test is run.
Something like:
Assert.IsTrue(Attribute.IsDefined(
typeof(IMyServer).GetMethod("ServerInfo"),
typeof(DynamicResponseTypeAttribute)));
You could also do something involving generics and delegates or expressions (instead of the string "ServerInfo"), but I'm not sure it is worth it.
For [WebGet]
:
WebGetAttribute attrib = (WebGetAttribute)Attribute.GetCustomAttribute(
typeof(IMyServer).GetMethod("ServerInfo"),
typeof(WebGetAttribute));
Assert.IsNotNull(attrib);
Assert.AreEqual("info", attrib.UriTemplate);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With