public void Should_Get_Item() { var categoryGet = new Entities.Category { Id = 1, Title = "MyCategory" }; var repositoryMock = new Mock <IRepository <Entities.Category> >(); repositoryMock.Setup(u => u.Get(1)).Returns(categoryGet); var unitOfWorkMock = new Mock <IUnitOfWork>(); unitOfWorkMock.Setup(u => u.Categories).Returns(() => repositoryMock.Object); var service = new CategoryService(unitOfWorkMock.Object, mapper); var actualGet = service.GetById(1); Assert.NotNull(actualGet); Assert.Equal(categoryGet.Title, actualGet.Title); repositoryMock.Verify(m => m.Get(1)); }
public IActionResult SyncPartCategories() { //get all categories from rebrickable //get all categories from db //iterate through rebrickable list //add-edit db item //iterate through db //remove any that don't exist in rebrickable var sourceCategories = _rebrickableInfoRepository.GetAllPartCategories(); var destCategories = _setInfoRepository.GetCategories(); foreach (var sc in sourceCategories) { if (destCategories.Any(c => c.Id == sc.Id)) { destCategories.First(c => c.Id == sc.Id).Name = sc.Name; } else { var dc = new Entities.Category() { Id = sc.Id, Name = sc.Name }; _setInfoRepository.AddCategory(dc); } } _setInfoRepository.Save(); return(NoContent()); }
public async Task Should_Update() { var oldCategory = new Entities.Category { Id = 1, Title = "Category 1", ParentCategoryId = 0 }; var newCategoryDto = mapper.Map <Entities.Category, CategoryDTO>(oldCategory); newCategoryDto.Title = "Category 2"; newCategoryDto.ParentCategoryId = 3; var repositoryMock = new Mock <IRepository <Entities.Category> >(); repositoryMock.Setup(u => u.Get(1)).Returns(oldCategory); var unitOfWorkMock = new Mock <IUnitOfWork>(); unitOfWorkMock.Setup(u => u.Categories).Returns(() => repositoryMock.Object); var service = new CategoryService(unitOfWorkMock.Object, mapper); await service.UpdateAsync(newCategoryDto); repositoryMock.Verify(m => m.Update(It.Is <Entities.Category>(t => t.Title == newCategoryDto.Title && (t.ParentCategoryId == newCategoryDto.ParentCategoryId)))); unitOfWorkMock.Verify(m => m.SaveAsync()); }
public void DeleteCategory(Entities.Category category) { category.IsActive = false; category.IsDeleted = true; category.UpdateDate = DateTime.UtcNow; _categoryRepository.Update(category); }
static Dtos.Category ToDto(Entities.Category category) { return(new Dtos.Category { Id = category.Id, Description = category.Description, Categories = category.Categories == null ? null : category.Categories.Select(c => ToDto(c)).ToList() }); }
public ActionResult Create(Entities.Category category) { var principal = Thread.CurrentPrincipal.Identity.Name; var CategoryProcess = new Process.CategoryProcess(); CategoryProcess.Create(category); return(RedirectToAction("Index")); }
public static bool Where(this Entities.Category category, string namePattern) { if (category == null) { throw new System.ArgumentNullException(nameof(category)); } return(category.Name.Contains(namePattern, System.StringComparison.OrdinalIgnoreCase)); }
public static Logic.Objects.Base_Objects.Logging.Category MapCategory(Entities.Category contextCategory) { Logic.Objects.Base_Objects.Logging.Category logicCategory = new Logic.Objects.Base_Objects.Logging.Category() { categoryID = contextCategory.CategoryId, categoryName = contextCategory.CategoryName, categoryDescription = contextCategory.CategoryDescription }; return(logicCategory); }
public static Entities.Category MapCategory(Logic.Objects.Base_Objects.Logging.Category logicCategory) { Entities.Category contextCategory = new Entities.Category() { CategoryId = logicCategory.categoryID, CategoryName = logicCategory.categoryName, CategoryDescription = logicCategory.categoryDescription }; return(contextCategory); }
public void UpdateCategory(Entities.Category category) { var count = _categoryRepository.GetCount(c => c.Name == category.Name && c.Id != category.Id); if (count > 0) { throw new InvalidOperationException("Category Already Exists"); } _categoryRepository.Update(category); }
public void AddCategory(Entities.Category category) { var count = _categoryRepository.GetCount(x => x.Name == category.Name); if (count > 0) { throw new InvalidOperationException("Category Already Exists"); } _categoryRepository.Insert(category); }
public void SetName_IncorrectName_ShouldThrowArgException() { // Arrange var category = new Entities.Category(1, "Home"); // Act var del = new TestDelegate(() => category.SetName(string.Empty)); // Assert Assert.Throws <System.ArgumentException>(del); }
public void AddIssue_UniqueIssue_ShouldAddIssue() { // Arrange var category = new Entities.Category(1, "Home"); // Act category.AddIssue("Clean up room"); // Assert Assert.AreEqual("Clean up room", category.GetIssues().First().Name); }
public void SetName_CorrectName_ShouldSetName() { // Arrange var category = new Entities.Category(1, "Home"); // Act category.SetName("Work"); // Assert Assert.AreEqual("Work", category.Name); }
public AtkEdit(Entities.PriceList price) { InitializeComponent(); this.price = price; sqlPriceListRepository = new SqlPriceListRepository(); List<Entities.Category> listCategory = sqlPriceListRepository.GetTypeOfSupplier(1); if (!Constant.VisitaJayaPerkasaApplication.anyConnection) { MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } categorySupplier = listCategory != null ? listCategory.FirstOrDefault() : null; if (categorySupplier != null) { listSupplier = sqlPriceListRepository.GetSupplier(categorySupplier.ID); if (!Constant.VisitaJayaPerkasaApplication.anyConnection) { MessageBox.Show(this, "Please check your connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } cbSupplier.Enabled = true; cbSupplier.DataSource = listSupplier; cbSupplier.DisplayMember = "SupplierName"; cbSupplier.ValueMember = "Id"; cbSupplier.SelectedIndex = -1; cbSupplier.Text = "-- Choose --"; if (this.price == null) { pickerDate.Value = DateTime.Now; wantToCreateNew = true; } else { cbSupplier.SelectedValue = price.SupplierID; if (cbSupplier.Text.Equals(Constant.VisitaJayaPerkasaApplication.cboDefaultText) || cbSupplier.Text.Equals("")) radButtonElement1.Enabled = false; pickerDate.Value = price.DateFrom; etItem.Text = price.Item; etPrice.Text = price.PriceSupplier.ToString(); wantToCreateNew = false; } } listCategory = null; sqlPriceListRepository = null; }
public void ChangeIssueName_IssueNotFound_ShouldThrowArgException() { // Arrange var category = new Entities.Category(1, "Home"); category.AddIssue("Clean up room"); // Act var del = new TestDelegate(() => category.ChangeIssueName("Clean out room", "Clean up room")); // Assert Assert.Throws <System.ArgumentException>(del); }
public void RemoveIssue_IssueName_ShouldRemoveIssue() { // Arrange var category = new Entities.Category(1, "Home"); category.AddIssue("Clean up room"); // Act category.RemoveIssue("Clean up room"); // Assert Assert.AreEqual(0, category.GetIssues().Count); }
public void ChangeIssueStatus_IssueName_ShouldCompleteIssue() { // Arrange var category = new Entities.Category(1, "Home"); category.AddIssue("Clean up room"); // Act category.ChangeIssueStatus("Clean up room"); // Assert Assert.IsTrue(category.GetIssues().First().IsCompleted); }
public void AddIssue_ExistingIssue_ShouldThrowArgException() { // Arrange var category = new Entities.Category(1, "Home"); category.AddIssue("Clean up room"); // Act var del = new TestDelegate(() => category.AddIssue("Clean up room")); // Assert Assert.Throws <System.ArgumentException>(del); }
public async Task <Unit> Handle(CreateCategoryCommand request, CancellationToken cancellationToken) { var entity = new Entities.Category { CategoryName = request.CategoryName, Description = request.Description, Picture = request.Picture }; _context.Set <Entities.Category>().Add(entity); await _context.SaveChangesAsync(true, cancellationToken); return(Unit.Value); }
public async Task <ApplicationCore.Models.Category> AddCategoryAsync(ApplicationCore.Models.Category category) { if (category is null) { throw new ArgumentNullException(nameof(category)); } Entities.Category entity = Mapper.Map(category); await _context.Category.AddAsync(entity); await _context.SaveChangesAsync(); return(Mapper.Map(entity)); }
public static void Load(string culture, Entities.CategoryParent categories) { ProductLanguage language = Repository.Memory.Languages.Instance.Items[culture]; string query = " SELECT CategoryId, CategoryName, UrlName" + " FROM Categories" + " WHERE (ParentId<0 AND LanguageId=@LanguageId)" + " ORDER BY CategoryName"; using (SqlConnection cnn = new SqlConnection(Configurations.ConnectionString)) { using (SqlCommand cmd = new SqlCommand(query, cnn)) { cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SqlParameter("@LanguageId", language.Id)); foreach (SqlParameter Parameter in cmd.Parameters) { if (Parameter.Value == null) { Parameter.Value = DBNull.Value; } } cnn.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader != null && reader.HasRows) { while (reader.Read()) { Entities.Category cat = new Entities.Category(); cat.CategoryId = Repository.Utils.Convert.ToInt32(reader[0]); cat.CategoryName = Repository.Utils.Convert.ToString(reader[1]); cat.UrlName = Repository.Utils.Convert.ToString(reader[2]); LoadSubCategories(cat.SubCategories, cat.CategoryId, language.Id); categories.Add(cat); } } cnn.Close(); } } }
public async Task Put_Normally_UpdatesExistingCategory() { var expected = new Entities.Category { CategoryId = Guid.Parse("96e2799e-e0e5-49e7-a44b-3858ce69d9f1"), CategoryName = "Updated" }; var response = await sut.PutAsync(expected.CategoryId, new UpdatedCategory { Name = expected.CategoryName }); var actual = response as NoContentResult; Assert.That(actual, Is.Not.Null); await fakeWebApi.Received(1).UpdateCategoryAsync(Arg.Is <Entities.Category>(actual => actual.CategoryId == expected.CategoryId && actual.CategoryName == expected.CategoryName)); }
public async Task <ResponseGeneric> Handle(ListProductsByCategoryRequest request, CancellationToken cancellationToken) { // validar id categoria Entities.Category category = this.categoryRepository.GetBy(x => x.Id == request.IdCategory); if (category == null) { // validar categoria não encontrada return(null); } //var list = this.productRepository.Test(request.IdCategory); var list = this.productRepository.ListAndOrderBy(x => x.Category.Id == request.IdCategory, x => x.Title, true, x => x.Images, x => x.Sizes); var response = new ResponseGeneric(true, $"Produtos da categoria \'{category.Title}\' listados com sucesso", list); return(await Task.FromResult(response)); }
public Guid Create(CategoryCreate input) { // check user and permissions Session.EnsureAuthenticated(); // validation var hasCategoryWithSameName = _categoryRepository.GetAll() .Where(x => x.ParentCategoryId == input.ParentCategoryId && x.Title == input.Title).Any(); if (hasCategoryWithSameName) { throw new Exceptions.BadRequestException("CATEGORY_WITH_SAME_NAME_EXIST"); } // build hierarchy var hierarchy = ""; if (input.ParentCategoryId.HasValue) { hierarchy = input.ParentCategoryId.Value.ToString(); var parentCategoryHierarchy = _categoryRepository.GetAll() .Where(x => x.Id == input.ParentCategoryId.Value) .Select(x => x.Hierarchy).FirstOrDefault(); if (string.IsNullOrWhiteSpace(parentCategoryHierarchy) == false) { hierarchy = parentCategoryHierarchy + ";" + hierarchy; } } var model = new Entities.Category { Id = Guid.NewGuid(), CreatedAt = DateTime.UtcNow, CreatedByUserId = Session.AuthenticatedUserId.Value, ParentCategoryId = input.ParentCategoryId, Hierarchy = hierarchy, Title = input.Title }; _categoryRepository.Insert(model); return(model.Id); }
//public string Desc { private get; // set {txtComment.Text = value} private void btnSave_Click(object sender, EventArgs e) { try { switch (_entityState) { case EntityState.New: new BusinessLayer.CategoryService().Add(new Entities.Category { Comment = txtComment.Text, Name = txtName.Text }); break; case EntityState.Dirty: Entities.Category category = new Entities.Category { Comment = txtComment.Text, Name = txtName.Text, CategoryID = CategoryID }; new BusinessLayer.GenericService <Entities.Category>().Update(category, c => c.CategoryID == category.CategoryID); break; default: break; } Helper.ClearForm(this); btnSave.Text = "Save"; _entityState = EntityState.New; Helper.ShowMessage("Category saved successfully", "Category Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); frmSetupDetails frmSetup = Helper.CreateInstanceFor <frmSetupDetails>("frmSetupDetails"); if (frmSetup != null) { frmSetup.LoadGridWithDataDatasource(() => new BusinessLayer.GenericService <Entities.Category>().GetAll()); } } catch (Exception ex) { _logger.LogError(ex, "An error occurred", "frmAddCategory", "btnSave"); Helper.ShowMessage("Category was not saved successfully \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static CategoryDto Build(Entities.Category category) { List <string> imageUrls = new List <string>(); if (category.CategoryImages != null) { foreach (var tagImage in category.CategoryImages) { imageUrls.Add(tagImage.FilePath); } } return(new CategoryDto { Id = category.Id, Name = category.Name, Description = category.Description, ImageUrls = imageUrls }); }
public static bool Has(this Entities.Category category, int?fromBookAmount, int?toBookAmount) { if (category == null) { throw new System.ArgumentNullException(nameof(category)); } bool has = true; int bookAmount = category.Books.Count; if (fromBookAmount != null) { has &= bookAmount >= fromBookAmount.Value; } if (toBookAmount != null) { has &= bookAmount <= toBookAmount.Value; } return(has); }
public async Task Should_Delete() { var categoryForDelete = new Entities.Category { Id = 1, Title = "MyCategory" }; var repositoryMock = new Mock <IRepository <Entities.Category> >(); repositoryMock.Setup(u => u.Get(1)).Returns(categoryForDelete); var unitOfWorkMock = new Mock <IUnitOfWork>(); unitOfWorkMock.Setup(u => u.Categories).Returns(() => repositoryMock.Object); var service = new CategoryService(unitOfWorkMock.Object, null); await service.DeleteAsync(1); repositoryMock.Verify(m => m.Delete(1)); unitOfWorkMock.Verify(m => m.SaveAsync()); }
public void Update(Domain.Category category) { Entities.Category categoryUpdated = _mapper.Map <Entities.Category>(category); _ctx.Categories.Attach(categoryUpdated); _ctx.Entry(categoryUpdated).State = EntityState.Modified; }
public static ViewModel.Category ToViewModel(this Entities.Category cat) => _mapper.Map <ViewModel.Category>(cat);