Exemplo n.º 1
0
            public void CloneResultsInClonedDocument()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();
                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);
            }
Exemplo n.º 2
0
            public void IdIsNotTheSameForDifferentDocuments()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();

                // When
                Document a = new Document(initialMetadata);
                Document b = new Document(initialMetadata);

                // Then
                Assert.AreNotEqual(a.Id, b.Id);
            }
Exemplo n.º 3
0
            public void ThrowsWhenCloneReturnsSameDocument()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();
                DocumentFactory documentFactory = new DocumentFactory(initialMetadata);
                CustomDocumentFactory<TestDocument> customDocumentFactory = new CustomDocumentFactory<TestDocument>(documentFactory);
                IExecutionContext context = Substitute.For<IExecutionContext>();
                CloneReturnsSameDocument document = new CloneReturnsSameDocument();

                // When, Then
                Assert.Throws<Exception>(() => customDocumentFactory.GetDocument(context, document, new Dictionary<string, object>()));
            }
Exemplo n.º 4
0
            public void IdIsTheSameAfterClone()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();
                Document document = new Document(initialMetadata);

                // When
                IDocument cloned = new Document(document, new MetadataItems());

                // Then
                Assert.AreEqual(document.Id, cloned.Id);
            }
Exemplo n.º 5
0
            public void ReturnsCorrectResultForKeysWithDifferentCase()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary
                {
                    ["A"] = new SimpleMetadataValue { Value = "a" }
                };
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                object value = metadata["a"];

                // Then
                Assert.AreEqual("a", value);
            }
Exemplo n.º 6
0
            public void NullKeyThrowsKeyNotFoundException()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                TestDelegate test = () =>
                {
                    object value = metadata[null];
                };

                // Then
                Assert.Throws<ArgumentNullException>(test);
            }
Exemplo n.º 7
0
            public void GetsInitialDocumentWithInitialMetadata()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();
                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);
            }
Exemplo n.º 8
0
            public void StreamIsDisposedCorrectlyAfterClone()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();
                DisposeCheckStream stream = new DisposeCheckStream();
                Document originalDoc = new Document(initialMetadata, new FilePath("Test", PathKind.Absolute), stream, null,
                    Array.Empty<KeyValuePair<string, object>>(), true);
                Document clonedDoc = new Document(originalDoc, Array.Empty<KeyValuePair<string, object>>());

                // When
                originalDoc.Dispose();
                bool originalDocDisposedStream = stream.Disposed;
                clonedDoc.Dispose();
                bool clonedDocDisposedStream = stream.Disposed;

                // Then
                Assert.AreEqual(false, originalDocDisposedStream);
                Assert.AreEqual(true, clonedDocDisposedStream);
            }
Exemplo n.º 9
0
            public void ConvertIntToString()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                metadata = metadata.Clone(new[] { new KeyValuePair<string, object>("A", 1) });
                IMetadata<string> metadataAs = metadata.MetadataAs<string>();

                // Then
                Assert.AreEqual(1, metadata["A"]);
                Assert.AreEqual("1", metadataAs["A"]);
            }
Exemplo n.º 10
0
            public void ReturnsCorrectDirectoryPathForString(string path, string expected)
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                metadata = metadata.Clone(new[] { new KeyValuePair<string, object>("A", path) });
                object result = metadata.DirectoryPath("A");

                // Then
                if (expected == null)
                {
                    Assert.IsNull(result);
                }
                else
                {
                    Assert.IsInstanceOf<DirectoryPath>(result);
                    Assert.AreEqual(expected, ((DirectoryPath)result).FullPath);
                }
            }
Exemplo n.º 11
0
            public void ReturnsCorrectFilePathForFilePath(string path, string expected)
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                metadata = metadata.Clone(new[] { new KeyValuePair<string, object>("A", new FilePath(path)) });
                object result = metadata.FilePath("A");

                // Then
                Assert.IsInstanceOf<FilePath>(result);
                Assert.AreEqual(expected, ((FilePath)result).FullPath);
            }
Exemplo n.º 12
0
            public void ReturnsCorrectStringForDirectoryPath(string path, string expected)
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                metadata = metadata.Clone(new[] { new KeyValuePair<string, object>("A", new DirectoryPath(path)) });
                object result = metadata.String("A");

                // Then
                Assert.IsInstanceOf<string>(result);
                Assert.AreEqual(expected, result);
            }
Exemplo n.º 13
0
            public void ReplacesValue()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary {["A"] = "a"};
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                MetadataStack clone = metadata.Clone(new Dictionary<string, object> {{"A", "b"}});

                // Then
                Assert.AreEqual("a", metadata["A"]);
                Assert.AreEqual("b", clone["A"]);
            }
Exemplo n.º 14
0
            public void ReturnsTrueForValidValue()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary {["A"] = "a"};
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                bool contains = metadata.ContainsKey("A");

                // Then
                Assert.IsTrue(contains);
            }
Exemplo n.º 15
0
            public void EnumeratingMetadataValuesReturnsCorrectResults()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary
                {
                    ["A"] = new SimpleMetadataValue {Value = "a"},
                    ["B"] = new SimpleMetadataValue {Value = "b"},
                    ["C"] = new SimpleMetadataValue {Value = "c"}
                };
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                object[] values = metadata.Select(x => x.Value).ToArray();

                // Then
                CollectionAssert.AreEquivalent(new[] {"a", "b", "c"}, values);
            }
