Ejemplo n.º 1
0
        public void AddUpdateDeleteUser()
        {
            userRepository = new MessagingRepository <User>(dbSettings);
            user           = new User {
                Id = 1, Login = "******"
            };
            userRepository.Add(user);
            userRepository.Save();

            var userFromDb = userRepository.GetItem(1);

            Assert.IsNotNull(userFromDb);
            Assert.AreEqual(userFromDb.Id, 1);
            Assert.AreEqual(userFromDb.Login, "NK");

            user.Login = "******";
            userRepository.Update(user);
            userRepository.Save();

            userFromDb = userRepository.GetItem(1);

            Assert.IsNotNull(userFromDb);
            Assert.AreEqual(userFromDb.Id, 1);
            Assert.AreEqual(userFromDb.Login, "neNK");

            userRepository.DeleteItem(1);
            userRepository.Save();

            userFromDb = userRepository.GetItem(1);

            Assert.IsNull(userFromDb);

            userRepository.Dispose();
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                int c = repos.Count();
                for (int i = 0; i <= c; i++)
                {
                    User user = repos.GetItem(i);
                    if (user != null)
                    {
                        if (Model.Login == user.Login)
                        {
                            //await Clients.Caller.SendAsync("ReceiveMessage", "This Login already exists");
                            ModelState.AddModelError("", "This Logis already exists");
                            return(Page());
                        }
                    }
                    if (i == c)
                    {
                        User nuser = new User();
                        nuser.Login = Model.Login;
                        nuser.Pass  = Model.Password;
                        nuser.Id    = c++;
                        repos.Add(nuser);
                        repos.Save();
                        await Authenticate(Model.Login); // аутентификация

                        return(RedirectToPage("/Chat"));
                    }
                }
            }
            ModelState.AddModelError("", "error");
            return(Page());
        }
Ejemplo n.º 3
0
        public void AddUpdateDeleteMessage()
        {
            messageRepository = new MessagingRepository <Message>(dbSettings);
            message           = new Message {
                Id = 1, UserId = 1, Text = "NK"
            };
            messageRepository.Add(message);
            messageRepository.Save();

            var messageFromDb = messageRepository.GetItem(1);

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

            message.Text = "neNK";
            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, "neNK");

            messageRepository.DeleteItem(1);
            messageRepository.Save();

            messageFromDb = messageRepository.GetItem(1);

            Assert.IsNull(messageFromDb);

            messageRepository.Dispose();
        }