示例#1
0
        public void AddGetUpdateDeleteUser()
        {
            userRepository = new SimpleChatRepository <Users>(databaseSettings);
            userRepository.CreatDatabase();
            user = new Users
            {
                //Id = 1,
                Name = "Serge"
            };

            userRepository.Add(user);
            userRepository.Save();
            var userFromDb = userRepository.GetItem(1);

            Assert.IsNotNull(userFromDb);
            Assert.AreEqual(userFromDb.Id, 1);
            Assert.AreEqual(userFromDb.Name, "Serge");

            user.Name = "Andrei";
            userRepository.Update(user);
            userRepository.Save();
            userFromDb = userRepository.GetItem(1);

            Assert.IsNotNull(userFromDb);
            Assert.AreEqual(userFromDb.Id, 1);
            Assert.AreEqual(userFromDb.Name, "Andrei");

            userRepository.DeleteItem(1);
            userRepository.Save();
            userFromDb = userRepository.GetItem(1);;
            Assert.IsNull(userFromDb);

            userRepository.ContextDispose();
        }
示例#2
0
        public void AddGetUpdateDeleteRole()
        {
            roleRepository = new SimpleChatRepository <Roles>(databaseSettings);

            role = new Roles
            {
                NameRole = "main",
                Id       = 1
            };

            roleRepository.Add(role);
            roleRepository.Save();
            var roleFromDb = roleRepository.GetItem(1);

            Assert.IsNotNull(role);
            Assert.AreEqual(roleFromDb.Id, 1);
            Assert.AreEqual(roleFromDb.NameRole, "main");

            role.NameRole = "admin";
            roleRepository.Update(role);
            roleRepository.Save();
            roleFromDb = roleRepository.GetItem(1);

            Assert.IsNotNull(roleFromDb);
            Assert.AreEqual(roleFromDb.Id, 1);
            Assert.AreEqual(roleFromDb.NameRole, "admin");

            roleRepository.DeleteItem(1);
            roleRepository.Save();
            roleFromDb = roleRepository.GetItem(1);
            Assert.IsNull(roleFromDb);

            roleRepository.ContextDispose();
        }
示例#3
0
        public string WriteMessage(string UserMessage, int userId)
        {
            try
            {
                messageRepository.CreatDatabase();

                message = new Messages();

                message.Text   = UserMessage;
                message.UserId = userId;

                messageRepository.Add(message);
                messageRepository.Save();


                Get();


                otvet = "Сообщение доставлено";
                log.Info($"Доставлено сообщение от {userId}");
            }
            catch (Exception e)
            {
                otvet = "Сообщение не доставлено";
                log.Error(otvet, e);
            }
            return(otvet);
        }
示例#4
0
        public string Registration(string name, string pass)
        {
            try
            {
                SetSettings();
                userRepository = new SimpleChatRepository <Users>(databaseSettings);
                userRepository.CreatDatabase();
                user = new Users();

                user.Name = name;
                user.Pass = Convert.ToInt32(pass);

                userRepository.Add(user);
                userRepository.Save();

                otvet = "Пользователь зарегистрирован";
                log.Info($"Пользователь {name} зарегистрирован");
            }
            catch (Exception e)
            {
                otvet = "Ошибка регистрации";
                log.Error(otvet, e);
            }
            return(otvet);
        }
示例#5
0
        public void AddGetUpdateDeleteMessage()
        {
            messageRepository = new SimpleChatRepository <Messages>(databaseSettings);

            message = new Messages
            {
                Id     = 1,
                UserId = 1,
                Text   = "textofmessage"
            };

            messageRepository.Add(message);
            messageRepository.Save();
            var messageFromDb = messageRepository.GetItem(1);

            Assert.IsNotNull(message);
            Assert.AreEqual(messageFromDb.Id, 1);
            Assert.AreEqual(messageFromDb.UserId, 1);
            Assert.AreEqual(messageFromDb.Text, "textofmessage");

            message.Text = "anotherText";
            messageRepository.Update(message);
            messageRepository.Save();
            messageFromDb = messageRepository.GetItem(1);

            Assert.IsNotNull(messageFromDb);
            Assert.AreEqual(messageFromDb.Id, 1);
            Assert.AreEqual(messageFromDb.UserId, 1);
            Assert.AreEqual(messageFromDb.Text, "anotherText");

            messageRepository.DeleteItem(1);
            messageRepository.Save();
            messageFromDb = messageRepository.GetItem(1);
            Assert.IsNull(messageFromDb);

            messageRepository.ContextDispose();
        }