コード例 #1
0
        public void TestGetData()
        {
            using (var requestHandler = new TestRequestHandler())
                using (var client = new RingMasterClient(requestHandler))
                {
                    string path         = this.GetRandomString();
                    var    watcher      = new TestWatcher(this.GetRandomInt());
                    byte[] expectedData = this.GetRandomData();

                    requestHandler.Implementation = request =>
                    {
                        Assert.IsTrue(request is RequestGetData);
                        var getDataRequest = (RequestGetData)request;
                        Assert.AreEqual(path, getDataRequest.Path);
                        Assert.AreEqual(watcher.Id, getDataRequest.Watcher.Id);

                        return(new RequestResponse()
                        {
                            ResultCode = (int)RingMasterException.Code.Ok,
                            Content = expectedData
                        });
                    };

                    client.SetWatcher(watcher);

                    var data = client.GetData(path, watch: true).Result;
                    CollectionAssert.AreEqual(expectedData, data);
                }
        }