public async Task FullPath_WritesMessage_True()
        {
            // The Trailing Service Path Tuner is an opt-in service.

            // This test demonstrates existing functionality is not changed
            // when the service is not registered in app startup (opted-in).

            // Arrange
            var logger = new NullLoggerFactory().CreateLogger <SoapEndpointMiddleware>();

            var         encoder = new MockMessageEncoder();
            SoapOptions options = new SoapOptions()
            {
                Path             = "/v1/Service.svc",     // this is the multi-part path registered in app startup
                Binding          = new CustomBinding(),
                MessageEncoders  = new MessageEncoder[] { encoder },
                ServiceType      = typeof(MockSoapService),
                SoapModelBounder = new MockModelBounder(),
                SoapSerializer   = SoapSerializer.DataContractSerializer
            };

            SoapEndpointMiddleware soapCore = new SoapEndpointMiddleware(logger, (innerContext) => Task.FromResult(TaskStatus.RanToCompletion), options);

            var context = new DefaultHttpContext();

            context.Request.Path = new PathString("/v1/Service.svc");

            // Act
            // MockServiceProvider(false) simulates not registering the TrailingServicePathTuner in app startup
            await soapCore.Invoke(context, new MockServiceProvider(false));

            // Assert
            Assert.AreEqual(true, encoder.DidWriteMessage);
        }
Example #2
0
        public void TestSoap11()
        {
            var x = new DefaultHttpContext();

            x.Request.Headers["SoapAction"] = "soapAction";
            var action = new SoapEndpointMiddleware(null, null).GetSoapAction(x.Request);

            Assert.Equal("soapAction", action);
        }
Example #3
0
        public void TestSoap12()
        {
            var x = new DefaultHttpContext();

            x.Request.Headers.Add(new KeyValuePair <string, StringValues>("content-Type", $"application/soap+xml;action=\"soapAction\""));
            var action = new SoapEndpointMiddleware(null, null).GetSoapAction(x.Request);

            Assert.Equal("soapAction", action);
        }
Example #4
0
        public void TestSoap12Other()
        {
            var x  = new DefaultHttpContext();
            var ms = new MemoryStream(Encoding.UTF8.GetBytes(@"<s:Envelope xmlns:s=""http://www.w3.org/2003/05/soap-envelope"" xmlns:a=""http://www.w3.org/2005/08/addressing""><s:Body><s:Header><a:Action s:mustUnderstand=""1"">soapAction</a:Action></s:Header></s:Body></s:Envelope>"));

            x.Request.Body = ms;
            var action = new SoapEndpointMiddleware(null, null).GetSoapAction(x.Request);

            Assert.Equal("soapAction", action);
        }
Example #5
0
        public async Task TrailingServicePath_WritesMessage_True()
        {
            // The Trailing Service Path Tuner is an opt-in service.

            // This test demonstrates the proper behavior when the service
            // is registered in app startup.

            // Arrange
            var logger = new NullLoggerFactory().CreateLogger <SoapEndpointMiddleware <CustomMessage> >();

            SoapOptions options = new SoapOptions()
            {
                Path           = "/Service.svc",       // this is the path registered in app startup
                Binding        = new CustomBinding(),
                EncoderOptions = new[]
                {
                    new SoapEncoderOptions
                    {
                        MessageVersion = MessageVersion.Soap12WSAddressing10,
                        WriteEncoding  = Encoding.UTF8,
                        ReaderQuotas   = XmlDictionaryReaderQuotas.Max
                    }
                },
                ServiceType      = typeof(MockSoapService),
                SoapModelBounder = new MockModelBounder(),
                SoapSerializer   = SoapSerializer.DataContractSerializer
            };

            SoapEndpointMiddleware <CustomMessage> soapCore = new SoapEndpointMiddleware <CustomMessage>(logger, (innerContext) => Task.FromResult(TaskStatus.RanToCompletion), options);

            var context = new DefaultHttpContext();

            context.Request.Path   = new PathString("/DynamicPath/Service.svc");
            context.Request.Method = "GET";
            context.Response.Body  = new MemoryStream();

            // Act
            // MockServiceProvider(false) simulates registering the TrailingServicePathTuner in app startup
            await soapCore.Invoke(context, new MockServiceProvider(true));

            // Assert
            Assert.IsTrue(context.Response.Body.Length > 0);
        }