public AuditEventTypeMappingTests()
        {
            Type mockControllerType = typeof(MockController);

            var actionDescriptors = new List <ActionDescriptor>()
            {
                new ControllerActionDescriptor()
                {
                    ControllerName = ControllerName,
                    ActionName     = AnonymousMethodName,
                    MethodInfo     = mockControllerType.GetMethod(AnonymousMethodName),
                },
                new ControllerActionDescriptor()
                {
                    ControllerName = ControllerName,
                    ActionName     = AudittedMethodName,
                    MethodInfo     = mockControllerType.GetMethod(AudittedMethodName),
                },
                new ControllerActionDescriptor()
                {
                    ControllerName = ControllerName,
                    ActionName     = NoAttributeMethodName,
                    MethodInfo     = mockControllerType.GetMethod(NoAttributeMethodName),
                },
                new PageActionDescriptor()
                {
                },
            };

            var actionDescriptorCollection = new ActionDescriptorCollection(actionDescriptors, 1);

            _actionDescriptorCollectionProvider.ActionDescriptors.Returns(actionDescriptorCollection);

            _auditEventTypeMapping = new AuditEventTypeMapping(_actionDescriptorCollectionProvider);
        }
Example #2
0
        public void GivenTwoMethodsWithTheSameNameAndDifferentAuditEvents_WhenMappingIsCreated_ThenDuplicateActionForAuditEventExceptionShouldBeThrown()
        {
            Type mockControllerType = typeof(MockController);

            var actionDescriptors = new List <ActionDescriptor>()
            {
                new ControllerActionDescriptor()
                {
                    ControllerName = ControllerName,
                    ActionName     = SameNameMethodName,
                    MethodInfo     = mockControllerType.GetMethod(SameNameMethodName, new Type[] { typeof(int) }),
                },
                new ControllerActionDescriptor()
                {
                    ControllerName = ControllerName,
                    ActionName     = SameNameMethodName,
                    MethodInfo     = mockControllerType.GetMethod(SameNameMethodName, new Type[] { typeof(string) }),
                },
            };

            var actionDescriptorCollection = new ActionDescriptorCollection(actionDescriptors, 1);

            _actionDescriptorCollectionProvider.ActionDescriptors.Returns(actionDescriptorCollection);

            var eventTypeMapping = new AuditEventTypeMapping(_actionDescriptorCollectionProvider);

            Assert.ThrowsAsync <DuplicateActionForAuditEventException>(() => ((IHostedService)eventTypeMapping).StartAsync(CancellationToken.None));
        }