Beispiel #1
0
        public void WhenWeLookForASpecificAllowAnonymousController_ThenWeFindIt()
        {
            var knownAllowAnonymousController = AllowAnonymousControllers
                                                .Where(c => c.FullName == typeof(AllowAnonymousPingController).FullName);

            knownAllowAnonymousController.Count().Should().Be(1, because: "we know there is at least one [AllowAnonymous] controller in the API so we are explicitly looking for it. Given we scan assemblies by convention, no matches could imply we are not scanning the assembly (not loaded into AppDomain) which is a false positive. This test helps prevent that happening. ");
        }
Beispiel #2
0
        public void ByConvention_EveryAllowAnonmousControllerMustBeAcknowledged()
        {
            // Arrange
            var controllersThatAreNotAuthorizedAndNotAcknowledgedAsAllowAnonymous = AllowAnonymousControllers
                                                                                    .Except(AcknowledgedAllowAnonymousControllers);

            // Assert
            controllersThatAreNotAuthorizedAndNotAcknowledgedAsAllowAnonymous.Count().Should().Be(0, because: $"every controller that is explicitly marked as [AllowAnonymous] must be acknowledged here by adding the [AcknowledgeAllowAnonymousController] attribute to this class with the following types: {string.Join(',', controllersThatAreNotAuthorizedAndNotAcknowledgedAsAllowAnonymous)}");
        }