private void СopyButton_Click(object sender, EventArgs e) { var selectedDto = GetSelectedDto(); if (selectedDto == null) { return; } var sizePrototype = new DTO.Size { Name = selectedDto.Name, Active = selectedDto.Active, SubCategory = selectedDto.SubCategory, Brand = selectedDto.Brand, Height = selectedDto.Height, Weight = selectedDto.Weight }; var form = IoCContainer.Get <IFormService>().CreateDtoEditForm <DTO.Size>(EditFormMode.Create, sizePrototype); if (form.ShowDialog(this) == DialogResult.OK) { RefreshAndSelect(form.Dto); } }
public void UpdateSize_Should_Throw_Exception_When_Current_User_Is_Not_Seller() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Olesya.Login, EncryptServiceMockFactory.OlesyaPasswordData.Password); var updatedSize = new DTO.Size { Id = SizeMockFactory.Carters_Boys_0_2_3M.Id, Name = "New Size", SubCategory = container.Get <IDtoService>().CreateSubCategory(SubCategoryMockFactory.Girls_0_2), Brand = container.Get <IDtoService>().CreateBrand(BrandMockFactory.Crazy8), Weight = "New Weight", Height = "New Height", Active = true }; var sizeService = container.Get <ISizeService>(); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => sizeService.UpdateSize(updatedSize), "Only seller can change size."); }
public void OverrideEquals() { var size1 = new DTO.Size(1, "size1", new Money(1), new DTO.Position(1, "1", "1")); var size2 = new DTO.Size(1, "size1", new Money(1), new DTO.Position(1, "1", "1")); Assert.AreEqual(size1, size2); }
public void UpdateSize_Should_Throw_Exception_When_Size_With_The_Same_Name_Brand_SubCategory_Already_Exists() { var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Diana.Login, EncryptServiceMockFactory.DianaPasswordData.Password); var updatedSize = new DTO.Size { Id = SizeMockFactory.Carters_Boys_0_2_3M.Id, Name = SizeMockFactory.TheChildrensPlace_Boys_0_2_0_3_Months.Name, Brand = container.Get <IDtoService>().CreateBrand(SizeMockFactory.TheChildrensPlace_Boys_0_2_0_3_Months.Brand), SubCategory = container.Get <IDtoService>().CreateSubCategory(SizeMockFactory.TheChildrensPlace_Boys_0_2_0_3_Months.SubCategory), Weight = "New Weight", Height = "New Height", Active = true }; var sizeService = container.Get <ISizeService>(); // Act // Assert ExceptionAssert.Throw <SizeServiceException>( () => sizeService.UpdateSize(updatedSize), "Размер с заданным названием уже существует для данной подкатегории и данного бренда."); }
public DTO.Size CreateSize(DataAccess.Size size, bool includeOnlyActive = true) { CheckHelper.ArgumentNotNull(size, "size"); CheckHelper.ArgumentWithinCondition(!size.IsNew(), "!size.IsNew()"); return (_dtoCache.Get( size, s => { var result = new DTO.Size { Id = s.Id, Name = s.Name, Height = s.Height, Weight = s.Weight, Active = s.Active }; CopyTrackableFields(result, s); return result; }, (sDto, s) => { sDto.Brand = CreateBrand(s.Brand, includeOnlyActive); sDto.SubCategory = CreateSubCategory(s.SubCategory, includeOnlyActive); })); }
public void CreateSize(DTO.Size createdSize) { CheckHelper.ArgumentNotNull(createdSize, "createdSize"); CheckHelper.ArgumentWithinCondition(createdSize.IsNew(), "Size is not new."); Container.Get <IValidateService>().CheckIsValid(createdSize); CheckHelper.ArgumentWithinCondition(!createdSize.SubCategory.IsNew(), "SubCategory of Size is new."); CheckHelper.ArgumentWithinCondition(!createdSize.Brand.IsNew(), "Brand of Size is new."); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in."); CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can create size."); var persistentService = Container.Get <IPersistentService>(); var doesAnotherSizeWithTheSameNameSubCategoryBrandExist = persistentService .GetEntitySet <DataAccess.Size>() .Any(s => s.Name == createdSize.Name && s.SubCategoryId == createdSize.SubCategory.Id && s.BrandId == createdSize.Brand.Id); if (doesAnotherSizeWithTheSameNameSubCategoryBrandExist) { throw new SizeServiceException("Размер с заданным названием уже существует для данной подкатегории и данного бренда."); } var subCategory = persistentService.GetEntityById <SubCategory>(createdSize.SubCategory.Id); CheckHelper.NotNull(subCategory, "SubCategory does not exist."); var brand = persistentService.GetEntityById <DataAccess.Brand>(createdSize.Brand.Id); CheckHelper.NotNull(brand, "Brand does not exist."); var size = new DataAccess.Size { Name = createdSize.Name, SubCategoryId = subCategory.Id, SubCategory = subCategory, BrandId = brand.Id, Brand = brand, Active = createdSize.Active, Weight = createdSize.Weight, Height = createdSize.Height }; size.UpdateTrackFields(Container); persistentService.Add(size); persistentService.SaveChanges(); createdSize.Id = size.Id; createdSize.CreateDate = size.CreateDate; createdSize.CreateUser = size.CreatedBy.GetFullName(); createdSize.ChangeDate = size.ChangeDate; createdSize.ChangeUser = size.ChangedBy.GetFullName(); }
public void CreateSize_Should_Create_Size_When_Size_With_The_Same_Name_But_In_Other_SubCategory_And_Brand_Already_Exists() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Diana.Login, EncryptServiceMockFactory.DianaPasswordData.Password); const string NEW_SIZE_WEIGHT = "New Weight"; const string NEW_SIZE_HEIGHT = "New Height"; var createdSize = new DTO.Size { Name = SizeMockFactory.TheChildrensPlace_Boys_0_2_0_3_Months.Name, SubCategory = container.Get <IDtoService>().CreateSubCategory(SubCategoryMockFactory.Boys_2_5), Brand = container.Get <IDtoService>().CreateBrand(BrandMockFactory.Carters), Weight = NEW_SIZE_WEIGHT, Height = NEW_SIZE_HEIGHT, Active = true }; var sizeService = container.Get <ISizeService>(); var persistentService = container.Get <IPersistentService>(); var timeService = container.Get <ITimeService>(); // Act sizeService.CreateSize(createdSize); // Assert var actualSize = persistentService .GetEntitySet <DataAccess.Size>() .Single(s => s.Name == SizeMockFactory.TheChildrensPlace_Boys_0_2_0_3_Months.Name && s.SubCategoryId == SubCategoryMockFactory.Boys_2_5.Id && s.BrandId == BrandMockFactory.Carters.Id); Assert.IsTrue(actualSize.Id > 0); Assert.AreEqual(SizeMockFactory.TheChildrensPlace_Boys_0_2_0_3_Months.Name, actualSize.Name); Assert.AreEqual(SubCategoryMockFactory.Boys_2_5.Id, actualSize.SubCategory.Id); Assert.AreEqual(SubCategoryMockFactory.Boys_2_5.Name, actualSize.SubCategory.Name); Assert.AreEqual(SubCategoryMockFactory.Boys_2_5.Active, actualSize.SubCategory.Active); Assert.AreEqual(BrandMockFactory.Carters.Id, actualSize.Brand.Id); Assert.AreEqual(BrandMockFactory.Carters.Name, actualSize.Brand.Name); Assert.AreEqual(BrandMockFactory.Carters.Active, actualSize.Brand.Active); Assert.AreEqual(NEW_SIZE_WEIGHT, actualSize.Weight); Assert.AreEqual(NEW_SIZE_HEIGHT, actualSize.Height); Assert.IsTrue(actualSize.Active); Assert.AreEqual(timeService.UtcNow, actualSize.CreateDate); Assert.AreEqual(timeService.UtcNow, actualSize.ChangeDate); Assert.AreEqual(UserMockFactory.Diana, actualSize.CreatedBy); Assert.AreEqual(UserMockFactory.Diana, actualSize.ChangedBy); Assert.AreEqual(createdSize, container.Get <IDtoService>().CreateSize(actualSize)); }
public void UpdateSize_Should_Update_Size_When_Name_SubCategory_Brand_Are_Not_Changed() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Diana.Login, EncryptServiceMockFactory.DianaPasswordData.Password); const string NEW_SIZE_WEIGHT = "New Weight"; const string NEW_SIZE_HEIGHT = "New Height"; var createDate = SizeMockFactory.Carters_Boys_0_2_3M.CreateDate; var createdBy = SizeMockFactory.Carters_Boys_0_2_3M.CreatedBy; var name = SizeMockFactory.Carters_Boys_0_2_3M.Name; var updatedSize = new DTO.Size { Id = SizeMockFactory.Carters_Boys_0_2_3M.Id, Name = name, SubCategory = container.Get <IDtoService>().CreateSubCategory(SizeMockFactory.Carters_Boys_0_2_3M.SubCategory), Brand = container.Get <IDtoService>().CreateBrand(SizeMockFactory.Carters_Boys_0_2_3M.Brand), Weight = NEW_SIZE_WEIGHT, Height = NEW_SIZE_HEIGHT, Active = false }; var sizeService = container.Get <ISizeService>(); var persistentService = container.Get <IPersistentService>(); var timeService = container.Get <ITimeService>(); // Act sizeService.UpdateSize(updatedSize); // Assert var actualSize = persistentService.GetEntityById <DataAccess.Size>(SizeMockFactory.Carters_Boys_0_2_3M.Id); Assert.AreEqual(actualSize.Id, SizeMockFactory.Carters_Boys_0_2_3M.Id); Assert.AreEqual(name, actualSize.Name); Assert.AreEqual(SubCategoryMockFactory.Boys_0_2.Id, actualSize.SubCategory.Id); Assert.AreEqual(SubCategoryMockFactory.Boys_0_2.Name, actualSize.SubCategory.Name); Assert.AreEqual(SubCategoryMockFactory.Boys_0_2.Active, actualSize.SubCategory.Active); Assert.AreEqual(BrandMockFactory.Carters.Id, actualSize.Brand.Id); Assert.AreEqual(BrandMockFactory.Carters.Name, actualSize.Brand.Name); Assert.AreEqual(BrandMockFactory.Carters.Active, actualSize.Brand.Active); Assert.AreEqual(NEW_SIZE_WEIGHT, actualSize.Weight); Assert.AreEqual(NEW_SIZE_HEIGHT, actualSize.Height); Assert.IsFalse(actualSize.Active); Assert.AreEqual(createDate, actualSize.CreateDate); Assert.AreEqual(timeService.UtcNow, actualSize.ChangeDate); Assert.AreEqual(createdBy, actualSize.CreatedBy); Assert.AreEqual(UserMockFactory.Diana, actualSize.ChangedBy); Assert.AreEqual(updatedSize, container.Get <IDtoService>().CreateSize(actualSize)); }
public void CreateSize_Should_Create_Size() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Diana.Login, EncryptServiceMockFactory.DianaPasswordData.Password); const string NEW_SIZE_NAME = "New Size"; const string NEW_SIZE_WEIGHT = "New Weight"; const string NEW_SIZE_HEIGHT = "New Height"; var createdSize = new DTO.Size { Name = NEW_SIZE_NAME, Brand = container.Get <IDtoService>().CreateBrand(BrandMockFactory.TheChildrensPlace), SubCategory = container.Get <IDtoService>().CreateSubCategory(SubCategoryMockFactory.Boys_0_2), Weight = NEW_SIZE_WEIGHT, Height = NEW_SIZE_HEIGHT, Active = true }; var sizeService = container.Get <ISizeService>(); var persistentService = container.Get <IPersistentService>(); var timeService = container.Get <ITimeService>(); // Act sizeService.CreateSize(createdSize); // Assert var actualSize = persistentService .GetEntitySet <DataAccess.Size>() .Single(s => s.Name == NEW_SIZE_NAME); Assert.IsTrue(actualSize.Id > 0); Assert.AreEqual(NEW_SIZE_NAME, actualSize.Name); Assert.AreEqual(SubCategoryMockFactory.Boys_0_2.Id, actualSize.SubCategory.Id); Assert.AreEqual(SubCategoryMockFactory.Boys_0_2.Name, actualSize.SubCategory.Name); Assert.AreEqual(SubCategoryMockFactory.Boys_0_2.Active, actualSize.SubCategory.Active); Assert.AreEqual(BrandMockFactory.TheChildrensPlace.Id, actualSize.Brand.Id); Assert.AreEqual(BrandMockFactory.TheChildrensPlace.Name, actualSize.Brand.Name); Assert.AreEqual(BrandMockFactory.TheChildrensPlace.Active, actualSize.Brand.Active); Assert.AreEqual(NEW_SIZE_WEIGHT, actualSize.Weight); Assert.AreEqual(NEW_SIZE_HEIGHT, actualSize.Height); Assert.IsTrue(actualSize.Active); Assert.AreEqual(timeService.UtcNow, actualSize.CreateDate); Assert.AreEqual(timeService.UtcNow, actualSize.ChangeDate); Assert.AreEqual(UserMockFactory.Diana, actualSize.CreatedBy); Assert.AreEqual(UserMockFactory.Diana, actualSize.ChangedBy); Assert.AreEqual(createdSize, container.Get <IDtoService>().CreateSize(actualSize)); }
public void UpdateSize(DTO.Size updatedSize) { CheckHelper.ArgumentNotNull(updatedSize, "updatedSize"); CheckHelper.ArgumentWithinCondition(!updatedSize.IsNew(), "Size is new."); Container.Get <IValidateService>().CheckIsValid(updatedSize); CheckHelper.ArgumentWithinCondition(!updatedSize.SubCategory.IsNew(), "SubCategory of Size is new."); CheckHelper.ArgumentWithinCondition(!updatedSize.Brand.IsNew(), "SubCategory of Brand is new."); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in."); CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can change size."); var persistentService = Container.Get <IPersistentService>(); var size = persistentService.GetEntityById <DataAccess.Size>(updatedSize.Id); CheckHelper.NotNull(size, "Size does not exist."); if (size.Name != updatedSize.Name || size.SubCategoryId != updatedSize.SubCategory.Id || size.BrandId != updatedSize.Brand.Id) { var doesAnotherSizeWithTheSameNameSubCategoryBrandExist = persistentService .GetEntitySet <DataAccess.Size>() .Any(s => s.Name == updatedSize.Name && s.SubCategoryId == updatedSize.SubCategory.Id && s.BrandId == updatedSize.Brand.Id); if (doesAnotherSizeWithTheSameNameSubCategoryBrandExist) { throw new SizeServiceException("Размер с заданным названием уже существует для данной подкатегории и данного бренда."); } } var subCategory = persistentService.GetEntityById <SubCategory>(updatedSize.SubCategory.Id); CheckHelper.NotNull(subCategory, "SubCategory does not exist."); var brand = persistentService.GetEntityById <DataAccess.Brand>(updatedSize.Brand.Id); CheckHelper.NotNull(brand, "Brand does not exist."); size.Name = updatedSize.Name; size.Active = updatedSize.Active; size.SubCategoryId = subCategory.Id; size.SubCategory = subCategory; size.BrandId = brand.Id; size.Brand = brand; size.Weight = updatedSize.Weight; size.Height = updatedSize.Height; size.UpdateTrackFields(Container); persistentService.SaveChanges(); }
public void OverrideEqualsOperator() { var size1 = new DTO.Size(1, "size1", new Money(1), new DTO.Position(1, "1", "1")); var size2 = new DTO.Size(1, "size1", new Money(1), new DTO.Position(1, "1", "1")); var size3 = new DTO.Size(2, "size2", new Money(1), new DTO.Position(2, "2", "2")); Size size4 = null; Assert.IsTrue(size1 == size2); Assert.IsFalse(size1 != size2); Assert.IsTrue(size1 != size3); Assert.IsFalse(size1 == size3); Assert.IsFalse(size1 == null); Assert.IsTrue(size1 != null); Assert.IsTrue(size4 == null); Assert.IsFalse(size4 != null); }
protected override object[] GetDtoValues(DTO.Size size) { var values = new object[] { size.Name, size.Active.ToYesNo(), size.SubCategory.ToString(), size.Brand.ToString(), size.Height, size.Weight }; return (values .Concat(TrackableDtoListFormHelper.GetValues(size)) .ToArray()); }
public List <DTO.Size> GetSize() { var sizes = db.Size; var dtoSizes = new List <DTO.Size>(); foreach (var size in sizes) { var dtoSize = new DTO.Size() { Name = size.Name, Price = size.Price }; dtoSizes.Add(dtoSize); } return(dtoSizes); }
public static List <DTO.Size> GetPizzaSizes() { Database1Entities db = new Database1Entities(); var dbSizes = db.PizzaSizes.ToList(); List <DTO.Size> Sizes = new List <DTO.Size>(); foreach (var dbItem in dbSizes) { DTO.Size size = new DTO.Size(); size.Id = dbItem.Id; size.Price = dbItem.Price; size.InchSize = dbItem.Size; size.Description = dbItem.Description; Sizes.Add(size); } return(Sizes); }
public List <DTO.Ingredient> GetIngredientList(DTO.Size size) { return(new List <DTOIngredient>()); }
public SizeListForm(ListFormMode mode, DTO.Size size) : this(mode, size, null) { }
public SizeListForm(ListFormMode mode, DTO.Size size, Func <DTO.Size, bool> filter) : base(mode, size, filter) { InitializeComponent(); }
public void DeleteSize(DTO.Size size) { throw new NotImplementedException(); }
public void UpdateSize(DTO.Size size) { SizeListChanged?.Invoke(this, new SizeListChangedEventArgs(GetSizeList(size.Position), null)); }