diff options
Diffstat (limited to 'src/DotNetOpenAuth.Test/Messaging')
18 files changed, 210 insertions, 210 deletions
diff --git a/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardExpirationBindingElementTests.cs b/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardExpirationBindingElementTests.cs index 3cc792b..9ba433d 100644 --- a/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardExpirationBindingElementTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardExpirationBindingElementTests.cs @@ -9,11 +9,11 @@ namespace DotNetOpenAuth.Test.Messaging.Bindings { using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.Test.Mocks; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; - [TestClass] + [TestFixture] public class StandardExpirationBindingElementTests : MessagingTestBase { - [TestMethod] + [TestCase] public void SendSetsTimestamp() { TestExpiringMessage message = new TestExpiringMessage(MessageTransport.Indirect); message.Recipient = new Uri("http://localtest"); @@ -24,13 +24,13 @@ namespace DotNetOpenAuth.Test.Messaging.Bindings { Assert.IsTrue(DateTime.UtcNow - ((IExpiringProtocolMessage)message).UtcCreationDate < TimeSpan.FromSeconds(3), "The timestamp on the message was not set on send."); } - [TestMethod] + [TestCase] public void VerifyGoodTimestampIsAccepted() { this.Channel = CreateChannel(MessageProtections.Expiration); this.ParameterizedReceiveProtectedTest(DateTime.UtcNow, false); } - [TestMethod, ExpectedException(typeof(ExpiredMessageException))] + [TestCase, ExpectedException(typeof(ExpiredMessageException))] public void VerifyBadTimestampIsRejected() { this.Channel = CreateChannel(MessageProtections.Expiration); this.ParameterizedReceiveProtectedTest(DateTime.UtcNow - StandardExpirationBindingElement.MaximumMessageAge - TimeSpan.FromSeconds(1), false); diff --git a/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardReplayProtectionBindingElementTests.cs b/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardReplayProtectionBindingElementTests.cs index 14651bc..d8698ce 100644 --- a/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardReplayProtectionBindingElementTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardReplayProtectionBindingElementTests.cs @@ -15,16 +15,16 @@ namespace DotNetOpenAuth.Test.Messaging.Bindings { using DotNetOpenAuth.OpenId.ChannelElements; using DotNetOpenAuth.OpenId.Messages; using DotNetOpenAuth.Test.Mocks; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; - [TestClass] + [TestFixture] public class StandardReplayProtectionBindingElementTests : MessagingTestBase { private Protocol protocol; private StandardReplayProtectionBindingElement nonceElement; private IReplayProtectedProtocolMessage message; private INonceStore nonceStore; - [TestInitialize] + [SetUp] public override void SetUp() { base.SetUp(); @@ -39,7 +39,7 @@ namespace DotNetOpenAuth.Test.Messaging.Bindings { /// <summary> /// Verifies that the generated nonce includes random characters. /// </summary> - [TestMethod] + [TestCase] public void RandomCharactersTest() { Assert.IsNotNull(this.nonceElement.ProcessOutgoingMessage(this.message)); Assert.IsNotNull(this.message.Nonce, "No nonce was set on the message."); @@ -56,7 +56,7 @@ namespace DotNetOpenAuth.Test.Messaging.Bindings { /// <summary> /// Verifies that a message is received correctly. /// </summary> - [TestMethod] + [TestCase] public void ValidMessageReceivedTest() { this.message.Nonce = "a"; Assert.IsNotNull(this.nonceElement.ProcessIncomingMessage(this.message)); @@ -65,7 +65,7 @@ namespace DotNetOpenAuth.Test.Messaging.Bindings { /// <summary> /// Verifies that a message that doesn't have a string of random characters is received correctly. /// </summary> - [TestMethod] + [TestCase] public void ValidMessageNoNonceReceivedTest() { this.message.Nonce = string.Empty; this.nonceElement.AllowZeroLengthNonce = true; @@ -75,7 +75,7 @@ namespace DotNetOpenAuth.Test.Messaging.Bindings { /// <summary> /// Verifies that a message that doesn't have a string of random characters is received correctly. /// </summary> - [TestMethod, ExpectedException(typeof(ProtocolException))] + [TestCase, ExpectedException(typeof(ProtocolException))] public void InvalidMessageNoNonceReceivedTest() { this.message.Nonce = string.Empty; this.nonceElement.AllowZeroLengthNonce = false; @@ -85,7 +85,7 @@ namespace DotNetOpenAuth.Test.Messaging.Bindings { /// <summary> /// Verifies that a replayed message is rejected. /// </summary> - [TestMethod, ExpectedException(typeof(ReplayedMessageException))] + [TestCase, ExpectedException(typeof(ReplayedMessageException))] public void ReplayDetectionTest() { this.message.Nonce = "a"; Assert.IsNotNull(this.nonceElement.ProcessIncomingMessage(this.message)); diff --git a/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs b/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs index 7846411..d22c2f7 100644 --- a/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs @@ -13,23 +13,23 @@ namespace DotNetOpenAuth.Test.Messaging { using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.Test.Mocks; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; - [TestClass] + [TestFixture] public class ChannelTests : MessagingTestBase { - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void CtorNull() { // This bad channel is deliberately constructed to pass null to // its protected base class' constructor. new TestBadChannel(true); } - [TestMethod] + [TestCase] public void ReadFromRequestQueryString() { this.ParameterizedReceiveTest("GET"); } - [TestMethod] + [TestCase] public void ReadFromRequestForm() { this.ParameterizedReceiveTest("POST"); } @@ -38,37 +38,37 @@ namespace DotNetOpenAuth.Test.Messaging { /// Verifies compliance to OpenID 2.0 section 5.1.1 by verifying the channel /// will reject messages that come with an unexpected HTTP verb. /// </summary> - [TestMethod, ExpectedException(typeof(ProtocolException))] + [TestCase, ExpectedException(typeof(ProtocolException))] public void ReadFromRequestDisallowedHttpMethod() { var fields = GetStandardTestFields(FieldFill.CompleteBeforeBindings); fields["GetOnly"] = "true"; this.Channel.ReadFromRequest(CreateHttpRequestInfo("POST", fields)); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void SendNull() { this.Channel.PrepareResponse(null); } - [TestMethod, ExpectedException(typeof(ArgumentException))] + [TestCase, ExpectedException(typeof(ArgumentException))] public void SendIndirectedUndirectedMessage() { IProtocolMessage message = new TestDirectedMessage(MessageTransport.Indirect); this.Channel.PrepareResponse(message); } - [TestMethod, ExpectedException(typeof(ArgumentException))] + [TestCase, ExpectedException(typeof(ArgumentException))] public void SendDirectedNoRecipientMessage() { IProtocolMessage message = new TestDirectedMessage(MessageTransport.Indirect); this.Channel.PrepareResponse(message); } - [TestMethod, ExpectedException(typeof(ArgumentException))] + [TestCase, ExpectedException(typeof(ArgumentException))] public void SendInvalidMessageTransport() { IProtocolMessage message = new TestDirectedMessage((MessageTransport)100); this.Channel.PrepareResponse(message); } - [TestMethod] + [TestCase] public void SendIndirectMessage301Get() { TestDirectedMessage message = new TestDirectedMessage(MessageTransport.Indirect); GetStandardTestMessage(FieldFill.CompleteBeforeBindings, message); @@ -77,29 +77,29 @@ namespace DotNetOpenAuth.Test.Messaging { OutgoingWebResponse response = this.Channel.PrepareResponse(message); Assert.AreEqual(HttpStatusCode.Redirect, response.Status); - StringAssert.StartsWith(response.Headers[HttpResponseHeader.Location], "http://provider/path"); + StringAssert.StartsWith("http://provider/path", response.Headers[HttpResponseHeader.Location]); foreach (var pair in expected) { string key = MessagingUtilities.EscapeUriDataStringRfc3986(pair.Key); string value = MessagingUtilities.EscapeUriDataStringRfc3986(pair.Value); string substring = string.Format("{0}={1}", key, value); - StringAssert.Contains(response.Headers[HttpResponseHeader.Location], substring); + StringAssert.Contains(substring, response.Headers[HttpResponseHeader.Location]); } } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void SendIndirectMessage301GetNullMessage() { TestBadChannel badChannel = new TestBadChannel(false); badChannel.Create301RedirectResponse(null, new Dictionary<string, string>()); } - [TestMethod, ExpectedException(typeof(ArgumentException))] + [TestCase, ExpectedException(typeof(ArgumentException))] public void SendIndirectMessage301GetEmptyRecipient() { TestBadChannel badChannel = new TestBadChannel(false); var message = new TestDirectedMessage(MessageTransport.Indirect); badChannel.Create301RedirectResponse(message, new Dictionary<string, string>()); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void SendIndirectMessage301GetNullFields() { TestBadChannel badChannel = new TestBadChannel(false); var message = new TestDirectedMessage(MessageTransport.Indirect); @@ -107,7 +107,7 @@ namespace DotNetOpenAuth.Test.Messaging { badChannel.Create301RedirectResponse(message, null); } - [TestMethod] + [TestCase] public void SendIndirectMessageFormPost() { // We craft a very large message to force fallback to form POST. // We'll also stick some HTML reserved characters in the string value @@ -122,29 +122,29 @@ namespace DotNetOpenAuth.Test.Messaging { Assert.AreEqual(HttpStatusCode.OK, response.Status, "A form redirect should be an HTTP successful response."); Assert.IsNull(response.Headers[HttpResponseHeader.Location], "There should not be a redirection header in the response."); string body = response.Body; - StringAssert.Contains(body, "<form "); - StringAssert.Contains(body, "action=\"http://provider/path\""); - StringAssert.Contains(body, "method=\"post\""); - StringAssert.Contains(body, "<input type=\"hidden\" name=\"age\" value=\"15\" />"); - StringAssert.Contains(body, "<input type=\"hidden\" name=\"Location\" value=\"http://host/path\" />"); - StringAssert.Contains(body, "<input type=\"hidden\" name=\"Name\" value=\"" + HttpUtility.HtmlEncode(message.Name) + "\" />"); - StringAssert.Contains(body, ".submit()", "There should be some javascript to automate form submission."); + StringAssert.Contains("<form ", body); + StringAssert.Contains("action=\"http://provider/path\"", body); + StringAssert.Contains("method=\"post\"", body); + StringAssert.Contains("<input type=\"hidden\" name=\"age\" value=\"15\" />", body); + StringAssert.Contains("<input type=\"hidden\" name=\"Location\" value=\"http://host/path\" />", body); + StringAssert.Contains("<input type=\"hidden\" name=\"Name\" value=\"" + HttpUtility.HtmlEncode(message.Name) + "\" />", body); + StringAssert.Contains(".submit()", body, "There should be some javascript to automate form submission."); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void SendIndirectMessageFormPostNullMessage() { TestBadChannel badChannel = new TestBadChannel(false); badChannel.CreateFormPostResponse(null, new Dictionary<string, string>()); } - [TestMethod, ExpectedException(typeof(ArgumentException))] + [TestCase, ExpectedException(typeof(ArgumentException))] public void SendIndirectMessageFormPostEmptyRecipient() { TestBadChannel badChannel = new TestBadChannel(false); var message = new TestDirectedMessage(MessageTransport.Indirect); badChannel.CreateFormPostResponse(message, new Dictionary<string, string>()); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void SendIndirectMessageFormPostNullFields() { TestBadChannel badChannel = new TestBadChannel(false); var message = new TestDirectedMessage(MessageTransport.Indirect); @@ -159,7 +159,7 @@ namespace DotNetOpenAuth.Test.Messaging { /// Since this is a mock channel that doesn't actually formulate a direct message response, /// we just check that the right method was called. /// </remarks> - [TestMethod, ExpectedException(typeof(NotImplementedException), "SendDirectMessageResponse")] + [TestCase, ExpectedException(typeof(NotImplementedException))] public void SendDirectMessageResponse() { IProtocolMessage message = new TestDirectedMessage { Age = 15, @@ -169,25 +169,25 @@ namespace DotNetOpenAuth.Test.Messaging { this.Channel.PrepareResponse(message); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void SendIndirectMessageNull() { TestBadChannel badChannel = new TestBadChannel(false); badChannel.PrepareIndirectResponse(null); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void ReceiveNull() { TestBadChannel badChannel = new TestBadChannel(false); badChannel.Receive(null, null); } - [TestMethod] + [TestCase] public void ReceiveUnrecognizedMessage() { TestBadChannel badChannel = new TestBadChannel(false); Assert.IsNull(badChannel.Receive(new Dictionary<string, string>(), null)); } - [TestMethod] + [TestCase] public void ReadFromRequestWithContext() { var fields = GetStandardTestFields(FieldFill.AllRequired); TestMessage expectedMessage = GetStandardTestMessage(FieldFill.AllRequired); @@ -195,24 +195,24 @@ namespace DotNetOpenAuth.Test.Messaging { HttpContext.Current = new HttpContext(request, new HttpResponse(new StringWriter())); IProtocolMessage message = this.Channel.ReadFromRequest(); Assert.IsNotNull(message); - Assert.IsInstanceOfType(message, typeof(TestMessage)); + Assert.IsInstanceOf<TestMessage>(message); Assert.AreEqual(expectedMessage.Age, ((TestMessage)message).Age); } - [TestMethod, ExpectedException(typeof(InvalidOperationException))] + [TestCase, ExpectedException(typeof(InvalidOperationException))] public void ReadFromRequestNoContext() { HttpContext.Current = null; TestBadChannel badChannel = new TestBadChannel(false); badChannel.ReadFromRequest(); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void ReadFromRequestNull() { TestBadChannel badChannel = new TestBadChannel(false); badChannel.ReadFromRequest(null); } - [TestMethod] + [TestCase] public void SendReplayProtectedMessageSetsNonce() { TestReplayProtectedMessage message = new TestReplayProtectedMessage(MessageTransport.Indirect); message.Recipient = new Uri("http://localtest"); @@ -222,33 +222,33 @@ namespace DotNetOpenAuth.Test.Messaging { Assert.IsNotNull(((IReplayProtectedProtocolMessage)message).Nonce); } - [TestMethod, ExpectedException(typeof(InvalidSignatureException))] + [TestCase, ExpectedException(typeof(InvalidSignatureException))] public void ReceivedInvalidSignature() { this.Channel = CreateChannel(MessageProtections.TamperProtection); this.ParameterizedReceiveProtectedTest(DateTime.UtcNow, true); } - [TestMethod] + [TestCase] public void ReceivedReplayProtectedMessageJustOnce() { this.Channel = CreateChannel(MessageProtections.ReplayProtection); this.ParameterizedReceiveProtectedTest(DateTime.UtcNow, false); } - [TestMethod, ExpectedException(typeof(ReplayedMessageException))] + [TestCase, ExpectedException(typeof(ReplayedMessageException))] public void ReceivedReplayProtectedMessageTwice() { this.Channel = CreateChannel(MessageProtections.ReplayProtection); this.ParameterizedReceiveProtectedTest(DateTime.UtcNow, false); this.ParameterizedReceiveProtectedTest(DateTime.UtcNow, false); } - [TestMethod, ExpectedException(typeof(ProtocolException))] + [TestCase, ExpectedException(typeof(ProtocolException))] public void MessageExpirationWithoutTamperResistance() { new TestChannel( new TestMessageFactory(), new StandardExpirationBindingElement()); } - [TestMethod, ExpectedException(typeof(ProtocolException))] + [TestCase, ExpectedException(typeof(ProtocolException))] public void TooManyBindingElementsProvidingSameProtection() { Channel channel = new TestChannel( new TestMessageFactory(), @@ -258,7 +258,7 @@ namespace DotNetOpenAuth.Test.Messaging { accessor.ProcessOutgoingMessage(new TestSignedDirectedMessage()); } - [TestMethod] + [TestCase] public void BindingElementsOrdering() { IChannelBindingElement transformA = new MockTransformationBindingElement("a"); IChannelBindingElement transformB = new MockTransformationBindingElement("b"); @@ -282,20 +282,20 @@ namespace DotNetOpenAuth.Test.Messaging { Assert.AreSame(sign, channel.BindingElements[4]); } - [TestMethod, ExpectedException(typeof(UnprotectedMessageException))] + [TestCase, ExpectedException(typeof(UnprotectedMessageException))] public void InsufficientlyProtectedMessageSent() { var message = new TestSignedDirectedMessage(MessageTransport.Direct); message.Recipient = new Uri("http://localtest"); this.Channel.PrepareResponse(message); } - [TestMethod, ExpectedException(typeof(UnprotectedMessageException))] + [TestCase, ExpectedException(typeof(UnprotectedMessageException))] public void InsufficientlyProtectedMessageReceived() { this.Channel = CreateChannel(MessageProtections.None, MessageProtections.TamperProtection); this.ParameterizedReceiveProtectedTest(DateTime.Now, false); } - [TestMethod, ExpectedException(typeof(ProtocolException))] + [TestCase, ExpectedException(typeof(ProtocolException))] public void IncomingMessageMissingRequiredParameters() { var fields = GetStandardTestFields(FieldFill.IdentifiableButNotAllRequired); this.Channel.ReadFromRequest(CreateHttpRequestInfo("GET", fields)); diff --git a/src/DotNetOpenAuth.Test/Messaging/CollectionAssert.cs b/src/DotNetOpenAuth.Test/Messaging/CollectionAssert.cs index db136f5..506a6b2 100644 --- a/src/DotNetOpenAuth.Test/Messaging/CollectionAssert.cs +++ b/src/DotNetOpenAuth.Test/Messaging/CollectionAssert.cs @@ -11,7 +11,7 @@ namespace DotNetOpenAuth.Test.Messaging { using System.Diagnostics.Contracts; using System.Linq; using DotNetOpenAuth.Messaging; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; internal class CollectionAssert<T> { internal static void AreEquivalent(ICollection<T> expected, ICollection<T> actual) { diff --git a/src/DotNetOpenAuth.Test/Messaging/EnumerableCacheTests.cs b/src/DotNetOpenAuth.Test/Messaging/EnumerableCacheTests.cs index 55f4394..1c9f5a8 100644 --- a/src/DotNetOpenAuth.Test/Messaging/EnumerableCacheTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/EnumerableCacheTests.cs @@ -11,12 +11,12 @@ namespace DotNetOpenAuth.Test.Messaging { using System.Collections.ObjectModel; using System.Linq; using DotNetOpenAuth.Messaging; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; /// <summary> /// Tests for cached enumeration. /// </summary> - [TestClass] + [TestFixture] public class EnumerableCacheTests { /// <summary> /// The number of times the generator method's implementation is started. @@ -29,20 +29,15 @@ namespace DotNetOpenAuth.Test.Messaging { private int generatorCompleted; /// <summary> - /// Gets or sets the test context. - /// </summary> - public TestContext TestContext { get; set; } - - /// <summary> /// Sets up a test. /// </summary> - [TestInitialize] + [SetUp] public void Setup() { this.generatorInvocations = 0; this.generatorCompleted = 0; } - [TestMethod] + [TestCase] public void EnumerableCache() { // Baseline var generator = this.NumberGenerator(); @@ -63,7 +58,7 @@ namespace DotNetOpenAuth.Test.Messaging { CollectionAssert.AreEqual(list1, list4); } - [TestMethod] + [TestCase] public void GeneratesOnlyRequiredElements() { var generator = this.NumberGenerator().CacheGeneratedResults(); Assert.AreEqual(0, this.generatorInvocations); @@ -72,28 +67,28 @@ namespace DotNetOpenAuth.Test.Messaging { Assert.AreEqual(0, this.generatorCompleted, "Only taking part of the list should not have completed the generator."); } - [TestMethod] + [TestCase] public void PassThruDoubleCache() { var cache1 = this.NumberGenerator().CacheGeneratedResults(); var cache2 = cache1.CacheGeneratedResults(); Assert.AreSame(cache1, cache2, "Two caches were set up rather than just sharing the first one."); } - [TestMethod] + [TestCase] public void PassThruList() { var list = this.NumberGenerator().ToList(); var cache = list.CacheGeneratedResults(); Assert.AreSame(list, cache); } - [TestMethod] + [TestCase] public void PassThruArray() { var array = this.NumberGenerator().ToArray(); var cache = array.CacheGeneratedResults(); Assert.AreSame(array, cache); } - [TestMethod] + [TestCase] public void PassThruCollection() { var collection = new Collection<int>(); var cache = collection.CacheGeneratedResults(); @@ -103,7 +98,7 @@ namespace DotNetOpenAuth.Test.Messaging { /// <summary> /// Tests calling IEnumerator.Current before first call to MoveNext. /// </summary> - [TestMethod, ExpectedException(typeof(InvalidOperationException))] + [TestCase, ExpectedException(typeof(InvalidOperationException))] public void EnumerableCacheCurrentThrowsBefore() { var foo = this.NumberGenerator().CacheGeneratedResults().GetEnumerator().Current; } @@ -111,7 +106,7 @@ namespace DotNetOpenAuth.Test.Messaging { /// <summary> /// Tests calling IEnumerator.Current after MoveNext returns false. /// </summary> - [TestMethod, ExpectedException(typeof(InvalidOperationException))] + [TestCase, ExpectedException(typeof(InvalidOperationException))] public void EnumerableCacheCurrentThrowsAfter() { var enumerator = this.NumberGenerator().CacheGeneratedResults().GetEnumerator(); while (enumerator.MoveNext()) { diff --git a/src/DotNetOpenAuth.Test/Messaging/ErrorUtilitiesTests.cs b/src/DotNetOpenAuth.Test/Messaging/ErrorUtilitiesTests.cs index 36b6ae7..4408708 100644 --- a/src/DotNetOpenAuth.Test/Messaging/ErrorUtilitiesTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/ErrorUtilitiesTests.cs @@ -7,31 +7,31 @@ namespace DotNetOpenAuth.Test.Messaging { using System; using DotNetOpenAuth.Messaging; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; - [TestClass] + [TestFixture] public class ErrorUtilitiesTests { - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void VerifyArgumentNotNullThrows() { ErrorUtilities.VerifyArgumentNotNull(null, "someArg"); } - [TestMethod] + [TestCase] public void VerifyArgumentNotNullDoesNotThrow() { ErrorUtilities.VerifyArgumentNotNull("hi", "someArg"); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void VerifyNonZeroLengthOnNull() { ErrorUtilities.VerifyNonZeroLength(null, "someArg"); } - [TestMethod, ExpectedException(typeof(ArgumentException))] + [TestCase, ExpectedException(typeof(ArgumentException))] public void VerifyNonZeroLengthOnEmpty() { ErrorUtilities.VerifyNonZeroLength(string.Empty, "someArg"); } - [TestMethod] + [TestCase] public void VerifyNonZeroLengthOnNonEmpty() { ErrorUtilities.VerifyNonZeroLength("some Value", "someArg"); } diff --git a/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs b/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs index fd77746..0085d59 100644 --- a/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/HttpRequestInfoTests.cs @@ -9,17 +9,17 @@ namespace DotNetOpenAuth.Test.Messaging { using System.Collections.Specialized; using System.Web; using DotNetOpenAuth.Messaging; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; - [TestClass] + [TestFixture] public class HttpRequestInfoTests : TestBase { - [TestMethod] + [TestCase] public void CtorDefault() { HttpRequestInfo info = new HttpRequestInfo(); Assert.AreEqual("GET", info.HttpMethod); } - [TestMethod] + [TestCase] public void CtorRequest() { HttpRequest request = new HttpRequest("file", "http://someserver?a=b", "a=b"); ////request.Headers["headername"] = "headervalue"; // PlatformNotSupportedException prevents us mocking this up @@ -33,7 +33,7 @@ namespace DotNetOpenAuth.Test.Messaging { } // All these tests are ineffective because ServerVariables[] cannot be set. - ////[TestMethod] + ////[TestCase] ////public void CtorRequestWithDifferentPublicHttpHost() { //// HttpRequest request = new HttpRequest("file", "http://someserver?a=b", "a=b"); //// request.ServerVariables["HTTP_HOST"] = "publichost"; @@ -44,7 +44,7 @@ namespace DotNetOpenAuth.Test.Messaging { //// Assert.AreEqual(request.QueryString["a"], info.QueryString["a"]); ////} - ////[TestMethod] + ////[TestCase] ////public void CtorRequestWithDifferentPublicHttpsHost() { //// HttpRequest request = new HttpRequest("file", "https://someserver?a=b", "a=b"); //// request.ServerVariables["HTTP_HOST"] = "publichost"; @@ -55,7 +55,7 @@ namespace DotNetOpenAuth.Test.Messaging { //// Assert.AreEqual(request.QueryString["a"], info.QueryString["a"]); ////} - ////[TestMethod] + ////[TestCase] ////public void CtorRequestWithDifferentPublicHostNonstandardPort() { //// HttpRequest request = new HttpRequest("file", "http://someserver?a=b", "a=b"); //// request.ServerVariables["HTTP_HOST"] = "publichost:550"; @@ -66,7 +66,7 @@ namespace DotNetOpenAuth.Test.Messaging { //// Assert.AreEqual(request.QueryString["a"], info.QueryString["a"]); ////} - ////[TestMethod] + ////[TestCase] ////public void CtorRequestWithDifferentPublicIPv6Host() { //// HttpRequest request = new HttpRequest("file", "http://[fe80::587e:c6e5:d3aa:657a]:8089/v3.1/", ""); //// request.ServerVariables["HTTP_HOST"] = "[fe80::587e:c6e5:d3aa:657b]:8089"; @@ -80,7 +80,7 @@ namespace DotNetOpenAuth.Test.Messaging { /// Checks that a property dependent on another null property /// doesn't generate a NullReferenceException. /// </summary> - [TestMethod] + [TestCase] public void QueryBeforeSettingUrl() { HttpRequestInfo info = new HttpRequestInfo(); Assert.IsNull(info.Query); @@ -89,7 +89,7 @@ namespace DotNetOpenAuth.Test.Messaging { /// <summary> /// Verifies that looking up a querystring variable is gracefully handled without a query in the URL. /// </summary> - [TestMethod] + [TestCase] public void QueryStringLookupWithoutQuery() { HttpRequestInfo info = new HttpRequestInfo(); Assert.IsNull(info.QueryString["hi"]); @@ -98,7 +98,7 @@ namespace DotNetOpenAuth.Test.Messaging { /// <summary> /// Verifies SSL forwarders are correctly handled when they supply X_FORWARDED_PROTO and HOST /// </summary> - [TestMethod] + [TestCase] public void GetPublicFacingUrlSSLForwarder1() { HttpRequest req = new HttpRequest("a.aspx", "http://someinternalhost/a.aspx?a=b", "a=b"); var serverVariables = new NameValueCollection(); @@ -112,7 +112,7 @@ namespace DotNetOpenAuth.Test.Messaging { /// <summary> /// Verifies SSL forwarders are correctly handled when they supply X_FORWARDED_PROTO and HOST:port /// </summary> - [TestMethod] + [TestCase] public void GetPublicFacingUrlSSLForwarder2() { HttpRequest req = new HttpRequest("a.aspx", "http://someinternalhost/a.aspx?a=b", "a=b"); var serverVariables = new NameValueCollection(); @@ -126,7 +126,7 @@ namespace DotNetOpenAuth.Test.Messaging { /// <summary> /// Verifies SSL forwarders are correctly handled when they supply just HOST /// </summary> - [TestMethod] + [TestCase] public void GetPublicFacingUrlSSLForwarder3() { HttpRequest req = new HttpRequest("a.aspx", "http://someinternalhost/a.aspx?a=b", "a=b"); var serverVariables = new NameValueCollection(); @@ -139,7 +139,7 @@ namespace DotNetOpenAuth.Test.Messaging { /// <summary> /// Verifies SSL forwarders are correctly handled when they supply just HOST:port /// </summary> - [TestMethod] + [TestCase] public void GetPublicFacingUrlSSLForwarder4() { HttpRequest req = new HttpRequest("a.aspx", "http://someinternalhost/a.aspx?a=b", "a=b"); var serverVariables = new NameValueCollection(); diff --git a/src/DotNetOpenAuth.Test/Messaging/MessageSerializerTests.cs b/src/DotNetOpenAuth.Test/Messaging/MessageSerializerTests.cs index 481a715..91cccf1 100644 --- a/src/DotNetOpenAuth.Test/Messaging/MessageSerializerTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/MessageSerializerTests.cs @@ -9,30 +9,30 @@ namespace DotNetOpenAuth.Test.Messaging { using System.Collections.Generic; using System.Xml; using DotNetOpenAuth.Messaging; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; /// <summary> /// Tests for the <see cref="MessageSerializer"/> class. /// </summary> - [TestClass()] + [TestFixture()] public class MessageSerializerTests : MessagingTestBase { - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void SerializeNull() { var serializer = MessageSerializer.Get(typeof(Mocks.TestMessage)); serializer.Serialize(null); } - [TestMethod, ExpectedException(typeof(ArgumentException))] + [TestCase, ExpectedException(typeof(ArgumentException))] public void GetInvalidMessageType() { MessageSerializer.Get(typeof(string)); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void GetNullType() { MessageSerializer.Get(null); } - [TestMethod()] + [TestCase()] public void SerializeTest() { var serializer = MessageSerializer.Get(typeof(Mocks.TestMessage)); var message = GetStandardTestMessage(FieldFill.CompleteBeforeBindings); @@ -52,13 +52,13 @@ namespace DotNetOpenAuth.Test.Messaging { Assert.IsFalse(actual.ContainsKey("EmptyMember")); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void DeserializeNull() { var serializer = MessageSerializer.Get(typeof(Mocks.TestMessage)); serializer.Deserialize(null, null); } - [TestMethod] + [TestCase] public void DeserializeSimple() { var serializer = MessageSerializer.Get(typeof(Mocks.TestMessage)); Dictionary<string, string> fields = new Dictionary<string, string>(StringComparer.Ordinal); @@ -81,7 +81,7 @@ namespace DotNetOpenAuth.Test.Messaging { /// The element sorting rules are first inheritance order, then alphabetical order. /// This test validates correct behavior on both. /// </remarks> - [TestMethod] + [TestCase] public void DeserializeVerifyElementOrdering() { var serializer = MessageSerializer.Get(typeof(Mocks.TestDerivedMessage)); Dictionary<string, string> fields = new Dictionary<string, string>(StringComparer.Ordinal); @@ -105,7 +105,7 @@ namespace DotNetOpenAuth.Test.Messaging { Assert.AreEqual("privateValue", actual.PrivatePropertyAccessor); } - [TestMethod] + [TestCase] public void DeserializeWithExtraFields() { var serializer = MessageSerializer.Get(typeof(Mocks.TestMessage)); Dictionary<string, string> fields = new Dictionary<string, string>(StringComparer.Ordinal); @@ -122,7 +122,7 @@ namespace DotNetOpenAuth.Test.Messaging { Assert.IsNull(actual.EmptyMember); } - [TestMethod, ExpectedException(typeof(ProtocolException))] + [TestCase, ExpectedException(typeof(ProtocolException))] public void DeserializeInvalidMessage() { IProtocolMessage message = new Mocks.TestDirectedMessage(); var serializer = MessageSerializer.Get(message.GetType()); diff --git a/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs b/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs index accb182..72f3359 100644 --- a/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs +++ b/src/DotNetOpenAuth.Test/Messaging/MessagingTestBase.cs @@ -13,7 +13,7 @@ namespace DotNetOpenAuth.Test { using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.Test.Mocks; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; /// <summary> /// The base class that all messaging test classes inherit from. @@ -45,7 +45,7 @@ namespace DotNetOpenAuth.Test { internal Channel Channel { get; set; } - [TestInitialize] + [SetUp] public override void SetUp() { base.SetUp(); @@ -156,7 +156,7 @@ namespace DotNetOpenAuth.Test { IDirectedProtocolMessage requestMessage = this.Channel.ReadFromRequest(CreateHttpRequestInfo(method, fields)); Assert.IsNotNull(requestMessage); - Assert.IsInstanceOfType(requestMessage, typeof(TestMessage)); + Assert.IsInstanceOf<TestMessage>(requestMessage); TestMessage actualMessage = (TestMessage)requestMessage; Assert.AreEqual(expectedMessage.Age, actualMessage.Age); Assert.AreEqual(expectedMessage.Name, actualMessage.Name); @@ -174,7 +174,7 @@ namespace DotNetOpenAuth.Test { } IProtocolMessage requestMessage = this.Channel.ReadFromRequest(CreateHttpRequestInfo("GET", fields)); Assert.IsNotNull(requestMessage); - Assert.IsInstanceOfType(requestMessage, typeof(TestSignedDirectedMessage)); + Assert.IsInstanceOf<TestSignedDirectedMessage>(requestMessage); TestSignedDirectedMessage actualMessage = (TestSignedDirectedMessage)requestMessage; Assert.AreEqual(expectedMessage.Age, actualMessage.Age); Assert.AreEqual(expectedMessage.Name, actualMessage.Name); diff --git a/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs b/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs index 4fc89a7..2b0e8f9 100644 --- a/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs @@ -15,11 +15,11 @@ namespace DotNetOpenAuth.Test.Messaging using System.Web; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Test.Mocks; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; - [TestClass] + [TestFixture] public class MessagingUtilitiesTests : TestBase { - [TestMethod] + [TestCase] public void CreateQueryString() { var args = new Dictionary<string, string>(); args.Add("a", "b"); @@ -27,17 +27,17 @@ namespace DotNetOpenAuth.Test.Messaging Assert.AreEqual("a=b&c%2Fd=e%2Ff", MessagingUtilities.CreateQueryString(args)); } - [TestMethod] + [TestCase] public void CreateQueryStringEmptyCollection() { Assert.AreEqual(0, MessagingUtilities.CreateQueryString(new Dictionary<string, string>()).Length); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void CreateQueryStringNullDictionary() { MessagingUtilities.CreateQueryString(null); } - [TestMethod] + [TestCase] public void AppendQueryArgs() { UriBuilder uri = new UriBuilder("http://baseline.org/page"); var args = new Dictionary<string, string>(); @@ -51,17 +51,17 @@ namespace DotNetOpenAuth.Test.Messaging Assert.AreEqual("http://baseline.org/page?a=b&c%2Fd=e%2Ff&g=h", uri.Uri.AbsoluteUri); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void AppendQueryArgsNullUriBuilder() { MessagingUtilities.AppendQueryArgs(null, new Dictionary<string, string>()); } - [TestMethod] + [TestCase] public void AppendQueryArgsNullDictionary() { MessagingUtilities.AppendQueryArgs(new UriBuilder(), null); } - [TestMethod] + [TestCase] public void ToDictionary() { NameValueCollection nvc = new NameValueCollection(); nvc["a"] = "b"; @@ -73,7 +73,7 @@ namespace DotNetOpenAuth.Test.Messaging Assert.AreEqual(nvc["c"], actual["c"]); } - [TestMethod, ExpectedException(typeof(ArgumentException))] + [TestCase, ExpectedException(typeof(ArgumentException))] public void ToDictionaryWithNullKey() { NameValueCollection nvc = new NameValueCollection(); nvc[null] = "a"; @@ -81,7 +81,7 @@ namespace DotNetOpenAuth.Test.Messaging nvc.ToDictionary(true); } - [TestMethod] + [TestCase] public void ToDictionaryWithSkippedNullKey() { NameValueCollection nvc = new NameValueCollection(); nvc[null] = "a"; @@ -91,27 +91,27 @@ namespace DotNetOpenAuth.Test.Messaging Assert.AreEqual(nvc["b"], dictionary["b"]); } - [TestMethod] + [TestCase] public void ToDictionaryNull() { Assert.IsNull(MessagingUtilities.ToDictionary(null)); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void ApplyHeadersToResponseNullAspNetResponse() { MessagingUtilities.ApplyHeadersToResponse(new WebHeaderCollection(), (HttpResponse)null); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void ApplyHeadersToResponseNullListenerResponse() { MessagingUtilities.ApplyHeadersToResponse(new WebHeaderCollection(), (HttpListenerResponse)null); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void ApplyHeadersToResponseNullHeaders() { MessagingUtilities.ApplyHeadersToResponse(null, new HttpResponse(new StringWriter())); } - [TestMethod] + [TestCase] public void ApplyHeadersToResponse() { var headers = new WebHeaderCollection(); headers[HttpResponseHeader.ContentType] = "application/binary"; @@ -128,7 +128,7 @@ namespace DotNetOpenAuth.Test.Messaging /// <remarks> /// The tests in this method come from http://wiki.oauth.net/TestCases /// </remarks> - [TestMethod] + [TestCase] public void EscapeUriDataStringRfc3986Tests() { Assert.AreEqual("abcABC123", MessagingUtilities.EscapeUriDataStringRfc3986("abcABC123")); Assert.AreEqual("-._~", MessagingUtilities.EscapeUriDataStringRfc3986("-._~")); @@ -145,7 +145,7 @@ namespace DotNetOpenAuth.Test.Messaging /// <summary> /// Verifies the overall format of the multipart POST is correct. /// </summary> - [TestMethod] + [TestCase] public void PostMultipart() { var httpHandler = new TestWebRequestHandler(); bool callbackTriggered = false; @@ -174,7 +174,7 @@ namespace DotNetOpenAuth.Test.Messaging /// <summary> /// Verifies proper behavior of GetHttpVerb /// </summary> - [TestMethod] + [TestCase] public void GetHttpVerbTest() { Assert.AreEqual("GET", MessagingUtilities.GetHttpVerb(HttpDeliveryMethods.GetRequest)); Assert.AreEqual("POST", MessagingUtilities.GetHttpVerb(HttpDeliveryMethods.PostRequest)); @@ -192,7 +192,7 @@ namespace DotNetOpenAuth.Test.Messaging /// <summary> /// Verifies proper behavior of GetHttpVerb on invalid input. /// </summary> - [TestMethod, ExpectedException(typeof(ArgumentException))] + [TestCase, ExpectedException(typeof(ArgumentException))] public void GetHttpVerbOutOfRangeTest() { MessagingUtilities.GetHttpVerb(HttpDeliveryMethods.PutRequest | HttpDeliveryMethods.PostRequest); } @@ -200,7 +200,7 @@ namespace DotNetOpenAuth.Test.Messaging /// <summary> /// Verifies proper behavior of GetHttpDeliveryMethod /// </summary> - [TestMethod] + [TestCase] public void GetHttpDeliveryMethodTest() { Assert.AreEqual(HttpDeliveryMethods.GetRequest, MessagingUtilities.GetHttpDeliveryMethod("GET")); Assert.AreEqual(HttpDeliveryMethods.PostRequest, MessagingUtilities.GetHttpDeliveryMethod("POST")); @@ -212,7 +212,7 @@ namespace DotNetOpenAuth.Test.Messaging /// <summary> /// Verifies proper behavior of GetHttpDeliveryMethod for an unexpected input /// </summary> - [TestMethod, ExpectedException(typeof(ArgumentException))] + [TestCase, ExpectedException(typeof(ArgumentException))] public void GetHttpDeliveryMethodOutOfRangeTest() { MessagingUtilities.GetHttpDeliveryMethod("UNRECOGNIZED"); } diff --git a/src/DotNetOpenAuth.Test/Messaging/MultipartPostPartTests.cs b/src/DotNetOpenAuth.Test/Messaging/MultipartPostPartTests.cs index 57614ba..08524b2 100644 --- a/src/DotNetOpenAuth.Test/Messaging/MultipartPostPartTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/MultipartPostPartTests.cs @@ -11,14 +11,14 @@ namespace DotNetOpenAuth.Test.Messaging { using System.IO; using System.Net; using DotNetOpenAuth.Messaging; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; - [TestClass] + [TestFixture] public class MultipartPostPartTests : TestBase { /// <summary> /// Verifies that the Length property matches the length actually serialized. /// </summary> - [TestMethod] + [TestCase] public void FormDataSerializeMatchesLength() { var part = MultipartPostPart.CreateFormPart("a", "b"); VerifyLength(part); @@ -27,7 +27,7 @@ namespace DotNetOpenAuth.Test.Messaging { /// <summary> /// Verifies that the length property matches the length actually serialized. /// </summary> - [TestMethod] + [TestCase] public void FileSerializeMatchesLength() { using (TempFileCollection tfc = new TempFileCollection()) { string file = tfc.AddExtension(".txt"); @@ -40,7 +40,7 @@ namespace DotNetOpenAuth.Test.Messaging { /// <summary> /// Verifies file multiparts identify themselves as files and not merely form-data. /// </summary> - [TestMethod] + [TestCase] public void FilePartAsFile() { var part = MultipartPostPart.CreateFormFilePart("somename", "somefile", "plain/text", new MemoryStream()); Assert.AreEqual("file", part.ContentDisposition); @@ -49,7 +49,7 @@ namespace DotNetOpenAuth.Test.Messaging { /// <summary> /// Verifies MultiPartPost sends the right number of bytes. /// </summary> - [TestMethod] + [TestCase] public void MultiPartPostAscii() { using (TempFileCollection tfc = new TempFileCollection()) { string file = tfc.AddExtension("txt"); @@ -64,7 +64,7 @@ namespace DotNetOpenAuth.Test.Messaging { /// <summary> /// Verifies MultiPartPost sends the right number of bytes. /// </summary> - [TestMethod] + [TestCase] public void MultiPartPostMultiByteCharacters() { using (TempFileCollection tfc = new TempFileCollection()) { string file = tfc.AddExtension("txt"); @@ -94,9 +94,9 @@ namespace DotNetOpenAuth.Test.Messaging { bool posted = false; handler.Callback = req => { foreach (string header in req.Headers) { - TestContext.WriteLine("{0}: {1}", header, req.Headers[header]); + TestUtilities.TestLogger.InfoFormat("{0}: {1}", header, req.Headers[header]); } - TestContext.WriteLine(handler.RequestEntityAsString); + TestUtilities.TestLogger.InfoFormat(handler.RequestEntityAsString); Assert.AreEqual(req.ContentLength, handler.RequestEntityStream.Length); posted = true; return null; diff --git a/src/DotNetOpenAuth.Test/Messaging/OutgoingWebResponseTests.cs b/src/DotNetOpenAuth.Test/Messaging/OutgoingWebResponseTests.cs index 2923af4..10045de 100644 --- a/src/DotNetOpenAuth.Test/Messaging/OutgoingWebResponseTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/OutgoingWebResponseTests.cs @@ -9,14 +9,14 @@ namespace DotNetOpenAuth.Test.Messaging { using System.Net.Mime; using System.Text; using DotNetOpenAuth.Messaging; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; - [TestClass] + [TestFixture] public class OutgoingWebResponseTests { /// <summary> /// Verifies that setting the Body property correctly converts to a byte stream. /// </summary> - [TestMethod] + [TestCase] public void SetBodyToByteStream() { var response = new OutgoingWebResponse(); string stringValue = "abc"; diff --git a/src/DotNetOpenAuth.Test/Messaging/ProtocolExceptionTests.cs b/src/DotNetOpenAuth.Test/Messaging/ProtocolExceptionTests.cs index 430b929..c9e3d24 100644 --- a/src/DotNetOpenAuth.Test/Messaging/ProtocolExceptionTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/ProtocolExceptionTests.cs @@ -7,22 +7,22 @@ namespace DotNetOpenAuth.Test.Messaging { using System; using DotNetOpenAuth.Messaging; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; - [TestClass] + [TestFixture] public class ProtocolExceptionTests : TestBase { - [TestMethod] + [TestCase] public void CtorDefault() { ProtocolException ex = new ProtocolException(); } - [TestMethod] + [TestCase] public void CtorWithTextMessage() { ProtocolException ex = new ProtocolException("message"); Assert.AreEqual("message", ex.Message); } - [TestMethod] + [TestCase] public void CtorWithTextMessageAndInnerException() { Exception innerException = new Exception(); ProtocolException ex = new ProtocolException("message", innerException); @@ -30,14 +30,14 @@ namespace DotNetOpenAuth.Test.Messaging { Assert.AreSame(innerException, ex.InnerException); } - [TestMethod] + [TestCase] public void CtorWithProtocolMessage() { IProtocolMessage message = new Mocks.TestDirectedMessage(); ProtocolException ex = new ProtocolException("message", message); Assert.AreSame(message, ex.FaultedMessage); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void CtorWithNullProtocolMessage() { new ProtocolException("message", (IProtocolMessage)null); } diff --git a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs index 76c454a..e57df65 100644 --- a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDescriptionTests.cs @@ -8,26 +8,26 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { using System; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Reflection; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; - [TestClass] + [TestFixture] public class MessageDescriptionTests : MessagingTestBase { - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void CtorNullType() { new MessageDescription(null, new Version(1, 0)); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void CtorNullVersion() { new MessageDescription(typeof(Mocks.TestMessage), null); } - [TestMethod, ExpectedException(typeof(ArgumentException))] + [TestCase, ExpectedException(typeof(ArgumentException))] public void CtorNonMessageType() { new MessageDescription(typeof(string), new Version(1, 0)); } - [TestMethod] + [TestCase] public void MultiVersionedMessageTest() { var v10 = new MessageDescription(typeof(MultiVersionMessage), new Version(1, 0)); var v20 = new MessageDescription(typeof(MultiVersionMessage), new Version(2, 0)); diff --git a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs index b9e7436..9e3f4c5 100644 --- a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessageDictionaryTests.cs @@ -12,20 +12,20 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { using System.Xml; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Reflection; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; - [TestClass] + [TestFixture] public class MessageDictionaryTests : MessagingTestBase { private Mocks.TestMessage message; - [TestInitialize] + [SetUp] public override void SetUp() { base.SetUp(); this.message = new Mocks.TestDirectedMessage(); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void CtorNull() { this.MessageDescriptions.GetAccessor(null); } @@ -33,7 +33,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// A test for System.Collections.Generic.IDictionary<System.String,System.String>.Values /// </summary> - [TestMethod] + [TestCase] public void Values() { IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message); Collection<string> expected = new Collection<string> { @@ -59,7 +59,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// A test for System.Collections.Generic.IDictionary<System.String,System.String>.Keys /// </summary> - [TestMethod] + [TestCase] public void Keys() { // We expect that non-nullable value type fields will automatically have keys // in the dictionary for them. @@ -80,7 +80,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// A test for System.Collections.Generic.IDictionary<System.String,System.String>.Item /// </summary> - [TestMethod] + [TestCase] public void Item() { IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message); @@ -103,7 +103,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// A test for System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.String,System.String<<.IsReadOnly /// </summary> - [TestMethod] + [TestCase] public void IsReadOnly() { ICollection<KeyValuePair<string, string>> target = this.MessageDescriptions.GetAccessor(this.message); Assert.IsFalse(target.IsReadOnly); @@ -112,7 +112,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// A test for System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.String,System.String<<.Count /// </summary> - [TestMethod] + [TestCase] public void Count() { ICollection<KeyValuePair<string, string>> target = this.MessageDescriptions.GetAccessor(this.message); IDictionary<string, string> targetDictionary = (IDictionary<string, string>)target; @@ -124,7 +124,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// A test for System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.String,System.String<<.GetEnumerator /// </summary> - [TestMethod] + [TestCase] public void GetEnumerator() { IEnumerable<KeyValuePair<string, string>> target = this.MessageDescriptions.GetAccessor(this.message); IDictionary<string, string> targetDictionary = (IDictionary<string, string>)target; @@ -147,7 +147,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { Assert.IsTrue(keysLast == valuesLast && keysLast == actualLast); } - [TestMethod] + [TestCase] public void GetEnumeratorUntyped() { IEnumerable target = this.MessageDescriptions.GetAccessor(this.message); IDictionary<string, string> targetDictionary = (IDictionary<string, string>)target; @@ -174,7 +174,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// A test for System.Collections.Generic.IDictionary<System.String,System.String>.TryGetValue /// </summary> - [TestMethod] + [TestCase] public void TryGetValue() { IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message); this.message.Name = "andrew"; @@ -194,7 +194,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// A test for System.Collections.Generic.IDictionary<System.String,System.String>.Remove /// </summary> - [TestMethod] + [TestCase] public void RemoveTest1() { IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message); this.message.Name = "andrew"; @@ -211,7 +211,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// A test for System.Collections.Generic.IDictionary<System.String,System.String>.ContainsKey /// </summary> - [TestMethod] + [TestCase] public void ContainsKey() { IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message); Assert.IsTrue(target.ContainsKey("age"), "Value type declared element should have a key."); @@ -225,7 +225,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// A test for System.Collections.Generic.IDictionary<System.String,System.String>.Add /// </summary> - [TestMethod] + [TestCase] public void AddByKeyAndValue() { IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message); target.Add("extra", "value"); @@ -234,7 +234,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { Assert.AreEqual("Andrew", this.message.Name); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void AddNullValue() { IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message); target.Add("extra", null); @@ -243,35 +243,35 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// A test for System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.String,System.String<<.Add /// </summary> - [TestMethod] + [TestCase] public void AddByKeyValuePair() { IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message); target.Add(new KeyValuePair<string, string>("extra", "value")); Assert.IsTrue(target.Contains(new KeyValuePair<string, string>("extra", "value"))); } - [TestMethod, ExpectedException(typeof(ArgumentException))] + [TestCase, ExpectedException(typeof(ArgumentException))] public void AddExtraFieldThatAlreadyExists() { IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message); target.Add("extra", "value"); target.Add("extra", "value"); } - [TestMethod, ExpectedException(typeof(ArgumentException))] + [TestCase, ExpectedException(typeof(ArgumentException))] public void AddDeclaredValueThatAlreadyExists() { IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message); target.Add("Name", "andrew"); target.Add("Name", "andrew"); } - [TestMethod] + [TestCase] public void DefaultReferenceTypeDeclaredPropertyHasNoKey() { IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message); Assert.IsFalse(target.ContainsKey("Name"), "A null value should result in no key."); Assert.IsFalse(target.Keys.Contains("Name"), "A null value should result in no key."); } - [TestMethod] + [TestCase] public void RemoveStructDeclaredProperty() { IDictionary<string, string> target = this.MessageDescriptions.GetAccessor(this.message); this.message.Age = 5; @@ -284,7 +284,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// A test for System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.String,System.String<<.Remove /// </summary> - [TestMethod] + [TestCase] public void RemoveByKeyValuePair() { ICollection<KeyValuePair<string, string>> target = this.MessageDescriptions.GetAccessor(this.message); this.message.Name = "Andrew"; @@ -297,7 +297,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// A test for System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.String,System.String<<.CopyTo /// </summary> - [TestMethod] + [TestCase] public void CopyTo() { ICollection<KeyValuePair<string, string>> target = this.MessageDescriptions.GetAccessor(this.message); IDictionary<string, string> targetAsDictionary = (IDictionary<string, string>)target; @@ -314,7 +314,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// A test for System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.String,System.String<<.Contains /// </summary> - [TestMethod] + [TestCase] public void ContainsKeyValuePair() { ICollection<KeyValuePair<string, string>> target = this.MessageDescriptions.GetAccessor(this.message); IDictionary<string, string> targetAsDictionary = (IDictionary<string, string>)target; @@ -330,7 +330,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// A test for System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.String,System.String<<.Clear /// </summary> - [TestMethod] + [TestCase] public void ClearValues() { MessageDictionary target = this.MessageDescriptions.GetAccessor(this.message); IDictionary<string, string> targetAsDictionary = (IDictionary<string, string>)target; @@ -347,7 +347,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { /// <summary> /// Verifies that the Clear method throws the expected exception. /// </summary> - [TestMethod, ExpectedException(typeof(NotSupportedException))] + [TestCase, ExpectedException(typeof(NotSupportedException))] public void Clear() { MessageDictionary target = this.MessageDescriptions.GetAccessor(this.message); target.Clear(); diff --git a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessagePartTests.cs b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessagePartTests.cs index 19e6a82..66237e7 100644 --- a/src/DotNetOpenAuth.Test/Messaging/Reflection/MessagePartTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/Reflection/MessagePartTests.cs @@ -12,42 +12,47 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Reflection; using DotNetOpenAuth.Test.Mocks; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; - [TestClass] + [TestFixture] public class MessagePartTests : MessagingTestBase { - [TestMethod, ExpectedException(typeof(ArgumentException))] + [TestCase, ExpectedException(typeof(ArgumentException))] public void OptionalNonNullableStruct() { this.ParameterizedMessageTypeTest(typeof(MessageWithNonNullableOptionalStruct)); } - [TestMethod] + [TestCase] public void RequiredNonNullableStruct() { this.ParameterizedMessageTypeTest(typeof(MessageWithNonNullableRequiredStruct)); } - [TestMethod] + [TestCase] public void OptionalNullableStruct() { - this.ParameterizedMessageTypeTest(typeof(MessageWithNullableOptionalStruct)); + var message = new MessageWithNullableOptionalStruct(); + var part = this.ParameterizedMessageTypeTest(message.GetType()); + + Assert.IsNull(part.GetValue(message)); + part.SetValue(message, "3"); + Assert.AreEqual("3", part.GetValue(message)); } - [TestMethod] + [TestCase] public void RequiredNullableStruct() { this.ParameterizedMessageTypeTest(typeof(MessageWithNullableRequiredStruct)); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void CtorNullMember() { new MessagePart(null, new MessagePartAttribute()); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void CtorNullAttribute() { PropertyInfo field = typeof(MessageWithNullableOptionalStruct).GetProperty("OptionalInt", BindingFlags.NonPublic | BindingFlags.Instance); new MessagePart(field, null); } - [TestMethod] + [TestCase] public void SetValue() { var message = new MessageWithNonNullableRequiredStruct(); MessagePart part = this.ParameterizedMessageTypeTest(message.GetType()); @@ -55,7 +60,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { Assert.AreEqual(5, message.OptionalInt); } - [TestMethod] + [TestCase] public void GetValue() { var message = new MessageWithNonNullableRequiredStruct(); message.OptionalInt = 8; @@ -63,7 +68,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { Assert.AreEqual("8", part.GetValue(message)); } - [TestMethod] + [TestCase] public void Base64Member() { var message = new MessageWithBase64EncodedString(); message.LastName = "andrew"; @@ -73,7 +78,7 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { Assert.AreEqual("arnott", message.LastName); } - [TestMethod] + [TestCase] public void ConstantFieldMemberValidValues() { var message = new MessageWithConstantField(); MessagePart part = GetMessagePart(message.GetType(), "ConstantField"); @@ -82,20 +87,20 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { Assert.AreEqual("abc", part.GetValue(message)); } - [TestMethod, ExpectedException(typeof(ProtocolException))] + [TestCase, ExpectedException(typeof(ProtocolException))] public void ConstantFieldMemberInvalidValues() { var message = new MessageWithConstantField(); MessagePart part = GetMessagePart(message.GetType(), "ConstantField"); part.SetValue(message, "def"); } - [TestMethod, ExpectedException(typeof(ArgumentException))] + [TestCase, ExpectedException(typeof(ArgumentException))] public void NonFieldOrPropertyMember() { MemberInfo method = typeof(MessageWithNullableOptionalStruct).GetMethod("Equals", BindingFlags.Public | BindingFlags.Instance); new MessagePart(method, new MessagePartAttribute()); } - [TestMethod] + [TestCase] public void RequiredMinAndMaxVersions() { Type messageType = typeof(MessageWithMinAndMaxVersionParts); FieldInfo newIn2Field = messageType.GetField("NewIn2", BindingFlags.Public | BindingFlags.Instance); diff --git a/src/DotNetOpenAuth.Test/Messaging/Reflection/ValueMappingTests.cs b/src/DotNetOpenAuth.Test/Messaging/Reflection/ValueMappingTests.cs index c4a79b5..60c8bc3 100644 --- a/src/DotNetOpenAuth.Test/Messaging/Reflection/ValueMappingTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/Reflection/ValueMappingTests.cs @@ -7,18 +7,18 @@ namespace DotNetOpenAuth.Test.Messaging.Reflection { using System; using DotNetOpenAuth.Messaging.Reflection; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; - [TestClass] + [TestFixture] public class ValueMappingTests { - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void CtorNullToString() { - new ValueMapping(null, str => new object()); + new ValueMapping(null, null, str => new object()); } - [TestMethod, ExpectedException(typeof(ArgumentNullException))] + [TestCase, ExpectedException(typeof(ArgumentNullException))] public void CtorNullToObject() { - new ValueMapping(obj => obj.ToString(), null); + new ValueMapping(obj => obj.ToString(), null, null); } } } diff --git a/src/DotNetOpenAuth.Test/Messaging/ResponseTests.cs b/src/DotNetOpenAuth.Test/Messaging/ResponseTests.cs index 89d165a..63be45a 100644 --- a/src/DotNetOpenAuth.Test/Messaging/ResponseTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/ResponseTests.cs @@ -9,17 +9,17 @@ namespace DotNetOpenAuth.Test.Messaging { using System.IO; using System.Web; using DotNetOpenAuth.Messaging; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; - [TestClass] + [TestFixture] public class ResponseTests : TestBase { - [TestMethod, ExpectedException(typeof(InvalidOperationException))] + [TestCase, ExpectedException(typeof(InvalidOperationException))] public void SendWithoutAspNetContext() { HttpContext.Current = null; new OutgoingWebResponse().Send(); } - [TestMethod] + [TestCase] public void Send() { StringWriter writer = new StringWriter(); HttpRequest httpRequest = new HttpRequest("file", "http://server", string.Empty); |