コード例 #1
0
        public void CopyToOfCollectionOfKeyValuePairsCopiesItems()
        {
            // given
            var initialKvPs = new List <KeyValuePair <int, string> >()
            {
                new KeyValuePair <int, string>(1, "One"),
                new KeyValuePair <int, string>(2, "Two")
            };

            using (var observableDictionary = new ObservableDictionary <int, string>(initialKvPs))
            {
                // when
                var targetArray = new KeyValuePair <int, string> [observableDictionary.Count];
                ((ICollection <KeyValuePair <int, string> >)observableDictionary).CopyTo(targetArray, 0);

                // then
                targetArray.Should().NotBeEmpty();
                targetArray.Length.Should().Be(observableDictionary.Count);

                foreach (var keyValuePair in initialKvPs)
                {
                    targetArray.Should().Contain(keyValuePair);
                }
            }
        }
コード例 #2
0
        public void CopyTo()
        {
            var headers = new NameValueCollection()
            {
                { "Header#1", "Value #1-A" },
                { "Header#2", "Value #2" },
                { "Header#1", "Value #1-B" },
                { "Header#3", "Value #3" },
                { "Header#4", "Value #4" },
            };

            var response = new Mock <HttpResponseBase>(MockBehavior.Strict);

            response.SetupGet(r => r.Headers)
            .Returns(headers);

            var responseFeature = new HttpResponseHeaderDictionary(response.Object);

            var array = new KeyValuePair <string, StringValues> [10];

            responseFeature.CopyTo(array, 2);

            array.Should().Equal(
                new KeyValuePair <string, StringValues>(null, StringValues.Empty),
                new KeyValuePair <string, StringValues>(null, StringValues.Empty),
                new KeyValuePair <string, StringValues>("Header#1", "Value #1-A,Value #1-B"),
                new KeyValuePair <string, StringValues>("Header#2", "Value #2"),
                new KeyValuePair <string, StringValues>("Header#3", "Value #3"),
                new KeyValuePair <string, StringValues>("Header#4", "Value #4"),
                new KeyValuePair <string, StringValues>(null, StringValues.Empty),
                new KeyValuePair <string, StringValues>(null, StringValues.Empty),
                new KeyValuePair <string, StringValues>(null, StringValues.Empty),
                new KeyValuePair <string, StringValues>(null, StringValues.Empty));
        }
コード例 #3
0
        public void Properties_Map()
        {
            Client model = new Client {
                Properties = { { "foo1", "bar1" }, { "foo2", "bar2" } }
            };


            Entities.Client mappedEntity = model.ToEntity();

            mappedEntity.Properties.Count.Should().Be(2);
            KeyValuePair <string, string> foo1 = mappedEntity.Properties.FirstOrDefault(x => x.Key == "foo1");

            foo1.Should().NotBeNull();
            foo1.Value.Should().Be("bar1");
            KeyValuePair <string, string> foo2 = mappedEntity.Properties.FirstOrDefault(x => x.Key == "foo2");

            foo2.Should().NotBeNull();
            foo2.Value.Should().Be("bar2");


            Client mappedModel = mappedEntity.ToModel();

            mappedModel.Properties.Count.Should().Be(2);
            mappedModel.Properties.ContainsKey("foo1").Should().BeTrue();
            mappedModel.Properties.ContainsKey("foo2").Should().BeTrue();
            mappedModel.Properties["foo1"].Should().Be("bar1");
            mappedModel.Properties["foo2"].Should().Be("bar2");
        }
コード例 #4
0
        public void When_header_is_not_found_should_return_preferred_header_without_value()
        {
            // Act
            KeyValuePair <string, string> header = _sut.GetCorrelationIdHeader(new[] { TestHeaderName });

            // Assert
            header.Should().BeEquivalentTo(new KeyValuePair <string, string>(TestHeaderName, null));
        }
コード例 #5
0
        public void CopyTo_ShouldBeOk_Index1()
        {
            var array = new KeyValuePair <string, string> [1];

            _dictionary.CopyTo(array, 0);
            array.Should().BeEquivalentTo(new KeyValuePair <string, string>[] {
                new KeyValuePair <string, string>("key", "value")
            });
        }
