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 ClonedMetadataDoesNotContainNewValues() { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); engine.Metadata["A"] = "a"; Metadata metadata = new Metadata(engine); // When Metadata clone = metadata.Clone(new Dictionary<string, object> { { "B", "b" } }); // Then Assert.IsFalse(metadata.ContainsKey("B")); }
public void CloneContainsPreviousValues() { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); engine.Metadata["A"] = "a"; Metadata metadata = new Metadata(engine); // When Metadata clone = metadata.Clone(new Dictionary<string, object> { { "B", "b" } }); // Then Assert.AreEqual("a", clone["A"]); }
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 ConvertIntToString() { // 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<string> metadataAs = metadata.MetadataAs<string>(); // Then Assert.AreEqual(1, metadata["A"]); Assert.AreEqual("1", metadataAs["A"]); }
public void TryGetValueWithMetadataValueReturnsCorrectResult() { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); engine.Metadata["A"] = new SimpleMetadataValue { Value = "a" }; Metadata metadata = new Metadata(engine); // When object value; bool contains = metadata.TryGetValue("A", out value); // Then Assert.IsTrue(contains); Assert.AreEqual("a", value); }
public void TryGetValueReturnsTrueForValidValue() { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); engine.Metadata["A"] = "a"; Metadata metadata = new Metadata(engine); // When object value; bool contains = metadata.TryGetValue("A", out value); // Then Assert.IsTrue(contains); Assert.AreEqual("a", value); }
public void LinkReturnsCorrectResult(string value, bool pretty, string link) { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); engine.Metadata["A"] = new SimpleMetadataValue { Value = value }; Metadata metadata = new Metadata(engine); // When object result = metadata.Link("A", pretty: pretty); // Then Assert.AreEqual(link, result); }
public void IndexerWithMetadataValueReturnsCorrectResult() { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); engine.Metadata["A"] = new SimpleMetadataValue { Value = "a" }; Metadata metadata = new Metadata(engine); // When object value = metadata["A"]; // Then Assert.AreEqual("a", value); }
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 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 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 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 ContainsReturnsFalseForInvalidValue() { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); engine.Metadata["A"] = "a"; Metadata metadata = new Metadata(engine); // When bool contains = metadata.ContainsKey("B"); // Then Assert.IsFalse(contains); }