public void SendCustomActionExceptionStillReturnsResponse() { var injector = new MockInjector(); var client = injector.Create<Client>(); var endpointProvider = injector.GetMock<IEndpointProvider>(); var webRequestFactory = injector.GetMock<IWebRequestFactory>(); var request = new Mock<IHttpWebRequest>(); var response = new Mock<HttpWebResponse>(); response .Setup(r => r.GetResponseStream()) .Returns(new MemoryStream()); endpointProvider .Setup(e => e.ClientEndpoint) .Returns(new Queue<string>(new[] { "moo" })); webRequestFactory .Setup(f => f.CreateHttp("moo")) .Returns(request.Object); webRequestFactory .Setup(f => f.WithLoggingProxy(response.Object.ActLike<IHttpWebResponse>())) .Returns(response.Object.ActLike<IHttpWebResponse>()); request.Setup(r => r.GetResponse()) .Throws(new WebException( "moo", null, WebExceptionStatus.ProtocolError, response.Object)); client.Send(r => r.Should().Be(request.Object)) .Should().Be(response.Object); }
public void SendCustomAction() { var injector = new MockInjector(); var client = injector.Create<Client>(); var endpointProvider = injector.GetMock<IEndpointProvider>(); var webRequestFactory = injector.GetMock<IWebRequestFactory>(); var request = new Mock<IHttpWebRequest>(); var response = new Mock<IHttpWebResponse>(); endpointProvider.Setup(e => e.ClientEndpoint).Returns(new Queue<string>(new[] { "moo" })); webRequestFactory.Setup(f => f.CreateHttp("moo")).Returns(request.Object); request.Setup(r => r.GetResponse()).Returns(response.Object); client.Send(r => r.Should().Be(request.Object)) .Should().Be(response.Object); }
public void Prefixes() { var injector = new MockInjector(); var listener = injector.SetupAndGetListener(); var baseUrlProvider = injector.GetMock<IEndpointProvider>(); baseUrlProvider.Setup(b => b.ServerBaseUrl).Returns("moo"); var server = injector.Create<Server>(); listener.Object.Prefixes.Should().BeEquivalentTo(new[] {"moo"}); }
public void SendCustomActionExceptionNoResponse() { var injector = new MockInjector(); var client = injector.Create<Client>(); var endpointProvider = injector.GetMock<IEndpointProvider>(); var webRequestFactory = injector.GetMock<IWebRequestFactory>(); var request = new Mock<IHttpWebRequest>(); endpointProvider.Setup(e => e.ClientEndpoint).Returns(new Queue<string>(new[] { "moo" })); webRequestFactory.Setup(f => f.CreateHttp("moo")).Returns(request.Object); request.Setup(r => r.GetResponse()) .Throws(new WebException( "moo", null, WebExceptionStatus.ProtocolError, null)); Action action = () => client.Send(r => r.Should().Be(request.Object)); action.ShouldThrow<WebException>(); }
public void FromMessage() { var injector = new MockInjector(); SoapDecoder decoder = injector.Create<SoapDecoder>(); var contentTypeProvider = injector.GetMock<IContentTypeProvider>(); var messageProvider = injector.GetMock<IMessageProvider>(); var endpointProvider = injector.GetMock<IEndpointProvider>(); var securityHeaderFactory = injector.GetMock<ISecurityHeaderFactory>(); var response = injector.GetMock<IHttpListenerResponse>(); var responseMessage = Message.CreateMessage(MessageVersion.Default, "moo"); var requestMessage = Message.CreateMessage(MessageVersion.Default, "moo"); var request = injector.GetMock<IHttpListenerRequest>(); var stream = new MemoryStream(); messageProvider.Setup(m => m.GetMessage(stream)).Returns(requestMessage); request.Setup(r => r.InputStream).Returns(stream); request.Setup(r => r.ContentType).Returns("text/xml"); endpointProvider.Setup(e => e.SkipAuthentication).Returns(true); response.Setup(r => r.OutputStream).Returns(stream); contentTypeProvider.Setup(p => p.ValidContentTypes).Returns(new[] { "text/xml" }); var securityHeader = MessageHeader.CreateHeader("security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "secure"); securityHeaderFactory.Setup(s => s.CreateWithoutUserToken(requestMessage)).Returns(securityHeader); decoder.FromMessage(response.Object, responseMessage, request.Object); responseMessage.Headers.Should().HaveCount(2) .And.Contain(securityHeader); }
public void ScenarioOptionThrowingException() { var injector = new MockInjector(); var program = injector.Create<Program>(); var runner = injector.GetMock<IRunner>(); var output = injector.GetMock<IOutput>(); var options = new Options { Scenario = "s" }; var exception = new InvalidOperationException("moo"); runner.Setup(r => r.Run(It.IsAny<string>(), It.IsAny<string[]>(), null)) .Throws(exception); program.Run(options) .Should().Be(1); output.Verify(o => o.Display(It.Is<ResultModel>(r => r.Result == Result.Fail && r.Message == exception.ToString()))); }
public void Default() { var injector = new MockInjector(); var factory = injector.Create<SecurityHeaderFactory>(); var endpointProvider = injector.GetMock<IEndpointProvider>(); var dateTimeProvider = injector.GetMock<IDateTimeProvider>(); var randomProvider = injector.GetMock<IRandomNumberGeneratorProvider>(); endpointProvider.Setup(e => e.Username).Returns("someuser"); endpointProvider.Setup(e => e.Password).Returns("somepass"); dateTimeProvider.Setup(d => d.Now).Returns(new DateTime(2013, 01, 20)); randomProvider.Setup(r => r.GetBytes(It.IsAny<byte[]>())) .Callback<byte[]>(bytes => { for (int i = 0; i < bytes.Length; i++) { bytes[i] = 7; } }); var header = factory.Create(); header.Name.Should().Be("Security"); header.Namespace.Should().Be("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); const string expectedXml = @"<Security xmlns=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> <UsernameToken> <Username>someuser</Username> <Password Type=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"">somepass</Password> <Nonce EncodingType=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"">BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBw==</Nonce> <Created xmlns=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"">2013-01-20T00:00:00.000Z</Created> </UsernameToken> </Security>"; header.ToString().Should().Be(expectedXml); }
public void ScenarioOption() { var injector = new MockInjector(); var program = injector.Create<Program>(); var runner = injector.GetMock<IRunner>(); var options = new Options { Scenario = "whee" }; program.Run(options) .Should().Be(0); runner.Verify(r => r.Run("whee", null, null)); }
public void ScenarioOptionWithArguments() { var injector = new MockInjector(); var program = injector.Create<Program>(); var runner = injector.GetMock<IRunner>(); var options = new Options { Scenario = "moo", ScenarioArguments = new[] {"a1", "a2"} }; program.Run(options) .Should().Be(0); runner.Verify(r => r.Run("moo", new[] {"a1", "a2"}, null)); }
public void RespondWithXml() { var injector = new MockInjector(); var listener = injector.SetupAndGetListener(); var server = injector.Create<Server>(); var soapDecoder = injector.GetMock<ISoapDecoder>(); var request = new Mock<IHttpListenerRequest>(); var response = new Mock<IHttpListenerResponse>(); injector.SetupProxy(request); injector.SetupProxy(response); const string xml = "<moo>"; listener.Setup(l => l.GetContextAsync().Result.Request).Returns(request.Object); listener.Setup(l => l.GetContextAsync().Result.Response).Returns(response.Object); server.Receive(); server.Respond(xml); soapDecoder.Verify(s => s.FromXml(response.Object, xml)); }
public void RespondWithMessage() { var injector = new MockInjector(); var listener = injector.SetupAndGetListener(); var server = injector.Create<Server>(); var soapDecoder = injector.GetMock<ISoapDecoder>(); var request = new Mock<IHttpListenerRequest>(); var response = new Mock<IHttpListenerResponse>(); injector.SetupProxy(request); injector.SetupProxy(response); var message = Message.CreateMessage(MessageVersion.Default, "moo"); listener.Setup(l => l.GetContextAsync().Result.Request).Returns(request.Object); listener.Setup(l => l.GetContextAsync().Result.Response).Returns(response.Object); server.Receive(); server.Respond(message, request.Object); soapDecoder.Verify(s => s.FromMessage(response.Object, message, request.Object)); }
public void RespondWithData() { var injector = new MockInjector(); var listener = injector.SetupAndGetListener(); var server = injector.Create<Server>(); var soapDecoder = injector.GetMock<ISoapDecoder>(); var request = new Mock<IHttpListenerRequest>(); var response = new Mock<IHttpListenerResponse>(); injector.SetupProxy(request); injector.SetupProxy(response); var data = new { }; listener.Setup(l => l.GetContextAsync().Result.Request).Returns(request.Object); listener.Setup(l => l.GetContextAsync().Result.Response).Returns(response.Object); server.Receive(); server.Respond("moo", data, request.Object); soapDecoder.Verify(s => s.FromData(response.Object, "moo", data, request.Object)); }
public void SendMissingClientEndpoint() { var injector = new MockInjector(); var client = injector.Create<Client>(); var endpointProvider = injector.GetMock<IEndpointProvider>(); var webRequestFactory = injector.GetMock<IWebRequestFactory>(); var request = new Mock<IHttpWebRequest>(); var response = new Mock<IHttpWebResponse>(); webRequestFactory.Setup(f => f.CreateHttp("moo")).Returns(request.Object); request.Setup(r => r.GetResponse()).Returns(response.Object); var ex = Assert.Throws<NotSupportedException>(() => client.Send(r => r.Should().Be(request.Object))); ex.Message.Should().Be("Client endpoint should be specified with -c"); }
public void SendMessageSecurityHeader() { var injector = new MockInjector(); var client = injector.Create<Client>(); var endpointProvider = injector.GetMock<IEndpointProvider>(); var webRequestFactory = injector.GetMock<IWebRequestFactory>(); var securityHeaderFactory = injector.GetMock<ISecurityHeaderFactory>(); var soapDecoder = injector.GetMock<ISoapDecoder>(); var request = new Mock<IHttpWebRequest>(); var response = new Mock<IHttpWebResponse>(); var message = Message.CreateMessage(MessageVersion.Default, "moo"); var messageHeader = MessageHeader.CreateHeader("TestHeader", "", ""); endpointProvider.Setup(e => e.ClientEndpoint).Returns(new Queue<string>(new[] { "moo" })); securityHeaderFactory.Setup(s => s.Create()).Returns(messageHeader); webRequestFactory.Setup(f => f.CreateHttp("moo")).Returns(request.Object); request.Setup(r => r.GetResponse()).Returns(response.Object); client.Send(message); message.Headers.Single(h => h.Name == "TestHeader") .Should().Be(messageHeader); }
public void SendData() { var injector = new MockInjector(); var client = injector.Create<Client>(); var endpointProvider = injector.GetMock<IEndpointProvider>(); var webRequestFactory = injector.GetMock<IWebRequestFactory>(); var soapDecoder = injector.GetMock<ISoapDecoder>(); var securityHeaderFactory = injector.GetMock<ISecurityHeaderFactory>(); var request = new Mock<IHttpWebRequest>(); var response = new Mock<IHttpWebResponse>(); var data = new { }; var message = Message.CreateMessage(MessageVersion.Default, "moo"); endpointProvider.Setup(e => e.ClientEndpoint).Returns(new Queue<string>(new[] { "moo" })); securityHeaderFactory.Setup(s => s.Create()).Returns(MessageHeader.CreateHeader("Moo", "", "")); webRequestFactory.Setup(f => f.CreateHttp("moo")).Returns(request.Object); request.Setup(r => r.GetResponse()).Returns(response.Object); soapDecoder.Setup(s => s.ToMessage("moo", data)) .Returns(message); client.Send("moo", data) .Should().Be(response.Object); soapDecoder.Verify(s => s.FromMessage(request.Object, message)); }