コード例 #1
0
ファイル: FridgeTests.cs プロジェクト: kjelag/Fridge
            public void IsItemAvailable()
            {
                var fakeInventoryRepository = new FakeInventoryRepository();
                var fridge = new FridgeService(fakeInventoryRepository);

                Assert.AreEqual(false, fridge.IsItemAvailable(inventoryName, 7));
            }
コード例 #2
0
        public void UpdateItemInFridge()
        {
            var repository = new FakeItemRepository();
            var flourItem  = new Item
            {
                Name     = "Egg",
                Quantity = new Quantity()
                {
                    Unit = "P", Total = 8
                }
            };

            repository.Items.Add(flourItem);

            var worker = new FridgeService(repository);

            var eggItem = new Item
            {
                Name     = "Egg",
                Quantity = new Quantity()
                {
                    Unit = "P", Total = 8
                }
            };

            var result = worker.AddItem(eggItem);

            Assert.AreEqual(result.Unit, "P");
            Assert.AreEqual(result.Total, 16);
        }
コード例 #3
0
ファイル: FridgeTests.cs プロジェクト: kjelag/Fridge
            public void RemoveInventoryItem()
            {
                var fakeInventoryRepository = new FakeInventoryRepository();
                var fridge = new FridgeService(fakeInventoryRepository);

                Assert.AreEqual(-5, fridge.TakeItemFromFridge(inventoryName, 5));
            }
コード例 #4
0
        public ItemController(IItemRepository repository)
        {
            _repository = repository;

            var flourItem = new Item
            {
                Name     = "Flour",
                Quantity = new Quantity()
                {
                    Unit = "L", Total = 1
                }
            };

            _repository.Add(flourItem);
            var eggItem = new Item
            {
                Name     = "Egg",
                Quantity = new Quantity()
                {
                    Unit = "P", Total = 8
                }
            };

            _repository.Add(eggItem);

            _fridgeService = new FridgeService(_repository);
        }
コード例 #5
0
ファイル: FridgeTests.cs プロジェクト: kjelag/Fridge
            public void IsItemAvailable()
            {
                var fakeInventoryRepository = new FakeInventoryRepository();
                var fridge        = new FridgeService(fakeInventoryRepository);
                var inventoryItem = new InventoryItem(inventoryName, 10);

                fridge.AddIngredientToFridge(inventoryItem);
                Assert.AreEqual(true, fridge.IsItemAvailable(inventoryName, 7));
            }
コード例 #6
0
ファイル: FridgeTests.cs プロジェクト: kjelag/Fridge
            public void ListAllInventoryItems()
            {
                var fakeInventoryRepository = new FakeInventoryRepository();
                var fridge = new FridgeService(fakeInventoryRepository);

                var result = fridge.GetAllInventoryItems();

                Assert.AreEqual(0, result.Count);
            }
コード例 #7
0
ファイル: FridgeTests.cs プロジェクト: kjelag/Fridge
            public void GetItem()
            {
                var fakeInventoryRepository = new FakeInventoryRepository();
                var fridge = new FridgeService(fakeInventoryRepository);

                var result = fridge.GetInventoryItem("Gorgonzola");

                Assert.AreEqual(null, result);
            }
コード例 #8
0
ファイル: FridgeTests.cs プロジェクト: kjelag/Fridge
            public void AddOneInventoryItem()
            {
                var fakeInventoryRepository = new FakeInventoryRepository();
                var fridge        = new FridgeService(fakeInventoryRepository);
                var inventoryItem = new InventoryItem(inventoryName, 10);

                fridge.AddIngredientToFridge(inventoryItem);

                Assert.AreEqual(1, fakeInventoryRepository.InventoryItems.Count);
                Assert.AreEqual(inventoryName, fakeInventoryRepository.InventoryItems[0].Name);
                Assert.AreEqual(10, fakeInventoryRepository.InventoryItems[0].Quantity);
            }
コード例 #9
0
ファイル: FridgeTests.cs プロジェクト: kjelag/Fridge
            public void GetNonExistingItem()
            {
                var fakeInventoryRepository = new FakeInventoryRepository();
                var fridge = new FridgeService(fakeInventoryRepository);

                var inventoryItem = new InventoryItem(inventoryName, 10);

                fridge.AddIngredientToFridge(inventoryItem);

                var result = fridge.GetInventoryItem("Gorgonzola");

                Assert.AreEqual(null, result);
            }
コード例 #10
0
        public async Task CleanFridgeDoesNothingOnEmptyFridge()
        {
            var mockRepo = new Mock <IKitchenRepo>();

            mockRepo.Setup(r => r.GetAllFridgeItemsAsync())
            .ReturnsAsync(Enumerable.Empty <FridgeItem>());

            var service = new FridgeService(mockRepo.Object);

            bool cleaned = await service.CleanFridgeAsync();

            Assert.False(cleaned);
        }
