Exemple #1
0
        public void GetUsers()
        {
            using var db = new SoPContext();
            var user = db.Users.FirstOrDefault();

            Assert.AreEqual(user.Username, "admin");
        }
 public PasswordEntry GetById(int passwordEntryId, int userId)
 {
     using var context = new SoPContext();
     return(context.PasswordEntries
            .Include(pass => pass.Category)
            .FirstOrDefault(pass => pass.Id == passwordEntryId && pass.Category.UserId == userId));
 }
Exemple #3
0
        public void AddUser()
        {
            var user = User.CreateNew("testuser", "password");

            using var db = new SoPContext();
            db.Users.Add(user);
            db.SaveChanges();
        }
        public void Delete(int passwordEntryId)
        {
            using var context = new SoPContext();
            var pass = context.PasswordEntries.FirstOrDefault(pass => pass.Id == passwordEntryId);

            if (pass != null)
            {
                context.PasswordEntries.Remove(pass);
                context.SaveChanges();
            }
        }
Exemple #5
0
        public void Delete(int categoryId)
        {
            using var context = new SoPContext();
            var cat = context.Categories.FirstOrDefault(cat => cat.Id == categoryId);

            if (cat != null)
            {
                context.Categories.Remove(cat);
                context.SaveChanges();
            }
        }
        public List <PasswordEntry> GetForUser(int userId)
        {
            using var context = new SoPContext();
            var categories = context.Categories
                             .Where(cat => cat.UserId == userId)
                             .Select(cat => cat.Id)
                             .ToList();

            return(context.PasswordEntries
                   .Where(pass => categories.Contains(pass.CategoryId))
                   .ToList());
        }
Exemple #7
0
 public bool Create(User user)
 {
     try
     {
         using var dbContext = new SoPContext();
         dbContext.Users.Add(user);
         dbContext.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #8
0
 public bool Create(Category category)
 {
     try
     {
         using var context = new SoPContext();
         context.Categories.Add(category);
         context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #9
0
        public void Initialize()
        {
            using var db = new SoPContext();
            //Remove users
            var userList = db.Users.ToList();

            db.Users.RemoveRange(userList);
            db.SaveChanges();

            //Add Admin User
            var adminUser = User.CreateNew("admin", "admin");

            db.Users.Add(adminUser);
            db.SaveChanges();
        }
Exemple #10
0
        public void AddData()
        {
            using var db = new SoPContext();
            var dbUser = db.Users.FirstOrDefault(u => u.Username == "admin");
            var id     = 0;

            if (dbUser != null)
            {
                id = dbUser.Id;
            }
            else
            {
                var user = User.CreateNew("admin", "admin");
                id = db.Users.Add(user).Entity.Id;
            }
            var password1 = new PasswordEntry()
            {
                Description = "Password 1 for category 1",
                Password    = "******",
                Title       = "Password 1"
            };
            var password2 = new PasswordEntry()
            {
                Description = "Password 2 for category 1",
                Password    = "******",
                Title       = "Password 2"
            };
            var password3 = new PasswordEntry()
            {
                Description = "Password 3 for category 2",
                Password    = "******",
                Title       = "Password 3"
            };
            var cat1 = Category.CreateNew("TestCategory 1", "Category for testing 1", id);

            cat1.Passwords.Add(password1);
            cat1.Passwords.Add(password2);
            var cat2 = Category.CreateNew("TestCategory 2", "Category for testing 2", id);

            cat2.Passwords.Add(password3);
            db.Categories.Add(cat1);
            db.Categories.Add(cat2);
            db.SaveChanges();
        }
 public void Save(PasswordEntry passwordEntry)
 {
     using var context = new SoPContext();
     context.Update(passwordEntry);
     context.SaveChanges();
 }
Exemple #12
0
 private User Get(Func <User, bool> func)
 {
     using var dbContext = new SoPContext();
     return(dbContext.Users.FirstOrDefault(func));
 }
Exemple #13
0
 private Category Get(Func <Category, bool> func)
 {
     using var context = new SoPContext();
     return(context.Categories.Include(cat => cat.Passwords).FirstOrDefault(func));
 }
Exemple #14
0
 public List <Category> GetForUser(int userId)
 {
     using var context = new SoPContext();
     return(context.Categories.Where(cat => cat.UserId == userId).Include(cat => cat.Passwords).ToList());
 }
Exemple #15
0
 public void Save(Category category)
 {
     using var context = new SoPContext();
     context.Update(category);
     context.SaveChanges();
 }