示例#1
0
        public void UpdateInventoryLineItemShouldUpdateLineItem()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <IceShopContext>().UseInMemoryDatabase("UpdateInventoryLineItemShouldUpdateLineItem").Options;

            using var testContext = new IceShopContext(options);
            // add sample data to testContext
            testContext.InventoryLineItems.AddRange(SampleData.GetSampleInventoryLineItems());
            // This data needs to be added so that navigation properties of the Inventory Line Items aren't null.
            testContext.Locations.AddRange(SampleData.GetSampleLocations());
            testContext.Products.AddRange(SampleData.GetSampleProducts());
            testContext.SaveChanges();

            repo = new DBRepo(testContext);

            //Act
            // get a location that has an InventoryLineItem
            int sampleLocationId             = repo.GetAllLocations().First().Id;
            InventoryLineItem sampleLineItem = repo.GetAllInventoryLineItemsAtLocation(sampleLocationId).FindLast(ili => ili.LocationId == sampleLocationId);
            int startingQuantity             = sampleLineItem.ProductQuantity;

            sampleLineItem.ProductQuantity += 1;


            repo.UpdateInventoryLineItem(sampleLineItem);
            repo.SaveChanges();

            //Assert
            //using var assertContext = new IceShopContext(options);
            Assert.NotEqual(startingQuantity, sampleLineItem.ProductQuantity);
        }
示例#2
0
        public void AddManagerShouldAdd()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <IceShopContext>().UseInMemoryDatabase("AddManagerShouldAdd").Options;

            using var testContext = new IceShopContext(options);
            repo = new DBRepo(testContext);

            //Act
            repo.AddManager(testManager);
            repo.SaveChanges();

            //Assert
            using var assertContext = new IceShopContext(options);
            Assert.NotNull(assertContext.Managers.Single(m => m.Id == testManager.Id));
        }
示例#3
0
        public void GetCustomerByEmailShouldGetCustomer()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <IceShopContext>().UseInMemoryDatabase("GetCustomerByEmailShouldGetCustomer").Options;

            using var testContext = new IceShopContext(options);
            repo = new DBRepo(testContext);

            //Act
            repo.AddCustomer(testCustomer);
            repo.SaveChanges();
            Customer fetchedTestCustomer = repo.GetCustomerByEmail(testCustomer.Email);

            //Assert
            using var assertContext = new IceShopContext(options);

            Assert.NotNull(assertContext.Customers.Single(c => c.Id == fetchedTestCustomer.Id));
        }
示例#4
0
        public void GetManagerByEmailShouldGetManager()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <IceShopContext>().UseInMemoryDatabase("GetManagerByEmailShouldGetManager").Options;

            using var testContext = new IceShopContext(options);
            repo = new DBRepo(testContext);
            testContext.Locations.AddRange(SampleData.GetSampleLocations());

            //Act
            repo.AddManager(testManager);
            repo.SaveChanges();


            Manager fetchedTestManager = repo.GetManagerByEmail(testManager.Email);

            //Assert
            //using var assertContext = new IceShopContext(options);
            Assert.NotNull(testContext.Managers.Single(m => m.Id == fetchedTestManager.Id));
        }
示例#5
0
        private static void Main()
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.File("logs/log.txt",
                                       outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
                         .CreateLogger();


            if (Log.Logger == null)
            {
                throw new Exception("Logger isn't working.");
            }


            Console.WriteLine("Welcome Friend! What would you like to do today?");

            IceShopContext context   = new IceShopContext();
            IRepository    repo      = new DBRepo(context);
            IMenu          startMenu = new StartMenu(ref repo);

            MenuManager.Instance.ReadyNextMenu(startMenu);
            MenuManager.Instance.RunThroughMenuChain();
        }
示例#6
0
 public DBRepo(IceShopContext context)
 {
     this.context = context;
 }