コード例 #1
0
        public void TestSetData()
        {
            using (var requestHandler = new TestRequestHandler())
                using (var client = new RingMasterClient(requestHandler))
                {
                    string path         = this.GetRandomString();
                    int    version      = this.GetRandomInt();
                    byte[] data         = this.GetRandomData();
                    var    expectedStat = new Stat()
                    {
                        Version = this.GetRandomInt()
                    };

                    requestHandler.Implementation = request =>
                    {
                        Assert.IsTrue(request is RequestSetData);
                        var setDataRequest = (RequestSetData)request;
                        Assert.AreEqual(path, setDataRequest.Path);
                        Assert.AreEqual(version, setDataRequest.Version);
                        CollectionAssert.AreEqual(data, setDataRequest.Data);

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

                    var stat = client.SetData(path, data, version).Result;
                    Assert.AreEqual(expectedStat.Version, stat.Version);
                }
        }