コード例 #1
0
        public void ApiConventionAttributeIsAdded_IfAttributeExistsInAssembly()
        {
            // Arrange
            var controllerType = CreateTestControllerType();
            var model          = new ControllerModel(controllerType.GetTypeInfo(), Array.Empty <object>());

            // Act
            ApiBehaviorApplicationModelProvider.AddGloballyConfiguredApiConventions(model);

            // Assert
            Assert.Collection(
                model.Filters,
                filter => Assert.IsType <ApiConventionAttribute>(filter));
        }
コード例 #2
0
        public void ApiConventionAttributeIsNotAdded_IfModelAlreadyHasAttribute()
        {
            // Arrange
            var attribute      = new ApiConventionAttribute(typeof(DefaultApiConventions));
            var controllerType = CreateTestControllerType();

            var model = new ControllerModel(controllerType.GetTypeInfo(), new[] { attribute })
            {
                Filters = { attribute, },
            };

            // Act
            ApiBehaviorApplicationModelProvider.AddGloballyConfiguredApiConventions(model);

            // Assert
            Assert.Collection(
                model.Filters,
                filter => Assert.Same(attribute, filter));
        }