public async Task TestPartialUpdate()
        {
            var user1 = new User
            {
                ID   = Guid.NewGuid().ToString(),
                Role = Role.Admin,
            };

            await this._client.Users.Upsert(user1);

            var customData = new GenericData();

            customData.SetData("color", "red");
            customData.SetData("age", 18);
            var channel     = this._client.Channel("messaging", Guid.NewGuid().ToString(), customData);
            var channelResp = await channel.Create(user1.ID);

            Assert.AreEqual(channelResp.Channel.GetData <string>("color"), "red");
            Assert.AreEqual(channelResp.Channel.GetData <int>("age"), 18);

            var req = new PartialUpdateChannelRequest
            {
                UserId = user1.ID,
                Unset  = new List <string> {
                    "age"
                },
                Set = new Dictionary <string, object> {
                    { "color", "blue" }
                }
            };
            var resp = await channel.PartialUpdate(req);

            Assert.AreEqual(resp.Channel.GetData <string>("color"), "blue");
            Assert.AreEqual(resp.Channel.GetData <int>("age"), default(int));
        }
Example #2
0
        public async Task TestUpdate()
        {
            var user1 = new User()
            {
                ID   = Guid.NewGuid().ToString(),
                Role = Role.Admin,
            };

            var customData = new GenericData();

            customData.SetData("foo", "bar");
            await this._client.Users.Update(user1);

            var channel = _client.Channel("messaging", Guid.NewGuid().ToString(), customData);

            await channel.Create(user1.ID);

            var newData = new GenericData();

            newData.SetData("updated", "stuff");
            var updateChanResponse = await channel.Update(newData);

            Assert.IsNotNull(updateChanResponse);
            Assert.IsNull(updateChanResponse.Message);
            Assert.IsNotNull(updateChanResponse.Channel);
            Assert.IsNull(updateChanResponse.Channel.GetData <string>("foo"));
            Assert.AreEqual("stuff", updateChanResponse.Channel.GetData <string>("updated"));

            newData = new GenericData();
            newData.SetData("more complex", new Dictionary <string, int>()
            {
                { "field", 123 }
            });
            var msg = new MessageInput()
            {
                Text = Guid.NewGuid().ToString(),
                User = user1
            };

            updateChanResponse = await channel.Update(newData, msg);

            Assert.IsNotNull(updateChanResponse);
            Assert.IsNotNull(updateChanResponse.Channel);
            Assert.IsNull(updateChanResponse.Channel.GetData <string>("foo"));
            Assert.IsNull(updateChanResponse.Channel.GetData <string>("updated"));
            Assert.AreEqual(123, updateChanResponse.Channel.GetData <Dictionary <string, int> >("more complex")["field"]);
            Assert.IsNotNull(updateChanResponse.Message);
            Assert.AreEqual(msg.Text, updateChanResponse.Message.Text);
            Assert.AreEqual(user1.ID, updateChanResponse.Message.User.ID);

            var chanState = await channel.Query(new ChannelQueryParams());

            Assert.AreEqual(123, chanState.Channel.GetData <Dictionary <string, int> >("more complex")["field"]);
        }
Example #3
0
        public async Task TestChannelCreate()
        {
            var user1 = new User()
            {
                ID   = Guid.NewGuid().ToString(),
                Role = Role.Admin,
            };

            user1.SetData("name", "BOB");

            var user2 = new User()
            {
                ID   = Guid.NewGuid().ToString(),
                Role = Role.User,
            };

            user2.SetData("details", new Dictionary <string, string>()
            {
                { "foo", "bar" }
            });

            var members = new User[] { user1, user2 };

            await this._client.Users.UpdateMany(members);

            var chanData = new GenericData();

            chanData.SetData("name", "one big party");
            chanData.SetData("food", new string[] { "pizza", "gabagool" });
            var channel = _client.Channel("messaging", null, chanData);

            var chanState = await channel.Create(user1.ID, members.Select(u => u.ID));

            Assert.AreEqual(chanState.Channel.ID, channel.ID);
            Assert.AreEqual(2, chanState.Channel.MemberCount);
            Assert.AreEqual(2, chanState.Members.Count);

            var u1 = chanState.Members.Find(u => u.User.ID == user1.ID);

            Assert.NotNull(u1);

            Assert.AreEqual(u1.Role, ChannelRole.Owner);
            Assert.AreEqual(u1.User.GetData <string>("name"), user1.GetData <string>("name"));
            Assert.NotNull(u1.UpdatedAt);

            var u2 = chanState.Members.Find(u => u.User.ID == user2.ID);

            Assert.NotNull(u2);
            Assert.AreEqual(u2.Role, ChannelRole.Member);
            Assert.AreEqual(u2.User.GetData <Dictionary <string, string> >("details")["foo"], user2.GetData <Dictionary <string, string> >("details")["foo"]);
            Assert.NotNull(u2.UpdatedAt);

            Assert.NotNull(chanState.Channel.CreatedBy);
            Assert.AreEqual(chanState.Channel.CreatedBy.ID, user1.ID);
            Assert.AreEqual(chanState.Channel.CreatedBy.Role, user1.Role);
            Assert.AreEqual(chanState.Channel.GetData <string>("name"), chanData.GetData <string>("name"));
            Assert.AreEqual(chanState.Channel.GetData <string[]>("food"), chanData.GetData <string[]>("food"));

            var chanId   = Guid.NewGuid().ToString();
            var channel2 = _client.Channel("messaging", chanId);

            chanState = await channel2.Create(user2.ID);

            Assert.AreEqual(chanState.Channel.ID, channel2.ID);
            Assert.AreEqual(chanId, channel2.ID);
            Assert.AreEqual(0, chanState.Channel.MemberCount);
            Assert.AreEqual(0, chanState.Members.Count);
            Assert.AreEqual(chanState.Channel.CreatedBy.ID, user2.ID);
        }