//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.Test.OpenId { using System; using System.Diagnostics.Contracts; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.Provider; using DotNetOpenAuth.OpenId.RelyingParty; using DotNetOpenAuth.Test.Mocks; internal class OpenIdCoordinator : CoordinatorBase { internal OpenIdCoordinator(Action rpAction, Action opAction) : base(WrapAction(rpAction), WrapAction(opAction)) { } internal OpenIdProvider Provider { get; set; } internal OpenIdRelyingParty RelyingParty { get; set; } internal override void Run() { this.EnsurePartiesAreInitialized(); var rpCoordinatingChannel = new CoordinatingChannel(this.RelyingParty.Channel, this.IncomingMessageFilter, this.OutgoingMessageFilter); var opCoordinatingChannel = new CoordinatingChannel(this.Provider.Channel, this.IncomingMessageFilter, this.OutgoingMessageFilter); rpCoordinatingChannel.RemoteChannel = opCoordinatingChannel; opCoordinatingChannel.RemoteChannel = rpCoordinatingChannel; this.RelyingParty.Channel = rpCoordinatingChannel; this.Provider.Channel = opCoordinatingChannel; RunCore(this.RelyingParty, this.Provider); } private static Action WrapAction(Action action) { Contract.Requires(action != null); return rp => { action(rp); ((CoordinatingChannel)rp.Channel).Close(); }; } private static Action WrapAction(Action action) { Contract.Requires(action != null); return op => { action(op); ((CoordinatingChannel)op.Channel).Close(); }; } private void EnsurePartiesAreInitialized() { if (this.RelyingParty == null) { this.RelyingParty = new OpenIdRelyingParty(new StandardRelyingPartyApplicationStore()); this.RelyingParty.DiscoveryServices.Add(new MockIdentifierDiscoveryService()); } if (this.Provider == null) { this.Provider = new OpenIdProvider(new StandardProviderApplicationStore()); this.Provider.DiscoveryServices.Add(new MockIdentifierDiscoveryService()); } } } }