Beispiel #1
0
        public Item EnsureItemWithUnit(string itemDescription)
        {
            itemDescription = itemDescription ?? "";

            var parts = itemDescription.Split(',');

            string name = parts[0].Trim();
            string unit = parts.Count() > 1 ? parts[1] : null;

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new Exception($"Incorrect item description provided: {itemDescription}");
            }

            var entity = _rep.GetByText(name);

            if (entity == null)
            {
                entity = new ItemEntity
                {
                    Text = name,
                    Unit = CodeUtils.CreateCode(unit),
                    Code = CodeUtils.CreateCode(name)
                };
                _rep.Add(entity);
            }

            return(ItemMapper.MapToModel(entity));
        }
Beispiel #2
0
 public void CreateCode_ReturnsCorrectCode()
 {
     Assert.Equal(null, CodeUtils.CreateCode(null));
     Assert.Equal(null, CodeUtils.CreateCode(""));
     Assert.Equal("kg", CodeUtils.CreateCode(" kg "));
     Assert.Equal("kg", CodeUtils.CreateCode("KG"));
     Assert.Equal("ces", CodeUtils.CreateCode(" Čęš "));
     Assert.Equal("kgas_(1)", CodeUtils.CreateCode("kg.as,(1)"));
     Assert.Equal("kg_as", CodeUtils.CreateCode("kg,    as"));
 }