コード例 #6
0
        public void When_getting_by_custom_header_name_should_get_value()
        {
            _sut.Add(TestHeaderName, new StringValues(CorrelationId));

            // Act
            KeyValuePair <string, string> header = _sut.GetCorrelationIdHeader(new[] { TestHeaderName });

            // Assert
            header.Should().BeEquivalentTo(new KeyValuePair <string, string>(TestHeaderName, CorrelationId));
        }
コード例 #7
0
        public void When_getting_by_name_it_should_get_value()
        {
            _sut.Add(CorrelationHttpHeaders.CorrelationId, new StringValues(CorrelationId));

            // Act
            KeyValuePair <string, string> header = _sut.GetCorrelationIdHeader(new [] { CorrelationHttpHeaders.CorrelationId });

            // Assert
            header.Should().BeEquivalentTo(new KeyValuePair <string, string>(CorrelationHttpHeaders.CorrelationId, CorrelationId));
        }
コード例 #8
0
        public void ReadOnlyDictionary_CopyTo()
        {
            // Arrange
            var copy = new KeyValuePair <string, string> [10];

            // Act
            ReadOnlyTarget.CopyTo(copy, 0);

            // Assert
            copy.Should().BeEquivalentTo(ReadOnlyTarget);
        }
コード例 #9
0
        public void When_using_empty_accepted_headers_should_throw()
        {
            _sut.Add(CorrelationHttpHeaders.CorrelationId, new StringValues(CorrelationId));
            var expectedHeader = new KeyValuePair <string, string>(CorrelationHttpHeaders.CorrelationId, null);

            // Act
            KeyValuePair <string, string> header = _sut.GetCorrelationIdHeader(new string[0]);

            // Assert
            header.Should().BeEquivalentTo(expectedHeader, "it should not take correlation id from header dictionary but still return header key");
        }
コード例 #10
0
            public void CopiesToSpecifiedArray()
            {
                var inputArray = new KeyValuePair <string, object> [2];

                _sut.CopyTo(inputArray, 0);

                var expectedArray = new[] {
                    new KeyValuePair <string, object>("A", 1),
                    new KeyValuePair <string, object>("B", 2)
                };

                inputArray.Should().BeEquivalentTo(expectedArray);
            }
コード例 #11
0
        public void Given_list_of_accepted_headers_when_request_contains_one_of_the_headers_it_should_get_value(string requestHeaderKey)
        {
            _sut.Add(requestHeaderKey, new StringValues(CorrelationId));

            // Act
            KeyValuePair <string, string> header = _sut.GetCorrelationIdHeader(new [] {
                "first-header",
                "second-header",
                "third-header"
            });

            // Assert
            header.Should().BeEquivalentTo(new KeyValuePair <string, string>(requestHeaderKey, CorrelationId));
        }
コード例 #12
0
        public void CopyTo()
        {
            IDictionary <string, string> dictionary = new LockFreeArrayBasedDictionary <string, string>();

            dictionary.Add("Foo", "Bar");
            dictionary.Add("Baz", "Qux");
            dictionary.Add("Quux", "Quuz");
            var array = new KeyValuePair <string, string> [3];

            dictionary.CopyTo(array, 0);

            var expected = new[]
            {
                new KeyValuePair <string, string>("Foo", "Bar"),
                new KeyValuePair <string, string>("Baz", "Qux"),
                new KeyValuePair <string, string>("Quux", "Quuz")
            };

            array.Should().BeEquivalentTo(expected);
        }
        public void CopyToOfCollectionOfKeyValuePairsCopiesItems()
        {
            // given
            var initialKvPs = new List<KeyValuePair<int, string>>()
            {
                new KeyValuePair<int, string>(1, "One"),
                new KeyValuePair<int, string>(2, "Two")
            };

            using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs))
            {
                // when
                var targetArray = new KeyValuePair<int, string>[observableDictionary.Count];
                ((ICollection<KeyValuePair<int, string>>) observableDictionary).CopyTo(targetArray, 0);

                // then
                targetArray.Should().NotBeEmpty();
                targetArray.Length.Should().Be(observableDictionary.Count);

                foreach (var keyValuePair in initialKvPs)
                {
                    targetArray.Should().Contain(keyValuePair);
                }
            }
        }