protected override int ExecuteWorkImplementation() { var bookTypeEnum = Mapper.Map <BookTypeEnum>(m_data.BookType); var bookType = m_categoryRepository.GetBookTypeByEnum(bookTypeEnum); if (bookType == null) { bookType = new BookType { Type = bookTypeEnum }; m_categoryRepository.Create(bookType); } var parentCategory = m_data.ParentCategoryId != null ? m_categoryRepository.FindById <DataEntities.Database.Entities.Category>(m_data.ParentCategoryId) : null; var parentPath = parentCategory != null ? parentCategory.Path : string.Empty; var category = new DataEntities.Database.Entities.Category { BookType = bookType, Description = m_data.Description, ExternalId = m_data.ExternalId, Path = string.Empty, ParentCategory = parentCategory }; var resultId = (int)m_categoryRepository.Create(category); category.Path = string.Format("{0}/{1}", parentPath, resultId); m_categoryRepository.Update(category); return(resultId); }
public new int Create(CategoryDto dto) { dto.Id = _catRepository.Create(ConvertDtoToDB(dto)); _catRepository.Create(ConvertDtoToTranslationDB(dto)); return(dto.Id); }
static void Main(string[] args) { log4net.Config.XmlConfigurator.Configure(); List <Product> products = new List <Product>() { new Product() { Id = 1, Description = "Producto 1", Price = 1 }, new Product() { Id = 2, Description = "Producto 2", Price = 2 } }; Category category = new Category(); category.Description = "Prueba"; category.Products = products; CategoryRepository categoryRepository = new CategoryRepository(); long id = categoryRepository.Create(category); Console.WriteLine("Registro generado con código: " + id); Console.WriteLine("Presione una tecla para finalizar..."); Console.ReadLine(); }
public void CanStoreAndRecoverCategoryWithPageVersion() { Category target = new Category(); target.Name = "Test Category"; target.ParentId = "0"; target.StoreId = 0; target.SourceType = CategorySourceType.FlexPage; CategoryRepository repo = CategoryRepository.InstantiateForMemory(new RequestContext()); Assert.IsTrue(repo.Create(target), "Create should be true"); string categoryId = target.Bvin; Assert.AreNotEqual(string.Empty, categoryId, "Category Bvin should not be empty."); Category found = repo.Find(categoryId); Assert.IsNotNull(found, "Found category should not be null"); Assert.AreEqual(found.Name, target.Name, "Names should match"); Assert.AreEqual(1, found.Versions.Count, "Versions count should be one."); CategoryPageVersion foundVersion = found.Versions[0]; Assert.IsNotNull(foundVersion, "Found page version should not be null."); Assert.IsTrue(foundVersion.Id > 0, "Found version should have Id > 0 assigned."); }
public async Task CreateOwnedEntity() { var(connection, options) = await CreateUniqueMockDbConnectionForThisTest(); try { using (var context = new FittifyContext(options)) { var newCategory = new Category() { Name = "NewOwnedCategory", OwnerGuid = _ownerGuid }; var categoryRepository = new CategoryRepository(context); var createdCategory = await categoryRepository.Create(newCategory, _ownerGuid); var serializedCategory = JsonConvert.SerializeObject(newCategory); var serializedCreatedCategory = JsonConvert.SerializeObject(createdCategory); Assert.AreEqual(serializedCategory, serializedCreatedCategory); } } finally { connection.Close(); } }
public void AddCategory(CategoryViewModel category) { try { if (ValidateModel(category)) { _categoryRepository.Create( new Category() { categoryName = category.categoryName, description = category.description }); return; } else { //TO DO: send back error message if Model was not valid. } } catch (Exception e) { Console.WriteLine(e); throw; } }
public void Update_WithValidEntity_ShouldUpdateRecords() { //Arrange var context = new ECommerceDbContext(); var sut = new CategoryRepository(context); var category = new Category { Name = "Shoes", Description = "Shoes Department" }; sut.Create(category); var actual = sut.Retrieve(category.ID); var expectedName = "Shoepatos"; var expectedDescription = "Sapatos natin"; actual.Name = expectedName; actual.Description = expectedDescription; //Act sut.Update(actual.ID, actual); //Assert var expected = sut.Retrieve(actual.ID); Assert.Equal(expectedName, expected.Name); Assert.Equal(expectedDescription, expected.Description); //Cleanup sut.Delete(actual.ID); }
public void Retrieve_WithValidEntityID_ShouldReturnAValidProduct() { // Arrange var context = new ECommerceDbContext(); var sut = new ProductRepository(context); var categoryRepo = new CategoryRepository(context); Category category = new Category { Name = "Shoes", Description = "Shoes Department" }; categoryRepo.Create(category); Product product = new Product { Name = "Rubber Shoes", Description = "This is a pair of rubber shoes.", Price = 2000, CategoryID = category.ID, ImageUrl = "rubbershoes.jpg" }; sut.Create(product); // Act var actual = sut.Retrieve(product.ID); // Assert Assert.NotNull(actual); // Cleanup sut.Delete(actual.ID); categoryRepo.Delete(category.ID); }
public void Create_WithValidEntity_ShouldCreateDatabaseRecord() { // Arrange var context = new ECommerceDbContext(); var sut = new ProductRepository(context); var categoryRepo = new CategoryRepository(context); Category category = new Category { Name = "Shoes", Description = "Shoes Department" }; categoryRepo.Create(category); Product product = new Product { Name = "Rubber Shoes", Description = "This is a pair of rubber shoes.", Price = 2000, CategoryID = category.ID, ImageUrl = "rubbershoes.jpg" }; // Act sut.Create(product); // Assert var result = sut.Retrieve(product.ID); Assert.NotNull(result); // Cleanup sut.Delete(result.ID); categoryRepo.Delete(category.ID); }
private void UpdateCategory(IList <Category> dbCategories, Category parentCategory, CategoryData categoryData) { var parentPath = parentCategory != null ? parentCategory.Path : string.Empty; var dbCategory = dbCategories.FirstOrDefault(x => x.ExternalId == categoryData.XmlId); if (dbCategory == null) { dbCategory = new Category { Categories = new List <Category>(), Description = categoryData.Description, ExternalId = categoryData.XmlId, Path = string.Empty, ParentCategory = parentCategory }; var categoryId = m_categoryRepository.Create(dbCategory); dbCategory.Path = $"{parentPath}/{categoryId}"; m_categoryRepository.Update(dbCategory); dbCategories.Add(dbCategory); } foreach (var subcategoryData in categoryData.SubCategories) { UpdateCategory(dbCategories, dbCategory, subcategoryData); } }
public void Retrieve_WithValidID_ReturnsValidEntity() { //Arrange var context = new ECommerceDbContext(); var cat = new CategoryRepository(context); var category = new Category { Name = "Shoe", Description = "Shoe Department" }; cat.Create(category); var fillerCategory = cat.Retrieve(category.ID); var sut = new ProductRepository(context); var product = new Product { Name = "Nike", Description = "Airmax", Price = 3000, Category = fillerCategory, ImageUrl = "picture" }; sut.Create(product); //Act var actual = sut.Retrieve(product.ID); //Assert Assert.NotNull(actual); //Cleanup sut.Delete(actual.ID); cat.Delete(category.ID); }
public void Update_CategoryWithValidID_ShouldChangeCurrentData() { //Arrange var context = new ECommerceDbContext(); var sut = new CategoryRepository(context); var category = new Category { Name = "Kids Shoes", Description = "Kids Department" }; sut.Create(category); //Act var entity = sut.Retrieve(category.ID); var updatedName = "New Shoes"; entity.Name = updatedName; var updatedDescription = "New Shoes Department"; entity.Description = updatedDescription; sut.Update(entity.ID, entity); var updatedEntity = sut.Retrieve(category.ID); //Arrange Assert.Equal(updatedName, updatedEntity.Name); Assert.Equal(updatedDescription, updatedEntity.Description); sut.Delete(entity.ID); Assert.NotNull(entity); }
public void Update_WithValidEntity_ShouldUpdateDatabaseRecord() { var context = new ECommerceDbContext(); var sut = new CategoryRepository(context); var category = new Category { Name = "shoes", Description = "Shoes Department" }; sut.Create(category); var record = sut.Retrieve(category.ID); var expectedName = "Bag"; var expectedDescription = "Bag Department"; //Act record.Name = expectedName; record.Description = expectedDescription; var actual = sut.Update(record.ID, category); //Assert Assert.Equal(expectedName, actual.Name); Assert.Equal(expectedDescription, actual.Description); //Cleanup sut.Delete(actual.ID); }
public void Retrieve_WithSkipAndCount_ReturnsTheCorrectPage() { //Arrange var context = new ECommerceDbContext(); var sut = new CategoryRepository(context); for (var i = 1; i <= 20; i += 1) { sut.Create(new Category { Name = string.Format("Category {0}", i), Description = string.Format("Description {0}", i) }); } //Act var list = sut.Retrieve(5, 5); //Assert Assert.True(list.Count() == 5); //Cleanup list = sut.Retrieve(0, 41); foreach (var item in list) { sut.Delete(item.ID); } }
public void Update_WithValidProperty_ShouldUpdateEntity() { //Arrange var context = new ECommerceDbContext(); var sut = new CategoryRepository(context); var oldCategory = new Category { Name = "Shoes", Description = "Shoes Department", IsActive = true }; sut.Create(oldCategory); var retrieve = sut.Retrieve(oldCategory.ID); retrieve.Name = "Pants"; retrieve.Description = "Pants Department"; //Act sut.Update(retrieve.ID, retrieve); //Assert var expected = sut.Retrieve(retrieve.ID); Assert.True(retrieve.Equals(expected)); //Cleanup sut.Delete(expected.ID); }
public void Update_WithValidEntity_ShouldUpdateDatabaseRecord() { //Arrange var context = new ECommerceDbContext(); var sut = new CategoryRepository(context); var category = new Category { Name = "Shoes", Description = "Shoes Department" }; sut.Create(category); category.Name = "Boots"; category.Description = "Shoes Department Updated"; var actual = sut.Retrieve(category.ID); //Act sut.Update(category.ID, category); var expected = sut.Retrieve(category.ID); //Assert Assert.Equal(actual.ID, expected.ID); Assert.Equal(actual.Name, expected.Name); Assert.Equal(actual.Description, expected.Description); //Cleanup sut.Delete(category.ID); }
public void Retrieve_WithSkipAndCount_ReturnsTheCorrectPage() { //Arrange var context = new ECommerceDbContext(); var sut = new CategoryRepository(context); for (var i = 1; i <= 20; i += 1) { sut.Create(new Category { Name = string.Format("Category {0}", i), Description = string.Format("Description {0}", i) }); } //Act var list = sut.Retrieve(5, 5); //Assert Assert.True(list.Count() == 5); //Cleanup list = sut.Retrieve(0, Int32.MaxValue); list.All(c => { sut.Delete(c.ID); return(true); }); //count max, then -- }
public void Create_WithValidEntity_ShouldCreateDatabaseRecord() { //Arrange var context = new ECommerceDbContext(); var sut = new CategoryRepository(context); var category = new Category { Name = "Shoes", Description = "Shoes Department" }; //Act sut.Create(category); //Assert Assert.True(category.ID != 0); var entity = sut.Retrieve(category.ID); Assert.NotNull(entity); //Cleanup sut.Delete(category.ID); }
public void Delete_ById_Category() { CategoryRepository repoCategory = new CategoryRepository(); // //creamos una nueva categoria // Category categoryNew = new Category() { CategoryName = "CatName2", Description = "Desc2" }; repoCategory.Create(categoryNew); // //la eliminamos // repoCategory.Delete(new Category() { CategoryId = categoryNew.CategoryId }); // // se recupera para validar que no exista // var categorySel = repoCategory.GetById(categoryNew.CategoryId); Assert.IsNull(categorySel); }
public void Create_WithValidEntity_ShouldCreateDatabaseRecord() { var options = ConnectionOptionHelper.Sqlite(); var category = new Category { Name = "Bag", Description = "Bag Department" }; using (var context = new ECommerceDbContext(options)) { context.Database.OpenConnection(); context.Database.EnsureCreated(); var sut = new CategoryRepository(context); //Act sut.Create(category); } using (var context = new ECommerceDbContext(options)) { //Assert Assert.True(category.ID != 0); var entity = context.Categories.Find(category.ID); Assert.NotNull(entity); } }
public ActionResult CreateCategory(Category category) { var rep = new CategoryRepository(); rep.Create(category); return RedirectToAction("Group"); }
public void CreateItem(Category item) { if (item != null) { _categoryRepository.Create(item); } }
/// <summary> /// Creating new category /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Create_Click(object sender, RoutedEventArgs e) { // Validation for new category name if (!App.ContainNumbers(mainText.Text) && mainText.Text.Length != 0) { Category customCategory = new Category { Name = mainText.Text }; CategoryRepository repository = new CategoryRepository(); repository.Create(customCategory); mainText.Text = ""; // Updating ComboBox Items UpdateComboBox(customCategory.Name); // Change UI to default Cancel_Click(sender, e); } else { MessageBox.Show("Incorrect name of category."); } }
public ActionResult Create(CategoryViewModel model) { var mapper = new Mapper(new MapperConfiguration(cfg => cfg.CreateMap <Category, CategoryViewModel>())); var announ = mapper.Map <Category>(model); categoryRepository.Create(announ); return(Redirect("/Home/Index")); }
public void GetAllCategoriesSingleResultTest() { var repository = CategoryRepository.Create(); var category = this.CreateArticle(repository, SeedCategory.Create()); var service = this.GetArticlesService(repository); var result = service.GetAllCategories <CategoryDumyModel>(); Assert.Single(result); }
public void DeleteByIdTest() { var repository = CategoryRepository.Create(); var category = this.CreateArticle(repository, SeedCategory.Create()); var service = this.GetArticlesService(repository); var result = service.DeleteById(category.Id); Assert.True(category.IsDeleted); }
public Category Add([FromBody] CategoryInput category) { var entity = new Category() { Name = category.Name, ParentCategoryId = category.ParentCategoryId, IsActive = category.IsActive }; return(_repository.Create(entity)); }
public async void AddCategoryButton_Click(object sender, RoutedEventArgs e) { var category = new Category { Description = $"Categoria {Categories.Count + 1}", Color = App.AvailableColors.Except(Categories.Select(c => c.Color)).First() }; await CategoryRepository.Create(category); }
public void HardDeleteByIdTest() { var repository = CategoryRepository.Create(); var category = this.CreateArticle(repository, SeedCategory.Create()); var service = this.GetArticlesService(repository); service.HardDeleteById(category.Id).GetAwaiter(); Assert.Equal(0, repository.AllWithDeleted().Count()); }
public void CreateCategory(Category payload) { Category category = new Category { Name = payload.Name, Id = Guid.NewGuid() }; _categoryRepository.Create(category); }
public ActionResult Create(Category category) { if (category == null || string.IsNullOrWhiteSpace(category.Name)) { return(RedirectToAction("Index")); } CategoryRepository.Create(category); return(RedirectToAction("Index")); }