Ejemplo n.º 1
0
        public async Task Sends_alert_when_test_fails()
        {
            using (var teacup = _teapot.BeginScope())
            {
                var testResult = teacup.Mock("/api/v2.0/Gunter/Alerts/TestResult").ArrangePost((request, response) =>
                {
                    request
                    .AsUserAgent(ProgramInfo.Name, ProgramInfo.Version)
                    .AcceptsHtml()
                    .WithContentTypeJson(body =>
                    {
                        body
                        .PropertyEquals("$.Subject", "Glitch alert [Debug]")
                        .HasProperty("$.Subject");
                    })
                    .Occurs(1);

                    response
                    .Once(200, "OK");
                });

                using (var program = Program.Create(_loggerFactory, builder => { }))
                {
                    await program.RunAsync(@"batch -tests example");

                    //await Task.Delay(300);

                    var exceptions = _memoryRx.Exceptions <Exception>();

                    False(exceptions.Any());

                    testResult.Assert();
                }
            }
        }
Ejemplo n.º 2
0
        public async Task Can_post_email_and_receive_html()
        {
            using (var teacup = _teapot.BeginScope())
            {
                var mailrMessagesTestMock =
                    teacup
                    .Mock("/api/mailr/messages/test")
                    .ArrangePost((request, response) =>
                {
                    request
                    .AcceptsHtml()
                    .AsUserAgent("IOnymous", "1.0")
                    //.WithApiVersion("1.0")
                    .WithContentTypeJson(json =>
                    {
                        json
                        .HasProperty("$.To")
                        .HasProperty("$.Subject")
                        //.HasProperty("$.From") // Boom! This property does not exist.
                        .HasProperty("$.Body.Greeting");
                    });

                    response
                    .Once(200, "OK!");
                });

                var email = Email.CreateHtml(new[] { "*****@*****.**" }, "Testmail", new { Greeting = "Hallo Mailr!" });
                var html  = await _http.SendAsync("mailr/messages/test", email, "IOnymous", "1.0");

                Assert.Equal("OK!", html);
                mailrMessagesTestMock.Assert();
            }
        }
Ejemplo n.º 3
0
        public async Task Can_post_json()
        {
            using (var teacup = _teapot.BeginScope())
            {
                var test =
                    teacup
                    .Mock("/api/test?param=true")
                    .ArrangePost((request, response) =>
                {
                    request
                    .AsUserAgent("Teapot", "1.0")
                    .Occurs(1)
                    .AcceptsJson()
                    .WithApiVersion("1.0")
                    .WithContentTypeJson(content => { content.HasProperty("$.Greeting"); });

                    response
                    .Once(200, new { Message = "OK" })
                    .Echo();
                });

                // conflicting 'response' variables
                {
                    // Request made by the application somewhere deep down the rabbit hole
                    var response = await _http.PostAsync
                                   (
                        "test?param=true",
                        () => ResourceHelper.SerializeAsJsonAsync(new { Greeting = "Hallo" }),
                        ImmutableSession.Empty.Set(Use <IHttpNamespace> .Namespace, x => x.ConfigureRequestHeaders, headers =>
                    {
                        headers.ApiVersion("1.0");
                        headers.UserAgent("Teapot", "1.0");
                        headers.AcceptJson();
                    })
                                   );

                    Assert.True(response.Exists);
                    var original = await response.DeserializeJsonAsync <object>();
                }

                test.Assert();
            }
        }