public void GivenActionIsRemovedInPreviousOrCurrentVersion_ThenActionDeprecatedApiVersionsSet(ushort versionRemoved, params int[] deprecatedVersion)
        {
            // Arrange
            var builder = new IntroducedApiVersionConventionBuilder(new Version(1, 0), new Version(3, 0), _apiVersionConventionBuilder.Object);

            var action = ActionModelBuilder
                         .WithAction <StubController>(c => c.Get())
                         .WithRemovedAsOfApiVersionAttribute(versionRemoved)
                         .Build();

            var controllerModel = ControllerModelBuilder
                                  .ForController <StubController>()
                                  .WithIntroducedInApiVersionAttribute(1)
                                  .WithAction(action)
                                  .Build();

            _controllerApiConventionBuilder
            .Setup(b => b.Action(action.ActionMethod))
            .Returns(_actionApiVersionConventionBuilder.Object);

            // Act
            var result = builder.ApplyTo(controllerModel);

            // Assert
            _actionApiVersionConventionBuilder.Verify(b => b.HasDeprecatedApiVersion(It.IsAny <ApiVersion>()), Times.Exactly(deprecatedVersion.Length));
            foreach (var deprecated in deprecatedVersion)
            {
                _actionApiVersionConventionBuilder.Verify(b => b.HasDeprecatedApiVersion(new ApiVersion(deprecated, 0)), Times.Once);
            }
        }
        public void GivenActionIsRemovedInPreviousOrCurrentVersion_ThenActionSupportedApiVersionsSetToEmpty(ushort versionRemoved)
        {
            // Arrange
            var builder = new IntroducedApiVersionConventionBuilder(new Version(1, 0), new Version(3, 0), _apiVersionConventionBuilder.Object);

            var action = ActionModelBuilder
                         .WithAction <StubController>(c => c.Get())
                         .WithRemovedAsOfApiVersionAttribute(versionRemoved)
                         .Build();

            var controllerModel = ControllerModelBuilder
                                  .ForController <StubController>()
                                  .WithIntroducedInApiVersionAttribute(1)
                                  .WithAction(action)
                                  .Build();

            _controllerApiConventionBuilder
            .Setup(b => b.Action(action.ActionMethod))
            .Returns(_actionApiVersionConventionBuilder.Object);

            // Act
            var result = builder.ApplyTo(controllerModel);

            // Assert
            _actionApiVersionConventionBuilder.Verify(b => b.HasApiVersion(It.IsAny <ApiVersion>()), Times.Never);
        }
        public void GivenActionIsIntroducedInNewerVersionThanController_ThenActionDeprecatedApiVersionsSet()
        {
            // Arrange
            var builder = new IntroducedApiVersionConventionBuilder(new Version(1, 0), new Version(3, 0), _apiVersionConventionBuilder.Object);

            var action = ActionModelBuilder
                         .WithAction <StubController>(c => c.Get())
                         .WithIntroducedInApiVersionAttribute(2)
                         .Build();

            var controllerModel = ControllerModelBuilder
                                  .ForController <StubController>()
                                  .WithIntroducedInApiVersionAttribute(1)
                                  .WithAction(action)
                                  .Build();

            _controllerApiConventionBuilder
            .Setup(b => b.Action(action.ActionMethod))
            .Returns(_actionApiVersionConventionBuilder.Object);

            // Act
            var result = builder.ApplyTo(controllerModel);

            // Assert
            _actionApiVersionConventionBuilder.Verify(b => b.HasDeprecatedApiVersion(new ApiVersion(2, 0)), Times.Once);
            _actionApiVersionConventionBuilder.Verify(b => b.HasDeprecatedApiVersion(It.IsAny <ApiVersion>()), Times.Once);
        }
        public void GivenControllerIsIntroducedAndActionHasNoAttribute_ThenActionSupportedSetToControllerSupported()
        {
            // Arrange
            var builder = new IntroducedApiVersionConventionBuilder(new Version(1, 0), new Version(3, 0), _apiVersionConventionBuilder.Object);

            var action = ActionModelBuilder
                         .WithAction <StubController>(c => c.Get())
                         .Build();

            var controllerModel = ControllerModelBuilder
                                  .ForController <StubController>()
                                  .WithIntroducedInApiVersionAttribute(1)
                                  .WithAction(action)
                                  .Build();

            _controllerApiConventionBuilder
            .Setup(b => b.Action(action.ActionMethod))
            .Returns(_actionApiVersionConventionBuilder.Object);

            // Act
            var result = builder.ApplyTo(controllerModel);

            // Assert
            _actionApiVersionConventionBuilder.Verify(b => b.HasApiVersion(new ApiVersion(3, 0)), Times.Once);
        }
        public void GivenControllerDoesNotHaveIntroducedVersion_ThenUseApiConvention()
        {
            var builder         = new IntroducedApiVersionConventionBuilder(new Version(1, 0), new Version(3, 0), _apiVersionConventionBuilder.Object);
            var controllerModel = ControllerModelBuilder.ForController <StubController>().Build();

            var result = builder.ApplyTo(controllerModel);

            _apiVersionConventionBuilder.Verify(b => b.ApplyTo(controllerModel), Times.Once);
            _apiVersionConventionBuilder.Verify(b => b.Controller(It.IsAny <TypeInfo>()), Times.Never);
        }
        public void GivenControllerIsRemovedBeforeIntroduced_ThenInvalidOperationExceptionIsThrown()
        {
            var builder         = new IntroducedApiVersionConventionBuilder(new Version(1, 0), new Version(3, 0), _apiVersionConventionBuilder.Object);
            var controllerModel = ControllerModelBuilder.ForController <StubController>()
                                  .WithIntroducedInApiVersionAttribute(2)
                                  .WithRemovedAsOfApiVersionAttribute(1)
                                  .Build();

            Assert.Throws <InvalidOperationException>(() => builder.ApplyTo(controllerModel));
        }
        public void GivenControllerIsRemovedBeforeStartVersion_ThenUseApiConvention()
        {
            var builder         = new IntroducedApiVersionConventionBuilder(new Version(3, 0), new Version(3, 0), _apiVersionConventionBuilder.Object);
            var controllerModel = ControllerModelBuilder.ForController <StubController>()
                                  .WithIntroducedInApiVersionAttribute(1)
                                  .WithRemovedAsOfApiVersionAttribute(2)
                                  .Build();

            var result = builder.ApplyTo(controllerModel);

            _apiVersionConventionBuilder.Verify(b => b.ApplyTo(controllerModel), Times.Once);
            _apiVersionConventionBuilder.Verify(b => b.Controller(It.IsAny <TypeInfo>()), Times.Never);
        }
        public void GivenControllerIsIntroduced_ThenControllerSupportedApiVersionSetToCurrentVersion()
        {
            var builder         = new IntroducedApiVersionConventionBuilder(new Version(1, 0), new Version(3, 0), _apiVersionConventionBuilder.Object);
            var controllerModel = ControllerModelBuilder.ForController <StubController>()
                                  .WithIntroducedInApiVersionAttribute(1)
                                  .Build();

            var result = builder.ApplyTo(controllerModel);

            Assert.True(result);
            _controllerApiConventionBuilder.Verify(b => b.HasApiVersion(new ApiVersion(3, 0)));
            _controllerApiConventionBuilder.Verify(b => b.HasApiVersion(It.IsAny <ApiVersion>()), Times.Once);
            _apiVersionConventionBuilder.Verify(b => b.ApplyTo(controllerModel), Times.Once);
        }
        public void GivenActionIsIntroducedBeforeIntroducedInController_ThenInvalidOperationExceptionIsThrown()
        {
            // Arrange
            var builder = new IntroducedApiVersionConventionBuilder(new Version(1, 0), new Version(3, 0), _apiVersionConventionBuilder.Object);

            var action = ActionModelBuilder
                         .WithAction <StubController>(c => c.Get())
                         .WithIntroducedInApiVersionAttribute(1)
                         .Build();

            var controllerModel = ControllerModelBuilder
                                  .ForController <StubController>()
                                  .WithIntroducedInApiVersionAttribute(2)
                                  .WithAction(action)
                                  .Build();

            _controllerApiConventionBuilder
            .Setup(b => b.Action(action.ActionMethod))
            .Returns(_actionApiVersionConventionBuilder.Object);

            // Act/Assert
            Assert.Throws <InvalidOperationException>(() => builder.ApplyTo(controllerModel));
        }