Esempio n. 1
0
        public void Test_SessionFromToken()
        {
            var serverInfoMessage = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                                            ""version"": ""4.0.6"",
                                            ""features"": [
                                            ""seafile-basic"",
                                            ]}")
            };

            // From Token automatically checks the token using the CheckAccountInfo() command
            var message = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("{\"usage\": 26038531,\"total\": 104857600,\"email\": \"[email protected]\"}")
            };

            var mockedConnection = new MockedSeafConnection();

            mockedConnection.FakeResponseFor <GetServerInfoRequest>(serverInfoMessage);
            mockedConnection.FakeResponseFor <AccountInfoRequest>(message);
            var session = ExecuteSync(() => SeafSession.FromToken(mockedConnection, new Uri("http://www.example.com"), FakeToken));

            Assert.IsNotNull(session);
            Assert.AreEqual(FakeToken, session.AuthToken);
            Assert.AreEqual("*****@*****.**", session.Username);
        }
Esempio n. 2
0
        public void Test_SessionFromUsernameAndToken()
        {
            var session = SeafSession.FromToken(new Uri("http://www.example.com"), "*****@*****.**", FakeToken);

            Assert.IsNotNull(session);
            Assert.AreEqual(FakeToken, session.AuthToken);
            Assert.AreEqual("*****@*****.**", session.Username);
        }
        public async Task <SeafSession> GetSession()
        {
            if (!string.IsNullOrEmpty(Token))
            {
                return(await SeafSession.FromToken(ServerUri, Token));
            }

            return(await SeafSession.Establish(ServerUri, Username, Password.ToCharArray()));
        }