Example #1
0
        public async void Valid_param_and_no_header()
        {
            var opts = AppSettings.NrlsApiSettings;

            var settingsMock = new Mock <IOptionsSnapshot <NrlsApiSetting> >();

            settingsMock.Setup(op => op.Get(It.IsAny <string>())).Returns(opts);

            var requestMock = new Mock <HttpRequest>();

            requestMock.Setup(x => x.Scheme).Returns("http");
            requestMock.Setup(x => x.Host).Returns(new HostString("localhost"));
            requestMock.Setup(x => x.Path).Returns(new PathString("/test"));
            requestMock.Setup(x => x.PathBase).Returns(new PathString("/"));
            requestMock.Setup(x => x.Method).Returns("GET");
            requestMock.Setup(x => x.Body).Returns(new MemoryStream());
            requestMock.Setup(x => x.QueryString).Returns(new QueryString($"?_format={_validFormat}"));
            requestMock.Setup(x => x.Headers).Returns(new HeaderDictionary()
            {
            });


            var contextMock = new Mock <HttpContext>();

            contextMock.Setup(x => x.Request).Returns(requestMock.Object);

            var fhirInputMiddleware = new FhirRequestOutputMiddleware(next: (innerHttpContext) => Task.FromResult(0));

            //Test will fail if invalid
            await fhirInputMiddleware.Invoke(contextMock.Object, settingsMock.Object);
        }
Example #2
0
        public void Invalid_param_and_header()
        {
            var opts = AppSettings.NrlsApiSettings;

            var settingsMock = new Mock <IOptionsSnapshot <NrlsApiSetting> >();

            settingsMock.Setup(op => op.Get(It.IsAny <string>())).Returns(opts);

            var requestMock = new Mock <HttpRequest>();

            requestMock.Setup(x => x.Scheme).Returns("http");
            requestMock.Setup(x => x.Host).Returns(new HostString("localhost"));
            requestMock.Setup(x => x.Path).Returns(new PathString("/test"));
            requestMock.Setup(x => x.PathBase).Returns(new PathString("/"));
            requestMock.Setup(x => x.Method).Returns("GET");
            requestMock.Setup(x => x.Body).Returns(new MemoryStream());
            requestMock.Setup(x => x.QueryString).Returns(new QueryString("?_format=invalidFormat"));
            requestMock.Setup(x => x.Headers).Returns(new HeaderDictionary()
            {
                { HeaderNames.Accept, "blaa" }
            });


            var contextMock = new Mock <HttpContext>();

            contextMock.Setup(x => x.Request).Returns(requestMock.Object);

            var fhirInputMiddleware = new FhirRequestOutputMiddleware(next: (innerHttpContext) => Task.FromResult(0));


            Assert.ThrowsAsync <HttpFhirException>(async delegate
            {
                await fhirInputMiddleware.Invoke(contextMock.Object, settingsMock.Object);
            });
        }