Exemplo n.º 1
0
        public void Matches_request_doc_to_expectations()
        {
            AutoMockPlug autoPlug = MockPlug.Register(new XUri("http://auto/plug"));

            autoPlug.Expect().Verb("POST").Uri(new XUri("http://auto/plug/a")).RequestDocument(new XDoc("foo"));
            Async.Fork(() => Plug.New("http://auto/plug/a").PostAsync(new XDoc("foo")), new Result());
            Assert.IsTrue(autoPlug.WaitAndVerify(TimeSpan.FromSeconds(1)), autoPlug.VerificationFailure);
        }
Exemplo n.º 2
0
        public void Can_match_request_DreamMessages_for_expectation()
        {
            AutoMockPlug autoPlug = MockPlug.Register(new XUri("http://auto/plug"));

            autoPlug.Expect().Verb("POST").Uri(new XUri("http://auto/plug/a")).Request(DreamMessage.Ok(MimeType.TEXT_UTF8, "blah"));
            Async.Fork(() => Plug.New("http://auto/plug/a").PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, "blah")), new Result());
            Assert.IsTrue(autoPlug.WaitAndVerify(TimeSpan.FromSeconds(1)), autoPlug.VerificationFailure);
        }
Exemplo n.º 3
0
        public void Ignores_excess_headers()
        {
            AutoMockPlug autoPlug = MockPlug.Register(new XUri("http://auto/plug"));

            autoPlug.Expect().Verb("POST").Uri(new XUri("http://auto/plug/a"));
            Async.Fork(() => Plug.New("http://auto/plug/a").WithHeader("Foo", "123").PostAsync(), new Result());
            Assert.IsTrue(autoPlug.WaitAndVerify(TimeSpan.FromSeconds(1)), autoPlug.VerificationFailure);
        }
Exemplo n.º 4
0
        public void Excess_expectations_are_BadRequest()
        {
            AutoMockPlug autoPlug = MockPlug.Register(new XUri("http://auto/plug"));
            DreamMessage message  = Plug.New("http://auto/plug/a").GetAsync().Wait();

            Assert.IsFalse(message.IsSuccessful);
            Assert.AreEqual(DreamStatus.BadRequest, message.Status);
            Assert.IsFalse(autoPlug.WaitAndVerify(TimeSpan.FromSeconds(1)), autoPlug.VerificationFailure);
            Assert.AreEqual(1, autoPlug.ExcessInterceptions.Length);
        }
Exemplo n.º 5
0
        public void Catches_missing_headers()
        {
            AutoMockPlug autoPlug = MockPlug.Register(new XUri("http://auto/plug"));

            autoPlug.Expect().Verb("GET").Uri(new XUri("http://auto/plug/a"))
            .RequestHeader("Foo", "123")
            .RequestHeader("Bar", "required");
            Async.Fork(() => Plug.New("http://auto/plug/a").WithHeader("Foo", "123").GetAsync(), new Result());
            Assert.IsFalse(autoPlug.WaitAndVerify(TimeSpan.FromSeconds(1)), autoPlug.VerificationFailure);
            Assert.AreEqual("Expectations were unmet:\r\nExpectation #1: Expected header 'Bar', got none\r\n", autoPlug.VerificationFailure);
        }
Exemplo n.º 6
0
        public void Autoplug_without_expectations_should_still_fail_on_excess()
        {
            AutoMockPlug autoPlug = MockPlug.Register(new XUri("http://auto/plug"));

            Async.Fork(() => {
                Plug.New("http://auto/plug/b").PutAsync(new XDoc("foo"));
                Plug.New("http://auto/plug/a").PostAsync();
            }, new Result());
            Assert.IsFalse(autoPlug.WaitAndVerify(TimeSpan.FromSeconds(1)), autoPlug.VerificationFailure);
            Assert.AreEqual(2, autoPlug.ExcessInterceptions.Length);
        }
Exemplo n.º 7
0
        public void Catches_mismatched_request_headers()
        {
            AutoMockPlug autoPlug = MockPlug.Register(new XUri("http://auto/plug"));

            autoPlug.Expect().Verb("GET").Uri(new XUri("http://auto/plug/a"))
            .RequestHeader("Foo", "123")
            .RequestHeader("Bar", "right");
            AsyncUtil.Fork(() => Plug.New("http://auto/plug/a").WithHeader("Foo", "123").WithHeader("Bar", "wrong").Get(new Result <DreamMessage>()), new Result());
            Assert.IsFalse(autoPlug.WaitAndVerify(TimeSpan.FromSeconds(1)), autoPlug.VerificationFailure);
            Assert.AreEqual("Expectations were unmet:\r\nExpectation #1: Expected header 'Bar:\r\nExpected: right\r\nGot:      wrong\r\n", autoPlug.VerificationFailure);
        }
Exemplo n.º 8
0
        public void Considers_missordered_expectations_as_unmet()
        {
            AutoMockPlug autoPlug = MockPlug.Register(new XUri("http://auto/plugx"));

            autoPlug.Expect("POST", new XUri("http://auto/plugx/a"));
            autoPlug.Expect("PUT", new XUri("http://auto/plugx/b"), new XDoc("foo"));
            Async.Fork(() => {
                Plug.New("http://auto/plugx/b").Put(new XDoc("foo"));
                Plug.New("http://auto/plugx/a").Post();
            }, new Result());
            Assert.IsFalse(autoPlug.WaitAndVerify(TimeSpan.FromSeconds(1)), autoPlug.VerificationFailure);
            Assert.AreEqual(0, autoPlug.MetExpectationCount);
        }
