summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/Mocks/TestMessageFactory.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-11-20 06:54:14 -0800
committerAndrew <andrewarnott@gmail.com>2008-11-20 06:54:14 -0800
commit1a882368e2e99e9360cfd1f4f23f5acb70306436 (patch)
treeab0d370a8b8b9d5b638524f189a39991970834bb /src/DotNetOpenAuth.Test/Mocks/TestMessageFactory.cs
parentd51be63270463542a308a9a2cef992b7d55baaa6 (diff)
downloadDotNetOpenAuth-1a882368e2e99e9360cfd1f4f23f5acb70306436.zip
DotNetOpenAuth-1a882368e2e99e9360cfd1f4f23f5acb70306436.tar.gz
DotNetOpenAuth-1a882368e2e99e9360cfd1f4f23f5acb70306436.tar.bz2
Reworked the way messages are instantiated and deserialized.
This was a whole lot of work to just get multi-version capability added to message types so that OpenID could handle its few versions.
Diffstat (limited to 'src/DotNetOpenAuth.Test/Mocks/TestMessageFactory.cs')
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/TestMessageFactory.cs60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.Test/Mocks/TestMessageFactory.cs b/src/DotNetOpenAuth.Test/Mocks/TestMessageFactory.cs
new file mode 100644
index 0000000..7c88898
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/Mocks/TestMessageFactory.cs
@@ -0,0 +1,60 @@
+//-----------------------------------------------------------------------
+// <copyright file="TestMessageFactory.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.Mocks {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using DotNetOpenAuth.Messaging;
+
+ internal class TestMessageFactory : IMessageFactory {
+ private bool signedMessages;
+ private bool expiringMessages;
+ private bool replayMessages;
+
+ internal TestMessageFactory()
+ : this(false, false, false) {
+ }
+
+ internal TestMessageFactory(bool signed, bool expiring, bool replay) {
+ if ((!signed && expiring) || (!expiring && replay)) {
+ throw new ArgumentException("Invalid combination of protection.");
+ }
+ this.signedMessages = signed;
+ this.expiringMessages = expiring;
+ this.replayMessages = replay;
+ }
+
+ #region IMessageFactory Members
+
+ public IDirectedProtocolMessage GetNewRequestMessage(MessageReceivingEndpoint recipient, IDictionary<string, string> fields) {
+ ErrorUtilities.VerifyArgumentNotNull(fields, "fields");
+
+ if (fields.ContainsKey("age")) {
+ if (this.signedMessages) {
+ if (this.expiringMessages) {
+ if (this.replayMessages) {
+ return new TestReplayProtectedMessage();
+ }
+ return new TestExpiringMessage();
+ }
+ return new TestSignedDirectedMessage();
+ }
+ return new TestDirectedMessage();
+ }
+ return null;
+ }
+
+ public IDirectResponseProtocolMessage GetNewResponseMessage(IDirectedProtocolMessage request, IDictionary<string, string> fields) {
+ TestMessage message = (TestMessage)this.GetNewRequestMessage(null, fields);
+ message.OriginatingRequest = request;
+ return message;
+ }
+
+ #endregion
+ }
+}