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"));
        }
        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."));
        }
        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."));
        }
        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"));
        }
        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."));
        }
        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."));
        }