public List <DTOSize> ValidateSizes(ICollection <DTOSize> sizes, out string error) { var result = new List <DTOSize>(); error = null; foreach (var size in sizes) { if (size.Position.Id != this.Id) { error += Texts.Instance.SizeCorrespondsToAnotherPosition(size.Name) + " /n"; continue; } if (Size.DoesSizeExist(size, result, out string existError)) { error += existError + " /n"; continue; } if (Size.DoesSizeNameExist(size, result, out existError)) { error += existError + " /n"; continue; } result.Add(size); } return(result); }
public void DoesSizeExistFail_DTOList() { var size1 = new DTOSize(1, "1", new Money(1), new DTO.Position(1, "1", "1")); var size2 = new DTOSize(2, "2", new Money(1), new DTO.Position(1, "1", "1")); var size3 = new DTOSize(3, "3", new Money(1), new DTO.Position(1, "1", "1")); var sizes = new List <DTOSize>() { size1, size2 }; var result = Size.DoesSizeExist(size3, sizes, out var error); Assert.IsFalse(result); Assert.AreEqual($"Size {size3.Name} cannot be found", error); }
public void DoesSizeExistSuccess_DTOList() { var size1 = new DTOSize(1, "1", new Money(1), new DTO.Position(1, "1", "1")); var size2 = new DTOSize(2, "2", new Money(1), new DTO.Position(1, "1", "1")); var size3 = new DTOSize(1, "3", new Money(1), new DTO.Position(1, "1", "1")); var sizes = new List <DTOSize>() { size1, size2 }; var result = Size.DoesSizeExist(size3, sizes, out var error); Assert.IsTrue(result); Assert.AreEqual($"Size {size3.Name} already exists", error); }