public void shouldGetListOfAvailableCategories() { CategoryRepository repository = new CategoryRepository(); repository.Add(new Entities.Category { Name = "Gas" }); repository.Add(new Entities.Category { Name = "Food" }); repository.Add(new Entities.Category { Name = "Gym" }); var interaction = new ListCategoriesInteraction<RAMRepository.CategoryRepository>(repository); interaction.performAction(); var categories = interaction.ResponseModel.Categories; Assert.IsTrue(categories.Contains("Gas")); Assert.IsTrue(categories.Contains("Food")); Assert.IsTrue(categories.Contains("Gym")); }
public void initialize() { RAMRepository.RAMRepository.SharedInstance.Expenses.Clear(); // Create categories manually CategoryRepository categoryRepository = new CategoryRepository(); categoryRepository.Add(gasCategory); categoryRepository.Add(foodCategory); categoryRepository.Add(gymCategory); // Create expenses manually ExpenseRepository expenseRepository = new ExpenseRepository(); gas0.ExpenseId = expenseRepository.Add(gas0); gas1.ExpenseId = expenseRepository.Add(gas1); food0.ExpenseId = expenseRepository.Add(food0); food0.ExpenseId = expenseRepository.Add(food1); gym0.ExpenseId = expenseRepository.Add(gym0); gym1.ExpenseId = expenseRepository.Add(gym1); }
public void AddReturnsId() { var repository = new CategoryRepository(dbFactory, personRepository); var response = repository.Add(new Category()); Assert.IsNotNull(response); Assert.AreEqual(response.Id, 1); }
public void shouldNotAlreadyExist() { CategoryRepository repository = new CategoryRepository(); repository.Add(new Entities.Category {Name = CategoryName}); var interaction = new AddCategoryInteraction<RAMRepository.CategoryRepository>(new Interactions.RequestModels.AddCategory { Name = CategoryName }, repository); interaction.performAction(); var response = interaction.ResponseModel; Assert.IsTrue(response.Error.HasValue); Assert.AreEqual<Interactions.ResponseModels.Error.Codes>(response.Error.Value.Code, Interactions.ResponseModels.Error.Codes.CATEGORY_ALREADY_EXISTS); }
private SVP.CIL.Domain.Category CategoryCreate(AppDbContext dbc, SVP.CIL.Domain.Category target) { var category = Mapper.Map <Category>(target); var repo = new CategoryRepository(dbc); repo.Add(category); dbc.SaveChanges(); var domainCategory = Mapper.Map <SVP.CIL.Domain.Category>(category); return(domainCategory); }
public IHttpActionResult PostCategory(Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _repo.Add(category); return(CreatedAtRoute("DefaultApi", new { id = category.Id }, category)); }
public void Add() { Category category = new Category { Title = "Root" }; CategoryRepository repo = new CategoryRepository(); repo.Add(category); }
public void WhenGetCategory_GetSuccessfully() { var categoryRepository = new CategoryRepository(); var category = new Category("IPhone 3"); categoryRepository.Add(category); var selectedCategory = categoryRepository.GetByID(0); Assert.NotNull(selectedCategory); }
public IActionResult Post(Category category) { var currentUser = GetCurrentUser(); if (currentUser.UserType.Name != "Admin") { return(Unauthorized()); } _categoryRepository.Add(category); return(CreatedAtAction(nameof(Get), new { id = category.Id }, category)); }
public bool Add(Category category) { if (category == null && category.Name.Length < 2) { throw new Exception("Sorry, Invalid Name Inserted!"); } bool isAdded = _repository.Add(category); return(isAdded); }
public void DeleteSheet_Successful() { //Arrange var options = new DbContextOptionsBuilder <LibraryContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new LibraryContext(options); ISheetRepository sheetRepository = new SheetRepository(context); ICategoryRepository categoryRepository = new CategoryRepository(context); //Act var category = new CategoryTO { Name = "Musique de films" }; var addedCategory = categoryRepository.Add(category); var category2 = new CategoryTO { Name = "Musique de classique" }; var addedCategory2 = categoryRepository.Add(category2); context.SaveChanges(); var sheet = new SheetTO { Name = "BestOf", Arranger = "Jean-Luc", Category = addedCategory, Composer = "Morricone", IsCurrent = false, IsGarde = false, IsIndependance = true }; var sheet2 = new SheetTO { Name = "Young Amadeus", Arranger = "Jan de Haan", Category = addedCategory2, Composer = "Mozart", IsCurrent = true, IsGarde = false, IsIndependance = true }; var addedSheet = sheetRepository.Add(sheet); var addedSheet2 = sheetRepository.Add(sheet2); context.SaveChanges(); //Act var result = sheetRepository.Delete(addedSheet); context.SaveChanges(); //Assert Assert.AreEqual(1, sheetRepository.GetAll().Count()); }
public ActionResult AddForm(Category category) { if (ModelState.IsValid) { repo.Add(category); } else { return(View()); } return(RedirectToAction("Index")); }
public ActionResult Create(CategoryViewModel categoryViewModel) { Category categoryToBase = new Category { CategoryName = categoryViewModel.CategoryName, EspecialCategory = categoryViewModel.EspecialCategory }; _categoryRepository.Add(categoryToBase); return(RedirectToAction("Index")); }
public bool AddCategory(Category category) { bool isExist = categoryRepo.IsExist(category); if (isExist) { return(true); } categoryRepo.Add(category); return(false); }
public ActionResult Create(Category category) { try { _categoryRepository.Add(category); return(RedirectToAction("Index")); } catch { return(View(category)); } }
public ActionResult Create(Category category, int parantCategoryId) { try { dbCategores.Add(category, parantCategoryId); return(RedirectToAction("List", "Article")); } catch { return(PartialView()); } }
public ActionResult Create([Bind(Include = "CategoryID,CategoryName,Notes")] Category category) { if (ModelState.IsValid) { //db.Categories.Add(category); //db.SaveChanges(); repo.Add(category); return(RedirectToAction("Index")); } return(View(category)); }
//Add Data public bool Add(Category objCategory, HttpPostedFileBase file) { var isAdded = false; isAdded = repository.Add(objCategory, file); if (isAdded) { return(true); } return(isAdded); }
public void Test1() { _database.DropCollection("Categories"); var repo = new CategoryRepository(_database); var rootCategory = new Category(Guid.NewGuid(), "root1", true); var cat1 = new Category(Guid.NewGuid(), "cat1"); var cat2 = new Category(Guid.NewGuid(), "cat2"); var cat1_1 = new Category(Guid.NewGuid(), "cat1_1"); var p1 = new Product(Guid.NewGuid(), "p1"); cat1.AddProduct(p1); var p2 = new Product(Guid.NewGuid(), "p2"); cat2.AddProduct(p2); var p1_1 = new Product(Guid.NewGuid(), "p1_1"); cat1_1.AddProduct(p1_1); var root2 = new Category(Guid.NewGuid(), "root2", true); var cat3 = new Category(Guid.NewGuid(), "cat3"); var cat3_1 = new Category(Guid.NewGuid(), "cat3_1"); var cat3_2 = new Category(Guid.NewGuid(), "cat3_2"); root2.AddChildCategory(cat3); cat3.AddChildCategory(cat3_1); cat3.AddChildCategory(cat3_2); rootCategory.AddChildCategory(cat1); rootCategory.AddChildCategory(cat2); cat1.AddChildCategory(cat1_1); repo.Add(rootCategory); repo.Add(root2); }
public void AddCategory_AddNull_ThrowException() { //Arrange var options = new DbContextOptionsBuilder <LibraryContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new LibraryContext(options); ICategoryRepository categoryRepository = new CategoryRepository(context); //Act & Assert Assert.ThrowsException <ArgumentNullException>(() => categoryRepository.Add(null)); }
static void Main(string[] args) { Category category = new Category { Name = "Бытовая техника", ImagePath = @"C:/data", }; ICategoryRepository repository = new CategoryRepository(); repository.Add(category); var result = repository.GetAll(); }
public void WhenAddCategory_AddedSuccessfully() { var categoryRepository = new CategoryRepository(); var category = new Category("IPhone 3"); var expectedResult = categoryRepository.GetAll().Count + 1; var result = categoryRepository.Add(category); var lastCount = categoryRepository.GetAll().Count; Assert.True(result.IsSucceed); Assert.Equal(expectedResult, lastCount); }
public async void Add_AddMultipleEntries() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new CategoryRepository(dbFactory); // Act repository.Add(new CategoryEntity { Name = "TestCategory" }); repository.Add(new CategoryEntity { Name = "TestCategory" }); repository.Add(new CategoryEntity { Name = "TestCategory" }); await unitOfWork.Commit(); // Assert Assert.Equal(3, repository.GetAll().Count()); }
public ActionResult Create(Category category) { if (ModelState.IsValid) { category.Date = DateTime.Now.Day.ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Year.ToString(); categoryRepository.Add(category); return(RedirectToAction("Index")); } else { return(View(category)); } }
public async Task <int> Add(AddCategoryDto dto) { Category category = new Category() { Title = dto.Title }; _repository.Add(category); await _unitOfWork.ComplateAysnc(); return(category.Id); }
public async void Add_NewEntryWithoutName() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new CategoryRepository(dbFactory); var testEntry = new CategoryEntity(); // Act // Assert repository.Add(testEntry); await Assert.ThrowsAsync <DbUpdateException>(async() => await unitOfWork.Commit()); }
public ActionResult Add(Category category) { ValidateCategory(category); if (ModelState.IsValid) { _categoryRepository.Add(category); TempData["Message"] = "Your category has been added."; return(RedirectToAction("Details", new { id = category.Id })); } return(View(category)); }
public void AddSheet_AddExistingSheet_DoNotInsertTwiceInDb() { //Arrange var options = new DbContextOptionsBuilder <LibraryContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new LibraryContext(options); ISheetRepository sheetRepository = new SheetRepository(context); ICategoryRepository categoryRepository = new CategoryRepository(context); //Act var category = new CategoryTO { Name = "Musique de films" }; var addedCategory = categoryRepository.Add(category); var category2 = new CategoryTO { Name = "Musique de classique" }; var addedCategory2 = categoryRepository.Add(category2); context.SaveChanges(); var sheet = new SheetTO { Name = "BestOf", Arranger = "Jean-Luc", Category = addedCategory, Composer = "Morricone", IsCurrent = false, IsGarde = false, IsIndependance = true }; var sheet2 = new SheetTO { Id = 1, Name = "BestOf", Arranger = "Jean-Luc", Category = addedCategory2, Composer = "Morricone", IsCurrent = false, IsGarde = false, IsIndependance = true }; var addedSheet = sheetRepository.Add(sheet); var addedSheet2 = sheetRepository.Add(sheet2); context.SaveChanges(); //Assert Assert.IsNotNull(sheet); Assert.AreEqual(1, sheetRepository.GetAll().Count()); }
public ActionResult AddCategory(PostViewModel model) { if (model.NewCategory != "" || model.NewCategory != null) { var categorymodel = new Category(); categorymodel.Name = model.NewCategory; CategoryRepository.Add(categorymodel); return(RedirectToAction("Index")); } else { return(RedirectToAction("Index")); } }
private void btnAdd_Click(object sender, EventArgs e) { try { service.Add(txtAddName.Text, txtAddDescription.Text); dataGridView1.DataSource = service.TakeList(); service.TextBoxCmbBoxEraser(groupBox1); MessageBox.Show("Category has been added"); } catch (Exception) { MessageBox.Show("Please check values you entered!"); } }
public ActionResult AddCategory(Category model) { if (ModelState.IsValid) { cRep.Add(model); ViewBag.Status = 1; } else { ViewBag.Status = 2; return(View()); } return(View()); }
public void AddPersists() { var repository = new CategoryRepository(dbFactory, personRepository); repository.Add(new Category { Name = "Test Item" }); dbFactory.Run(db => { var response = db.Select<Category>(); Assert.AreEqual(response.Count, 1); Assert.AreEqual(response[0].Name, "Test Item"); }); }
public async void Add_NewEntryWithoutName() { // Arrange var repository = new CategoryRepository(ambientDbContextLocator); var testEntry = new CategoryEntity(); // Act // Assert using (var dbContextScope = dbContextScopeFactory.Create()) { repository.Add(testEntry); await Assert.ThrowsAsync <DbUpdateException>(async() => await dbContextScope.SaveChangesAsync()); } }
public async void Add_AddNewEntryOnEveryCall() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new CategoryRepository(dbFactory); var testEntry = new CategoryEntity { Name = "Testtext" }; // Act repository.Add(testEntry); await unitOfWork.Commit(); testEntry.Id = 0; repository.Add(testEntry); await unitOfWork.Commit(); // Assert Assert.Equal(2, repository.GetAll().Count()); }
public ActionResult AddCategory(Category item) { if (cat_repo.Any(x => x.CategoryName == item.CategoryName)) { ViewBag.Mevcut = "Kategori Zaten Mevcut"; } else { item.CreatedBy = (Session["admin"] as AppUser).UserName; cat_repo.Add(item); return(RedirectToAction("ListCategory")); } return(View()); }
public void shouldAddExpenseToSystemWithCurrentDate() { // Add category manully CategoryRepository categoryRepository = new CategoryRepository(); categoryRepository.Add(new Entities.Category { Name = ExpenseCategory }); ExpenseRepository repository = new ExpenseRepository(); var interaction = new AddExpenseInteraction<RAMRepository.ExpenseRepository>(new Interactions.RequestModels.AddExpense { Amount = ExpenseAmount, Category = ExpenseCategory}, repository); interaction.performAction(); var response = interaction.ResponseModel; Assert.IsFalse(response.Error.HasValue); Entities.Expense expense = repository.GetExpenseById(response.Id); Assert.IsNotNull(expense); Assert.AreEqual<DateTime>(expense.Date, DateTime.Today.Date); }
private void AddNewCategory(object sender, JavascriptMethodEventArgs e) { ErrorTypeEnum error = ErrorTypeEnum.None; string name = e.Arguments[0]; GameObjectTypeEnum gameObjectType = (GameObjectTypeEnum)Enum.Parse(typeof(GameObjectTypeEnum), e.Arguments[1]); Category newCategory = new Category { IsSystemResource = false, Name = name, GameObjectType = gameObjectType }; using (CategoryRepository repo = new CategoryRepository()) { newCategory = repo.Add(newCategory); } AsyncJavascriptCallback("CreateNewCategory_Callback", error == ErrorTypeEnum.None ? true : false, EnumerationHelper.GetEnumerationDescription(error), name, newCategory.ResourceID); }