1- using System . Threading . Tasks ;
1+ using System ;
2+ using System . Reflection ;
3+ using System . Threading . Tasks ;
24using FluentAssertions ;
35using PortaCapena . OdooJsonRpcClient . Consts ;
46using PortaCapena . OdooJsonRpcClient . Models ;
7+ using PortaCapena . OdooJsonRpcClient . Request ;
8+ using PortaCapena . OdooJsonRpcClient . Result ;
59using PortaCapena . OdooJsonRpcClient . Shared ;
610using PortaCapena . OdooJsonRpcClient . Shared . Models ;
711using Xunit ;
@@ -10,6 +14,55 @@ namespace PortaCapena.OdooJsonRpcClient.Example
1014{
1115 public class OdooRepositoryTests : RequestTestBase
1216 {
17+ [ Theory ]
18+ [ InlineData ( typeof ( ProductProductOdooModel ) ) ]
19+ [ InlineData ( typeof ( AccountAccountOdooModel ) ) ]
20+ [ InlineData ( typeof ( AccountAccountTypeOdooModel ) ) ]
21+ [ InlineData ( typeof ( AccountMoveLineOdooModel ) ) ]
22+ [ InlineData ( typeof ( AccountMoveOdooModel ) ) ]
23+ [ InlineData ( typeof ( AccountPaymentTermOdooModel ) ) ]
24+ [ InlineData ( typeof ( AccountTaxOdooModel ) ) ]
25+ [ InlineData ( typeof ( CompanyOdooDto ) ) ]
26+ [ InlineData ( typeof ( CouponProgramOdooDto ) ) ]
27+ [ InlineData ( typeof ( ProductPriceListOdooDto ) ) ]
28+ [ InlineData ( typeof ( ProductTemplateOdooDto ) ) ]
29+ [ InlineData ( typeof ( PurchaseOrderLineOdooModel ) ) ]
30+ [ InlineData ( typeof ( PurchaseOrderOdooModel ) ) ]
31+ [ InlineData ( typeof ( ResCompanyOdooModel ) ) ]
32+ [ InlineData ( typeof ( ResCountryOdooModel ) ) ]
33+ [ InlineData ( typeof ( ResCurrencyOdooModel ) ) ]
34+ [ InlineData ( typeof ( ResPartnerBankOdooModel ) ) ]
35+ [ InlineData ( typeof ( ResPartnerOdooModel ) ) ]
36+ [ InlineData ( typeof ( SaleOrderLineOdooDto ) ) ]
37+ [ InlineData ( typeof ( SaleOrderOdooModel ) ) ]
38+ [ InlineData ( typeof ( StockPickingTypeOdooModel ) ) ]
39+ [ InlineData ( typeof ( StockProductionLotOdooDto ) ) ]
40+ public async Task Can_get_lists ( Type type )
41+ {
42+ // arrange
43+ var repositoryType = typeof ( OdooRepository < > ) . MakeGenericType ( new [ ] { type } ) ;
44+ var queryBuilderType = typeof ( OdooQueryBuilder < > ) . MakeGenericType ( new [ ] { type } ) ;
45+
46+ var repository = Activator . CreateInstance ( repositoryType , new object [ ] { TestConfig } ) ;
47+
48+ // act
49+ var query = repositoryType . GetMethod ( "Query" ) . Invoke ( repository , null ) ;
50+
51+ dynamic awaitable = queryBuilderType . GetMethod ( "ToListAsync" ) . Invoke ( query , null ) ;
52+
53+ await awaitable ;
54+ var dynamicItems = awaitable . GetAwaiter ( ) . GetResult ( ) ;
55+
56+ var resultType = typeof ( OdooResult < > ) . MakeGenericType ( new [ ] { type . MakeArrayType ( ) } ) ;
57+ var items = Convert . ChangeType ( dynamicItems , resultType ) ;
58+
59+ // assert
60+ Assert . True ( dynamicItems . Succeed , "result.Succeed" ) ;
61+ Assert . Null ( dynamicItems . Error ) ;
62+ Assert . NotNull ( dynamicItems . Value ) ;
63+ Assert . NotEmpty ( dynamicItems . Value ) ;
64+ }
65+
1366 [ Fact ]
1467 public async Task Can_get_all_products ( )
1568 {
@@ -22,6 +75,16 @@ public async Task Can_get_all_products()
2275 products . Succeed . Should ( ) . BeTrue ( ) ;
2376 }
2477
78+ [ Fact ]
79+ public async Task Can_get_first_or_default_product_by_id ( )
80+ {
81+ var repository = new OdooRepository < ProductProductOdooModel > ( TestConfig ) ;
82+ var result = await repository . Query ( ) . ById ( 5 ) . FirstOrDefaultAsync ( ) ;
83+
84+ result . Succeed . Should ( ) . BeTrue ( ) ;
85+ result . Error . Should ( ) . BeNull ( ) ;
86+ }
87+
2588 [ Fact ]
2689 public async Task Can_get_product_by_id ( )
2790 {
@@ -205,7 +268,7 @@ public async Task Can_get_product_with_selected_language_using_repository_prop()
205268 public async Task Can_get_AccountPaymentTermOdooModel_by_id ( )
206269 {
207270 var repository = new OdooRepository < ResPartnerOdooModel > ( TestConfig ) ;
208- var context = new OdooContext ( ) { ForceCompany = 3 } ; // 1 My Company (San Francisco), 2 PL Company, 3 My Company (Chicago) // default My Company (San Francisco)
271+ var context = new OdooContext ( ) { ForceCompany = 3 } ; // 1 My Company (San Francisco), 2 PL Company, 3 My Company (Chicago) // default My Company (San Francisco)
209272 var products = await repository . Query ( ) . ById ( 14 )
210273 . WithContext ( context )
211274 . FirstOrDefaultAsync ( ) ;
0 commit comments