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); }
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); }
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); }
public void ReturnsNullWhenKeyNotFound() { // Given MetadataDictionary initialMetadata = new MetadataDictionary(); MetadataStack metadata = new MetadataStack(initialMetadata); // When IReadOnlyList<IDocument> result = metadata.DocumentList("A"); // Then Assert.IsNull(result); }
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); }
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"]); }
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"]); }
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); }
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); }
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"]); }
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"]); }
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")); }
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"]); }
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); }
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); }
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); }
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); }
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); } }
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); }
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"]); }
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"}); }
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); }
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}); }
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); }
public void ReturnsTrueForSameKeysWithDifferentCase() { // Given MetadataDictionary initialMetadata = new MetadataDictionary { ["A"] = "a" }; MetadataStack metadata = new MetadataStack(initialMetadata); // When bool contains = metadata.ContainsKey("a"); // Then Assert.IsTrue(contains); }