/// <summary>
 /// Thêm mới hoặc Cập nhật thông tin Nhà Cung Cấp
 /// </summary>
 /// <param name="colorName"></param>
 private Color InsertOrUpdateColor(string colorName)
 {
     if (!string.IsNullOrEmpty(colorName))
     {
         Color color;
         if (!_colorService.CheckUnitNameExit(colorName))
         {
             color = _colorService.GetColorByName(colorName);
         }
         else
         {
             color = new Color()
             {
                 ColorCode   = colorName,
                 Description = colorName,
                 ColorName   = colorName,
                 IsActive    = true,
             };
             try
             {
                 _colorService.Add(color);
             }
             catch (Exception ex)
             {
                 XtraMessageBox.Show(string.Format("Lỗi thêm Màu Sắc \n{0}", ex.Message));
             }
         }
         return(color);
     }
     return(null);
 }
        public void GetByNameShouldThrowNullException(string name)
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "AddAsync").Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Color>(dbContext);
            var service    = new ColorService(repository);

            Assert.Throws <ArgumentNullException>(() => service.GetColorByName(name));
        }
        public async Task GetByNameShouldWork(string name)
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetByName").Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Color>(dbContext);
            var service    = new ColorService(repository);
            await service.AddAsync(name);

            Assert.Equal(name, service.GetColorByName(name).Name);
        }