public AuditLoggingFilterTests()
        {
            _fhirResult = new FhirResult(new Patient()
            {
                Name = { new HumanName()
                         {
                             Text = "TestPatient"
                         } }
            });

            _executedContext = new ResultExecutedContext(
                new ActionContext(new DefaultHttpContext(), new RouteData(), new ControllerActionDescriptor()
            {
                DisplayName = "Executed Context Test Descriptor"
            }),
                new List <IFilterMetadata>(),
                _fhirResult,
                FilterTestsHelper.CreateMockFhirController());

            _executedContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.Created;
            _fhirResult.StatusCode = HttpStatusCode.Created;
            _fhirRequestContext.RequestType.Returns(new Coding("System", "TestRequestType"));
            _fhirRequestContext.RequestSubType = new Coding("System", "TestRequestSubType");
            _fhirRequestContext.Uri.Returns(new Uri("https://fhirtest/fhir?count=100"));
            _fhirRequestContextAccessor.FhirRequestContext.Returns(_fhirRequestContext);
            _fhirRequestContextAccessor.FhirRequestContext.Principal.Returns(_claimsPrincipal);

            _securityConfiguration.LastModifiedClaims.Returns(new HashSet <string> {
                "claim1"
            });
            _securityOptions.Value.Returns(_securityConfiguration);
            _claimsPrincipal.Claims.Returns(new List <System.Security.Claims.Claim> {
                Claim1
            });

            _claims = new KeyValuePair <string, string>[]
            {
                KeyValuePair.Create("claim", "value"),
            };

            _claimsIndexer = Substitute.For <IClaimsIndexer>();

            _claimsIndexer.Extract().Returns(_claims);

            _filter = new AuditLoggingFilterAttribute(
                _auditLogger,
                _fhirRequestContextAccessor,
                _claimsIndexer);
        }
Exemplo n.º 2
0
 public AuditLoggingFilterAttributeTests()
 {
     _filter = new AuditLoggingFilterAttribute(_claimsExtractor, _auditHelper);
 }
        private void AssertProperRequestSubTypeSet(ActionExecutingContext executingContext, string methodName, string requestSubType, AuditLoggingFilterAttribute filter)
        {
            executingContext.ActionDescriptor = new ControllerActionDescriptor();
            var descriptor = executingContext.ActionDescriptor as ControllerActionDescriptor;

            descriptor.MethodInfo = typeof(FhirController).GetMethod(methodName);
            filter.OnActionExecuting(executingContext);
            Assert.Equal(_fhirRequestContextAccessor.FhirRequestContext.RequestSubType.Code, requestSubType);
            Assert.Equal(_fhirRequestContextAccessor.FhirRequestContext.RequestSubType.System, AuditEventSubType.System);
        }
 public AuditLoggingFilterAttributeTests()
 {
     _filter = new AuditLoggingFilterAttribute(_auditHelper);
 }