public void GivenARequest_WhenAProfileIsPassed_ThenAnExceptionIsReturned(bool parameters) { var filter = new ValidationQueryFilterAndParameterParserAttribute(Options.Create(_featureConfiguration)); var context = CreateContext(null, "test", false, parameters); var exception = Assert.Throws <OperationNotImplementedException>(() => filter.OnActionExecuting(context)); Assert.Equal("Validation against a profile is not supported.", exception.Message); }
public void GivenARequestWithId_WhenAModeOfDeleteIsPassed_ThenAnOkMessageIsReturned(bool parameters) { var filter = new ValidationQueryFilterAndParameterParserAttribute(Options.Create(_featureConfiguration)); var context = CreateContext("DELETE", null, true, parameters); var exception = Assert.Throws <ResourceNotValidException>(() => filter.OnActionExecuting(context)); Assert.True(exception.Issues.Contains(ValidateOperationHandler.ValidationPassed)); }
public void GivenARequestWithId_WhenAModeIsPassed_ThenAnExceptionIsReturned(string mode, string message, Type issueType, bool parameters = false) { var filter = new ValidationQueryFilterAndParameterParserAttribute(Options.Create(_featureConfiguration)); var context = CreateContext(mode, null, true, parameters); var exception = Assert.Throws(issueType, () => filter.OnActionExecuting(context)); Assert.Equal(message, exception.Message); }
public void GivenARequest_WhenValidationIsNotSupported_ThenAnExceptionIsReturned() { var featureConfiguration = new FeatureConfiguration() { SupportsValidate = false, }; var filter = new ValidationQueryFilterAndParameterParserAttribute(Options.Create(featureConfiguration)); var context = CreateContext(); var exception = Assert.Throws <OperationNotImplementedException>(() => filter.OnActionExecuting(context)); Assert.Equal("$validate is not a supported endpoint.", exception.Message); }
public void GivenARequest_WhenTwoProfilesArePassed_ThenAnExceptionIsReturned() { var queryParams = new Dictionary <string, StringValues>(); queryParams.Add(KnownQueryParameterNames.Profile, "test"); var httpRequest = Substitute.For <HttpRequest>(); httpRequest.Query = new QueryCollection(queryParams); var httpContext = Substitute.For <HttpContext>(); httpContext.Request.Returns(httpRequest); var parameters = new Parameters(); parameters.Add(KnownQueryParameterNames.Profile, new FhirUri("otherTest")); var actionContext = new ActionExecutingContext( new ActionContext( httpContext, new RouteData { Values = { [KnownActionParameterNames.ResourceType] = "Observation" } }, new ActionDescriptor() { DisplayName = string.Empty }), new List <IFilterMetadata>(), new Dictionary <string, object> { { "resource", parameters } }, FilterTestsHelper.CreateMockFhirController()); var filter = new ValidationQueryFilterAndParameterParserAttribute(Options.Create(_featureConfiguration)); var exception = Assert.Throws <BadRequestException>(() => filter.OnActionExecuting(actionContext)); Assert.Equal("Only one profile can be provided between a Parameters resource and the URL", exception.Message); }