SendMessageToUsers() public method

Odešle zprávu uživatelům
public SendMessageToUsers ( User sender, ISet recievers, Message prevMessage, string text ) : void
sender User odesilatel zprávy
recievers ISet množina příjemců zprávy
prevMessage Message zpráva, na kterou tato zpráva odpovídá
text string vlastní text zprávy
return void
Esempio n. 1
0
        public void SendMessageToUsersTest()
        {
            FelBookDBEntities DbEntities = new FelBookDBEntities();
            MessageService target = new MessageService(DbEntities);

            User mockSender = User.CreateUser(0, "test", "test",
                DateTime.Now, "mail", "sender", "");
            DbEntities.UserSet.AddObject(mockSender);
            User mockReciever = User.CreateUser(0, "test", "test",
                DateTime.Now, "mail", "reciever", "");
            DbEntities.UserSet.AddObject(mockReciever);
            DbEntities.SaveChanges();

            ISet<User> recievers = new HashSet<User>();
            recievers.Add(mockReciever);
            Message prevMessage = null;
            string text = "some text";
            target.SendMessageToUsers(mockSender, recievers, prevMessage, text);

            Message message1 = DbEntities.MessageSet.Single(m => m.Sender.Username == mockSender.Username);
            Assert.AreEqual(mockSender, message1.Sender);
            Assert.IsTrue(message1.Recievers.Contains(mockReciever));
            Assert.AreEqual(text, message1.Text);
            Assert.IsNull(message1.ReplyTo);

            recievers = new HashSet<User>();
            recievers.Add(mockSender);
            prevMessage = message1;
            text = "some other text";
            target.SendMessageToUsers(mockReciever, recievers, prevMessage, text);

            Message message2 = DbEntities.MessageSet.Single(m => m.Sender.Username == mockReciever.Username);
            Assert.AreEqual(mockReciever, message2.Sender);
            Assert.IsTrue(message2.Recievers.Contains(mockSender));
            Assert.AreEqual(text, message2.Text);
            Assert.AreEqual(message1, message2.ReplyTo);

            DbEntities.MessageSet.DeleteObject(message2);
            DbEntities.MessageSet.DeleteObject(message1);
            DbEntities.UserSet.DeleteObject(mockReciever);
            DbEntities.UserSet.DeleteObject(mockSender);
            DbEntities.SaveChanges();
        }