public void NotAuthenticatedRaisesAbort()
        {
            MockSessionAuthenticationFactory mockSessionAuthenticationFactory =
                new MockSessionAuthenticationFactory();

            WampPendingClientDetails authenticatorFactoryParameters = null;

            mockSessionAuthenticationFactory.SetGetSessionAuthenticator
                ((clientDetails, transportAuthenticator) =>
            {
                authenticatorFactoryParameters = clientDetails;
                MockSessionAuthenticator mockSessionAuthenticator = new MockSessionAuthenticator();
                mockSessionAuthenticator.SetAuthenticationMethod("ticket");

                mockSessionAuthenticator.SetAuthenticate((signature, extraData) =>
                {
                    mockSessionAuthenticator.SetAuthenticationId(clientDetails.HelloDetails.AuthenticationId);
                    mockSessionAuthenticator.SetIsAuthenticated(false);
                });

                return(mockSessionAuthenticator);
            });

            WampAuthenticationPlayground playground =
                new WampAuthenticationPlayground(mockSessionAuthenticationFactory);

            playground.Host.Open();

            Mock <IWampClient <JToken> > clientMock = new Mock <IWampClient <JToken> >();

            IWampServerProxy serverProxy =
                playground.CreateRawConnection(clientMock.Object);

            serverProxy.Hello("realm1", new HelloDetailsHack()
            {
                AuthenticationId      = "joe",
                AuthenticationMethods = new string[] { "wampcra", "ticket" }
            });

            serverProxy.Authenticate("Barack Hussein", new AuthenticateExtraData());

            clientMock.Verify(x => x.Abort(It.IsAny <AbortDetails>(), It.IsAny <string>()));
        }
        public void WelcomeParametersArePassedToClient()
        {
            MockSessionAuthenticationFactory mockSessionAuthenticationFactory =
                new MockSessionAuthenticationFactory();

            WampPendingClientDetails authenticatorFactoryParameters = null;

            mockSessionAuthenticationFactory.SetGetSessionAuthenticator
                ((clientDetails, transportAuthenticator) =>
            {
                authenticatorFactoryParameters = clientDetails;
                MockSessionAuthenticator mockSessionAuthenticator = new MockSessionAuthenticator();
                mockSessionAuthenticator.SetAuthenticationMethod("ticket");

                mockSessionAuthenticator.SetAuthenticate((signature, extraData) =>
                {
                    mockSessionAuthenticator.SetAuthenticationId(clientDetails.HelloDetails.AuthenticationId);
                    mockSessionAuthenticator.SetIsAuthenticated(true);
                    mockSessionAuthenticator.SetWelcomeDetails(new MyWelcomeDetails()
                    {
                        AuthenticationProvider = "unittest",
                        AuthenticationRole     = "testee",
                        Country = "United States of America"
                    });

                    mockSessionAuthenticator.SetAuthorizer(new WampStaticAuthorizer(new List <WampUriPermissions>()));
                });

                return(mockSessionAuthenticator);
            });

            WampAuthenticationPlayground playground =
                new WampAuthenticationPlayground(mockSessionAuthenticationFactory);

            playground.Host.Open();

            long?          clientSessionId      = null;
            WelcomeDetails clientWelcomeDetails = null;

            Mock <IWampClient <JToken> > clientMock = new Mock <IWampClient <JToken> >();

            clientMock.Setup(x => x.Welcome(It.IsAny <long>(), It.IsAny <WelcomeDetails>()))
            .Callback((long sessionId, WelcomeDetails details) =>
            {
                clientSessionId      = sessionId;
                clientWelcomeDetails = details;
            });

            IWampServerProxy serverProxy =
                playground.CreateRawConnection(clientMock.Object);

            serverProxy.Hello("realm1", new HelloDetailsHack()
            {
                AuthenticationId      = "joe",
                AuthenticationMethods = new string[] { "wampcra", "ticket" }
            });

            serverProxy.Authenticate("Barack Hussein", new AuthenticateExtraData());

            Assert.That(clientWelcomeDetails.AuthenticationMethod, Is.EqualTo("ticket"));
            Assert.That(clientWelcomeDetails.AuthenticationId, Is.EqualTo("joe"));
            Assert.That(clientWelcomeDetails.AuthenticationProvider, Is.EqualTo("unittest"));
            Assert.That(clientWelcomeDetails.AuthenticationRole, Is.EqualTo("testee"));
            Assert.That(clientSessionId, Is.EqualTo(authenticatorFactoryParameters.SessionId));

            MyWelcomeDetails deserializedWelcomeDetails =
                clientWelcomeDetails.OriginalValue.Deserialize <MyWelcomeDetails>();

            Assert.That(deserializedWelcomeDetails.Country, Is.EqualTo("United States of America"));
        }