/// <summary>
        /// Tests whether a customer was created and sent to the DB. Retreives it and compares its result with local
        /// object.
        /// </summary>
        public void CreatingCustomerTest()
        {
            //arrange
            var options = new DbContextOptionsBuilder <StoreAppDBContext>().UseInMemoryDatabase(databaseName: "TestDb").Options;

            //add
            using (var context = new StoreAppDBContext(options)) //might cause
            //problems bc i have no constructor that just takes option
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                StoreAppRepositoryLayer repo = new StoreAppRepositoryLayer(context);
                repo.CreateCustomer("fname", "lname", "username");
                context.SaveChanges();
            }

            using (var context = new StoreAppDBContext(options))
            {
                StoreAppRepositoryLayer repo = new StoreAppRepositoryLayer(context);
                int status = repo.CreateCustomer("fname", "lname", "username");
                if (status == 0) //created customer
                {
                    Customer fromDB = context.customers.Find("username");
                    Assert.True(fromDB.Equals("username"));
                }
            }
        }
Example #2
0
        public static IMenu GetMenu(string menuType)
        {
            //configure
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json")
                                .Build();

            //connect
            string connectionString = configuration.GetConnectionString("StoreAppDB");
            //Console.WriteLine(connectionString);

            //option
            DbContextOptions <StoreAppDBContext> options = new DbContextOptionsBuilder <StoreAppDBContext>()
                                                           .UseSqlServer(connectionString)
                                                           .Options;

            //context
            var context = new StoreAppDBContext(options);

            IRepository        repo            = new RepoDB(context);
            IValidationService inputValidation = new ValidationService();
            ICustomerBL        customerBL      = new CustomerBL(repo);
            ILocationBL        locationBL      = new LocationBL(repo);
            IProductBL         productBL       = new ProductBL(repo);
            IInventoryBL       inventoryBL     = new InventoryBL(repo);
            IOrderBL           orderBL         = new OrderBL(repo);

            switch (menuType.ToLower())
            {
            case "main":
                return(new MainMenu());

            case "branch":
                return(new BranchMenu(locationBL, inputValidation));

            case "product":
                return(new ProductMenu(productBL, inputValidation));

            case "inventory":
                return(new InventoryMenu(locationBL, productBL, inventoryBL, orderBL, inputValidation));

            case "customer":
                return(new CustomerMenu(customerBL));

            case "order":
                return(new OrderMenu(customerBL, locationBL, productBL, inventoryBL, orderBL, inputValidation));

            default:
                return(null);
            }
        }
        /// <summary>
        /// Will look for nonexistent player in DB. Should return 0 if found, will return -1 to show it
        /// looked through DB and found did not find it.
        ///  </summary>
        public void LogInTest()
        {
            //arrange
            var options = new DbContextOptionsBuilder <StoreAppDBContext>().UseInMemoryDatabase(databaseName: "TestDb").Options;

            //add
            using (var context = new StoreAppDBContext(options)) //might cause
            //problems bc i have no constructor that just takes option
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                StoreAppRepositoryLayer repo = new StoreAppRepositoryLayer(context);
                int status = repo.LogIn("I_AM_NON_EXISTENT");
                Assert.Equal(status, -1);
            }
        }
        static void Main(string[] args)
        {
            //get configuration file
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json")
                                .Build();

            //setting up db connection
            string connectionString = configuration.GetConnectionString("StoreAppDB");
            DbContextOptions <StoreAppDBContext> options = new DbContextOptionsBuilder <StoreAppDBContext>()
                                                           .UseSqlServer(connectionString)
                                                           .Options;

            //using statement used to dispose of the context when its no longer used
            using var context = new StoreAppDBContext(options);

            IMenu menu = new StartMenu(new storeBL(new StoreRepoDB(context, new StoreMapper())));

            menu.Start();
        }