Exemplo n.º 1
0
        public void TestCreateAndGetStat()
        {
            using (var requestHandler = new TestRequestHandler())
                using (var client = new RingMasterClient(requestHandler))
                {
                    string path = this.GetRandomString();
                    byte[] data = this.GetRandomData();
                    var    acl  = new List <Acl>()
                    {
                        new Acl((int)Acl.Perm.ALL, new Id(AuthSchemes.Digest, this.GetRandomString()))
                    };
                    var createMode   = CreateMode.Persistent;
                    var expectedStat = new Stat()
                    {
                        Version = this.GetRandomInt()
                    };

                    requestHandler.Implementation = request =>
                    {
                        Assert.IsTrue(request is RequestCreate);
                        var createRequest = (RequestCreate)request;
                        Assert.AreEqual(path, createRequest.Path);
                        Assert.AreEqual(data, createRequest.Data);
                        Assert.AreEqual(acl.Count, createRequest.Acl.Count);
                        Assert.IsTrue(Acl.AreEqual(acl[0], createRequest.Acl[0]));
                        Assert.AreEqual(createMode, createRequest.CreateMode);

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

                    IStat stat = client.CreateAndGetStat(path, data, acl, createMode).Result;
                    Assert.AreEqual(expectedStat.Version, stat.Version);
                }
        }