Exemplo n.º 1
0
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new ProductsClient(connection);

                var filters = new ProductSearchFilters
                {
                    ExactMatch = true,
                    PageSize   = 1,
                    PageCount  = 1,
                    StartPage  = 0,
                };

                await client.Search("product", filters);

                Received.InOrder(async() =>
                {
                    await connection.SearchAll <SearchResult <SimpleProduct> >(
                        Arg.Is <Uri>(u => u.ToString() == "products/search"),
                        Arg.Is <Dictionary <string, string> >(d => d.Count == 2 &&
                                                              d["term"] == "product" &&
                                                              d["exact_match"] == "True"),
                        Arg.Is <ApiOptions>(o => o.PageSize == 1 &&
                                            o.PageCount == 1 &&
                                            o.StartPage == 0));
                });
            }
Exemplo n.º 2
0
            public async Task EnsuresSearchTermIsMoreThan2Characters()
            {
                var client = new ProductsClient(Substitute.For <IApiConnection>());

                var exception = await Assert.ThrowsAsync <ArgumentException>(() => client.Search("p", ProductSearchFilters.None));

                Assert.Equal("The search term must have at least 2 characters (Parameter 'term')", exception.Message);
            }
Exemplo n.º 3
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new ProductsClient(Substitute.For <IApiConnection>());

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Search(null, null));
            }