Esempio n. 1
0
            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"]);
            }
Esempio n. 2
0
            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"));
            }
Esempio n. 3
0
            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"]);
            }
Esempio n. 4
0
        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"]);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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"]);
        }
Esempio n. 7
0
        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"]);
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
            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"]);
            }
Esempio n. 10
0
            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});
            }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
            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);
            }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
            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);
            }
Esempio n. 15
0
            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);
            }
Esempio n. 16
0
            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);
            }
Esempio n. 17
0
            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);
            }
Esempio n. 18
0
            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);
            }
Esempio n. 19
0
            public void ReturnsNullWhenKeyNotFound()
            {
                // Given
                InitialMetadata initialMetadata = new InitialMetadata();
                Metadata metadata = new Metadata(initialMetadata);

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

                // Then
                Assert.IsNull(result);
            }
Esempio n. 20
0
            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);
            }
Esempio n. 21
0
            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"]);
            }
Esempio n. 22
0
        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);
        }
Esempio n. 23
0
            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"]);
            }
Esempio n. 24
0
            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);
            }
Esempio n. 25
0
            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);
            }
Esempio n. 26
0
            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);
            }
Esempio n. 27
0
            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"]);
            }
Esempio n. 28
0
            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);
            }
Esempio n. 29
0
            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);
            }
Esempio n. 30
0
            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);
            }