示例#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"]);
            }
示例#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"));
            }
示例#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"]);
            }
示例#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"]);
        }
示例#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);
        }
示例#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"]);
        }
示例#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"]);
        }
示例#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);
        }
示例#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"]);
            }
示例#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});
            }
示例#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);
        }
示例#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);
            }
示例#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);
        }
示例#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);
            }
示例#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);
            }
示例#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);
            }
示例#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);
            }
示例#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);
            }
示例#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);
            }
示例#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);
            }
示例#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"]);
            }
示例#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);
        }
示例#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"]);
            }
示例#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);
            }
示例#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);
            }
示例#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);
            }
示例#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"]);
            }
示例#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);
            }
示例#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);
            }
示例#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);
            }