Пример #1
0
        public void RegistersTheChannelDuringConstructionAndUnregistersItOnDispose()
        {
            IpcClientChannel channel = new IpcClientChannel();
            Uri uri = new Uri("ipc://foo");

            using (StubChannel stub = new StubChannel(channel, uri))
            {
                Assert.Contains(ChannelServices.RegisteredChannels, channel);

                Assert.AreSame(channel, stub.Channel);
                Assert.AreEqual(uri, stub.ChannelUri);
            }

            Assert.DoesNotContain(ChannelServices.RegisteredChannels, channel);
        }
Пример #2
0
        public void RegistersTheChannelDuringConstructionAndUnregistersItOnDispose()
        {
            IpcClientChannel channel = new IpcClientChannel();
            Uri uri = new Uri("ipc://foo");

            using (StubChannel stub = new StubChannel(channel, uri))
            {
                Assert.Contains(ChannelServices.RegisteredChannels, channel);

                Assert.AreSame(channel, stub.Channel);
                Assert.AreEqual(uri, stub.ChannelUri);
            }

            Assert.DoesNotContain(ChannelServices.RegisteredChannels, channel);
        }
Пример #3
0
        public void MatchedRequest_ShouldReturnStubResponse_WhenMethodAndPathMatch()
        {
            var returnPayload = new { CustomerID = 1, FirstName = "Mitch", LastName = "Abaza" }.ToJson();
            var client  = new StubChannel(Settings.Url);
            var builder = new StubBuilder();

            var behaviorRegistrationRequest = builder.AllRequests
                                              .WithPath("customer/get/1")
                                              .AndMethod(Method.Get).WillReturnResponse()
                                              .WithStatusCode(HttpStatusCode.OK).WithBody(returnPayload, "application/json", Encoding.UTF8.WebName)
                                              .Build();

            client.Register(behaviorRegistrationRequest);

            var response = client.Send(behaviorRegistrationRequest.Request);

            response.StatusCode.Should().Be(HttpStatusCode.OK);
            response.Content.Should().Be(returnPayload);
            response.ContentType.Should().Be("application/json; charset=utf-8");
        }
Пример #4
0
        public void MatchedRequest_ShouldReturnStubResponse_WhenMethodHeaderAndPathMatch()
        {
            var returnPayload = new { OrderId = Guid.NewGuid().ToString(), Date = DateTime.Now }.ToJson();
            var client    = new StubChannel(Settings.Url);
            var builder   = new StubBuilder();
            var authToken = "kj298sadnlsad93koasdzxcnkajsre191";

            var behaviorRegistrationRequest = builder.AllRequests
                                              .WithPath("customer/get/1").AndHeader("AuthToken", authToken)
                                              .AndMethod(Method.Get).WillReturnResponse()
                                              .WithStatusCode(HttpStatusCode.OK).WithBody(returnPayload, "application/json", Encoding.UTF8.WebName)
                                              .Build();

            client.Register(behaviorRegistrationRequest);
            Console.WriteLine(behaviorRegistrationRequest.ToJson());

            var response = client.Send(behaviorRegistrationRequest.Request);

            response.StatusCode.Should().Be(HttpStatusCode.OK);
            response.Content.Should().Be(returnPayload);
            response.ContentType.Should().Be("application/json; charset=utf-8");
        }
Пример #5
0
 public void GetServiceUriThrowsIfNameIsNull()
 {
     using (StubChannel stub = new StubChannel(new IpcClientChannel(), new Uri("ipc://foo")))
         stub.GetServiceUri(null);
 }
Пример #6
0
 public void GetServiceUriCombinesTheServiceNameWithTheChannelUri()
 {
     using (StubChannel stub = new StubChannel(new IpcClientChannel(), new Uri("ipc://foo")))
         Assert.AreEqual("ipc://foo/Service", stub.GetServiceUri("Service"));
 }
Пример #7
0
 public void GetServiceUriThrowsIfNameIsNull()
 {
     using (StubChannel stub = new StubChannel(new IpcClientChannel(), new Uri("ipc://foo")))
         stub.GetServiceUri(null);
 }
Пример #8
0
 public void GetServiceUriCombinesTheServiceNameWithTheChannelUri()
 {
     using (StubChannel stub = new StubChannel(new IpcClientChannel(), new Uri("ipc://foo")))
         Assert.AreEqual("ipc://foo/Service", stub.GetServiceUri("Service"));
 }
Пример #9
0
 public StubBuilder(StubChannel channel)
 {
     Channel         = channel;
     RequestBuilder  = new RequestBuilder(this);
     ResponseBuilder = new ResponseBuilder(this);
 }
Пример #10
0
        public void View_ShouldReturnNull_WhenNoRegistrations()
        {
            var client = new StubChannel(Settings.Url);

            client.List().ShouldBeEquivalentTo(new StubRegistration[0]);
        }
Пример #11
0
 public void SetUp()
 {
     Settings.SetServerUrl("http://localhost/EasyStub");
     _channel = new StubChannel(Settings.Url);
     _channel.Reset();
 }