1+ using System ;
2+ using System . Threading . Tasks ;
3+ using FluentAssertions ;
4+ using PortaCapena . OdooJsonRpcClient . Consts ;
5+ using PortaCapena . OdooJsonRpcClient . Extensions ;
6+ using PortaCapena . OdooJsonRpcClient . Models ;
7+ using PortaCapena . OdooJsonRpcClient . Request ;
8+ using PortaCapena . OdooJsonRpcClient . Shared ;
9+ using PortaCapena . OdooJsonRpcClient . Shared . Models ;
10+ using Xunit ;
11+
12+ namespace PortaCapena . OdooJsonRpcClient . Example
13+ {
14+ public class ProductTemplateOdooModelRepositoryTests : RequestTestBase
15+ {
16+ private class ProductTemplateRepository : OdooRepository < ProductTemplateOdooModel >
17+ {
18+ public ProductTemplateRepository ( ) : base ( TestConfig ) { }
19+ }
20+
21+ [ Fact ]
22+ public async Task Get_All ( )
23+ {
24+ var repo = new ProductTemplateRepository ( ) ;
25+
26+ var result = await repo . Query ( ) . ToListAsync ( ) ;
27+
28+ result . Error . Should ( ) . BeNull ( ) ;
29+ result . Succeed . Should ( ) . BeTrue ( ) ;
30+ result . Value . Should ( ) . NotBeNull ( ) . And . NotBeEmpty ( ) ;
31+ }
32+
33+ [ Fact ]
34+ public async Task Get_By_Id ( )
35+ {
36+ var repo = new ProductTemplateRepository ( ) ;
37+
38+ var result = await repo . Query ( ) . ById ( 1 ) . FirstOrDefaultAsync ( ) ;
39+
40+ result . Error . Should ( ) . BeNull ( ) ;
41+ result . Succeed . Should ( ) . BeTrue ( ) ;
42+ result . Value . Should ( ) . NotBeNull ( ) ;
43+ }
44+
45+ [ Fact ]
46+ public async Task Get_By_Ids ( )
47+ {
48+ var repo = new ProductTemplateRepository ( ) ;
49+
50+ var result = await repo . Query ( ) . ByIds ( 1 , 2 ) . ToListAsync ( ) ;
51+
52+ result . Error . Should ( ) . BeNull ( ) ;
53+ result . Succeed . Should ( ) . BeTrue ( ) ;
54+ result . Value . Should ( ) . NotBeNull ( ) . And . NotBeEmpty ( ) ;
55+ result . Value . Length . Should ( ) . Be ( 2 ) ;
56+ }
57+
58+
59+
60+ [ Fact ]
61+ public async Task Get_name_in_nl ( )
62+ {
63+ var repo = new ProductTemplateRepository ( ) ;
64+
65+ var result = await repo . Query ( ) . ById ( 23 ) . FirstOrDefaultAsync ( ) ;
66+
67+ result . Error . Should ( ) . BeNull ( ) ;
68+ result . Succeed . Should ( ) . BeTrue ( ) ;
69+ result . Value . Should ( ) . NotBeNull ( ) ;
70+ result . Value . Name . Should ( ) . Be ( "Acoustic Bloc Screens" ) ;
71+ result . Value . Name . Should ( ) . NotBe ( "Akoestische blokschermen" ) ;
72+
73+
74+ repo . Config . Context . Language = "nl_NL" ;
75+
76+ var resultInNL = await repo . Query ( ) . ById ( result . Value . Id ) . Select ( x => new { x . Name } ) . FirstOrDefaultAsync ( ) ;
77+
78+ resultInNL . Error . Should ( ) . BeNull ( ) ;
79+ resultInNL . Succeed . Should ( ) . BeTrue ( ) ;
80+ resultInNL . Value . Should ( ) . NotBeNull ( ) ;
81+
82+ resultInNL . Value . Name . Should ( ) . NotBe ( "Acoustic Bloc Screens" ) ;
83+ resultInNL . Value . Name . Should ( ) . Be ( "Akoestische blokschermen" ) ;
84+
85+ repo . Config . Context . Language = "en_US" ;
86+
87+ var resultInEn = await repo . Query ( ) . ById ( result . Value . Id ) . FirstOrDefaultAsync ( ) ;
88+
89+ resultInEn . Error . Should ( ) . BeNull ( ) ;
90+ resultInEn . Succeed . Should ( ) . BeTrue ( ) ;
91+ resultInEn . Value . Should ( ) . NotBeNull ( ) ;
92+
93+ resultInEn . Value . Name . Should ( ) . Be ( "Acoustic Bloc Screens" ) ;
94+ resultInEn . Value . Name . Should ( ) . NotBe ( "Akoestische blokschermen" ) ;
95+ }
96+
97+ //[Fact]
98+ [ Fact ( Skip = "Test for working on Odoo" ) ]
99+ public async Task Update_name_in_nl ( )
100+ {
101+ var repo = new ProductTemplateRepository ( ) ;
102+
103+ var result = await repo . Query ( ) . ById ( 15 ) . FirstOrDefaultAsync ( ) ;
104+
105+ result . Error . Should ( ) . BeNull ( ) ;
106+ result . Succeed . Should ( ) . BeTrue ( ) ;
107+ result . Value . Should ( ) . NotBeNull ( ) ;
108+ result . Value . Name . Should ( ) . Be ( "Acoustic Bloc Screens" ) ;
109+ result . Value . Name . Should ( ) . NotBe ( "Akoestische blokschermen" ) ;
110+
111+ var model = OdooDictionaryModel . Create < ProductProductOdooModel > ( ) . Add ( x => x . Name , "Product new name NL" ) ;
112+
113+ repo . Config . Context . Language = "nl_BE" ;
114+
115+ var updateResult = await repo . UpdateAsync ( model , result . Value . Id ) ;
116+
117+ updateResult . Error . Should ( ) . BeNull ( ) ;
118+ updateResult . Succeed . Should ( ) . BeTrue ( ) ;
119+ updateResult . Value . Should ( ) . BeTrue ( ) ;
120+
121+ var resultInNL = await repo . Query ( ) . ById ( result . Value . Id ) . FirstOrDefaultAsync ( ) ;
122+
123+ resultInNL . Error . Should ( ) . BeNull ( ) ;
124+ resultInNL . Succeed . Should ( ) . BeTrue ( ) ;
125+ resultInNL . Value . Should ( ) . NotBeNull ( ) ;
126+
127+ result . Value . Name . Should ( ) . NotBe ( "Acoustic Bloc Screens" ) ;
128+ result . Value . Name . Should ( ) . Be ( "Akoestische blokschermen" ) ;
129+
130+
131+ repo . Config . Context . Language = "en_US" ;
132+
133+ var resultInEn = await repo . Query ( ) . ById ( result . Value . Id ) . FirstOrDefaultAsync ( ) ;
134+
135+ resultInEn . Error . Should ( ) . BeNull ( ) ;
136+ resultInEn . Succeed . Should ( ) . BeTrue ( ) ;
137+ resultInEn . Value . Should ( ) . NotBeNull ( ) ;
138+
139+ resultInEn . Value . Name . Should ( ) . Be ( "Acoustic Bloc Screens" ) ;
140+ resultInEn . Value . Name . Should ( ) . NotBe ( "Akoestische blokschermen" ) ;
141+ }
142+ }
143+ }
0 commit comments