public int CreateRoom(string roomName, int creatorId) { if (string.IsNullOrEmpty(roomName)) { _logger.Debug("Create room ArgumentNullException"); throw new ArgumentNullException(); } Authorization.CheckRoles("Authenticated"); var roomRepository = ContainerService.Instance.Resolve<IRepository<Room>>(); Room room = new Room { Name = roomName, CreatorId = creatorId, Id = roomRepository.FindAll().Count() + 1 }; roomRepository.Add(room); roomRepository.SaveAll(); var userRoleRepository = ContainerService.Instance.Resolve<IRepository<User_Role>>(); var userRole = userRoleRepository.FindOne(u => u.UserId == creatorId); userRole.RoleId = 2; userRoleRepository.SaveAll(); return room.Id; }
public void ReceiveMessagesTest() { IChatManager target = ContainerService.Instance.Resolve<ChatManager>(); const string userId = "100"; const string chatRoomId = "100"; IRepository<User> userRepository = ContainerService.Instance.Resolve<IRepository<User>>(); var user = new User { Id = Convert.ToInt16(userId), Name = "Kiril", Password = "******", TimeLogIn = DateTime.Now }; userRepository.Add(user); userRepository.SaveAll(); IRepository<Room> roomRepository = ContainerService.Instance.Resolve<IRepository<Room>>(); var room = new Room { Id = Convert.ToInt16(chatRoomId), Name = "test" }; roomRepository.Add(room); roomRepository.SaveAll(); IRepository<Message> messageRepository = ContainerService.Instance.Resolve<IRepository<Message>>(); Message message = new Message { Date = DateTime.Now, Id = messageRepository.FindAll().Count() + 1, RoomId = 100, UserId = 100, Text = "testMessage" }; messageRepository.Add(message); messageRepository.SaveAll(); string str = target.ReceiveMessages(userId, chatRoomId); var s = str.Split(new[]{"Date"},StringSplitOptions.None); messageRepository.Delete(message); messageRepository.SaveAll(); userRepository.Delete(user); userRepository.SaveAll(); roomRepository.Delete(room); roomRepository.SaveAll(); Assert.AreEqual(1, s.Length); }
public void ReceiveRoomsTest() { var roomRepository = ContainerService.Instance.Resolve<IRepository<Room>>(); var roomCountBefore = roomRepository.FindAll().Count(); Room room = new Room { Id = roomCountBefore + 1, Name = "test room" }; roomRepository.Add(room); roomRepository.SaveAll(); //var actualAfter = target.ReceiveRooms().Split(';').Count(); roomRepository.Delete(room); roomRepository.SaveAll(); //Assert.AreEqual(actualBefore + 1, actualAfter); }
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); }
partial void DeleteRoom(Room instance);
partial void UpdateRoom(Room instance);
partial void InsertRoom(Room instance);