private static void AreEqual(XmlNode ctpNode, Crop crop, Catalog catalog, Dictionary<string, List<UniqueId>> linkList) { UniqueIdAssert.AreEqual(linkList, ctpNode.GetXmlAttribute("A"), crop.Id.UniqueIds); Assert.AreEqual(ctpNode.GetXmlAttribute("A"), crop.Id.FindIsoId()); Assert.AreEqual(ctpNode.GetXmlAttribute("B"), crop.Name); var matchingCropVarieties = catalog.Products.Where(x => x is CropVariety).Cast<CropVariety>().Where(cv => cv.CropId == crop.Id.ReferenceId).ToList(); CropVarietyAssert.AreEqual(ctpNode.SelectNodes("CVT"), matchingCropVarieties, linkList); }
private Crop Map(CTP isoCropType) { var crop = new Crop(); crop.Id.UniqueIds.Add(new UniqueId { Id = Guid.NewGuid().ToString(), CiTypeEnum = CompoundIdentifierTypeEnum.UUID, Source = "http://www.deere.com", SourceType = IdSourceTypeEnum.URI }); return crop; }
private void LoadVarieties(XmlNode inputNode, Crop crop) { var varieties = CropVarietyLoader.Load(inputNode.SelectNodes("CVT")); foreach (var variety in varieties) { variety.Value.CropId = crop.Id.ReferenceId; _taskDocument.CropVarieties.Add(variety.Key, variety.Value); _taskDocument.LoadLinkedIds(variety.Key, variety.Value.Id); } }
private void WriteVarieties(XmlWriter writer, Crop cropId) { if (TaskWriter.DataModel.Catalog.Products == null || TaskWriter.DataModel.Catalog.Products.Count == 0) return; var cropVarieties = new List<CropVariety>(); foreach (var cropVariety in TaskWriter.DataModel.Catalog.Products.Where(x => x is CropVariety).Cast<CropVariety>()) { if (cropVariety.CropId == cropId.Id.ReferenceId) cropVarieties.Add(cropVariety); } _cropVarietyWriter.Write(writer, cropVarieties); }
private string WriteCrop(XmlWriter writer, Crop crop) { var cropId = crop.Id.FindIsoId() ?? GenerateId(); TaskWriter.Ids.Add(cropId, crop.Id); writer.WriteStartElement(XmlPrefix); writer.WriteAttributeString("A", cropId); writer.WriteAttributeString("B", crop.Name); WriteVarieties(writer, crop); writer.WriteEndElement(); return cropId; }
private Crop LoadCrop(XmlNode inputNode, out string cropId) { var crop = new Crop(); // Required fields. Do not proceed if they are missing cropId = inputNode.GetXmlNodeValue("@A"); crop.Name = inputNode.GetXmlNodeValue("@B"); if (cropId == null || crop.Name == null) return null; crop.Id.UniqueIds.Add(ImportHelper.CreateUniqueId(cropId)); // Optional fields LoadVarieties(inputNode, crop); _taskDocument.LoadLinkedIds(cropId, crop.Id); return crop; }