Esempio n. 1
0
        public void When_use_where_with_OdooFilter_param_shoud_return_correct_filters_model()
        {
            var filters = OdooQuery <ProductProductOdooModel> .Create()
                          .Where(OdooFilter.Create().GreaterThanOrEqual("write_date", new DateTime(2020, 12, 2)))
                          .Where(OdooFilter.Create().EqualTo("name", "Bioboxen 610l"));

            filters.Filters.Count.Should().Be(2);
            var json = JsonConvert.SerializeObject(filters.Filters);

            json.Should().Be("[[\"write_date\",\">=\",\"2020-12-02T00:00:00\"],[\"name\",\"=\",\"Bioboxen 610l\"]]");

            filters.ReturnFields.Count.Should().Be(0);
            filters.Limit.Should().BeNull();
            filters.Offset.Should().BeNull();
        }
        public void RequestModel_should_return_request_with_corect_params_count()
        {
            var query = new OdooQuery()
            {
                ReturnFields = new HashSet <string> {
                    "name"
                },
                Filters = new OdooFilter {
                    new object[] { "id", "=", 66 }
                }
            };
            var request = OdooRequestModel.SearchRead(Config, 2, "table", query);

            request.Params.Args.Length.Should().Be(7);


            var query2 = new OdooQuery()
            {
                Filters = new OdooFilter {
                    new object[] { "id", "=", 66 }
                }
            };
            var request2 = OdooRequestModel.SearchRead(Config, 2, "table", query2);

            request2.Params.Args.Length.Should().Be(6);


            var query3 = new OdooQuery()
            {
                ReturnFields = new HashSet <string> {
                    "name"
                }
            };
            var request3 = OdooRequestModel.SearchRead(Config, 2, "table", query3);

            request3.Params.Args.Length.Should().Be(7);


            var request4 = OdooRequestModel.SearchRead(Config, 2, "table");

            request4.Params.Args.Length.Should().Be(5);


            var query5 = new OdooQuery()
            {
                Offset = 10
            };
            var request5 = OdooRequestModel.SearchRead(Config, 2, "table", query5);

            request5.Params.Args.Length.Should().Be(8);


            var query6 = new OdooQuery()
            {
                Limit = 10
            };
            var request6 = OdooRequestModel.SearchRead(Config, 2, "table", query6);

            request6.Params.Args.Length.Should().Be(9);


            var query7 = new OdooQuery()
            {
                Order = "id"
            };
            var request7 = OdooRequestModel.SearchRead(Config, 2, "table", query7);

            request7.Params.Args.Length.Should().Be(10);


            var queryTest = new OdooQuery()
            {
                ReturnFields = new HashSet <string> {
                    "name"
                },
                Filters = OdooFilter.Create().EqualTo("id", 66)
            };

            var requestTest = OdooRequestModel.SearchRead(Config, 2, "table", queryTest);

            requestTest.Params.Args.Length.Should().Be(7);
        }