public void Index_HasCorrectModelType_True() { //arrange ViewResult indexView = new RecipeController().Index() as ViewResult; //act var result = indexView.ViewData.Model; //assert Assert.IsInstanceOfType(result, typeof(List <Recipe>)); }
// Start is called before the first frame update void Start() { Recipe[] recipes = Resources.LoadAll <Recipe>("Recipe"); for (int i = 0; i < recipes.Length; i++) { GameObject go = Instantiate(RecipeTool); RecipeController recipeController = go.GetComponent <RecipeController>(); recipeController.setRecipe(recipes[i]); go.transform.SetParent(transform, false); } }
public void Index_ReturnIfTrue_View() { //arrange RecipeController controller = new RecipeController(); //act IActionResult indexView = controller.Index(); ViewResult result = indexView as ViewResult; //assert Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public void CreateRecipeForm_ReturnIfTrue_View() { //arrange RecipeController controller = new RecipeController(); //act IActionResult createRecipeFormView = controller.CreateRecipeForm(); ViewResult result = createRecipeFormView as ViewResult; //assert Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public EditModel(RecipeController recipeController, MeasureController measureController, CategoryController categoryController, IngredientDetailController ingredientDetailController, RecipeStepController recipeStepController) { _recipeController = recipeController; _measureController = measureController; _categoryController = categoryController; _ingredientDetailController = ingredientDetailController; _recipeStepController = recipeStepController; }
public void Awake() { if (instance == null) { instance = this; } else { Destroy(this.gameObject); } }
private static async Task FormIngredientListAsync(Recipe recipeToAdd, RecipeController recCont) { Console.WriteLine($"Enter ingredients for recipe {recipeToAdd.Name} below:"); Console.WriteLine("Or enter -1 in any field to stop adding ingredients"); while (true) { Console.Write("Ingredient name:"); string name = Console.ReadLine().Trim(); if (name == "-1") { break; } double amount; bool wasBreaked = false; bool parsed = false; while (true) { Console.Write("Amount:"); parsed = double.TryParse(Console.ReadLine().Trim(), out amount); if (parsed && amount == -1) { wasBreaked = true; break; } else if (parsed) { break; } } if (wasBreaked) { break; } Console.Write("Measured in:"); string measure = Console.ReadLine().Trim(); if (measure == "-1") { break; } try { await recCont.AddIngredientToRecipeAsync(recipeToAdd, name, measure, amount); } catch (Exception outer) { _logger.LogError(outer.Message); Console.WriteLine("Ingredient wasn't added to recipe, please try again"); } } }
public void DeleteRecipe_success() { //Arrange _recipeService.Setup(c => c.DeleteRecipe(Guid.Empty)).Returns(true); RecipeController recipeController = new RecipeController(_recipeService.Object); //Act var result = recipeController.Delete(Guid.Empty); var okObjectResult = result as AcceptedResult; //Assert Assert.NotNull(result); Assert.Equal(202, okObjectResult?.StatusCode); }
void OnEntitlementsRefreshed() { foreach (string id in pendingEntitlementIds) { //notify user of new inventory Entitlement ent = collectionCore.GetEntitlementById(id); Asset info = collectionCore.GetAssetInfoByName(ent.AssetName); string prefabName = (string)info.GetCustom("prefabName", ""); string descript = (string)info.Description; popupPrefab.SetPrefab(prefabName, descript); RecipeController ctrler = (RecipeController)AppController.Instance.GetController(Controller.RECIPE); //check recipes for completion string outcome = ctrler.OnNewInventory((string)info.Name); if (!String.IsNullOrEmpty(outcome)) { foreach (Image fuse in fusions) { if (fuse.gameObject.name == "icon_fus_" + outcome) { fuse.color = Color.white; break; } } } foreach (Image image in images) { if (image.gameObject.name == "icon_" + ent.AssetName) { image.color = Color.white; foreach (Image fuse in fusions) { if (fuse.gameObject.name == "icon_fus_" + ent.AssetName) { fuse.enabled = false; break; } } break; } } } pendingEntitlementIds.Clear(); }
public void GetSpecificRecipe_Failed() { //Arrange _recipeService.Setup(c => c.GetRecipe(Guid.Empty)).Returns((Recipe)null); RecipeController recipeController = new RecipeController(_recipeService.Object); //Act var result = recipeController.Get(Guid.Empty); var notFoundResult = result as NotFoundResult; //Assert Assert.NotNull(result); Assert.Equal(404, notFoundResult.StatusCode); }
public void Get_WhenCalled_ReturnsActionResult() { //Arrange controller = new RecipeController(mediatorMock.Object); mediatorMock.Setup(m => m.Send(It.IsAny <List.Query>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new List.RecipesEnvelope(new List <RecipeDto>(), new int())) .Verifiable("RecipesEnvelope was not sent"); //Act var response = controller.List(); //Assert Assert.IsType <ActionResult <List.RecipesEnvelope> >(response.Result); }
public RecipesViewModel(Label pageNumberLabel) { Title = "Recipes"; Items = new ObservableCollection <Recipe>(); RecipeController = new RecipeController(); PageNumberLabel = pageNumberLabel; LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand()); MessagingCenter.Subscribe <AddRecipePage, Recipe>(this, "AddRecipe", (obj, item) => { var newRecipe = item as Recipe; Items.Insert(0, newRecipe); }); }
public void DeleteRecipe_failed() { //Arrange _recipeService.Setup(c => c.DeleteRecipe(Guid.Empty)).Returns(false); RecipeController recipeController = new RecipeController(_recipeService.Object); //Act var result = recipeController.Delete(Guid.Empty); var okObjectResult = result as BadRequestResult; //Assert Assert.NotNull(result); Assert.Equal(400, okObjectResult?.StatusCode); }
void Update() { if (Input.GetKeyDown(KeyCode.R)) { CurrencyController currencyCtrler = (CurrencyController)AppController.Instance.GetController(Controller.CURRENCY); currencyCtrler.Convert(5); } if (Input.GetKeyDown(KeyCode.F)) { RecipeController recipeCtrler = (RecipeController)AppController.Instance.GetController(Controller.RECIPE); recipeCtrler.CheckRecipe(); } }
public void GetRecipesMockedTest() { // Arrange var service = new RecipeController(new MockedDatabaseFactory()); var mock = new MockedDatabaseFactory(); service.Request = new System.Net.Http.HttpRequestMessage(); service.Configuration = new System.Web.Http.HttpConfiguration(); // Act var result = service.Get(); // Assert Assert.AreEqual(result.Count, 3); }
public void PutRecipe_failed() { //Arrange Recipe recipe = new Recipe(); _recipeService.Setup(c => c.UpdateRecipe(recipe)).Returns(false); RecipeController recipeController = new RecipeController(_recipeService.Object); //Act var result = recipeController.Put(recipe); var okObjectResult = result as BadRequestResult; //Assert Assert.NotNull(result); Assert.Equal(400, okObjectResult?.StatusCode); }
private static int GetNumberRecipe(RecipeController recipeController, int numberSelectedCategory) { List <Recipe> recipesCategory = recipeController.GetSelectedRecipes(numberSelectedCategory); int numberSelectedCRecipe; do { Console.Write("Выберете рецепт: "); while (!int.TryParse(Console.ReadLine(), out numberSelectedCRecipe)) { Console.WriteLine("Не корректный выбор (введите число)"); Console.Write("Повторите выбор: "); } } while (numberSelectedCRecipe > recipesCategory.Count); return(numberSelectedCRecipe); }
public void PostRecipe_Success() { //Arrange Recipe recipe = new Recipe(); _recipeService.Setup(c => c.CreateRecipe(recipe)).Returns(true); RecipeController recipeController = new RecipeController(_recipeService.Object); //Act var result = recipeController.Post(recipe); var okObjectResult = result as AcceptedResult; //Assert Assert.NotNull(result); Assert.Equal(202, okObjectResult?.StatusCode); }
public async Task CreateRecipe_Should_Throw_When_RecipeNameEmpty() { // Arrange var recipeToAdd = new Recipe { }; Recipe newRecipe = null; _unitOfWorkMock.Setup(uow => uow.SaveChangesAsync()); // Act & Assert var controller = new RecipeController(_unitOfWorkMock.Object); var exception = await Assert.ThrowsAsync <EmptyFieldException>(async() => newRecipe = await controller.CreateRecipeAsync(recipeToAdd)); Assert.EndsWith("cannot be empty.", exception.Message); Assert.Null(newRecipe); _unitOfWorkMock.Verify(uow => uow.SaveChangesAsync(), Times.Never); }
public void GetSpecificRecipe_Success() { //Arrange Recipe recipe = new Recipe(); _recipeService.Setup(c => c.GetRecipe(Guid.Empty)).Returns(recipe); RecipeController recipeController = new RecipeController(_recipeService.Object); //Act var result = recipeController.Get(Guid.Empty); var okObjectResult = result as OkObjectResult; //Assert Assert.NotNull(result); Assert.Equal(200, okObjectResult.StatusCode); }
public async Task RecipeController_GetRecipe_EmptyId(string recipeId) { var directoryManager = new DirectoryManager(); var fileManager = new FileManager(); var deploymentManifestEngine = new DeploymentManifestEngine(directoryManager, fileManager); var consoleInteractiveServiceImpl = new ConsoleInteractiveServiceImpl(); var consoleOrchestratorLogger = new ConsoleOrchestratorLogger(consoleInteractiveServiceImpl); var commandLineWrapper = new CommandLineWrapper(consoleOrchestratorLogger); var customRecipeLocator = new CustomRecipeLocator(deploymentManifestEngine, consoleOrchestratorLogger, commandLineWrapper, directoryManager); var projectDefinitionParser = new ProjectDefinitionParser(fileManager, directoryManager); var recipeController = new RecipeController(customRecipeLocator, projectDefinitionParser); var response = await recipeController.GetRecipe(recipeId); Assert.IsType <BadRequestObjectResult>(response); }
public void GetRecipes_Failed() { //Arrange _recipeService.Setup(c => c.GetRecipes(25, 1)).Returns((List <RecipeDto>)null); RecipeController recipeController = new RecipeController(_recipeService.Object); //Act var result = recipeController.Get(new Paging { Size = 25, Page = 1 }); var notFoundResult = result as NotFoundResult; //Assert Assert.NotNull(result); Assert.Equal(404, notFoundResult.StatusCode); }
public void AddRecipeTest() { var fakeRepo = new FakeRecipeRepository(); var controller = new RecipeController(fakeRepo, null, null); var recipe = new Recipe() { RecipeName = "Test", Ingredients = "Test", Instructions = "Test" }; controller.EditRecipe(recipe); var retrieve = fakeRepo.Recipes.ToList()[0]; Assert.Equal("Test", retrieve.RecipeName); }
public void AddRecipeTest() { // Arrange var repo = new FakeRecipeRepository(); var recipeController = new RecipeController(repo); var ingredients = new List <Ingredient>(); // Act recipeController.AddRecipe("Smoothie", "2", "Put all ingredients in blender then blend on high", ingredients); // Assert Assert.Equal("Smoothie", repo.Recipes[repo.Recipes.Count - 1].Name); }
public void Delete_InvalidID_ReturnsNotFoundResult() { // Arrange DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build(); using (var context = new RepositoryContext(options)) { ICustomMapper _customMapper = new CustomMapper(context); IDataRepository <Recipe> mockRepository = new RecipeManager(context); RecipeController recipecontroller = new RecipeController(mockRepository, _mapper, _customMapper, _usermanager); //Act var notFoundResult = recipecontroller.Delete(68); // Assert Assert.IsType <Microsoft.AspNetCore.Mvc.NotFoundObjectResult>(notFoundResult); } }
public void GetRecipes_Success() { //Arrange List <RecipeDto> fakeList = new List <RecipeDto>(); _recipeService.Setup(c => c.GetRecipes(1, 25, "")).Returns(fakeList); RecipeController recipeController = new RecipeController(_recipeService.Object); //Act var result = recipeController.Get(new Paging { Size = 1, Page = 25, Uid = "" }); var okresult = result as OkObjectResult; //Assert Assert.NotNull(result); Assert.Equal(200, okresult.StatusCode); }
private static void FormIngredientList(Recipe recipeToAdd, RecipeController recCont) { Console.WriteLine($"Enter ingredients for recipe {recipeToAdd.Name} below:"); Console.WriteLine("Or enter -1 in any field to stop adding ingredients"); while (true) { Console.Write("Ingredient name:"); string name = Console.ReadLine().Trim(); if (name == "-1") { break; } double amount; bool wasBreaked = false; bool parsed = false; while (true) { Console.Write("Amount:"); parsed = double.TryParse(Console.ReadLine(), out amount); if (parsed && amount == -1) { wasBreaked = true; break; } else if (parsed) { break; } } if (wasBreaked) { break; } Console.Write("Measured in:"); string denomination = Console.ReadLine().Trim(); if (denomination == "-1") { break; } recCont.AddIngredientToRecipe(recipeToAdd, name, denomination, amount); } }
public RecipeControllerTests() { rnd = new Random(); options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase(databaseName: rnd.Next().ToString()) .Options; context = new ApplicationContext(options); navMenu = new NavMenu(context); recipeController = new RecipeController(context); var recipe1 = new Recipe { Categories = new List <string> { "1", "2" }, Ingredients = new List <string> { "cheese" }, Instructions = "just cook and eat", Name = "a", RecipeId = 1 }; var recipe2 = new Recipe { Categories = new List <string> { "1" }, Ingredients = new List <string> { "cheese" }, Instructions = "just cook and eat", Name = "b", RecipeId = 2 }; var recipe3 = new Recipe { Categories = new List <string> { "2" }, Ingredients = new List <string> { "cheese" }, Instructions = "just cook and eat", Name = "c", RecipeId = 3 }; context.Recipes.AddRange(recipe1, recipe2, recipe3); context.SaveChangesAsync(); }
public void Get_WhenCalled_ReturnsOkResult() { DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build(); using (var context = new RepositoryContext(options)) { ICustomMapper _customMapper = new CustomMapper(context); // Arrange IDataRepository <Recipe> mockRepository = Substitute.For <IDataRepository <Recipe> >(); RecipeController recipeCont = new RecipeController(mockRepository, _mapper, _customMapper, _usermanager); FilterModel fm = new FilterModel(); // Act var okResult = recipeCont.Get(fm); // Assert Assert.IsType <ActionResult <PagedCollectionResponse <RecipeViewModel> > >(okResult); } }
public static async Task FindAsync(RecipeController recipeController, IngredientController ingredientController) { Console.Write("1. Поиск рецепта.\n" + "2. Поиск ингредиента.\n" + "3. Вернуться.\n" + "4. Выйти.\n" + "(number):"); if (int.TryParse(Console.ReadLine(), out int result)) { Console.Clear(); switch (result) { case 1: #region Find Recipe await FindRecipeAsync(recipeController, ingredientController); #endregion break; case 2: #region Find Ingredient await FindIngredientAsync(ingredientController); #endregion break; case 3: return; case 4: Environment.Exit(0); break; default: Console.WriteLine("Ошибка в вводе данных."); break; } } else { Console.WriteLine("Ошибка в вводе данных."); } }
public void BeforeAll() { // Set up dependencies for controller this._recipesFromProvider = Builder<Recipe>.CreateListOfSize(10).Build(); var recipeProvider = MockRepository.GenerateStub<IRepository<Recipe,string>>(); recipeProvider.Stub(p => p.Get()).Return(this._recipesFromProvider); this._categoriesFromProvider = Builder<Category>.CreateListOfSize(20).Build(); var categoryProvider = MockRepository.GenerateStub<IRepository<Category,string>>(); categoryProvider.Stub(p => p.Get()).Return(this._categoriesFromProvider); var controller = new RecipeController(recipeProvider, categoryProvider, new AutoMapperMapper<Recipe, RecipeViewModel>(), new AutoMapperMapper<RecipeViewModel, Recipe>(), new AutoMapperMapper<Category, CategoryViewModel>(), MockRepository.GenerateStub<IImageProvider>(), MockRepository.GenerateStub<IFileProvider>(), MockRepository.GenerateStub<IFeatureUsageNotifier>() ); this._viewResult = controller.Index(string.Empty); this._viewModel = this._viewResult.Model as RecipeIndexViewModel; }
public void BeforeAll() { _newRecipeId = Guid.NewGuid().ToString(); // Set up dependencies for controller var recipeProvider = MockRepository.GenerateStub<IRepository<Recipe,string>>(); this._categoriesFromProvider = Builder<Category>.CreateListOfSize(20).Build(); var categoryProvider = MockRepository.GenerateStub<IRepository<Category,string>>(); categoryProvider.Stub(p => p.Get()).Return(this._categoriesFromProvider); var controller = new RecipeController(recipeProvider, categoryProvider, new AutoMapperMapper<Recipe, RecipeViewModel>(), new AutoMapperMapper<RecipeViewModel, Recipe>(), new AutoMapperMapper<Category, CategoryViewModel>(), MockRepository.GenerateStub<IImageProvider>(), MockRepository.GenerateStub<IFileProvider>(), MockRepository.GenerateStub<IFeatureUsageNotifier>() ); this._viewResult = controller.Edit(_newRecipeId,true); this._viewModel = this._viewResult.Model as SelectedRecipeViewModel; }
public void Setup() { roStub = Substitute.For<IRecipeOperations>(); sut = new RecipeController(roStub); }