コード例 #1
0
        public void BuildRouteMakesARouteSupportingTheSpecifiedVersions()
        {
            var configurationManager         = MockCurrentApiVersionAs("50");
            ApiRouteAttribute routeAttribute = new ApiRouteAttribute("GamingGroups")
            {
                ConfigurationManager = configurationManager,
                AcceptedVersions     = new [] { 2, 3, 4 }
            };

            string actualRoute = routeAttribute.BuildRoute();

            Assert.That(actualRoute, Is.EqualTo("api/v{version:int:regex(^(2|3|4)$)}/GamingGroups"));
        }
コード例 #2
0
        public void BuildRouteThrowsAnInvalidOperationExceptionIfTheStartingVersionIsGreaterThanTheCurrentApiversion()
        {
            var configurationManager         = MockCurrentApiVersionAs("1");
            ApiRouteAttribute routeAttribute = new ApiRouteAttribute("GamingGroups")
            {
                ConfigurationManager = configurationManager,
                StartingVersion      = 2
            };

            var exception = Assert.Throws <InvalidOperationException>(() => routeAttribute.BuildRoute());

            Assert.That(exception.Message, Is.EqualTo("The 'StartingVersion' cannot be greater than the 'currentApiVersion' specified in the config."));
        }
コード例 #3
0
        public void BuildRouteThrowsAnInvalidOperationExceptionIfOneOfTheExplicitlySetAcceptedVersionsIsNotAPositiveInteger()
        {
            var configurationManager         = MockCurrentApiVersionAs("50");
            ApiRouteAttribute routeAttribute = new ApiRouteAttribute("GamingGroups")
            {
                ConfigurationManager = configurationManager,
                AcceptedVersions     = new[] { 2, 3, -4 }
            };

            var exception = Assert.Throws <InvalidOperationException>(() => routeAttribute.BuildRoute());

            Assert.That(exception.Message, Is.EqualTo("The explicitly specified AcceptedVersion values must all be positive integers."));
        }
コード例 #4
0
        public void BuildRouteMakesARouteSupportingAllVersionsUpToTheCurrentVersion()
        {
            const string CURRENT_VERSION      = "3";
            var          configurationManager = MockCurrentApiVersionAs(CURRENT_VERSION);

            ApiRouteAttribute routeAttribute = new ApiRouteAttribute("GamingGroups")
            {
                ConfigurationManager = configurationManager
            };

            string actualRoute = routeAttribute.BuildRoute();

            Assert.That(actualRoute, Is.EqualTo("api/v{version:int:regex(^(1|2|3)$)}/GamingGroups"));
        }
コード例 #5
0
        public void BuildRouteThrowsAConfigurationErrorsExceptionIfTheCurrentApiVersionAppSettingIsNotAPositiveInteger()
        {
            const string CURRENT_VERSION      = "-1";
            var          configurationManager = MockCurrentApiVersionAs(CURRENT_VERSION);

            ApiRouteAttribute routeAttribute = new ApiRouteAttribute("GamingGroups")
            {
                ConfigurationManager = configurationManager
            };

            var exception = Assert.Throws <ConfigurationErrorsException>(() => routeAttribute.BuildRoute());

            Assert.That(exception.Message, Is.EqualTo("The 'currentApiVersion' app setting must be a positive integer."));
        }
コード例 #6
0
        public void BuildRouteThrowsAnInvalidOperationExceptionIfBothStartingVersionAndAcceptedVersionsAreSet()
        {
            var configurationManager         = MockCurrentApiVersionAs("50");
            ApiRouteAttribute routeAttribute = new ApiRouteAttribute("GamingGroups")
            {
                ConfigurationManager = configurationManager,
                AcceptedVersions     = new[] { 2 },
                StartingVersion      = 1
            };

            var exception = Assert.Throws <InvalidOperationException>(() => routeAttribute.BuildRoute());

            Assert.That(exception.Message, Is.EqualTo("Either 'AcceptedVersions' or 'StartingVersion' can be set, but not both."));
        }