예제 #1
0
        public async Task TestSendSilentMessage()
        {
            var user1 = new User()
            {
                ID   = Guid.NewGuid().ToString(),
                Role = Role.Admin,
            };

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

            var channel = this._client.Channel("messaging", Guid.NewGuid().ToString());
            await channel.Create(user1.ID, new string[] { user1.ID });

            var inMsg = new MessageInput()
            {
                Text   = Guid.NewGuid().ToString(),
                Silent = true
            };

            inMsg.SetData("foo", "barsky");

            var outMsg = await channel.SendMessage(inMsg, user1.ID);

            Assert.IsNull(outMsg.DeletedAt);
            Assert.AreEqual(outMsg.Silent, inMsg.Silent);
        }
예제 #2
0
        public async Task TestUpdateMessagePartial()
        {
            var user1 = new User()
            {
                ID   = Guid.NewGuid().ToString(),
                Role = Role.Admin,
            };

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

            var channel = this._client.Channel("messaging", Guid.NewGuid().ToString());
            await channel.Create(user1.ID, new string[] { user1.ID });

            var initialMsg = new MessageInput
            {
                Text = Guid.NewGuid().ToString()
            };

            initialMsg.SetData("foo", "barsky");
            initialMsg.SetData("bar", "baz");

            var msg = await channel.SendMessage(initialMsg, user1.ID);

            var resp = await _client.UpdateMessagePartial(msg.ID, new MessagePartialUpdateRequest
            {
                UserId = user1.ID,
                Set    = new Dictionary <string, object>
                {
                    { "foo", "new" }
                },
                Unset = new List <string> {
                    "bar"
                },
            });

            Assert.AreEqual(msg.ID, resp.Message.ID);
            Assert.AreEqual(msg.Text, resp.Message.Text);
            Assert.NotNull(resp.Duration);
            Assert.AreEqual(resp.Message.GetData <string>("foo"), "new");
            Assert.IsNull(resp.Message.GetData <string>("bar"));
        }
예제 #3
0
        public async Task TestSendMessage()
        {
            var user1 = new User()
            {
                ID   = Guid.NewGuid().ToString(),
                Role = Role.Admin,
            };

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

            var channel = this._client.Channel("messaging", Guid.NewGuid().ToString());
            await channel.Create(user1.ID, new string[] { user1.ID });

            var inMsg = new MessageInput()
            {
                Text = Guid.NewGuid().ToString()
            };

            inMsg.SetData("foo", "barsky");
            var attachment = new Attachment();

            attachment.SetData("baz", "bazky");
            inMsg.Attachments = new List <Attachment>()
            {
                attachment
            };

            var outMsg = await channel.SendMessage(inMsg, user1.ID);

            Assert.NotNull(outMsg);
            Assert.NotNull(outMsg.ID);
            Assert.NotZero(outMsg.ID.Count());
            Assert.NotNull(outMsg.CreatedAt);
            Assert.AreEqual(inMsg.Text, outMsg.Text);
            Assert.NotNull(outMsg.User);
            Assert.AreEqual(inMsg.User.ID, outMsg.User.ID);
            Assert.AreEqual("barsky", outMsg.GetData <string>("foo"));
            Assert.AreEqual("bazky", outMsg.Attachments[0].GetData <string>("baz"));

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

            Assert.NotNull(chanState);
            Assert.NotNull(chanState.Messages);
            Assert.AreEqual(1, chanState.Messages.Count);
            Assert.AreEqual(outMsg.ID, chanState.Messages[0].ID);
            Assert.AreEqual("barsky", chanState.Messages[0].GetData <string>("foo"));
            Assert.AreEqual("bazky", chanState.Messages[0].Attachments[0].GetData <string>("baz"));
        }
예제 #4
0
        public async Task TestUpdateMessage()
        {
            var user1 = new User()
            {
                ID   = Guid.NewGuid().ToString(),
                Role = Role.Admin,
            };

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

            var channel = this._client.Channel("messaging", Guid.NewGuid().ToString());
            await channel.Create(user1.ID, new string[] { user1.ID });

            var inMsg = new MessageInput()
            {
                Text = Guid.NewGuid().ToString()
            };

            inMsg.SetData("foo", "barsky");

            var outMsg = await channel.SendMessage(inMsg, user1.ID);

            var newMsg = new MessageInput()
            {
                Text = Guid.NewGuid().ToString(),
                ID   = outMsg.ID,
                User = new User()
                {
                    ID = outMsg.User.ID
                }
            };

            newMsg.SetData("new", "stuff");

            var updatedMessage = await this._client.UpdateMessage(newMsg);

            Assert.AreEqual(outMsg.ID, updatedMessage.ID);
            Assert.AreEqual(newMsg.Text, updatedMessage.Text);
            Assert.IsNull(updatedMessage.GetData <string>("foo"));
            Assert.AreEqual("stuff", updatedMessage.GetData <string>("new"));
        }
예제 #5
0
        public async Task TestFlag()
        {
            // flag user
            var user1 = new User()
            {
                ID   = Guid.NewGuid().ToString(),
                Role = Role.Admin,
            };
            var user2 = new User()
            {
                ID = Guid.NewGuid().ToString(),
            };

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

            await this._client.FlagUser(user2.ID, user1.ID);

            await this._client.UnflagUser(user2.ID, user1.ID);

            // flag message
            var channel = this._client.Channel("messaging", Guid.NewGuid().ToString());
            await channel.Create(user1.ID, new string[] { user1.ID });

            var inMsg = new MessageInput()
            {
                Text   = Guid.NewGuid().ToString(),
                Silent = true
            };

            inMsg.SetData("foo", "barsky");

            var outMsg = await channel.SendMessage(inMsg, user1.ID);

            await this._client.FlagUser(outMsg.ID, user1.ID);

            await this._client.UnflagUser(outMsg.ID, user1.ID);
        }