summaryrefslogtreecommitdiffstats
path: root/src/DotNetOAuth.Test
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOAuth.Test')
-rw-r--r--src/DotNetOAuth.Test/DotNetOAuth.Test.csproj6
-rw-r--r--src/DotNetOAuth.Test/Messaging/ChannelTests.cs46
-rw-r--r--src/DotNetOAuth.Test/Messaging/MessageSerializerTests.cs (renamed from src/DotNetOAuth.Test/Messaging/MessageSerializerTest.cs)19
-rw-r--r--src/DotNetOAuth.Test/Mocks/TestChannel.cs35
-rw-r--r--src/DotNetOAuth.Test/Mocks/TestMessageTypeProvider.cs32
-rw-r--r--src/DotNetOAuth.Test/OAuthChannelTests.cs18
6 files changed, 153 insertions, 3 deletions
diff --git a/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj b/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj
index 86edb3c..fd01adb 100644
--- a/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj
+++ b/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj
@@ -58,8 +58,12 @@
</Reference>
</ItemGroup>
<ItemGroup>
- <Compile Include="Messaging\MessageSerializerTest.cs" />
+ <Compile Include="Messaging\ChannelTests.cs" />
+ <Compile Include="OAuthChannelTests.cs" />
+ <Compile Include="Messaging\MessageSerializerTests.cs" />
+ <Compile Include="Mocks\TestChannel.cs" />
<Compile Include="Mocks\TestMessage.cs" />
+ <Compile Include="Mocks\TestMessageTypeProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServiceProviderTest.cs" />
<Compile Include="TestBase.cs" />
diff --git a/src/DotNetOAuth.Test/Messaging/ChannelTests.cs b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs
new file mode 100644
index 0000000..5d027fc
--- /dev/null
+++ b/src/DotNetOAuth.Test/Messaging/ChannelTests.cs
@@ -0,0 +1,46 @@
+//-----------------------------------------------------------------------
+// <copyright file="ChannelTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.Test.Messaging {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+ using DotNetOAuth.Messaging;
+ using DotNetOAuth.Test.Mocks;
+ using System.Web;
+
+ [TestClass]
+ public class ChannelTests : TestBase {
+ Channel channel;
+
+ [TestInitialize]
+ public override void SetUp() {
+ base.SetUp();
+
+ channel = new TestChannel();
+ }
+
+ [TestMethod]
+ public void DequeueIndirectOrResponseMessageReturnsNull() {
+ Assert.IsNull(this.channel.DequeueIndirectOrResponseMessage());
+ }
+
+ [TestMethod]
+ public void ReceiveFromQueryString() {
+ string queryString = "age=15&Name=Andrew&Location=http%3A%2F%2Fhostb%2FpathB";
+ var httpRequest = new HttpRequest("filename", "http://localhost/path?" + queryString, queryString);
+ IProtocolMessage requestMessage = this.channel.Receive(httpRequest);
+ Assert.IsNotNull(requestMessage);
+ Assert.IsInstanceOfType(requestMessage, typeof(TestMessage));
+ TestMessage testMessage = (TestMessage)requestMessage;
+ Assert.AreEqual(15, testMessage.Age);
+ Assert.AreEqual("Andrew", testMessage.Name);
+ Assert.AreEqual("http://hostb/pathB", testMessage.Location.AbsoluteUri);
+ }
+ }
+}
diff --git a/src/DotNetOAuth.Test/Messaging/MessageSerializerTest.cs b/src/DotNetOAuth.Test/Messaging/MessageSerializerTests.cs
index b59e48f..7224e84 100644
--- a/src/DotNetOAuth.Test/Messaging/MessageSerializerTest.cs
+++ b/src/DotNetOAuth.Test/Messaging/MessageSerializerTests.cs
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------
-// <copyright file="MessageSerializerTest.cs" company="Andrew Arnott">
+// <copyright file="MessageSerializerTests.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
@@ -14,7 +14,7 @@ namespace DotNetOAuth.Test.Messaging {
/// Tests for the <see cref="MessageSerializer"/> class.
/// </summary>
[TestClass()]
- public class MessageSerializerTest : TestBase {
+ public class MessageSerializerTests : TestBase {
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
public void SerializeNull() {
var serializer = MessageSerializer.Get(typeof(Mocks.TestMessage));
@@ -33,6 +33,21 @@ namespace DotNetOAuth.Test.Messaging {
serializer.Serialize(new Dictionary<string, string>(), null);
}
+ [TestMethod, ExpectedException(typeof(ArgumentException))]
+ public void GetInvalidMessageType() {
+ MessageSerializer.Get(typeof(string));
+ }
+
+ [TestMethod, ExpectedException(typeof(ArgumentNullException))]
+ public void GetNullType() {
+ MessageSerializer.Get(null);
+ }
+
+ [TestMethod]
+ public void GetReturnsSameSerializerTwice() {
+ Assert.AreSame(MessageSerializer.Get(typeof(Mocks.TestMessage)), MessageSerializer.Get(typeof(Mocks.TestMessage)));
+ }
+
[TestMethod, ExpectedException(typeof(ProtocolException))]
public void SerializeInvalidMessage() {
var serializer = MessageSerializer.Get(typeof(Mocks.TestMessage));
diff --git a/src/DotNetOAuth.Test/Mocks/TestChannel.cs b/src/DotNetOAuth.Test/Mocks/TestChannel.cs
new file mode 100644
index 0000000..c280243
--- /dev/null
+++ b/src/DotNetOAuth.Test/Mocks/TestChannel.cs
@@ -0,0 +1,35 @@
+//-----------------------------------------------------------------------
+// <copyright file="TestChannel.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.Test.Mocks {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using DotNetOAuth.Messaging;
+
+ internal class TestChannel : Channel {
+ internal TestChannel()
+ : base(new TestMessageTypeProvider()) {
+ }
+
+ protected override IProtocolMessage Request(IDirectedProtocolMessage request) {
+ throw new NotImplementedException();
+ }
+
+ protected override void SendDirectMessageResponse(IProtocolMessage response) {
+ throw new NotImplementedException();
+ }
+
+ protected override void ReportErrorToUser(ProtocolException exception) {
+ throw new NotImplementedException();
+ }
+
+ protected override void ReportErrorAsDirectResponse(ProtocolException exception) {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/src/DotNetOAuth.Test/Mocks/TestMessageTypeProvider.cs b/src/DotNetOAuth.Test/Mocks/TestMessageTypeProvider.cs
new file mode 100644
index 0000000..3caf81c
--- /dev/null
+++ b/src/DotNetOAuth.Test/Mocks/TestMessageTypeProvider.cs
@@ -0,0 +1,32 @@
+//-----------------------------------------------------------------------
+// <copyright file="TestMessageTypeProvider.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.Test.Mocks {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using DotNetOAuth.Messaging;
+
+ internal class TestMessageTypeProvider : IMessageTypeProvider {
+
+ #region IMessageTypeProvider Members
+
+ public Type GetRequestMessageType(IDictionary<string, string> fields) {
+ if (fields.ContainsKey("age")) {
+ return typeof(TestMessage);
+ } else {
+ return null;
+ }
+ }
+
+ public Type GetResponseMessageType(IProtocolMessage request, IDictionary<string, string> fields) {
+ return GetRequestMessageType(fields);
+ }
+
+ #endregion
+ }
+}
diff --git a/src/DotNetOAuth.Test/OAuthChannelTests.cs b/src/DotNetOAuth.Test/OAuthChannelTests.cs
new file mode 100644
index 0000000..2d55f8c
--- /dev/null
+++ b/src/DotNetOAuth.Test/OAuthChannelTests.cs
@@ -0,0 +1,18 @@
+//-----------------------------------------------------------------------
+// <copyright file="OAuthChannelTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.Test {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+ using DotNetOAuth.Messaging;
+
+ [TestClass]
+ public class OAuthChannelTests : TestBase {
+ }
+}