Пример #1
0
        public void SendMessageTest()
        {
            IRepository<User> userRepository = ContainerService.Instance.Resolve<IRepository<User>>();
            User user = new User
                            {
                                Id = 100,
                                Name = "Kiril",
                                Password = "******",
                                TimeLogIn = DateTime.Now
                            };
            userRepository.Add(user);
            userRepository.SaveAll();

            IRepository<Room> roomRepository = ContainerService.Instance.Resolve<IRepository<Room>>();

            Room room = new Room
                            {
                                Id = 100,
                                Name = "test"
                            };

            roomRepository.Add(room);
            roomRepository.SaveAll();

            var target = new ChatManager();
            const string text = "Hello";
            string userId = "100";
            string chatRoomId = "100";

            target.SendMessage(text, userId, chatRoomId);

            IRepository<Message> messageRepository = ContainerService.Instance.Resolve<IRepository<Message>>();

            var actual = messageRepository.FindAll(
                m => m.Text == text &&
                    m.UserId == Convert.ToInt16(userId) &&
                    m.RoomId == Convert.ToInt16(chatRoomId)).Count();

            var messageId = messageRepository.FindAll().Count();
            var message = messageRepository.FindOne(m => m.Id == messageId);
            messageRepository.Delete(message);

            userRepository.Delete(user);
            userRepository.SaveAll();

            roomRepository.Delete(room);
            roomRepository.SaveAll();

            Assert.AreEqual(1, actual);
        }
Пример #2
0
 public ChatService()
 {
     _mychat = new ChatManager();
 }