Exemplo n.º 1
0
        public void ShouldSubscriberHandleRemoved()
        {
            string id         = "SomeRandomId";
            string collection = "tasks";

            string mockResult = "{\"msg\":\"removed\",\"id\":\"" + id + "\",\"collection\":\"" + collection + "\"}";

            DdpSubscriber <TestClass> ddpSubscriber = _connection.GetSubscriber <TestClass>(collection);

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

            handler = delegate(object sender, SubRemovedModel changed)
            {
                wasRaised = true;
                Assert.AreEqual(id, changed.Id);
                ddpSubscriber.Removed -= handler;
            };
            ddpSubscriber.Removed += handler;

            _mock.Raise(webSocket => webSocket.DdpMessage += null, null, new DdpMessage("removed", mockResult));

            Assert.IsTrue(wasRaised);
            ddpSubscriber.Dispose();
        }
Exemplo n.º 2
0
        public void ShouldSubscriberHandleChanged()
        {
            string id         = "SomeRandomId";
            int    data       = 5;
            string collection = "tasks";

            TestClass res = new TestClass
            {
                Id   = id,
                Data = data
            };
            string mockResult = "{\"msg\":\"changed\",\"id\":\"" + id + "\",\"collection\":\"" + collection + "\",\"fields\": " + JsonConvert.SerializeObject(res) + "}";

            DdpSubscriber <TestClass> ddpSubscriber = _connection.GetSubscriber <TestClass>(collection);

            bool wasRaised = false;
            EventHandler <SubChangedModel <TestClass> > handler = null;

            handler = delegate(object sender, SubChangedModel <TestClass> changed)
            {
                wasRaised = true;
                Assert.AreEqual(id, changed.Id);
                Assert.AreEqual(id, changed.Object.Id);
                Assert.AreEqual(data, changed.Object.Data);
                ddpSubscriber.Changed -= handler;
            };
            ddpSubscriber.Changed += handler;

            _mock.Raise(webSocket => webSocket.DdpMessage += null, null, new DdpMessage("changed", mockResult));

            Assert.IsTrue(wasRaised);
            ddpSubscriber.Dispose();
        }