public async Task GetByIdAsync_Returns_OneFoodItem_WithSameGuid() { // Arrange // Setup fake Fooditem with a set GUID var fakeFoodItem = A.Fake <FoodItem>(options => options .ConfigureFake(fakeItem => fakeItem.Id = Guid.NewGuid())); // Fake the FoodRepository and pass it to controller var fakeFoodRepository = A.Fake <IFoodRepository>(); var foodItemController = new FoodItemController(fakeFoodRepository); // Configures a call to fake repository. Checks if passed-in GUID will match fake FoodItem created earlier A.CallTo(() => fakeFoodRepository.GetByIdAsync(A <Guid> .That.Matches(input => input == fakeFoodItem.Id))) .Returns(Task.FromResult(fakeFoodItem)); // Act // Call controller method by passing in required GUID parameter. Returns ActionResult with status OK // Then cast the value passed with OK result to the actual type of FoodItemDto var actionResult = (await foodItemController.GetByIdAsync(fakeFoodItem.Id)).Result as OkObjectResult; var returnedFoodItem = actionResult.Value as FoodItemDto; // Assert // Checking if an object is returned and if the GUID's still match Assert.NotNull(returnedFoodItem); Assert.Equal(fakeFoodItem.Id, returnedFoodItem.id); }
/// <summary> /// Set the amount of the dish <paramref name="dishManaged"/> that this player has to <paramref name="getFoodAmount"/>. /// </summary> /// <param name="dishManaged">The dish the player has.</param> /// <param name="getFoodAmount">The amount of that dish that the player has.</param> public void SetFoodAmountToPurchase(Dish dishManaged, int getFoodAmount) { // Set the new dish amount in the UI. FoodItemController foodItemController = GetFoodItemController(dishManaged); foodItemController.SetAmountOfFoodToBuy(getFoodAmount); }
public async Task GetAllAsync_Returns_AllFoodItemsPresent() { // Arrange const int fakeFoodItemCount = 1; var fakeFoodItem = A.CollectionOfDummy <FoodItem>(fakeFoodItemCount).ToList(); var fakeFoodRepository = A.Fake <IFoodRepository>(); var foodItemController = new FoodItemController(fakeFoodRepository); A.CallTo(() => fakeFoodRepository.GetAllAsync()) .Returns(Task.FromResult(fakeFoodItem)); // Act var actionResult = (await foodItemController.GetAllAsync()).Result as OkObjectResult; var returnedFoodItems = (actionResult.Value as IEnumerable <FoodItemDto>).ToList(); // Assert Assert.Equal(fakeFoodItemCount, returnedFoodItems.Count); }
/// <summary> /// Initialize this menu of dishes. /// </summary> /// <param name="_gameSceneManager">The GameSceneManager to </param> public void InitializeDishMenu(GameSceneManager _gameSceneManager) { // Start by clearing out all entries in the menu. GameObject dishMenuMenuHolder = this.menuHolder; dishMenuMenuHolder.DestroyAllChildren(); // For each dish, instantiate a prefab to represent the dish. foreach (Dish dish in _gameSceneManager.GetAcquiredRecipes()) { GameObject instantiatedMenuItem = Instantiate(_gameSceneManager.FOOD_CONTROLLER_PREFAB); dishMenuMenuHolder.AddChild(instantiatedMenuItem, false); // Then, initialize the script attached to the prefab with information on this GameSceneManager. FoodItemController foodItemController = instantiatedMenuItem.GetComponent <FoodItemController>(); foodItemController.Initialize(dish, _gameSceneManager); } this.SetDishDetails(this.gameSceneManager.gameState); }
public void SetDishInInventory(Dish dish, int dishCount) { FoodItemController foodItemController = GetFoodItemController(dish); foodItemController.SetAmountOfDishesInStockInUI(dishCount); }