public void Given_InvalidMethod_When_GetShortenerRequestAsync_Invoked_Then_It_Should_Throw_Exception(string method)
        {
            var req = new Mock <HttpRequest>();

            req.SetupGet(p => p.Method).Returns(method);

            Func <Task> func = async() => await HttpRequestExtensions.GetShortenerRequestAsync(req.Object).ConfigureAwait(false);

            func.Should().Throw <InvalidOperationException>();
        }
        public void Given_Query_When_GetShortenerRequestAsync_Invoked_Then_It_Should_Throw_Exception(string method, string original, string owner)
        {
            var dict = new Dictionary <string, StringValues>()
            {
                { "original", original },
                { "owner", owner },
            };
            var collection = new QueryCollection(dict);

            var req = new Mock <HttpRequest>();

            req.SetupGet(p => p.Method).Returns(method);
            req.SetupGet(p => p.Query).Returns(collection);

            Func <Task> func = async() => await HttpRequestExtensions.GetShortenerRequestAsync(req.Object).ConfigureAwait(false);

            func.Should().Throw <InvalidOperationException>();
        }
        public async Task Given_Query_When_GetShortenerRequestAsync_Invoked_Then_It_Should_Return_Result(string method, string original, string friendly, string title, string description, string owner, params string[] coOwners)
        {
            var dict = new Dictionary <string, StringValues>()
            {
                { "original", original },
                { "friendly", friendly },
                { "title", title },
                { "description", description },
                { "owner", owner },
                { "coowners", coOwners },
            };
            var query = new QueryCollection(dict);

            var req = new Mock <HttpRequest>();

            req.SetupGet(p => p.Method).Returns(method);
            req.SetupGet(p => p.Query).Returns(query);

            var result = await HttpRequestExtensions.GetShortenerRequestAsync(req.Object).ConfigureAwait(false);

            result.Should().NotBeNull();
            result.Original.ToString().TrimEnd('/').Should().Be(original.TrimEnd('/'));
            result.Friendly.Should().Be(friendly);
        }
        public async Task Given_Body_When_GetShortenerRequestAsync_Invoked_Then_It_Should_Return_Result(string method, string original, string friendly, string owner)
        {
            var payload = new ShortenerRequest()
            {
                Original = new Uri(original),
                Friendly = friendly,
                Owner    = owner
            };
            var serialised = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload));
            var body       = new MemoryStream(serialised);

            var req = new Mock <HttpRequest>();

            req.SetupGet(p => p.Method).Returns(method);
            req.SetupGet(p => p.Body).Returns(body);

            var result = await HttpRequestExtensions.GetShortenerRequestAsync(req.Object).ConfigureAwait(false);

            result.Should().NotBeNull();
            result.Original.ToString().TrimEnd('/').Should().Be(original.TrimEnd('/'));
            result.Friendly.Should().Be(friendly);

            body.Dispose();
        }
        public void Given_Null_When_GetShortenerRequestAsync_Invoked_Then_It_Should_Throw_Exception()
        {
            Func <Task> func = async() => await HttpRequestExtensions.GetShortenerRequestAsync(null).ConfigureAwait(false);

            func.Should().Throw <ArgumentNullException>();
        }