Ejemplo n.º 1
0
        public void Paging_should_ignore_default_values()
        {
            PaginationConfig.DefaultPageSize = 10;

            var request = new ProductsList.Query
            {
                Page     = 1,
                PageSize = PaginationConfig.DefaultPageSize
            };

            UrlLookup
            .Build(request)
            .ToString()
            .ShouldBe("/Products/List");

            UrlLookup
            .Build(request)
            .With(m => m.Page, 2)
            .ToString()
            .ShouldBe("/Products/List?Page=2");

            UrlLookup
            .Build(request)
            .With(m => m.PageSize, 20)
            .ToString()
            .ShouldBe("/Products/List?PageSize=20");
        }
Ejemplo n.º 2
0
        public void Should_ignore_enumerable_properties()
        {
            var request = new ProductsList.Query();

            request.Categories.Count().ShouldBe(2);

            UrlLookup
            .For(request)
            .ShouldNotContain("Categories");
        }
Ejemplo n.º 3
0
        public void Should_readonly_lists_or_collection_properties()
        {
            var request = new ProductsList.Query();

            request.Categories.Count().ShouldBe(2);

            var url = UrlLookup.For(request);

            url.ShouldNotContain(nameof(ProductsList.Query.ReadOnlyCollection));
            url.ShouldNotContain(nameof(ProductsList.Query.ReadOnlyList));
        }
Ejemplo n.º 4
0
        public void Bug_should_handle_input_filled_with_simple_property_and_one_override()
        {
            var request = new ProductsList.Query
            {
                CategoryId = 123
            };

            UrlLookup
            .Build(request)
            .With(m => m.Category, "Samsung")
            .ToString()
            .ShouldBe("/Products/List/Samsung?CategoryId=123");
        }
Ejemplo n.º 5
0
        public void Should_ignore_null_properties()
        {
            var request = new ProductsList.Query
            {
                CategoryId = 123,
                Category   = null,
                OnSales    = true
            };

            UrlLookup
            .For(request)
            .ShouldBe("/Products/List?CategoryId=123&OnSales=True");
        }
Ejemplo n.º 6
0
        public void Should_ignore_readonly_properties()
        {
            var request = new ProductsList.Query
            {
                Category = "Food"
            };

            request.Title.ShouldBe("Food");

            UrlLookup
            .For(request)
            .ShouldBe("/Products/List/Food");
        }
Ejemplo n.º 7
0
        public void When_paging_and_using_modifier_should_erase_paging_counters()
        {
            var request = new ProductsList.Query
            {
                Category = "Men",

                Page     = 399,
                PageSize = 20,
            };

            UrlLookup
            .Build(request)
            .With(m => m.Category, "Women")
            .ToString()
            .ShouldBe("/Products/List/Women");
        }
Ejemplo n.º 8
0
        public void Can_add_item_to_array_property()
        {
            var request = new ProductsList.Query
            {
                Size = new List <ProductsList.Size>
                {
                    ProductsList.Size.Small,
                    ProductsList.Size.Medium
                }
            };

            UrlLookup
            .Build(request).With(m => m.Size, ProductsList.Size.Large)
            .ToString()
            .ShouldBe("/Products/List?Size%5B0%5D=Small&Size%5B1%5D=Medium&Size%5B2%5D=Large");
        }
Ejemplo n.º 9
0
        public void Build_query_string_for_enumeration_of_t()
        {
            var request = new ProductsList.Query
            {
                ProductStatus = ProductsList.ProductStatus.OutOfStock,
            };

            UrlLookup
            .For(request)
            .ShouldBe($"/Products/List?ProductStatus={ProductsList.ProductStatus.OutOfStock.Value}");

            UrlLookup
            .Build(new ProductsList.Query())
            .With(x => x.ProductStatus, ProductsList.ProductStatus.OutOfStock)
            .ToString()
            .ShouldBe($"/Products/List?ProductStatus={ProductsList.ProductStatus.OutOfStock.Value}");
        }
Ejemplo n.º 10
0
        public void Can_ignore_whole_array()
        {
            var request = new ProductsList.Query
            {
                CategoryId = 123,
                Size       = new List <ProductsList.Size>
                {
                    ProductsList.Size.Small,
                    ProductsList.Size.Medium
                }
            };

            UrlLookup
            .Build(request).Without(m => m.Size)
            .ToString()
            .ShouldBe("/Products/List?CategoryId=123");
        }
