public void Successful_match_should_allow_getting_nullable_types_from_matches() { // given var matches = new Dictionary <string, object> { { "key", "5" } }; var templateMatches = new UriTemplateMatches(matches); // when var actualValue = templateMatches.Get <int?>("key"); // then actualValue.Should().Be(5); }
public void Successful_match_should_get_converted_values_for_existing_key() { // given var matches = new Dictionary <string, object> { { "key", "5" } }; var templateMatches = new UriTemplateMatches(matches); // when var actualValue = templateMatches.Get <int>("key"); // then actualValue.Should().Be(5); }
public void Failed_match_should_not_throw_on_dictionary_members() { // given var failure = UriTemplateMatches.Failure(); // then failure.Values.Should().BeEmpty(); failure.Keys.Should().BeEmpty(); failure.ContainsKey("whatever").Should().BeFalse(); object val; failure.TryGetValue("something", out val).Should().BeFalse(); failure.Count.Should().Be(0); failure.GetEnumerator().MoveNext().Should().BeFalse(); }
/// <inheritdoc/> public UriTemplateMatches Match <T>(Uri uri) { var template = uri.IsAbsoluteUri ? this.templates.GetAbsoluteTemplate(typeof(T)) : this.templates.GetTemplate(typeof(T)); var tunnelVisionMatches = new UriTemplate(template).Match(uri); if (tunnelVisionMatches != null) { var matchDict = tunnelVisionMatches.Bindings.Values.ToDictionary(m => m.Key.Name, m => m.Value); return(new UriTemplateMatches(matchDict)); } return(UriTemplateMatches.Failure()); }
public void Successful_match_should_get_values_as_is_when_no_conversions_required() { // given var list = new List <int>(); var matches = new Dictionary <string, object> { { "key", list } }; var templateMatches = new UriTemplateMatches(matches); // when var actualValue = templateMatches.Get <List <int> >("key"); // then actualValue.Should().BeSameAs(list); }