public ActionResult Details(int id) { using (var context = new ApplicationDbContext()) { var recipeService = new RecipeService(context, HttpContext); var recipe = recipeService.GetRecipe(id); if (recipe == null) { return(HttpNotFound()); } var viewModel = new RecipeDetailsViewModel(recipe); return(View(viewModel)); } }
public async Task Test_GetAllRecipe() { using var context = new RecipeContext(ContextOptions); var recipeService = new RecipeService(context, _mapper, _logger); var allRecipes = await recipeService.GetAllRecipes(); Assert.NotNull(allRecipes); Assert.Equal(2, allRecipes.Count()); Assert.Collection(allRecipes, item => Assert.Equal("Fruit Salad", item.Name), item => Assert.Equal("Apple Pie", item.Name)); Assert.Collection(allRecipes.FirstOrDefault().Ingredients, item => Assert.Equal("Apple", item.Name), item => Assert.Equal("Orange", item.Name), item => Assert.Equal("Peach", item.Name)); }
public async Task GetByMatchingIngredinets_ShouldReturnTheRightRecipes() { var dbContext = WantoeatDbContextInMemoryFactory.InitializeContext(); await SeedData(dbContext); var ingredient = dbContext.Ingredients.First(); var ids = new int[] { ingredient.Id }; var recipe = dbContext.Recipes.First(); var service = new RecipeService(dbContext); var actual = service.GetRecipesByMatchingIngredients(ids); Assert.True(actual.Count() == 1); Assert.True(recipe.Name == actual.First().Name); }
public async Task Create_WithIngredientsWithIncorrectQuantities_ShouldThrowException() { var dbContext = WantoeatDbContextInMemoryFactory.InitializeContext(); var service = new RecipeService(dbContext); var category = new Category { Name = "Vegan" }; var cookingTime = new CookingTime { Name = "15 min." }; dbContext.Categories.Add(category); dbContext.CookingTimes.Add(cookingTime); var ingredients = new List <Ingredient> { new Ingredient { Name = "Test" }, new Ingredient { Name = "Test2" } }; dbContext.Ingredients.AddRange(ingredients); await dbContext.SaveChangesAsync(); var recipeVM = new RecipeCreateInputModel { Name = "Recipe", CategoryId = category.Id, CookingTimeId = cookingTime.Id, IngredientQuantities = new IngredientQuantities { IngredientNames = new List <string> { "Test", "Test2" }, RecipeIngredientQuantity = new List <string> { "3" } } }; await Assert.ThrowsAsync <ArgumentNullException>(() => service.CreateAsync(recipeVM)); }
public async void AddProduct(SelectableProduct prod) { IngredientModel ingredient = new IngredientModel { ProductName = prod.Product.Name, ProductId = prod.Product.Id, UnitQuantity = prod.CurrentUnitQuantityTypeVolume, UnitQuantityType = prod.UnitQuantityType, RecipeId = RecipeId }; await RecipeService.InsertIngredient(ingredient); await OnIngredientAdded.InvokeAsync(ingredient); prod.IsAdding = false; }
public async Task GetGroupsByCategories_ShouldReturnCorrectGroupNames() { var dbContext = WantoeatDbContextInMemoryFactory.InitializeContext(); await SeedData(dbContext); var service = new RecipeService(dbContext); var expected = dbContext.Categories.Select(x => x.Name).ToList(); var result = service.GetGroupsByCategories(); for (int i = 0; i < result.Count(); i++) { Assert.True(result[i].GroupName == expected[i]); } }
public async void GetRecipesForUser_CallsClientWithProperFilters() { var recipeService = new RecipeService( _recipeServiceClientMock.Object, _beerCalculatorMock.Object, _cacheMock.Object ); await recipeService.GetRecipesForUser("foobaruserid"); _recipeServiceClientMock.Verify( _ => _.SearchRecipes( It.Is <RecipeSearchFilters>(x => x.UserId == "foobaruserid") ), Times.Once ); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(RecipesView), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); var storageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///CookbookCommands.xml")); await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(storageFile); VoiceCommandDefinition definition; if (VoiceCommandDefinitionManager.InstalledCommandDefinitions.TryGetValue("commandSet_de-de", out definition)) { var recipes = await RecipeService.GetRecipeDetails(); var ingredients = recipes.SelectMany(p => p.Title.Split(' ', '-')); await definition.SetPhraseListAsync("ingredient", ingredients); } }
public async void GetRecipeDetails_WillCombineResultsFromRequiredServices() { _recipeServiceClientMock.Setup(_ => _.GetById(It.IsAny <int>())) .Returns(Task.FromResult(new RecipeDetailsResponse { Id = 1, Name = "Foo", BatchSize = 20, Style = "IPA", Author = "*****@*****.**", UserId = "foobaruser" })); _beerCalculatorMock.Setup(_ => _.Calculate(It.IsAny <CalculationRequest>())) .Returns(Task.FromResult(new CalculationResponse { Abv = 6.0, Fg = 1.01, Og = 1.056, ColorName = "brown", ColorEbc = 7.6, Ibu = 50 })); var recipeService = new RecipeService( _recipeServiceClientMock.Object, _beerCalculatorMock.Object, _cacheMock.Object ); var recipe = await recipeService.GetRecipeById(1); Assert.Equal(1, recipe.Id); Assert.Equal("Foo", recipe.Name); Assert.Equal("IPA", recipe.Style); Assert.Equal(20, recipe.BatchSize); Assert.Equal("*****@*****.**", recipe.Author); Assert.Equal(6.0, recipe.Abv); Assert.Equal(1.01, recipe.FinalGravity); Assert.Equal(1.056, recipe.OriginalGravity); Assert.Equal("brown", recipe.ColorName); Assert.Equal(7.6, recipe.Color); Assert.Equal(50, recipe.Ibu); Assert.Equal("foobaruser", recipe.UserId); }
public async Task TestGetRecipeById() { var id = new ObjectId(); var repoMock = Substitute.For <IRecipeRepository>(); repoMock.GetItemById(Arg.Any <ObjectId>()).Returns(ci => new Recipe { Id = ci.Arg <ObjectId>() }); var service = new RecipeService(Substitute.For <IDateTimeProvider>(), repoMock); var product = await service.GetItemById(id); await repoMock.Received(1).GetItemById(Arg.Is(id)); product.Should().NotBeNull(); product !.Id.Should().Be(id); }
public ActionResult Edit(int id) { using (var context = new ApplicationDbContext()) { var recipeService = new RecipeService(context, HttpContext); var recipe = recipeService.GetRecipe(id); if (recipe == null) { return(HttpNotFound()); } var userService = new UserService(context, HttpContext); var classificationLevels = userService.GetAvailableClassificationLevels(); var viewModel = new RecipeEditViewModel(recipe, classificationLevels); return(View(viewModel)); } }
public async Task Edit_Bad_Id() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("Edit_Bad_Id") .Options; var recipe = new Recipe { Id = Guid.NewGuid(), RecipeVersions = new List <RecipeVersion>() }; recipe.RecipeVersions.Add(new RecipeVersion()); recipe.RecipeVersions.Add(new RecipeVersion()); using (var context = new ApplicationDbContext(options)) { var recipeService = new RecipeService(context); await Assert.ThrowsAsync <ArgumentException>(() => recipeService.Edit(recipe)); } }
public async Task GetRecipes_OrdersByName() { //Arrange var mockRecipes = SetTestRecipes(); var mockContext = new Mock <ICookBookDbContext>(); mockContext.Setup(m => m.Recipes).Returns(mockRecipes.Object); var recipeService = new RecipeService(mockContext.Object); //Act var recipes = await recipeService.GetRecipes(); //Assert Assert.AreEqual(3, recipes.Count); Assert.AreEqual("Cheesecake", recipes[0].Title); Assert.AreEqual("Cheesecake with Blueberries", recipes[1].Title); Assert.AreEqual("Chocolate Cake", recipes[2].Title); }
public ActionResult AddRecipe(RecipeViewModel recipe) { try { if (ModelState.IsValid) { recipe.User = UserViewMapper.ConvertUserModelToUserViewModel(UserService.GetList().FirstOrDefault()); RecipeService.AddItem(RecipeViewMapper.ConvertRecipeViewModelToRecipeModel(recipe)); return(RedirectToAction("ViewRecipeList")); } return(View("AddRecipe")); } catch (Exception e) { Logger.InitLogger(); Logger.Log.Error("Error: " + e); return(View("_Error")); } }
private void InitData() { Name = "Recipies"; /* Context injection - recipe change will be visible in Menu View without app restart */ Service = new RecipeService { Context = mealService.Context }; ingredientService = new IngredientService { Context = mealService.Context }; ingredientService.LoadAll(); AllRecipies = new ObservableCollection <Recipe>(Items); Items.CollectionChanged += HandleItemsChange; AllIngredients = ingredientService.GetObservableCollection(); }
public async Task GetRecipe_ShouldReturnIngridient() { //Arrange var(recipeRepository, ingridientService, dataBase) = GetMocks(); var recipeService = new RecipeService(recipeRepository.Object, ingridientService.Object); var idOfRecipe = 1; //Act var recipe = await recipeService.GetRecipe(idOfRecipe); //Assert Assert.AreEqual("Recipe1", recipe.Name); Assert.AreEqual(1, recipe.Time); Assert.AreEqual(500, recipe.TotalCost); Assert.AreEqual(new List <int>() { 1 }, recipe.IngridientsIds); }
public void GetRecipeWithoutDeletedShouldWorkProperly() { var recipeRepository = new Mock <IDeletableEntityRepository <Recipe> >(); var recipeIngredientRepository = new Mock <IRepository <RecipeIngredient> >(); recipeRepository.Setup(x => x.All()).Returns(this.DummyDataRecipes().Where(x => x.IsDeleted == false).AsQueryable()); var service = new RecipeService(recipeRepository.Object, recipeIngredientRepository.Object); var actualResult = service.GetRecipeWithoutDeleted <RecipeDetailsViewModel>(1); var expectedResult = this.DummyDataRecipes().SingleOrDefault(x => x.Id == 1); Assert.True(actualResult.Id == expectedResult.Id, "Recipe Id does not match."); Assert.True(actualResult.Name == expectedResult.Name, "Recipe Name does not match."); Assert.True(actualResult.Description == expectedResult.Description, "Recipe Description does not match."); Assert.True(actualResult.Price == expectedResult.Price, "Recipe Price does not match."); Assert.True(actualResult.Image == expectedResult.Image, "Recipe Image does not match."); Assert.True(actualResult.Ingredients.Count == expectedResult.RecipeIngredients.Count, "Recipe Ingredients Count does not match."); Assert.True(actualResult.Reviews.Count == expectedResult.Reviews.Count, "Recipe Reviews Count does not match."); }
public void FindRecipeByIdShouldReturnCorrectRecipe(int recipeId) { var recipeRepository = new Mock <IDeletableEntityRepository <Recipe> >(); var recipeIngredientRepository = new Mock <IRepository <RecipeIngredient> >(); recipeRepository.Setup(x => x.AllWithDeleted()).Returns(this.DummyDataRecipes().AsQueryable()); var service = new RecipeService(recipeRepository.Object, recipeIngredientRepository.Object); var actaulResult = service.FindRecipeById <RecipeEditBindingModel>(recipeId); var expectedResult = this.DummyDataRecipes().SingleOrDefault(x => x.Id == recipeId); Assert.True(expectedResult.Id == actaulResult.Id, "Recipe Id does not match."); Assert.True(expectedResult.Name == actaulResult.Name, "Recipe Name does not match."); Assert.True(expectedResult.Description == actaulResult.Description, "Recipe Description does not match."); Assert.True(expectedResult.Portions == actaulResult.Portions, "Recipe Portions does not match."); Assert.True(expectedResult.Price == actaulResult.Price, "Recipe Price does not match."); Assert.True(expectedResult.Image == actaulResult.Image, "Recipe Image does not match."); Assert.True(expectedResult.RecipeIngredients.Count == actaulResult.Ingredients.Count, "Recipe Ingredients Count does not match"); }
public void GetRecipeDetail_CanLoadFromContext() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <AppDbContext>() .UseSqlite(connection) .Options; using (var context = new AppDbContext(options)) { context.Database.EnsureCreated(); context.Recipes.AddRange( new Models.Recipe { RecipeId = 1, Name = "Recipe1" }, new Models.Recipe { RecipeId = 2, Name = "Recipe2" }, new Models.Recipe { RecipeId = 3, Name = "Recipe3" }); context.SaveChanges(); } using (var context = new AppDbContext(options)) { Mock <ILoggerFactory> factory = new Mock <ILoggerFactory>(); Mock <ILogger> logger = new Mock <ILogger>(); factory.Setup(f => f.CreateLogger("RecipeApp.RecipeService")).Returns(logger.Object); var service = new RecipeService(context, factory.Object); var recipe = service.GetRecipeDetail(id: 2); recipe.ShouldNotBeNull(); recipe.Id.ShouldBe(2); recipe.Name.ShouldBe("Recipe2"); } }
public async Task Create() { const string title = "Title", description = "Description"; Guid id; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("Create") .Options; using (var context = new ApplicationDbContext(options)) { var recipeService = new RecipeService(context); var recipeVersion = new RecipeVersion { Title = title, Description = description }; var recipe = await recipeService.Create(new Recipe { RecipeVersions = new List <RecipeVersion> { recipeVersion } }); id = recipe.Id; } using (var context = new ApplicationDbContext(options)) { var recipe = await context.Recipes .Include(x => x.RecipeVersions).SingleOrDefaultAsync(x => x.Id == id); Assert.NotNull(recipe); Assert.IsType <Recipe>(recipe); Assert.Single(recipe.RecipeVersions); var recipeVersion = recipe.RecipeVersions.First(); Assert.IsType <RecipeVersion>(recipeVersion); Assert.Equal(title, recipeVersion.Title); Assert.Equal(description, recipeVersion.Description); } }
public void Allergie_Recipes() { Mock <IRecipeRepository> recipeRepository = new Mock <IRecipeRepository>(); recipeRepository.Setup(u => u.Listar()).Returns(this.recipes); Mock <IAllergyRepository> allergyRepository = new Mock <IAllergyRepository>(); allergyRepository.Setup(u => u.Listar()).Returns(this.allergies); var servicio = new RecipeService(); servicio.setRecipeRepo(recipeRepository.Object); servicio.setAllergyRepo(allergyRepository.Object); List <Recipe> resultado = servicio.ListarbyFiltro(users[0]); Assert.AreNotEqual(recipesFiltradas, resultado); }
/// <summary> /// Initializes a new instance of the <see cref="RecipeViewModel"/> class. /// </summary> /// <param name="dialogService">Dialog service dependency.</param> /// <param name="imageService">Service for working with images.</param> /// <param name="container">IoC container.</param> /// <param name="recipeService">Recipe service dependency.</param> /// <param name="mapper">Mapper dependency.</param> /// <param name="eventAggregator">Dependency on Prism event aggregator.</param> /// <param name="localization">Localization provider dependency.</param> /// <param name="regionManager">Region manager for Prism navigation.</param> public RecipeViewModel(DialogService dialogService, ImageService imageService, IContainerExtension container, RecipeService recipeService, IMapper mapper, IEventAggregator eventAggregator, ILocalization localization, IRegionManager regionManager) { this.dialogService = dialogService; this.imageService = imageService; this.container = container; this.recipeService = recipeService; this.mapper = mapper; this.eventAggregator = eventAggregator; this.localization = localization; this.regionManager = regionManager; CloseCommand = new DelegateCommand(Close); ApplyChangesCommand = new AsyncDelegateCommand(ApplyChangesAsync, CanApplyChanges); DeleteRecipeCommand = new AsyncDelegateCommand <Guid>(DeleteRecipeAsync, canExecute: CanDeleteRecipe); ImageSearchCommand = new AsyncDelegateCommand(ImageSearchAsync); RemoveImageCommand = new DelegateCommand(RemoveImage, canExecute: CanRemoveImage); AddTagCommand = new AsyncDelegateCommand(AddTagAsync); RemoveTagCommand = new DelegateCommand <TagEdit>(RemoveTag); ViewTagCommand = new DelegateCommand <TagEdit>(ViewTag); AddIngredientGroupCommand = new AsyncDelegateCommand(AddIngredientGroupAsync); EditIngredientGroupCommand = new AsyncDelegateCommand <IngredientGroupEdit>(EditIngredientGroupAsync); AddIngredientToGroupCommand = new AsyncDelegateCommand <IngredientGroupEdit>(AddIngredientToGroupAsync); RemoveIngredientGroupCommand = new DelegateCommand <IngredientGroupEdit>(RemoveIngredientGroup); AddIngredientCommand = new AsyncDelegateCommand(AddIngredientAsync); EditIngredientCommand = new AsyncDelegateCommand <RecipeIngredientEdit>(EditIngredientAsync); RemoveIngredientCommand = new DelegateCommand <RecipeIngredientEdit>(RemoveIngredient); AddGarnishCommand = new AsyncDelegateCommand(AddGarnish); RemoveGarnishCommand = new DelegateCommand <RecipeEdit>(RemoveGarnish); }
public void GetRecipe_ReturnSingleRecipe() { //Arrange //var db = new GGDataContext(); var db = new Mock <GGDataContext>(); var expectedRecipe = new Recipe() { Id = 1, Description = "test recipe description", Name = "Test recipe", Image = "tet recipe img" }; var recipes = new List <Recipe>() { expectedRecipe }.AsQueryable(); var dbMock = new Mock <IDbSet <IRecipe> >(); //dbMock.Setup(x => x.FindAsync(It.IsAny(object[]))); //dbMock.Setup(x => x.Provider).Returns(recipes.Provider); //dbMock.Setup(x => x.Expression).Returns(recipes.Expression); //dbMock.Setup(x => x.ElementType).Returns(recipes.ElementType); //dbMock.Setup(x => x.GetEnumerator()).Returns(recipes.GetEnumerator); //db.Setup(x => x.Recipes).Returns(dbMock.Object); var recipeService = new RecipeService(db.Object); //Act var actualRecipe = recipeService.GetRecipeById(expectedRecipe.Id); //Assert Assert.IsNotNull(actualRecipe); Assert.AreEqual(expectedRecipe.Id, actualRecipe.Id); Assert.AreEqual(expectedRecipe.Name, actualRecipe.Id); }
public async Task Create_WithCorrectData__ShouldBeSuccessful() { var dbContext = WantoeatDbContextInMemoryFactory.InitializeContext(); var service = new RecipeService(dbContext); var category = new Category { Name = "Vegan" }; var cookingTime = new CookingTime { Name = "15 min." }; var ingredient = new Ingredient { Name = "Leafs" }; dbContext.Categories.Add(category); dbContext.CookingTimes.Add(cookingTime); dbContext.Ingredients.Add(ingredient); await dbContext.SaveChangesAsync(); var recipeVM = new RecipeCreateInputModel { Name = "Recipe", CategoryId = category.Id, CookingTimeId = cookingTime.Id, IngredientQuantities = new IngredientQuantities { IngredientNames = new List <string> { "Leafs" }, RecipeIngredientQuantity = new List <string> { "3 pcs." }, } }; Recipe recipe = await service.CreateAsync(recipeVM); Assert.NotNull(recipe); }
public async Task GetRecipeForEditShouldShouldReturnCorrectRecipe() { //Arange var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; //Act var db = new ApplicationDbContext(options); var config = new MapperConfiguration(cfg => { cfg.AddProfile <ApplicationProfile>(); }); var mapper = new Mapper(config); var recipeService = new RecipeService(db, mapper); var user = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; db.Users.Add(user); await db.SaveChangesAsync(); var recipeModel = new AddRecipeInputViewModel { CookingTime = 5, ImageUrl = "URL123123", Instructions = "instructions", Name = "Name", ProductType = ProductType.Salad }; var id = await recipeService.AddRecipeAsync(recipeModel, user.Id); var recipe = recipeService.GetRecipeForEdit(id); //assert Assert.Equal(recipe.Id, id); Assert.NotNull(recipe); }
public IEnumerable <Recipe> Get([FromQuery] String term, [FromQuery] String ingredients) { using (var ctx = MyContext.New()) { var query = ctx.Recipes.AsQueryable(); if (!String.IsNullOrEmpty(term)) { var lowered = term.ToLower(); query = query.Where(r => r.Name.ToLower().Contains(lowered)); } query = query .AsEnumerable() .Select(r => { return(RecipeService.CompleteRecipeTree(ctx, r)); }) .AsQueryable(); if (!String.IsNullOrEmpty(ingredients)) { var ingredientIds = ingredients.Split(",").Select(s => s.Trim()); // too lazy to write a proper query query = query .AsEnumerable() .Where(r => { bool containsAll = r.IngredientStacks.Count > 0; r.IngredientStacks.ForEach(i => containsAll &= ingredientIds.Contains(i.ItemId)); return(containsAll); }) .AsQueryable(); } return(query.ToList()); } }
public async Task CreateRecipe_ShouldCreateIngridient() { //Arrange var(recipeRepository, ingridientService, dataBase) = GetMocks(); var recipeService = new RecipeService(recipeRepository.Object, ingridientService.Object); var idOfRecipeToBeCreated = dataBase.Count + 1; var recipeModelToBeCreated = new Recipe() { Name = "CreatedRecipe1", Time = 300, TotalCost = 500, IngridientsIds = new List <int> { 1 } }; //Act var createdRecipetModel = await recipeService.CreateRecipe(recipeModelToBeCreated); //Assert Assert.AreEqual(createdRecipetModel.Name, dataBase[idOfRecipeToBeCreated].Name); Assert.AreEqual(createdRecipetModel.Time, dataBase[idOfRecipeToBeCreated].Time); Assert.AreEqual(createdRecipetModel.TotalCost, dataBase[idOfRecipeToBeCreated].TotalCost); Assert.AreEqual(createdRecipetModel.IngridientsIds, dataBase[idOfRecipeToBeCreated].IngridientsIds); }
public async Task UpdateRecipe_ShouldUpdateModel() { //Arrange var(recipeRepository, ingridientService, dataBase) = GetMocks(); var recipeService = new RecipeService(recipeRepository.Object, ingridientService.Object); var idOfRecipeToBeUpdated = 1; var recipeUpdateModel = new RecipeUpdateModel() { Name = "Recipe1", Time = 1.5f, TotalCost = 1000, IngridientIds = new List <int> { 1 } }; //Act var updatedRecipeModel = await recipeService.UpdateRecipe(idOfRecipeToBeUpdated, recipeUpdateModel); //Assert Assert.AreEqual(updatedRecipeModel.Name, dataBase[idOfRecipeToBeUpdated].Name); Assert.AreEqual(updatedRecipeModel.TotalCost, dataBase[idOfRecipeToBeUpdated].TotalCost); Assert.AreEqual(updatedRecipeModel.Time, dataBase[idOfRecipeToBeUpdated].Time); Assert.AreEqual(updatedRecipeModel.IngridientsIds, dataBase[idOfRecipeToBeUpdated].IngridientsIds); }
public void GetResturnExpected() { // Arrange var createdDateTestData = new DateTime(2017, 7, 3); var recipeData = new Recipe { Id = 1, Description = "Description 1" }; var recipeRepository = A.Fake <IRepository <Recipe, long> >(); A.CallTo(() => recipeRepository.Get(A <long> .Ignored)).Returns(recipeData); var recipeVersionRepository = A.Fake <IRepository <RecipeVersion, long> >(); var service = new RecipeService(recipeRepository, recipeVersionRepository); // Act var resultDto = service.Get(1); // Assert Assert.Equal(1, resultDto.Id); }
public ActionResult Create(RecipeCreateViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { using (var context = new ApplicationDbContext()) { var recipeService = new RecipeService(context, HttpContext); recipeService.Add(model); context.SaveChanges(); return(RedirectToAction("Index")); } } catch { return(View(model)); } }