public void read_should_not_throw_exception_when_duplicate_api_versions_are_requested(IQueryCollection query)
        {
            // arrange
            var request = new Mock <HttpRequest>();
            var reader  = new QueryStringApiVersionReader("api-version", "version");

            request.SetupProperty(r => r.Query, query);

            // act
            var version = reader.Read(request.Object);

            // assert
            version.Should().Be("1.0");
        }
        public void read_should_throw_exception_when_ambiguous_api_versions_are_requested(IQueryCollection query)
        {
            // arrange
            var request = new Mock <HttpRequest>();
            var reader  = new QueryStringApiVersionReader("api-version", "version");

            request.SetupProperty(r => r.Query, query);

            // act
            Action read = () => reader.Read(request.Object);

            // assert
            read.Should().Throw <AmbiguousApiVersionException>().And.ApiVersions.Should().BeEquivalentTo("1.0", "2.0");
        }
        public void read_should_return_null_when_query_parameter_is_empty()
        {
            // arrange
            var query   = new Mock <IQueryCollection>();
            var request = new Mock <HttpRequest>();
            var reader  = new QueryStringApiVersionReader();

            query.SetupGet(q => q["api-version"]).Returns(string.Empty);
            request.SetupProperty(r => r.Query, query.Object);

            // act
            var version = reader.Read(request.Object);

            // assert
            version.Should().BeNull();
        }
        public void read_should_not_throw_exception_when_duplicate_api_versions_are_requested()
        {
            // arrange
            var query   = new Mock <IQueryCollection>();
            var request = new Mock <HttpRequest>();
            var reader  = new QueryStringApiVersionReader();

            query.SetupGet(q => q["api-version"]).Returns(new StringValues(new[] { "1.0", "1.0" }));
            request.SetupProperty(r => r.Query, query.Object);

            // act
            var version = reader.Read(request.Object);

            // assert
            version.Should().Be("1.0");
        }
        public void read_should_throw_exception_when_ambiguous_api_versions_are_requested()
        {
            // arrange
            var query   = new Mock <IQueryCollection>();
            var request = new Mock <HttpRequest>();
            var reader  = new QueryStringApiVersionReader();

            query.SetupGet(q => q["api-version"]).Returns(new StringValues(new[] { "1.0", "2.0" }));
            request.SetupProperty(r => r.Query, query.Object);

            // act
            Action read = () => reader.Read(request.Object);

            // assert
            read.ShouldThrow <AmbiguousApiVersionException>().And.ApiVersions.Should().BeEquivalentTo("1.0", "2.0");
        }
        public void read_should_retrieve_version_from_query_string()
        {
            // arrange
            var requestedVersion = "2.1";
            var query            = new Mock <IQueryCollection>();
            var request          = new Mock <HttpRequest>();
            var reader           = new QueryStringApiVersionReader();

            query.SetupGet(q => q["api-version"]).Returns(requestedVersion);
            request.SetupProperty(r => r.Query, query.Object);

            // act
            var version = reader.Read(request.Object);

            // assert
            version.Should().Be(requestedVersion);
        }