Beispiel #1
0
        /// <summary>
        /// Creates a stub of a Document.
        /// </summary>
        /// <param name="relativePath">The Path of the Document.</param>
        /// <param name="metadata">The Metadata of the Document.</param>
        /// <returns></returns>
        private IDocument GetDocumentWithMetadata(string relativePath, KeyValuePair <string, object>[] metadata)
        {
            for (int i = 0; i < metadata.Length; i++)
            {
                IMetadataValue provider = metadata[i].Value as IMetadataValue;
                if (provider != null)
                {
                    metadata[i] = new KeyValuePair <string, object>(metadata[i].Key, provider.Get(null));
                }
            }

            IDocument document       = Substitute.For <IDocument>();
            IMetadata metadataObject = Substitute.For <IMetadata>();

            metadataObject.GetEnumerator().Returns(x => metadata.OfType <KeyValuePair <string, object> >().GetEnumerator());
            metadataObject.Keys.Returns(metadata.Select(x => x.Key));
            metadataObject.Values.Returns(metadata.Select(x => x.Value));

            document.Source.Returns(relativePath);
            document.Metadata.Returns(metadataObject);
            document.GetEnumerator().Returns(x => metadata.OfType <KeyValuePair <string, object> >().GetEnumerator());
            document.Keys.Returns(metadata.Select(x => x.Key));
            document.Values.Returns(metadata.Select(x => x.Value));

            foreach (KeyValuePair <string, object> m in metadata)
            {
                metadataObject[m.Key].Returns(m.Value);
                metadataObject.ContainsKey(Arg.Any <string>()).Returns((x => metadata.Any(y => y.Key == (string)x[0])));

                document[m.Key].Returns(m.Value);
                document.ContainsKey(Arg.Any <string>()).Returns((x => metadata.Any(y => y.Key == (string)x[0])));
            }

            return(document);
        }
Beispiel #2
0
        // This resolves the metadata value by expanding IMetadataValue
        // To reduce allocations, it returns the input KeyValuePair if value is not IMetadataValue
        private KeyValuePair <string, object> GetItem(KeyValuePair <string, object> item)
        {
            IMetadataValue metadataValue = item.Value as IMetadataValue;

            return(metadataValue != null ? new KeyValuePair <string, object>(item.Key, metadataValue.Get(item.Key, this)) : item);
        }
Beispiel #3
0
        // This resolves the metadata value by expanding IMetadataValue
        private object GetValue(string key, object value)
        {
            IMetadataValue metadataValue = value as IMetadataValue;

            return(metadataValue != null?metadataValue.Get(key, this) : value);
        }
Beispiel #4
0
        /// <summary>
        /// This resolves the metadata value by expanding IMetadataValue.
        /// </summary>
        private object GetValue(object originalValue)
        {
            IMetadataValue metadataValue = originalValue as IMetadataValue;

            return(metadataValue != null?metadataValue.Get(this) : originalValue);
        }