Ejemplo n.º 11
0
        public void Build_query_string_for_enumeration_of_t1_and_t2()
        {
            var request = new ProductsList.Query
            {
                OrderStatus = ProductsList.OrderStatus.Delivered,
            };

            UrlLookup
            .For(request)
            .ShouldBe($"/Products/List?OrderStatus={ProductsList.OrderStatus.Delivered.Value}");

            UrlLookup
            .Build(new ProductsList.Query())
            .With(x => x.OrderStatus, ProductsList.OrderStatus.Paid)
            .ToString()
            .ShouldBe($"/Products/List?OrderStatus={ProductsList.OrderStatus.Paid.Value}");
        }
Ejemplo n.º 12
0
        public void Build_query_string_for_date()
        {
            var currentCulture = CultureInfo.CurrentCulture;

            CultureInfo.CurrentCulture = new CultureInfo("pt-BR");

            var request = new ProductsList.Query
            {
                SoldBefore = new DateTime(2020, 1, 31, 10, 11, 12),
            };

            UrlLookup
            .For(request)
            .ShouldBe("/Products/List?SoldBefore=31%2F01%2F2020");

            CultureInfo.CurrentCulture = currentCulture;
        }
Ejemplo n.º 13
0
        public void When_paging_url_should_ignore_paging_counters()
        {
            var request = new ProductsList.Query()
            {
                Category = "Shoes",
                Page     = 2,
                PageSize = 100,

                // counters:
                Pages        = 5,
                CountShowing = 20,
                CountTotal   = 100
            };

            UrlLookup
            .For(request)
            .ShouldBe("/Products/List/Shoes?Page=2&PageSize=100");
        }
Ejemplo n.º 14
0
        public void Can_ignore_items_from_a_list()
        {
            var request = new ProductsList.Query
            {
                Size = new List <ProductsList.Size>
                {
                    ProductsList.Size.Small,
                    ProductsList.Size.Medium,
                    ProductsList.Size.Large
                }
            };

            UrlLookup
            .Build(request)
            .Without(m => m.Size, ProductsList.Size.Medium)
            .Without(m => m.Size, ProductsList.Size.Large)
            .ToString()
            .ShouldBe("/Products/List?Size%5B0%5D=Small");
        }
Ejemplo n.º 15
0
        public void Can_ignore_a_property_with_a_value()
        {
            var request = new ProductsList.Query
            {
                CategoryId = 123,
                Category   = "Apple"
            };

            UrlLookup
            .Build(request)
            .Without(m => m.CategoryId, 123)
            .ToString()
            .ShouldBe("/Products/List/Apple");

            UrlLookup
            .Build(request)
            .Without(m => m.CategoryId, 111)
            .ToString()
            .ShouldBe("/Products/List/Apple?CategoryId=123");
        }
Ejemplo n.º 16
0
        public void When_using_modifiers_should_not_change_request_state()
        {
            var request = new ProductsList.Query
            {
                CategoryId = 123,
                Category   = "Apple",
                OnSales    = true
            };

            UrlLookup
            .Build(request)
            .With(m => m.Category, "Samsung")
            .With(m => m.OnSales, false)
            .ToString().ShouldBe("/Products/List/Samsung?CategoryId=123&OnSales=False");

            // properties' values should remain as before
            request.CategoryId.ShouldBe(123);
            request.Category.ShouldBe("Apple");
            request.OnSales.ShouldBeTrue();
        }
Ejemplo n.º 17
0
        public void Should_ignore_if_property_type_is_named_result()
        {
            var request = new ProductsList.Query
            {
                Category = "Apple",
                Results  = new List <ProductsList.Result>
                {
                    new ProductsList.Result()
                    {
                        ProductName = "Product 1", ProductPrice = 10
                    },
                    new ProductsList.Result()
                    {
                        ProductName = "Product 2", ProductPrice = 20
                    }
                }
            };

            UrlLookup
            .For(request)
            .ShouldBe("/Products/List/Apple");
        }