コード例 #11
0
ファイル: FridgeTests.cs プロジェクト: kjelag/Fridge
            public void GetExistingItem()
            {
                var fakeInventoryRepository = new FakeInventoryRepository();
                var fridge = new FridgeService(fakeInventoryRepository);

                var inventoryItem = new InventoryItem(inventoryName, 10);

                fridge.AddIngredientToFridge(inventoryItem);

                var result = fridge.GetInventoryItem(inventoryName);

                Assert.AreEqual(inventoryName, result.Name);
                Assert.AreEqual(10, result.Quantity);
            }
コード例 #12
0
        public void ItemNotExistInFridge()
        {
            var repository = new FakeItemRepository();

            repository.Items.Add(new Item()
            {
                Name = "Flour"
            });

            var worker = new FridgeService(repository);
            var result = worker.IsAvailable("Egg");

            Assert.IsFalse(result);
        }
コード例 #13
0
ファイル: FridgeTests.cs プロジェクト: kjelag/Fridge
            public void RemoveNonExistingInventoryItem()
            {
                var invItem1      = "Meatballs";
                var invItem2      = "Potato";
                var invRemoveItem = "Sauce";

                var fakeInventoryRepository = new FakeInventoryRepository();
                var fridge = new FridgeService(fakeInventoryRepository);

                var inventoryItem = new InventoryItem(invItem1, 10);

                fridge.AddIngredientToFridge(inventoryItem);
                inventoryItem = new InventoryItem(invItem2, 50);
                fridge.AddIngredientToFridge(inventoryItem);

                Assert.AreEqual(-5, fridge.TakeItemFromFridge(invRemoveItem, 5));
            }
コード例 #14
0
ファイル: FridgeTests.cs プロジェクト: kjelag/Fridge
            public void RemoveExistingInventoryItem()
            {
                var invItem1 = "Meatballs";
                var invItem2 = "Potato";
                var invItem3 = "Pasta";

                var fakeInventoryRepository = new FakeInventoryRepository();
                var fridge = new FridgeService(fakeInventoryRepository);

                var inventoryItem = new InventoryItem(invItem1, 10);

                fridge.AddIngredientToFridge(inventoryItem);
                inventoryItem = new InventoryItem(invItem2, 50);
                fridge.AddIngredientToFridge(inventoryItem);
                inventoryItem = new InventoryItem(invItem3, 4);
                fridge.AddIngredientToFridge(inventoryItem);

                Assert.AreEqual(20, fridge.TakeItemFromFridge(invItem2, 30));
                Assert.AreEqual(-10, fridge.TakeItemFromFridge(invItem2, 30));
            }
コード例 #15
0
        public void RemoveItemInFridge()
        {
            var repository = new FakeItemRepository();
            var flourItem  = new Item
            {
                Name     = "Flour",
                Quantity = new Quantity()
                {
                    Unit = "L", Total = 1
                }
            };

            repository.Items.Add(flourItem);
            var eggItem = new Item
            {
                Name     = "Egg",
                Quantity = new Quantity()
                {
                    Unit = "P", Total = 8
                }
            };

            repository.Items.Add(eggItem);

            var worker       = new FridgeService(repository);
            var eggsToRemove = new Item
            {
                Name     = "Egg",
                Quantity = new Quantity()
                {
                    Unit = "P", Total = 3
                }
            };

            var result = worker.RemoveItem(eggsToRemove);

            Assert.AreEqual(result.Total, 5);
        }
コード例 #16
0
ファイル: FridgeTests.cs プロジェクト: kjelag/Fridge
            public void ListAllInventoryItems()
            {
                var invItem1 = "Meatballs";
                var invItem2 = "Potato";
                var invItem3 = "Pasta";

                var fakeInventoryRepository = new FakeInventoryRepository();
                var fridge = new FridgeService(fakeInventoryRepository);

                var inventoryItem = new InventoryItem(invItem1, 10);

                fridge.AddIngredientToFridge(inventoryItem);
                inventoryItem = new InventoryItem(invItem2, 50);
                fridge.AddIngredientToFridge(inventoryItem);
                inventoryItem = new InventoryItem(invItem3, 4);
                fridge.AddIngredientToFridge(inventoryItem);

                var result = fridge.GetAllInventoryItems();

                Assert.AreEqual(3, result.Count);
                Assert.AreEqual(invItem1, result[0].Name);
                Assert.AreEqual(invItem2, result[1].Name);
                Assert.AreEqual(invItem3, result[2].Name);
            }
コード例 #17
0
 public FridgeController()
 {
     _fridgeService = new FridgeService();
 }