Exemple #1
0
            public void CloneResultsInClonedDocument()
            {
                // Given
                SimpleMetadata initialMetadata = new SimpleMetadata();

                initialMetadata.Add("Foo", "Bar");
                DocumentFactory documentFactory = new DocumentFactory(initialMetadata);
                CustomDocumentFactory <TestDocument> customDocumentFactory = new CustomDocumentFactory <TestDocument>(documentFactory);
                IExecutionContext context        = Substitute.For <IExecutionContext>();
                CustomDocument    sourceDocument = (CustomDocument)customDocumentFactory.GetDocument(context);

                // When
                IDocument resultDocument = customDocumentFactory.GetDocument(context, sourceDocument, new Dictionary <string, object>
                {
                    { "Baz", "Bat" }
                });

                // Then
                CollectionAssert.AreEquivalent(new Dictionary <string, object>
                {
                    { "Foo", "Bar" }
                }, sourceDocument);
                CollectionAssert.AreEquivalent(new Dictionary <string, object>
                {
                    { "Foo", "Bar" },
                    { "Baz", "Bat" }
                }, resultDocument);
            }
Exemple #2
0
            public void GetsInitialDocumentWithInitialMetadata()
            {
                // Given
                SimpleMetadata initialMetadata = new SimpleMetadata();

                initialMetadata.Add("Foo", "Bar");
                DocumentFactory documentFactory = new DocumentFactory(initialMetadata);
                CustomDocumentFactory <TestDocument> customDocumentFactory = new CustomDocumentFactory <TestDocument>(documentFactory);
                IExecutionContext context = Substitute.For <IExecutionContext>();

                // When
                IDocument resultDocument = customDocumentFactory.GetDocument(context);

                // Then
                Assert.IsInstanceOf <TestDocument>(resultDocument);
                CollectionAssert.AreEqual(new Dictionary <string, object>
                {
                    { "Foo", "Bar" }
                }, resultDocument);
            }
        /// <summary>
        /// Parses command line args and outputs dictionary.
        /// </summary>
        /// <param name="args">Arguments from command line.</param>
        /// <returns></returns>
        public SimpleMetadata Parse(IEnumerable <string> args)
        {
            var metadata = new SimpleMetadata();

            foreach (var arg in args)
            {
                var pair = ParseSingle(arg);
                try
                {
                    metadata.Add(pair.Key, pair.Value);
                }
                catch (Exception ex)
                {
                    if (ex is ArgumentException || ex is ArgumentNullException)
                    {
                        throw new MetadataParseException(string.Format("Error while adding metadata \"{0}\" to dictionary: {1}", arg, ex.Message), ex);
                    }
                }
            }

            return(metadata);
        }