public void AddProdukt()
        {
            var options = new DbContextOptionsBuilder <EshopContext>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_database")
                          .Options;

            // Insert seed data into the database using one instance of the context
            using (var context = new EshopContext(options))
            {
                context.Produkter.Add(new Produkt {
                    Navn = "Test", Pris = 1243
                });
                context.Produkter.Add(new Produkt {
                    Navn = "Test 2", Pris = 1243
                });
                context.Produkter.Add(new Produkt {
                    Navn = "Test 3", Pris = 1243
                });
                context.SaveChanges();
            }

            // Use a clean instance of the context to run the test
            using (var context = new EshopContext(options))
            {
                var service = new ProduktService(context);
                var result  = service.AddProdukt();
                Assert.AreEqual(3, result.Count());
            }
        }
예제 #2
0
        public IActionResult Register(AppUsers acc)
        {
            var user = _context.AppUsers.Where(u => u.Username == acc.Username).ToList();

            if (user.Count == 0)
            {
                byte[] salt = new byte[128 / 8];
                using (var rng = RandomNumberGenerator.Create())
                {
                    rng.GetBytes(salt);
                }
                string saltSave = "";
                for (int i = 0; i < salt.Length; i++)
                {
                    saltSave = saltSave + salt[i] + " ";
                }
                //Console.WriteLine($"Salt: {Convert.ToBase64String(salt)}");

                // derive a 256-bit subkey (use HMACSHA1 with 10,000 iterations)
                string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
                                                           password: acc.Password,
                                                           salt: salt,
                                                           prf: KeyDerivationPrf.HMACSHA1,
                                                           iterationCount: 10000,
                                                           numBytesRequested: 256 / 8));
                acc.Password = hashed + "|" + saltSave;
                _context.AppUsers.Add(acc);
                _context.SaveChanges();
                return(Ok(salt));
            }

            return(BadRequest("user have been exited"));
        }
예제 #3
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }
예제 #4
0
 public int SaveChanges()
 {
     return(context.SaveChanges());
 }