コード例 #1
0
        public async Task GetNotFoundIfLinkNotExist()
        {
            var        factory = new UrlyWebApplicationFactory <Startup>();
            HttpClient client  = factory.CreateClient();

            HttpResponseMessage response = await client.GetAsync($"/api/v1/links/fake");

            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
コード例 #2
0
        public async Task PostLinkIsCorrect()
        {
            var        factory = new UrlyWebApplicationFactory <Startup>();
            HttpClient client  = factory.CreateClient();

            HttpResponseMessage response = await PostLink(client, "link/qwe?a=1&b=2");

            var linkDto = await JsonHelper.Deserialize <LinkDto>(response.Content);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            Assert.AreEqual("link/qwe?a=1&b=2", linkDto.FullUrl);
            Assert.AreEqual("e", linkDto.ShortCode);
        }
コード例 #3
0
        public async Task RedirectIsCorrect(string code, string expected)
        {
            var factory = new UrlyWebApplicationFactory <Startup>();
            var options = new WebApplicationFactoryClientOptions {
                AllowAutoRedirect = false
            };
            HttpClient client = factory.CreateClient(options);

            HttpResponseMessage response = await client.GetAsync($"/{code}");

            Assert.AreEqual(HttpStatusCode.Redirect, response.StatusCode);
            Assert.AreEqual(expected, response.Headers.Location.ToString());
        }
コード例 #4
0
        public async Task PostAndGetLinkIsCorrect()
        {
            var        factory = new UrlyWebApplicationFactory <Startup>();
            HttpClient client  = factory.CreateClient();

            await PostLink(client, "link/qwe?a=1&b=21");

            HttpResponseMessage response = await client.GetAsync($"/api/v1/links/e");

            response.EnsureSuccessStatusCode();
            var linkDto = await JsonHelper.Deserialize <LinkDto>(response.Content);

            Assert.AreEqual("link/qwe?a=1&b=21", linkDto.FullUrl);
            Assert.AreEqual("e", linkDto.ShortCode);
        }
コード例 #5
0
        public async Task GetLinkIsCorrect(string code, string expected)
        {
            var        factory = new UrlyWebApplicationFactory <Startup>();
            HttpClient client  = factory.CreateClient();

            HttpResponseMessage response = await client.GetAsync($"/api/v1/links/{code}");

            response.EnsureSuccessStatusCode();

            var linkDto = await JsonHelper.Deserialize <LinkDto>(response.Content);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual(expected, linkDto.FullUrl);
            Assert.AreEqual(code, linkDto.ShortCode);
        }
コード例 #6
0
        public async Task SwaggerResponseIsCorrect()
        {
            var        factory = new UrlyWebApplicationFactory <Startup>();
            HttpClient client  = factory.CreateClient();

            HttpResponseMessage response = await client.GetAsync("/swagger");

            response.EnsureSuccessStatusCode();

            response = await client.GetAsync("/api-docs/swagger/v1.0/swagger.json");

            string responseString = await response.Content.ReadAsStringAsync();

            string infoTitle;

            using (JsonDocument document = JsonDocument.Parse(responseString))
            {
                infoTitle = document.RootElement.GetProperty("info").GetProperty("title").GetString();
            }

            Assert.AreEqual("Urly API", infoTitle);
        }