private void ValidateBatchMetadata(PersistenceQueueItemInfo itemInfo, PersistenceQueueItemBatchInfo batchInfo) { Guard.ArgumentNotNull(itemInfo, "itemInfo"); if (batchInfo != null) { // Header segments are optional but we should check if they are provided if corresponding collection is not empty. if (batchInfo.HeaderSegments != null && batchInfo.HeaderSegments.Count == 0) { throw new CloudApplicationException(String.Format(CultureInfo.InstalledUICulture, ExceptionMessages.NoHeaderSegments, itemInfo.QueueItemId, itemInfo.QueueItemType)); } // Body segments are compulsory, these must always be provided. if (!(batchInfo.BodySegments != null && batchInfo.BodySegments.Count > 0)) { throw new CloudApplicationException(String.Format(CultureInfo.InstalledUICulture, ExceptionMessages.NoBodySegments, itemInfo.QueueItemId, itemInfo.QueueItemType)); } // Footer segments are optional but we should check if they are provided if corresponding collection is not empty. if (batchInfo.FooterSegments != null && batchInfo.FooterSegments.Count == 0) { throw new CloudApplicationException(String.Format(CultureInfo.InstalledUICulture, ExceptionMessages.NoFooterSegments, itemInfo.QueueItemId, itemInfo.QueueItemType)); } } else { throw new CloudApplicationException(String.Format(CultureInfo.InstalledUICulture, ExceptionMessages.UnresolvedBatchMetadata, itemInfo.QueueItemId, itemInfo.QueueItemType)); } }
public void DeserializeExecutePolicyRequest() { string testFileName = Path.Combine(testMessageFolder, "ExecutePolicyRequest.xml"); DataContractSerializer serializer = new DataContractSerializer(typeof(RulesEngineRequest)); using (FileStream fileStream = new FileStream(testFileName, FileMode.Open, FileAccess.Read, FileShare.None)) { XmlReaderSettings readerSettings = new XmlReaderSettings() { CheckCharacters = false, IgnoreComments = true, IgnoreProcessingInstructions = true, IgnoreWhitespace = true, ValidationType = ValidationType.None }; XmlReader xmlFileReader = XmlReader.Create(fileStream, readerSettings); while (!xmlFileReader.EOF && xmlFileReader.Name != WellKnownContractMember.MessageParameters.Request && xmlFileReader.NamespaceURI != WellKnownNamespace.DataContracts.General) { xmlFileReader.Read(); } Assert.IsFalse(xmlFileReader.EOF, "Unexpected end of file"); if (!xmlFileReader.EOF) { RulesEngineRequest request = serializer.ReadObject(xmlFileReader, false) as RulesEngineRequest; Assert.IsNotNull(request, "request is null"); Assert.IsFalse(String.IsNullOrEmpty(request.PolicyName)); Assert.IsNotNull(request.Facts); Assert.IsTrue(request.Facts.Count() == 2); PersistenceQueueItemBatchInfo batchInfo = null; PersistenceQueueItemInfo queueItemInfo = null; foreach (object fact in request.Facts) { if (fact is PersistenceQueueItemInfo) { queueItemInfo = fact as PersistenceQueueItemInfo; Assert.IsFalse(String.IsNullOrEmpty(queueItemInfo.QueueItemType)); Assert.IsFalse(queueItemInfo.QueueItemId == default(Guid)); } else if (fact is PersistenceQueueItemBatchInfo) { batchInfo = fact as PersistenceQueueItemBatchInfo; } } Assert.IsNotNull(batchInfo); Assert.IsNotNull(queueItemInfo); } } }