Example #1
0
        public void AddCustomerToDatabase(string strFirstName, string strLastName)
        {
            //Arrange
            DbContextOptions <StoreDbContext> options = new DbContextOptionsBuilder <StoreDbContext>()
                                                        .UseInMemoryDatabase(databaseName: "TestDb")
                                                        .Options;

            Customer myGeneratedCustomer = new Customer();

            //Act
            using (StoreDbContext dbContext = new StoreDbContext(options))
            {
                P0_RLayer myRepoLayer = new P0_RLayer(dbContext);

                myRepoLayer.CreateCustomer();
                myGeneratedCustomer = myRepoLayer.Customers.FirstOrDefault(x => x.ToString() == $"{strFirstName} {strLastName}");
            }

            //Assert
            using (StoreDbContext dbContext = new StoreDbContext(options))
            {
                P0_RLayer myRepoLayer = new P0_RLayer(dbContext);

                Customer DbCustomer = dbContext.Customers.FirstOrDefault(x => x.ToString() == $"{strFirstName} {strLastName}");

                Assert.Equal(myGeneratedCustomer.CustomerID, DbCustomer.CustomerID);
            }
        }
        static void Main(string[] args)
        {
            P0_RLayer myRepoLayer = new P0_RLayer();

            Console.WriteLine("Welcome to the Super");

            bool ExitMainMenu = false;

            do
            {
                Console.Write("Log in  (Press x to quit the app)\nFirst Name: ");
                string strUserFirstName = Console.ReadLine().Trim().Split(' ')[0];// Trim any white spaces that the user input in the beggining and split to get only the first...
                if (strUserFirstName.ToLower() == "x")
                {
                    Console.WriteLine("Exiting the console...\n");
                    ExitMainMenu = true;
                    break;
                }
                Console.Write("Last Name: ");
                string strUserLastName = Console.ReadLine().Trim().Split(' ')[0];

                // ->
                Console.WriteLine(myRepoLayer.CreateCustomer(strUserFirstName, strUserLastName));

                // Showing the Main menu

                //Call the switch method
                ExitMainMenu = MainMenuOptionsOperations(myRepoLayer);
            } while (!ExitMainMenu);
        }