blob: 35d7f1bba7b0b0844f3afce46f2bbba050cc8228 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
//-----------------------------------------------------------------------
// <copyright file="MockTransformationBindingElement.cs" company="Outercurve Foundation">
// Copyright (c) Outercurve Foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Test.Mocks {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using DotNetOpenAuth.Messaging;
using NUnit.Framework;
internal class MockTransformationBindingElement : IChannelBindingElement {
private readonly string transform;
internal MockTransformationBindingElement(string transform) {
if (transform == null) {
throw new ArgumentNullException("transform");
}
this.transform = transform;
}
#region IChannelBindingElement Members
MessageProtections IChannelBindingElement.Protection {
get { return MessageProtections.None; }
}
/// <summary>
/// Gets or sets the channel that this binding element belongs to.
/// </summary>
public Channel Channel { get; set; }
Task<MessageProtections?> IChannelBindingElement.ProcessOutgoingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) {
var testMessage = message as TestMessage;
if (testMessage != null) {
testMessage.Name = this.transform + testMessage.Name;
return MessageProtectionTasks.None;
}
return MessageProtectionTasks.Null;
}
Task<MessageProtections?> IChannelBindingElement.ProcessIncomingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) {
var testMessage = message as TestMessage;
if (testMessage != null) {
StringAssert.StartsWith(this.transform, testMessage.Name);
testMessage.Name = testMessage.Name.Substring(this.transform.Length);
return MessageProtectionTasks.None;
}
return MessageProtectionTasks.Null;
}
#endregion
}
}
|