Example #1
0
 public void Delete_ShouldRemoveAllRegistrations()
 {
     _channel.Register(
         new StubBuilder().AllRequests.WithPath("dance")
         .WillReturnResponse()
         .WithStatusCode(HttpStatusCode.Conflict)
         .Build());
     _channel.List().Length.Should().Be(1);
     _channel.Reset();
     _channel.List().ShouldBeEquivalentTo(new StubRegistration[0]);
 }
Example #2
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");
        }
Example #3
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");
        }