private static void AreEqual(LoggedData loggedData, TSK tsk, Catalog catalog, string cardPath) { var grower = catalog.Growers.SingleOrDefault(x => x.Id.ReferenceId == loggedData.GrowerId); var farm = catalog.Farms.SingleOrDefault(x => x.Id.ReferenceId == loggedData.FarmId); var field = catalog.Fields.SingleOrDefault(x => x.Id.ReferenceId == loggedData.FieldId); if(grower != null) Assert.AreEqual(grower.Id.FindIsoId(), tsk.C); if (farm != null) Assert.AreEqual(farm.Id.FindIsoId(), tsk.D); if (field != null) Assert.AreEqual(field.Id.FindIsoId(), tsk.E); if(loggedData.TimeScopes != null && loggedData.TimeScopes.Any()) { var tims = tsk.Items.Where(x => x.GetType() == typeof(TIM)).Cast<TIM>().ToList(); TimAssert.AreEqual(loggedData.TimeScopes, tims); } if(loggedData.OperationData != null && loggedData.OperationData.Any()) { var tlgs = tsk.Items.Where(x => x.GetType() == typeof(TLG)).Cast<TLG>().ToList(); TlgAssert.AreEqual(loggedData.OperationData.ToList(), tlgs, catalog, cardPath); } }
private void LoadGuidanceAllocations(XmlNode inputNode, LoggedData task) { var allocations = GuidanceAllocationLoader.Load(inputNode, _taskDocument); _taskDocument.GuidanceAllocations.AddRange(allocations); task.GuidanceAllocationIds = allocations.Select(x => x.Id.ReferenceId).ToList(); }
private void LoadFarm(string farmId, LoggedData task) { var farm = _taskDocument.Farms.FindById(farmId); if (farm != null) { task.FarmId = farm.Id.ReferenceId; task.GrowerId = farm.GrowerId; } }
private void LoadField(string fieldId, LoggedData task) { var field = _taskDocument.Fields.FindById(fieldId); if (field != null) { task.FieldId = field.Id.ReferenceId; task.FarmId = field.FarmId; } }
private LoggedData LoadTask(XmlNode inputNode) { var task = new LoggedData(); // Required fields. Do not proceed if they are missing var taskId = inputNode.GetXmlNodeValue("@A"); if (taskId == null) return null; // Optional fields task.Description = inputNode.GetXmlNodeValue("@B"); LoadField(inputNode.GetXmlNodeValue("@E"), task); LoadFarm(inputNode.GetXmlNodeValue("@D"), task); LoadCustomer(inputNode.GetXmlNodeValue("@C"), task); LoadGuidanceAllocations(inputNode, task); LoadCommentAllocations(inputNode, task); task.Id.UniqueIds.Add(new UniqueId { Id = taskId, Source = UniqueIdMapper.IsoSource, CiTypeEnum = CompoundIdentifierTypeEnum.String, }); _taskDocument.LoadLinkedIds(taskId, task.Id); return task; }
private void LoadCommentAllocations(XmlNode inputNode, LoggedData task) { task.Notes = CommentAllocationLoader.Load(inputNode, _taskDocument); }
private void LoadCustomer(string customerId, LoggedData task) { var customer = _taskDocument.Customers.FindById(customerId); if (customer != null) task.GrowerId = customer.Id.ReferenceId; }
private static void AreEqual(XmlNode tskNode, string currentPath, LoggedData loggedData, Catalog catalog) { var tlgNodes = tskNode.SelectNodes("TLG"); OperationDataAssert.AreEqual(tlgNodes, currentPath, loggedData.OperationData.ToList()); }
public void GivenTskWhenMapThenOperationDataAreMapped() { const string taskName = "TSK5"; var existingLoggedData = new LoggedData(); existingLoggedData.Id.UniqueIds.Add(new UniqueId{ CiTypeEnum = CompoundIdentifierTypeEnum.String, Id = taskName, Source = UniqueIdMapper.IsoSource}); _documents.LoggedData = new List<LoggedData> {existingLoggedData}; var tlgs = new List<TLG> {new TLG()}; _tsk.Items = tlgs.ToArray(); _tsk.A = taskName; var operationDatas = new List<OperationData>(); _operationDataMapper.Setup(x => x.Map(tlgs, null, _dataPath, It.IsAny<int>(), _linkIds)).Returns(operationDatas); var result = MapSingle(); Assert.AreSame(operationDatas, result.OperationData); }
public void GivenTskWithNullItemWhenMapThenPrescriptionIdIsNullToOperationMapper() { var existingLoggedData = new LoggedData(); existingLoggedData.Id.UniqueIds.Add(new UniqueId { CiTypeEnum = CompoundIdentifierTypeEnum.String, Id = "TSK0", Source = UniqueIdMapper.IsoSource }); _documents.LoggedData = new List<LoggedData> { existingLoggedData }; _tsk.A = "TSK0"; MapSingle(); _operationDataMapper.Verify(x => x.Map(It.IsAny<List<TLG>>(), null, _dataPath, existingLoggedData.Id.ReferenceId, _linkIds), Times.Once); }
public void GivenTskWithGrdWhenMapThenPrescriptionIdFromCatalogIsPassedToOperationMapper() { var prescription = new RasterGridPrescription(); prescription.Id.UniqueIds = new List<UniqueId> { new UniqueId { CiTypeEnum = CompoundIdentifierTypeEnum.String, Id = "FIX1", Source = "http://dictionary.isobus.net/isobus/" } }; _catalog.Prescriptions = new List<Prescription> { prescription }; var existingLoggedData = new LoggedData(); existingLoggedData.Id.UniqueIds.Add(new UniqueId { CiTypeEnum = CompoundIdentifierTypeEnum.String, Id = "FIX1", Source = UniqueIdMapper.IsoSource }); _documents.LoggedData = new List<LoggedData> { existingLoggedData }; var grd = new GRD(); _tsk.Items = new List<IWriter> {grd}.ToArray(); _tsk.A = "FIX1"; MapSingle(); _operationDataMapper.Verify(x => x.Map(It.IsAny<List<TLG>>(), prescription.Id.ReferenceId, _dataPath,existingLoggedData.Id.ReferenceId, _linkIds ), Times.Once); }
public void Setup() { _loggedData = new LoggedData(); _loggedDatas = new List<LoggedData>{ _loggedData }; _catalog = new Catalog(); _datacardPath = ""; _taskDocumentWriter = new TaskDocumentWriter(); _timeMapperMock = new Mock<ITimeMapper>(); _tlgMapperMock = new Mock<ITlgMapper>(); _taskMapper = new TaskMapper(_timeMapperMock.Object, _tlgMapperMock.Object); }