Exemplo n.º 16
0
            public void ClonedMetadataDoesNotContainNewValues()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary {["A"] = "a"};
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                MetadataStack clone = metadata.Clone(new Dictionary<string, object> {{"B", "b"}});

                // Then
                Assert.IsFalse(metadata.ContainsKey("B"));
            }
Exemplo n.º 17
0
            public void ReturnsCorrectResultForArray()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary {["A"] = new[] {1, 2, 3}};
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                IReadOnlyList<int> result = metadata.List<int>("A");

                // Then
                Assert.IsNotNull(result);
                CollectionAssert.AreEqual(result, new[] {1, 2, 3});
            }
Exemplo n.º 18
0
            public void ReturnsCorrectResultForConvertedIntList()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary {["A"] = new List<int> {1, 2, 3}};
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                IReadOnlyList<string> result = metadata.List<string>("A");

                // Then
                Assert.IsNotNull(result);
                CollectionAssert.AreEqual(result, new[] {"1", "2", "3"});
            }
Exemplo n.º 19
0
            public void MetadataValueCalledForEachRequest()
            {
                // Given
                SimpleMetadataValue metadataValue = new SimpleMetadataValue { Value = "a" };
                MetadataDictionary initialMetadata = new MetadataDictionary { ["A"] = metadataValue };
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                object value = metadata.Get("A");
                value = metadata.Get("A");
                value = metadata.Get("A");

                // Then
                Assert.AreEqual("a", value);
                Assert.AreEqual(3, metadataValue.Calls);
            }
Exemplo n.º 20
0
            public void ReturnsCorrectResultWithDerivedMetadataValue()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary
                {
                    ["A"] = new DerivedMetadataValue { Key = "X" },
                    ["X"] = "x"
                };
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                object value = metadata.Get("A");

                // Then
                Assert.AreEqual("x", value);
            }
Exemplo n.º 21
0
            public void GetWithMetadataValueReturnsCorrectResult()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary { ["A"] = "a" };
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                object value = metadata.Get("A");

                // Then
                Assert.AreEqual("a", value);
            }
Exemplo n.º 22
0
            public void ConvertIntArrayToStringEnumerable()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                metadata = metadata.Clone(new[] { new KeyValuePair<string, object>("A", new int[] { 1, 2, 3 }) });
                IMetadata<IEnumerable<string>> metadataAs = metadata.MetadataAs<IEnumerable<string>>();

                // Then
                CollectionAssert.AreEqual(new int[] { 1, 2, 3 }, (IEnumerable)metadata["A"]);
                CollectionAssert.AreEqual(new string[] { "1", "2", "3" }, metadataAs["A"]);
            }
Exemplo n.º 23
0
            public void ConvertStringToIntArray()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                metadata = metadata.Clone(new[] { new KeyValuePair<string, object>("A", "1") });
                IMetadata<int[]> metadataAs = metadata.MetadataAs<int[]>();

                // Then
                Assert.AreEqual("1", metadata["A"]);
                CollectionAssert.AreEqual(new int[] { 1 }, (IEnumerable)metadataAs["A"]);
            }
Exemplo n.º 24
0
            public void CanCloneWithNewValues()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                metadata = metadata.Clone(new[] { new KeyValuePair<string, object>("A", "a") });

                // Then
                Assert.AreEqual("a", metadata["A"]);
            }
Exemplo n.º 25
0
            public void ReturnsCorrectResultWithMetadataValue()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary
                {
                    ["A"] = new SimpleMetadataValue { Value = "a" }
                };
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                object value;
                bool contains = metadata.TryGetValue("A", out value);

                // Then
                Assert.IsTrue(contains);
                Assert.AreEqual("a", value);
            }
Exemplo n.º 26
0
            public void ReturnsFalseForInvalidValue()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary {["A"] = "a"};
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                object value;
                bool contains = metadata.TryGetValue("B", out value);

                // Then
                Assert.IsFalse(contains);
                Assert.AreEqual(null, value);
            }
Exemplo n.º 27
0
            public void ReturnsListForSingleDocument()
            {
                // Given
                IDocument a = Substitute.For<IDocument>();
                MetadataDictionary initialMetadata = new MetadataDictionary { ["A"] = a };
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                IReadOnlyList<IDocument> result = metadata.DocumentList("A");

                // Then
                Assert.IsNotNull(result);
                CollectionAssert.AreEqual(new[] { a }, result);
            }
Exemplo n.º 28
0
            public void ContainsNewValues()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary {["A"] = "a"};
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                MetadataStack clone = metadata.Clone(new Dictionary<string, object> {{"B", "b"}});

                // Then
                Assert.AreEqual("b", clone["B"]);
            }
Exemplo n.º 29
0
            public void ReturnsNullWhenKeyNotFound()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                IReadOnlyList<IDocument> result = metadata.DocumentList("A");

                // Then
                Assert.IsNull(result);
            }
Exemplo n.º 30
0
            public void ReturnsEmptyListForSingleInt()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary { ["A"] = 1 };
                MetadataStack metadata = new MetadataStack(initialMetadata);

                // When
                IReadOnlyList<IDocument> result = metadata.DocumentList("A");

                // Then
                Assert.IsNotNull(result);
                CollectionAssert.IsEmpty(result);
            }