public void CanCloneWithNewValues() { // Given InitialMetadata initialMetadata = new InitialMetadata(); Metadata metadata = new Metadata(initialMetadata); // When metadata = metadata.Clone(new[] { new KeyValuePair<string, object>("A", "a") }); // Then Assert.AreEqual("a", metadata["A"]); }
public void ClonedMetadataDoesNotContainNewValues() { // Given InitialMetadata initialMetadata = new InitialMetadata {["A"] = "a"}; Metadata metadata = new Metadata(initialMetadata); // When Metadata clone = metadata.Clone(new Dictionary<string, object> {{"B", "b"}}); // Then Assert.IsFalse(metadata.ContainsKey("B")); }
public void ContainsPreviousValues() { // Given InitialMetadata initialMetadata = new InitialMetadata {["A"] = "a"}; Metadata metadata = new Metadata(initialMetadata); // When Metadata clone = metadata.Clone(new Dictionary<string, object> {{"B", "b"}}); // Then Assert.AreEqual("a", clone["A"]); }
public void CanCloneWithNewValues() { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); Metadata metadata = new Metadata(engine); // When metadata = metadata.Clone(new [] { new KeyValuePair<string, object>("A", "a") }); // Then Assert.AreEqual("a", metadata["A"]); }
public void ContainsKeyReturnsTrueForValidValue() { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); engine.Metadata["A"] = "a"; Metadata metadata = new Metadata(engine); // When bool contains = metadata.ContainsKey("A"); // Then Assert.IsTrue(contains); }
public void ConvertStringArrayToIntArray() { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); Metadata metadata = new Metadata(engine); // When metadata = metadata.Clone(new[] { new KeyValuePair<string, object>("A", new string[] { "1", "2", "3" }) }); IMetadata<int[]> metadataAs = metadata.MetadataAs<int[]>(); // Then CollectionAssert.AreEqual(new string[] { "1", "2", "3" }, (IEnumerable)metadata["A"]); CollectionAssert.AreEqual(new int[] { 1, 2, 3 }, (IEnumerable)metadataAs["A"]); }
public void ConvertStringToInt() { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); Metadata metadata = new Metadata(engine); // When metadata = metadata.Clone(new[] { new KeyValuePair<string, object>("A", "1") }); IMetadata<int> metadataAs = metadata.MetadataAs<int>(); // Then Assert.AreEqual("1", metadata["A"]); Assert.AreEqual(1, metadataAs["A"]); }
public void IndexerNullKeyThrowsKeyNotFoundException() { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); Metadata metadata = new Metadata(engine); // When TestDelegate test = () => { object value = metadata[null]; }; // Then Assert.Throws<ArgumentNullException>(test); }
public void ConvertIntArrayToStringEnumerable() { // Given InitialMetadata initialMetadata = new InitialMetadata(); Metadata metadata = new Metadata(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 ReturnsCorrectResultForList() { // Given InitialMetadata initialMetadata = new InitialMetadata {["A"] = new List<int> {1, 2, 3}}; Metadata metadata = new Metadata(initialMetadata); // When IReadOnlyList<int> result = metadata.List<int>("A"); // Then Assert.IsNotNull(result); CollectionAssert.AreEqual(result, new[] {1, 2, 3}); }
public void EnumeratingMetadataValuesReturnsCorrectResults() { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); engine.Metadata["A"] = new SimpleMetadataValue { Value = "a" }; engine.Metadata["B"] = new SimpleMetadataValue { Value = "b" }; engine.Metadata["C"] = new SimpleMetadataValue { Value = "c" }; Metadata metadata = new Metadata(engine); // When object[] values = metadata.Select(x => x.Value).ToArray(); // Then CollectionAssert.AreEquivalent(new [] { "a", "b", "c" }, values); }
public void ReturnsEmptyListForSingleInt() { // Given InitialMetadata initialMetadata = new InitialMetadata { ["A"] = 1 }; Metadata metadata = new Metadata(initialMetadata); // When IReadOnlyList<IDocument> result = metadata.Documents("A"); // Then Assert.IsNotNull(result); CollectionAssert.IsEmpty(result); }
public void GetWithMetadataValueCalledForEachRequest() { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); SimpleMetadataValue metadataValue = new SimpleMetadataValue { Value = "a" }; engine.Metadata["A"] = metadataValue; Metadata metadata = new Metadata(engine); // 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 ReturnsCorrectResultWithMetadataValue() { // Given InitialMetadata initialMetadata = new InitialMetadata { ["A"] = new SimpleMetadataValue { Value = "a" } }; Metadata metadata = new Metadata(initialMetadata); // When object value; bool contains = metadata.TryGetValue("A", out value); // Then Assert.IsTrue(contains); Assert.AreEqual("a", value); }
public void ReturnsCorrectResultWithDerivedMetadataValue() { // Given InitialMetadata initialMetadata = new InitialMetadata { ["A"] = new DerivedMetadataValue { Key = "X" }, ["X"] = "x" }; Metadata metadata = new Metadata(initialMetadata); // When object value = metadata.Get("A"); // Then Assert.AreEqual("x", value); }
public void GetWithMetadataValueReturnsCorrectResult() { // Given InitialMetadata initialMetadata = new InitialMetadata { ["A"] = "a" }; Metadata metadata = new Metadata(initialMetadata); // When object value = metadata.Get("A"); // Then Assert.AreEqual("a", value); }
public void MetadataValueCalledForEachRequest() { // Given SimpleMetadataValue metadataValue = new SimpleMetadataValue { Value = "a" }; InitialMetadata initialMetadata = new InitialMetadata { ["A"] = metadataValue }; Metadata metadata = new Metadata(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 EnumeratingMetadataValuesReturnsCorrectResults() { // Given InitialMetadata initialMetadata = new InitialMetadata { ["A"] = new SimpleMetadataValue {Value = "a"}, ["B"] = new SimpleMetadataValue {Value = "b"}, ["C"] = new SimpleMetadataValue {Value = "c"} }; Metadata metadata = new Metadata(initialMetadata); // When object[] values = metadata.Select(x => x.Value).ToArray(); // Then CollectionAssert.AreEquivalent(new[] {"a", "b", "c"}, values); }
public void ReturnsNullWhenKeyNotFound() { // Given InitialMetadata initialMetadata = new InitialMetadata(); Metadata metadata = new Metadata(initialMetadata); // When IReadOnlyList<IDocument> result = metadata.Documents("A"); // Then Assert.IsNull(result); }
public void ReturnsListForSingleDocument() { // Given IDocument a = Substitute.For<IDocument>(); InitialMetadata initialMetadata = new InitialMetadata { ["A"] = a }; Metadata metadata = new Metadata(initialMetadata); // When IReadOnlyList<IDocument> result = metadata.Documents("A"); // Then Assert.IsNotNull(result); CollectionAssert.AreEqual(new[] { a }, result); }
public void ConvertStringToInt() { // Given InitialMetadata initialMetadata = new InitialMetadata(); Metadata metadata = new Metadata(initialMetadata); // When metadata = metadata.Clone(new[] { new KeyValuePair<string, object>("A", "1") }); IMetadata<int> metadataAs = metadata.MetadataAs<int>(); // Then Assert.AreEqual("1", metadata["A"]); Assert.AreEqual(1, metadataAs["A"]); }
public void GetWithDerivedMetadataValueReturnsCorrectResult() { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); engine.Metadata["X"] = "x"; engine.Metadata["A"] = new DerivedMetadataValue { Key = "X" }; Metadata metadata = new Metadata(engine); // When object value = metadata.Get("A"); // Then Assert.AreEqual("x", value); }
public void ConvertStringToIntArray() { // Given InitialMetadata initialMetadata = new InitialMetadata(); Metadata metadata = new Metadata(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 NullKeyThrowsKeyNotFoundException() { // Given InitialMetadata initialMetadata = new InitialMetadata(); Metadata metadata = new Metadata(initialMetadata); // When TestDelegate test = () => { object value = metadata[null]; }; // Then Assert.Throws<ArgumentNullException>(test); }
public void ReturnsTrueForValidValue() { // Given InitialMetadata initialMetadata = new InitialMetadata {["A"] = "a"}; Metadata metadata = new Metadata(initialMetadata); // When object value; bool contains = metadata.TryGetValue("A", out value); // Then Assert.IsTrue(contains); Assert.AreEqual("a", value); }
public void ReturnsCorrectResultWithMetadataValue() { // Given InitialMetadata initialMetadata = new InitialMetadata { ["A"] = new SimpleMetadataValue { Value = "a" } }; Metadata metadata = new Metadata(initialMetadata); // When object value = metadata["A"]; // Then Assert.AreEqual("a", value); }
public void ReplacesValue() { // Given InitialMetadata initialMetadata = new InitialMetadata {["A"] = "a"}; Metadata metadata = new Metadata(initialMetadata); // When Metadata clone = metadata.Clone(new Dictionary<string, object> {{"A", "b"}}); // Then Assert.AreEqual("a", metadata["A"]); Assert.AreEqual("b", clone["A"]); }
public void ReturnsCorrectResult(string value, bool pretty, string link) { // Given InitialMetadata initialMetadata = new InitialMetadata { ["A"] = new SimpleMetadataValue {Value = value} }; Metadata metadata = new Metadata(initialMetadata); // When object result = metadata.Link("A", pretty: pretty); // Then Assert.AreEqual(link, result); }
public void MissingKeyThrowsKeyNotFoundException() { // Given InitialMetadata initialMetadata = new InitialMetadata(); Metadata metadata = new Metadata(initialMetadata); // When TestDelegate test = () => { object value = metadata["A"]; }; // Then Assert.Throws<KeyNotFoundException>(test); }
public void ReturnsTrueForValidValue() { // Given InitialMetadata initialMetadata = new InitialMetadata {["A"] = "a"}; Metadata metadata = new Metadata(initialMetadata); // When bool contains = metadata.ContainsKey("A"); // Then Assert.IsTrue(contains); }