Exemplo n.º 1
0
        public CreateSessionResponse CreateSession(CreateSessionRequest request)
        {
            string userName = request.Username;
            string password = request.Password;

            if (ValidateUserPassword(userName, password))
            {
                SimpleSession session = sessions.Find(s => s.UserName == userName);
                if (session == null)
                {
                    session = new SimpleSession(userName);
                    sessions.Add(session);
                }
                else
                {
                    if (!session.IsValid())
                    {
                        sessions.Remove(session);
                        session = new SimpleSession(userName);
                        sessions.Add(session);
                    }
                }
                session.Login();
                return(new CreateSessionResponse {
                    Session = session.GetSession()
                });
            }
            throw new InvalidOperationException("Unable to login with username and password");
        }
Exemplo n.º 2
0
        public void CreateSessionInvalid()
        {
            SimpleSecurityWebServiceClient webServiceClient = new SimpleSecurityWebServiceClient("User");

            CreateSessionRequest request = new CreateSessionRequest {
                Username = "******", Password = "******"
            };

            Assert.Throws <InvalidOperationException>(() => webServiceClient.CreateSession(request));
        }
Exemplo n.º 3
0
        public void CreateSessionDuplicateLogin()
        {
            SimpleSecurityWebServiceClient webServiceClient = new SimpleSecurityWebServiceClient("User");

            CreateSessionRequest request = new CreateSessionRequest {
                Username = "******", Password = "******"
            };

            webServiceClient.CreateSession(request);

            webServiceClient.CreateSession(request);

            Assert.That(webServiceClient.Sessions, Is.Not.Empty);
            Assert.That(webServiceClient.Sessions.Count, Is.EqualTo(1));

            SimpleSession session = webServiceClient.Sessions[0];

            Assert.That(session.IsValid(), Is.True);
            Assert.That(session.Count, Is.EqualTo(2));
        }
Exemplo n.º 4
0
        public void CreateSession()
        {
            SimpleSecurityWebServiceClient webServiceClient = new SimpleSecurityWebServiceClient("User");

            CreateSessionRequest request = new CreateSessionRequest {
                Username = "******", Password = "******"
            };

            CreateSessionResponse response = webServiceClient.CreateSession(request);

            Assert.That(response, Is.Not.Null);
            Assert.That(response.Session, Is.Not.Null);

            Assert.That(response.Session.User, Is.EqualTo("User"));
            Assert.That(response.Session.SessionID, Is.Not.Empty);

            Assert.That(webServiceClient.Sessions, Is.Not.Empty);
            Assert.That(webServiceClient.Sessions.Count, Is.EqualTo(1));

            SimpleSession session = webServiceClient.Sessions[0];

            Assert.That(session.IsValid(), Is.True);
            Assert.That(session.Count, Is.EqualTo(1));
        }
Exemplo n.º 5
0
 public CreateSessionResponse CreateSession(CreateSessionRequest request)
 {
     return(Create().CreateSession(request));
 }