Пример #1
0
        public void ShouldLoginWithTokenSuccess()
        {
            String methodId = "SomeRandomId";

            _connection.IdGenerator = () => methodId;

            MethodResponse response = new MethodResponse
            {
                Id     = methodId,
                Error  = null,
                Result = new JObject(new JProperty("tokenExpires", JToken.FromObject(new DdpDate())), new JProperty("token", "SomeTokenId"))
            };

            _mock.Setup(websocket => websocket.SendJson(It.IsAny <MethodModel>()))
            .Callback(() => _mock.Raise(socket => socket.DdpMessage += null, null, new DdpMessage("result", JsonConvert.SerializeObject(response))));

            string token = "SomeRandomToken";

            bool wasRaised = false;
            EventHandler <LoginResponse> handler = null;

            handler = delegate(object sender, LoginResponse loginResponse)
            {
                wasRaised = true;
                Assert.IsFalse(loginResponse.HasError());
                Assert.IsNotNull(loginResponse.Token);
                Assert.IsNotNull(loginResponse.TokenExpires);
                _connection.Login -= handler;
            };
            _connection.Login += handler;

            _connection.LoginWithToken(token);

            _mock.Verify(websocket => websocket.SendJson(It.Is <MethodModel>(method =>
                                                                             method.Id == methodId &&
                                                                             method.Method == "login" &&
                                                                             method.Params.Length == 1 &&
                                                                             method.Params[0] is BasicTokenModel)));
            Assert.IsTrue(wasRaised);
        }
Пример #2
0
 public void LoginToken(string token)
 {
     _client.LoginWithToken(token);
 }