public void GetAllStoresCheker()
        {
            var data = new List <Store>

            {
                new Store("billa"),
                new Store("lidl"),
                new Store("metro")
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Store> >();

            mockSet.As <IQueryable <Store> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Store> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Store> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Store> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock <FoodStoreContext>();

            mockContext.Setup(c => c.Stores).Returns(mockSet.Object);

            var service = new StoreController(mockContext.Object);

            data.ToList().ForEach(p => service.AddStore(p));
            Assert.AreEqual(data.ToList(), service.GetStore()
                            , "GetStore doesnt return right list of stores");
        }
        public void GetStoreByGivenId()
        {
            var data = new List <Store>

            {
                new Store("billa"),
                new Store("lidl"),
                new Store("metro")
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Store> >();

            mockSet.As <IQueryable <Store> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Store> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Store> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Store> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock <FoodStoreContext>();

            mockContext.Setup(c => c.Stores).Returns(mockSet.Object);

            var service = new StoreController(mockContext.Object);

            data.ToList().ForEach(p => service.AddStore(p));
            var expected = service.GetStore(1);//billa

            Assert.AreEqual(expected, data.FirstOrDefault(x => x.Id == 1)
                            , "GetStore by given id doesn't return right store. Check StoreiD!");
        }
Exemplo n.º 3
0
        public void AddStore_ReturnsBadRequestResult_WhenViewModelNull()
        {
            Console.WriteLine("Running test: AddStore_ReturnsBadRequestResult_WhenViewModelNull");

            // Arrange
            var mockRepo = new Mock <IStoreRepository>();

            mockRepo.Setup(repo => repo.AddStore(new Store {
                StoreNumber = 1
            })).Returns(true);
            var controller = new StoreController(mockRepo.Object, new LoggerFactory());

            // Act
            var result = controller.AddStore(null);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
Exemplo n.º 4
0
        public void AddStore_ReturnsObjectResult_WhenValid()
        {
            Console.WriteLine("Running test: AddStore_ReturnsObjectResult_WhenValid");

            // Arrange
            var mockRepo = new Mock <IStoreRepository>();

            mockRepo.Setup(repo => repo.AddStore(new Store {
                StoreNumber = 1
            })).Returns(true);
            var controller = new StoreController(mockRepo.Object, new LoggerFactory());

            // Act
            var result = controller.AddStore(new StoreViewModel {
                StoreNumber = 1
            });

            // Assert
            Assert.IsAssignableFrom <ObjectResult>(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Shows the Store Managment
        /// </summary>
        public void ShowStoreManagment()
        {
            string[] command;
            var      storeController = new StoreController();

            do
            {
                Console.WriteLine("Store managment Menu:\n" +
                                  "Current Stores:\n");
                var stores = storeController.GetStore();

                if (stores.Count == 0)
                {
                    Console.WriteLine("There are no stores in the database");
                    Console.WriteLine("B. Exit Managment Menu\n\n");
                    command = Console.ReadLine()?.Split(' ');
                }
                else
                {
                    foreach (var store in stores)
                    {
                        Console.WriteLine($"ID:{store.Id}\t " +
                                          $"Name:{store.Name}\t ");
                    }

                    Console.WriteLine("\nTo add a new store use ADD");
                    Console.WriteLine("To remove a store use DELETE (Store ID)");
                    Console.WriteLine("To update a store use UPDATE");
                    Console.WriteLine("If you want to delete the whole store table and reset it's id use DELETEALL");
                    Console.WriteLine("B. Exit Managment Menu\n\n");

                    Console.Beep(500, 100);
                    command = Console.ReadLine()?.Split();

                    if (command?[0].ToUpper() == "ADD")
                    {
                        Console.Write("Store Name: ");
                        var name = Console.ReadLine();

                        var store = new Store(name);
                        try
                        {
                            storeController.AddStore(store);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            Console.WriteLine("Press B to go back");
                            var dummy = Console.ReadLine();
                        }
                    }

                    if (command?[0].ToUpper() == "DELETE")
                    {
                        try
                        {
                            storeController.DeleteStore(int.Parse(command[1]));
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            Console.WriteLine("Press B to go back");
                            var dummy = Console.ReadLine();
                        }
                    }

                    if (command?[0].ToUpper() == "UPDATE")
                    {
                        Console.Write("Store ID: ");
                        var id    = int.Parse(Console.ReadLine());
                        var store = storeController.GetStore(id);

                        Console.Write("Store Name: ");
                        store.Name = Console.ReadLine();

                        try
                        {
                            storeController.UpdateStore(store);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            Console.WriteLine("Press B to go back");
                            var dummy = Console.ReadLine();
                        }
                    }

                    if (command?[0].ToUpper() == "DELETEALL")
                    {
                        Console.WriteLine("ARE YOU SURE? Y/N");
                        command = Console.ReadLine()?.Split();
                        if (command?[0].ToUpper() == "YES" || command?[0].ToUpper() == "Y")
                        {
                            foreach (var store in stores)
                            {
                                storeController.DeleteStore(store.Id);
                            }

                            storeController.ResetWholeStore();
                            Console.WriteLine("It is done. The whole table has been reset");
                            Console.WriteLine("Press B to go back");
                            var dummy = Console.ReadLine();
                        }
                    }
                }

                Console.Clear();
            } while (command?[0].ToUpper() != "B");
        }