Exemplo n.º 9
0
        public void Should_be_able_to_call_same_url_with_different_headers()
        {
            AutoMockPlug autoPlug = MockPlug.Register(new XUri("http://auto/plug"));

            autoPlug.Expect().Verb("GET").Uri(new XUri("http://auto/plug/a")).RequestHeader("Foo", "");
            autoPlug.Expect().Verb("GET").Uri(new XUri("http://auto/plug/a")).RequestHeader("Foo", "baz");
            Plug p = Plug.New("http://auto/plug/a");

            Async.Fork(() => {
                p.WithHeader("Foo", "").GetAsync().Block();
                p.WithHeader("Foo", "baz").GetAsync().Block();
            }, new Result());
            Assert.IsTrue(autoPlug.WaitAndVerify(TimeSpan.FromSeconds(1)), autoPlug.VerificationFailure);
        }
Exemplo n.º 10
0
        public void Complains_about_unmet_expectations_after_timeout()
        {
            AutoMockPlug autoPlug = MockPlug.Register(new XUri("http://auto/plug"));

            autoPlug.Expect("POST", new XUri("http://auto/plug/a"));
            autoPlug.Expect("PUT", new XUri("http://auto/plug/b"), new XDoc("foo"));
            Assert.IsFalse(autoPlug.WaitAndVerify(TimeSpan.FromSeconds(1)), autoPlug.VerificationFailure);

            autoPlug.Reset();
            autoPlug.Expect("POST", new XUri("http://auto/plug/a"));
            autoPlug.Expect("PUT", new XUri("http://auto/plug/b"), new XDoc("foo"));
            Async.Fork(() => Plug.New("http://auto/plug/a").Post(), new Result());
            Assert.IsFalse(autoPlug.WaitAndVerify(TimeSpan.FromSeconds(1)), autoPlug.VerificationFailure);
            Assert.AreEqual(1, autoPlug.MetExpectationCount);
        }
Exemplo n.º 11
0
        public void Collects_excess_expectations()
        {
            AutoMockPlug autoPlug = MockPlug.Register(new XUri("http://auto/plug"));

            autoPlug.Expect("POST");
            Async.Fork(() => {
                Plug.New("http://auto/plug/a").PostAsync().Block();
                Plug.New("http://auto/plug/b").PostAsync().Block();
                Plug.New("http://auto/plug/c").PostAsync().Block();
                Plug.New("http://auto/plug/d").PostAsync().Block();
            }, new Result());
            Assert.IsFalse(autoPlug.WaitAndVerify(TimeSpan.FromSeconds(15)), autoPlug.VerificationFailure);
            Assert.IsTrue(autoPlug.HasInterceptsInExcessOfExpectations);
            Assert.AreEqual(3, autoPlug.ExcessInterceptions.Length);
            Assert.AreEqual("http://auto/plug/b", autoPlug.ExcessInterceptions[0].Uri.ToString());
            Assert.AreEqual("http://auto/plug/c", autoPlug.ExcessInterceptions[1].Uri.ToString());
            Assert.AreEqual("http://auto/plug/d", autoPlug.ExcessInterceptions[2].Uri.ToString());
        }
Exemplo n.º 12
0
        public void Waits_until_expectations_are_met_after_each_reset()
        {
            AutoMockPlug autoPlug = MockPlug.Register(new XUri("http://auto/plug"));

            autoPlug.Expect("POST", new XUri("http://auto/plug/a"));
            autoPlug.Expect("PUT", new XUri("http://auto/plug/b"), new XDoc("foo"));
            Async.Fork(() => {
                Plug.New("http://auto/plug/a").Post();
                Plug.New("http://auto/plug/b").Put(new XDoc("foo"));
            }, new Result());
            Assert.IsTrue(autoPlug.WaitAndVerify(TimeSpan.FromSeconds(2)), autoPlug.VerificationFailure);
            autoPlug.Reset();
            autoPlug.Expect("GET", new XUri("http://auto/plug/c"));
            autoPlug.Expect("GET", new XUri("http://auto/plug/d"));
            Async.Fork(() => {
                Plug.New("http://auto/plug/c").Get();
                Plug.New("http://auto/plug/d").Get();
            }, new Result());
            Assert.IsTrue(autoPlug.WaitAndVerify(TimeSpan.FromSeconds(2)), autoPlug.VerificationFailure);
        }
Exemplo n.º 13
0
 public AutoMockInvokeExpectation(AutoMockPlug.MockAutoInvokeDelegate autoInvokeDelegate)
 {
     _autoInvokeDelegate = autoInvokeDelegate;
 }
Exemplo n.º 14
0
        public void Autoplug_without_expectations_wait_for_timeout()
        {
            AutoMockPlug autoPlug = MockPlug.Register(new XUri("http://auto/plug"));

            Assert.IsTrue(autoPlug.WaitAndVerify(TimeSpan.FromSeconds(1)), autoPlug.VerificationFailure);
        }