コード例 #1
0
ファイル: ServerTest.cs プロジェクト: NSWPlanning/edais
            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));
            }
コード例 #2
0
ファイル: ServerTest.cs プロジェクト: NSWPlanning/edais
            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));
            }
コード例 #3
0
ファイル: ServerTest.cs プロジェクト: NSWPlanning/edais
            public void RespondWithCustomAction()
            {
                var injector = new MockInjector();
                var listener = injector.SetupAndGetListener();
                var server = injector.Create<Server>();
                var request = new Mock<IHttpListenerRequest>();
                var response = new Mock<IHttpListenerResponse>();
                injector.SetupProxy(request);
                injector.SetupProxy(response);

                listener.Setup(l => l.GetContextAsync().Result.Request).Returns(request.Object);
                listener.Setup(l => l.GetContextAsync().Result.Response).Returns(response.Object);

                var called = false;
                server.Receive();
                server.Respond(r =>
                {
                    r.Should().Be(response.Object);
                    called = true;
                });

                called.Should().BeTrue();
            }
コード例 #4
0
ファイル: ServerTest.cs プロジェクト: NSWPlanning/edais
            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));
            }
コード例 #5
0
ファイル: ServerTest.cs プロジェクト: NSWPlanning/edais
            public void RespondOnlyWorksOnce()
            {
                var injector = new MockInjector();
                var listener = injector.SetupAndGetListener();
                var server = injector.Create<Server>();
                var request = new Mock<IHttpListenerRequest>();
                var response = new Mock<IHttpListenerResponse>();
                injector.SetupProxy(request);
                injector.SetupProxy(response);

                listener.Setup(l => l.GetContextAsync().Result.Request).Returns(request.Object);
                listener.Setup(l => l.GetContextAsync().Result.Response).Returns(response.Object);

                server.Receive();
                server.Respond(r => r.ContentType = "space");
                server.Invoking(s => s.Respond(r => r.ContentType = "moo"))
                      .ShouldThrow<InvalidOperationException>()
                      .WithMessage("no request", ComparisonMode.Substring);
            }
コード例 #6
0
ファイル: ServerTest.cs プロジェクト: NSWPlanning/edais
            public void Abort()
            {
                var injector = new MockInjector();
                var listener = injector.SetupAndGetListener();
                var server = injector.Create<Server>();
                var request = new Mock<IHttpListenerRequest>();
                var response = new Mock<IHttpListenerResponse>();
                injector.SetupProxy(request);
                injector.SetupProxy(response);

                listener.Setup(l => l.GetContextAsync().Result.Request).Returns(request.Object);
                listener.Setup(l => l.GetContextAsync().Result.Response).Returns(response.Object);

                server.Receive();
                server.AbortResponse();

                response.Verify(r => r.Abort(), Times.Once());
            }
コード例 #7
0
ファイル: ServerTest.cs プロジェクト: NSWPlanning/edais
            public void TwiceWhenPreviousResponseAborted()
            {
                var injector = new MockInjector();
                var listener = injector.SetupAndGetListener();
                var server = injector.Create<Server>();
                var request1 = new Mock<IHttpListenerRequest>();
                injector.SetupProxy(request1);
                var response1 = new Mock<IHttpListenerResponse>();
                injector.SetupProxy(response1);
                var request2 = new Mock<IHttpListenerRequest>();
                injector.SetupProxy(request2);

                listener.SetupSequence(l => l.GetContextAsync().Result.Request)
                        .Returns(request1.Object)
                        .Returns(request2.Object);

                listener.Setup(l => l.GetContextAsync().Result.Response)
                        .Returns(response1.Object);

                server.Receive();
                server.AbortResponse();
                server.Receive()
                      .Should().Be(request2.Object);
            }
コード例 #8
0
ファイル: ServerTest.cs プロジェクト: NSWPlanning/edais
            public void TwiceWhenPreviousRequestNotRespondedTo()
            {
                var injector = new MockInjector();
                var listener = injector.SetupAndGetListener();
                var server = injector.Create<Server>();
                var request = new Mock<IHttpListenerRequest>();
                injector.SetupProxy(request);

                listener.Setup(l => l.GetContextAsync().Result.Request).Returns(request.Object);

                server.Receive();

                server.Invoking(s => s.Receive())
                      .ShouldThrow<InvalidOperationException>();
            }
コード例 #9
0
ファイル: ServerTest.cs プロジェクト: NSWPlanning/edais
            public void OnceWhenAlreadyListening()
            {
                var injector = new MockInjector();
                var listener = injector.SetupAndGetListener();
                var server = injector.Create<Server>();
                var request = new Mock<IHttpListenerRequest>();
                injector.SetupProxy(request);

                listener.Setup(l => l.IsListening).Returns(true);
                listener.Setup(l => l.GetContextAsync().Result.Request).Returns(request.Object);

                server.Receive()
                      .Should().Be(request.Object);

                listener.Verify(l => l.Start(), Times.Never());
            }