public DbContextOptions <WebStoreAppContext> SetUp(string databaseName) { var options = new DbContextOptionsBuilder <WebStoreAppContext>() .UseInMemoryDatabase(databaseName: databaseName) .Options; using (var context = new WebStoreAppContext(options)) { context.UserTypes.Add(new UserType()); context.SaveChanges(); context.Users.Add(new User { UserType = context.UserTypes.First(), UserInfo = new UserInfo() }); context.Locations.Add(new Location()); context.SaveChanges(); var product = context.Products.Add(new Product { Location = context.Locations.First() }); context.SaveChanges(); var order = context.Orders.Add(new Order { User = context.Users.First(), Location = context.Locations.First(), OrderInfo = new OrderInfo() }); context.SaveChanges(); } return(options); }
public void AddingOrderWithDatabaseContext() { // Arrange var options = new DbContextOptionsBuilder <WebStoreAppContext>() .UseInMemoryDatabase(databaseName: "AddingOrderWithDatabaseContext") .Options; // Act using (var context = new WebStoreAppContext(options)) { var user = context.Users.Add(new User()).Entity; var location = context.Locations.Add(new Location()).Entity; var product = context.Products.Add(new Product { Location = location }).Entity; context.Orders.Add(new Order() { User = user, Location = location }); context.SaveChanges(); } // Assert using (var context = new WebStoreAppContext(options)) { var orders = context.Orders.ToList(); Assert.Single(orders); } }
public void AddingProductWithDatabaseContext() { // Arrange var options = new DbContextOptionsBuilder <WebStoreAppContext>() .UseInMemoryDatabase(databaseName: "AddingProductWithDatabaseContext") .Options; // Act using (var context = new WebStoreAppContext(options)) { var product = new Product { Name = "", Price = 1.00M, Quantity = 1 }; product.Location = new Location(); context.Products.Add(product); context.SaveChanges(); } // Assert using (var context = new WebStoreAppContext(options)) { var products = context.Products.ToList(); Assert.Single(products); } }
public void DeleteOrderWithDatabaseContext() { var options = SetUp("DeleteOrderWithDatabaseContext"); using (var context = new WebStoreAppContext(options)) { context.Orders.Remove(context.Orders.First()); context.SaveChanges(); } using (var context = new WebStoreAppContext(options)) { Assert.Empty(context.Orders); } }
public void AddingUserWithDatabaseContext() { // Arrange var options = new DbContextOptionsBuilder <WebStoreAppContext>() .UseInMemoryDatabase(databaseName: "AddingUserWithDatabaseContext") .Options; // Act using (var context = new WebStoreAppContext(options)) { // Add new Admin user to Database. string password = "******"; byte[] salt = new byte[128 / 8]; using (var rng = RandomNumberGenerator.Create()) { rng.GetBytes(salt); } string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2( password: password, salt: salt, prf: KeyDerivationPrf.HMACSHA1, iterationCount: 10000, numBytesRequested: 256 / 8 )); User user = new User(); user.UserInfo = new UserInfo { FirstName = "FirstName", LastName = "LastName" }; user.UserType = new UserType { Name = "", Description = "" }; user.LoginInfo = new LoginInfo { Username = "******", Hashed = hashed, Salt = salt }; context.Users.Add(user); context.SaveChanges(); } // Assert using (var context = new WebStoreAppContext(options)) { Assert.Single(context.Users.ToList()); Assert.Single(context.UserInfos.ToList()); Assert.Single(context.LoginInfos.ToList()); Assert.Single(context.UserTypes.ToList()); } }
public void DeleteLocationWithDatabaseContext() { // Arrange var options = SetUp("DeleteLocationWithDatabaseContext"); // Act using (var context = new WebStoreAppContext(options)) { context.Locations.Remove(context.Locations.Include(location => location.Products).First()); context.SaveChanges(); } // Assert using (var context = new WebStoreAppContext(options)) { Assert.Empty(context.Locations); Assert.Empty(context.Products); } }
public void DeleteUserWithDatabaseContext() { // Arrange var options = SetUp("DeleteUserWithDatabaseContext"); // Act using (var context = new WebStoreAppContext(options)) { context.Users.Remove(context.Users.Include(user => user.UserInfo).First()); context.SaveChanges(); } // Assert using (var context = new WebStoreAppContext(options)) { Assert.Empty(context.Users); Assert.Empty(context.UserInfos); } }
public void AddingLocationWithDatabaseContext() { // Arrange var options = new DbContextOptionsBuilder <WebStoreAppContext>() .UseInMemoryDatabase(databaseName: "AddingLocationWithDatabaseContext") .Options; // Act using (var context = new WebStoreAppContext(options)) { context.Locations.Add(new Location { Name = "" }); context.SaveChanges(); } // Assert using (var context = new WebStoreAppContext(options)) { var locations = context.Locations.ToList(); Assert.Single(locations); } }
public void AddingUserTypeWithDatabaseContext() { // Arrange var options = new DbContextOptionsBuilder <WebStoreAppContext>() .UseInMemoryDatabase(databaseName: "AddingUserTypeWithDatabaseContext") .Options; // Act using (var context = new WebStoreAppContext(options)) { context.UserTypes.Add(new UserType { Name = "Admin", Description = "" }); context.SaveChanges(); } // Assert using (var context = new WebStoreAppContext(options)) { var userTypes = context.UserTypes.ToList(); Assert.Single(userTypes); } }
public UserModelService(WebStoreAppContext context) { this._unitOfWork = new UnitOfWork(context); }
public OrderRepository(WebStoreAppContext context) : base(context) { }
public LocationsModelService(WebStoreAppContext context, ILogger <LocationsModelService> logger) { this._unitOfWork = new UnitOfWork(context); this._logger = logger; }
public BaseRepository(WebStoreAppContext context) { this._context = context; this.dbSet = context.Set <TEntity>(); }
public ProductRepository(WebStoreAppContext context) : base(context) { }
public UserTypeRepository(WebStoreAppContext context) : base(context) { }