Skip to content

Commit 1ecd933

Browse files
authored
Merge pull request #15 from patricoos/new_context
New context
2 parents c03282c + d8bf8dc commit 1ecd933

22 files changed

Lines changed: 2465 additions & 352 deletions

PortaCapena.OdooJsonRpcClient.Example/CompanyRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
namespace PortaCapena.OdooJsonRpcClient.Example
99
{
10-
public class CompanyOdooRepository : TestBase
10+
public class CompanyOdooRepository : RequestTestBase
1111
{
1212
private class CompanyRepository : OdooRepository<ResCompanyOdooModel>
1313
{
14-
public CompanyRepository() : base(Config) { }
14+
public CompanyRepository() : base(TestConfig) { }
1515
}
1616

1717
[Fact]

PortaCapena.OdooJsonRpcClient.Example/OdooClientRequests.cs

Lines changed: 79 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
namespace PortaCapena.OdooJsonRpcClient.Example
2121
{
22-
public class OdooClientRequests : TestBase
22+
public class OdooClientRequests : RequestTestBase
2323
{
2424

2525
[Fact]
2626
public async Task Can_get_odoo_version()
2727
{
28-
var odooClient = new OdooClient(Config);
28+
var odooClient = new OdooClient(TestConfig);
2929

3030
var result = await odooClient.GetVersionAsync();
3131

@@ -34,10 +34,23 @@ public async Task Can_get_odoo_version()
3434
}
3535

3636

37+
[Fact]
38+
public async Task Get_DotNet_model_should_return_string()
39+
{
40+
var odooClient = new OdooClient(TestConfig);
41+
var tableName = "product.product";
42+
var modelResult = await odooClient.GetModelAsync(tableName);
43+
44+
modelResult.Succeed.Should().BeTrue();
45+
46+
var model = OdooModelMapper.GetDotNetModel(tableName, modelResult.Value);
47+
}
48+
49+
3750
[Fact]
3851
public async Task Can_get_all_products()
3952
{
40-
var odooClient = new OdooClient(Config);
53+
var odooClient = new OdooClient(TestConfig);
4154

4255
var products = await odooClient.GetAsync<ResCountryOdooModel>();
4356

@@ -46,15 +59,13 @@ public async Task Can_get_all_products()
4659
products.Value.Should().NotBeNull();
4760
products.Value.Length.Should().BeGreaterThan(0);
4861
products.Succeed.Should().BeTrue();
49-
50-
var dupa = products.Value.Where(x => x.XStudioIsInEu == true).ToList();
5162
}
5263

5364

5465
[Fact]
5566
public async Task Can_get_all_countries()
5667
{
57-
var odoorepository = new OdooRepository<ResCountryOdooModel>(Config);
68+
var odoorepository = new OdooRepository<ResCountryOdooModel>(TestConfig);
5869

5970
var products = await odoorepository.Query().Where(x => x.XStudioIsInEu, OdooOperator.EqualsTo, true).ToListAsync();
6071

@@ -69,7 +80,7 @@ public async Task Can_get_all_countries()
6980
[Fact]
7081
public async Task Get_product_by_Id_test()
7182
{
72-
var odooClient = new OdooClient(Config);
83+
var odooClient = new OdooClient(TestConfig);
7384

7485
var query = OdooQuery<ProductProductOdooDto>.Create()
7586
.Where(x => x.Id, OdooOperator.EqualsTo, 303);
@@ -86,7 +97,7 @@ public async Task Get_product_by_Id_test()
8697
[Fact]
8798
public async Task Shoud_get_products_using_query_take()
8899
{
89-
var odooClient = new OdooClient(Config);
100+
var odooClient = new OdooClient(TestConfig);
90101
var query = OdooQuery<ProductProductOdooDto>.Create()
91102
.Take(10);
92103

@@ -101,9 +112,8 @@ public async Task Shoud_get_products_using_query_take()
101112
[Fact]
102113
public async Task Shoud_get_products_using_query_skip()
103114
{
104-
var odooClient = new OdooClient(Config);
105-
var query = OdooQuery<ProductProductOdooDto>.Create()
106-
.Skip(5);
115+
var odooClient = new OdooClient(TestConfig);
116+
var query = OdooQuery<ProductProductOdooDto>.Create().Skip(5);
107117

108118
var products = await odooClient.GetAsync<ProductProductOdooDto>(query);
109119

@@ -122,7 +132,7 @@ public async Task Shoud_get_products_using_query_skip()
122132
[Fact]
123133
public async Task Get_products_with_order_query()
124134
{
125-
var odooClient = new OdooClient(Config);
135+
var odooClient = new OdooClient(TestConfig);
126136
var query = OdooQuery<ProductProductOdooDto>.Create()
127137
.OrderBy(x => x.Id);
128138

@@ -141,7 +151,7 @@ public async Task Get_products_with_order_query()
141151
[Fact]
142152
public async Task Get_products_with_order_desc_query()
143153
{
144-
var odooClient = new OdooClient(Config);
154+
var odooClient = new OdooClient(TestConfig);
145155
var query = OdooQuery<ProductProductOdooDto>.Create()
146156
.OrderByDescending(x => x.Id);
147157

@@ -162,7 +172,7 @@ public async Task Get_products_with_order_desc_query()
162172
[Fact]
163173
public async Task Should_get_products_with_selected_properties_using_query()
164174
{
165-
var odooClient = new OdooClient(Config);
175+
var odooClient = new OdooClient(TestConfig);
166176

167177
var filters = OdooQuery<ProductProductOdooDto>.Create()
168178
.Select(x => new
@@ -178,22 +188,11 @@ public async Task Should_get_products_with_selected_properties_using_query()
178188

179189
products.Error.Should().BeNull();
180190
products.Value.Should().NotBeNull();
181-
products.Value.Length.Should().Be(1);
191+
// products.Value.Length.Should().Be(1);
182192
products.Succeed.Should().BeTrue();
183193
}
184194

185195

186-
[Fact]
187-
public async Task Get_DotNet_model_should_return_string()
188-
{
189-
var odooClient = new OdooClient(Config);
190-
var tableName = "account.move.line";
191-
var modelResult = await odooClient.GetModelAsync(tableName);
192-
193-
modelResult.Succeed.Should().BeTrue();
194-
195-
var model = OdooModelMapper.GetDotNetModel(tableName, modelResult.Value);
196-
}
197196

198197

199198
#region Create
@@ -222,19 +221,56 @@ public async Task Can_Create_customer()
222221
CompanyType = test ?? CompanyTypeResPartnerOdooEnum.Individual
223222
});
224223

225-
var odooClient = new OdooClient(Config);
224+
var odooClient = new OdooClient(TestConfig);
226225

227226
var products = await odooClient.CreateAsync(model);
228227

229228
products.Succeed.Should().BeTrue();
230229
}
231230

231+
[Fact]
232+
public async Task Can_create_update_get_and_delete_customer()
233+
{
234+
var model = OdooDictionaryModel.Create(() => new ResPartnerOdooModel()
235+
{
236+
Name = "dupa",
237+
CountryId = 20,
238+
City = "dupa",
239+
Zip = "dupa",
240+
Street = "dupa",
241+
CompanyType = CompanyTypeResPartnerOdooEnum.Individual
242+
});
243+
244+
var odooClient = new OdooClient(TestConfig);
245+
var products = await odooClient.CreateAsync(model);
246+
247+
products.Succeed.Should().BeTrue();
248+
products.Value.Should().BePositive();
249+
250+
model.Add(x => x.Name, "new name");
251+
252+
var editedCustomer = await odooClient.UpdateAsync(model, products.Value);
253+
editedCustomer.Succeed.Should().BeTrue();
254+
255+
var query = new OdooQuery();
256+
query.Filters.EqualTo("id", products.Value);
257+
var customers = await odooClient.GetAsync<ResPartnerOdooModel>(query);
258+
259+
customers.Succeed.Should().BeTrue();
260+
customers.Value.Length.Should().Be(1);
261+
customers.Value.First().Name.Should().Be("new name");
262+
263+
var deleteResult = await odooClient.DeleteAsync(customers.Value.First());
264+
265+
deleteResult.Succeed.Should().BeTrue();
266+
}
267+
232268

233269
[Fact(Skip = "Test for working on Odoo")]
234270
// [Fact]
235271
public async Task Can_create_product()
236272
{
237-
var odooClient = new OdooClient(Config);
273+
var odooClient = new OdooClient(TestConfig);
238274

239275
var model = new OdooCreateProduct()
240276
{
@@ -254,7 +290,7 @@ public async Task Can_create_product()
254290
//[Fact]
255291
public async Task Can_create_update_delete_product()
256292
{
257-
var odooClient = new OdooClient(Config);
293+
var odooClient = new OdooClient(TestConfig);
258294

259295
var model = new OdooCreateProduct()
260296
{
@@ -299,7 +335,7 @@ public async Task Can_create_update_delete_product()
299335
// [Fact]
300336
public async Task Can_create_product_from_dictionary_model()
301337
{
302-
var odooClient = new OdooClient(Config);
338+
var odooClient = new OdooClient(TestConfig);
303339

304340
var dictModel = OdooDictionaryModel.Create(() => new ProductProductOdooDto
305341
{
@@ -326,7 +362,7 @@ public async Task Can_create_product_from_dictionary_model()
326362
// [Fact]
327363
public async Task Can_create_product_and_delete_using_object()
328364
{
329-
var odooClient = new OdooClient(Config);
365+
var odooClient = new OdooClient(TestConfig);
330366

331367
var model = new OdooCreateProduct()
332368
{
@@ -354,7 +390,7 @@ public async Task Can_create_product_and_delete_using_object()
354390
//[Fact]
355391
public async Task Can_create_voucher()
356392
{
357-
var odooClient = new OdooClient(Config);
393+
var odooClient = new OdooClient(TestConfig);
358394

359395
var model = new OdooVoucherCreateOrUpdate()
360396
{
@@ -375,7 +411,7 @@ public async Task Can_create_voucher()
375411
// [Fact]
376412
public async Task Can_create_sale_order()
377413
{
378-
var odooClient = new OdooClient(Config);
414+
var odooClient = new OdooClient(TestConfig);
379415

380416
var companyResult = await odooClient.GetAsync<CompanyOdooDto>(OdooQuery<CompanyOdooDto>.Create().ById(1));
381417
companyResult.Succeed.Should().BeTrue();
@@ -430,9 +466,9 @@ public async Task OnChange_test()
430466
{
431467
try
432468
{
433-
var loginResult = await OdooClient.LoginAsync(Config);
469+
var loginResult = await OdooClient.LoginAsync(TestConfig);
434470

435-
var param = new OdooRequestParams(Config.ApiUrlJson, "object", "execute", Config.DbName, loginResult.Value, Config.Password, "sale.order", OdooOperation.OnChage,
471+
var param = new OdooRequestParams(TestConfig.ApiUrlJson, "object", "execute", TestConfig.DbName, loginResult.Value, TestConfig.Password, "sale.order", OdooOperation.OnChage,
436472
new Dictionary<string, int>() { { "onchange_pricelist_id", 17 } }, 135);
437473
var request = new OdooRequestModel(param);
438474

@@ -446,12 +482,12 @@ public async Task OnChange_test()
446482
}
447483
}
448484

449-
// [Fact(Skip = "Test for working on Odoo")]
450-
[Fact]
485+
[Fact(Skip = "Test for working on Odoo")]
486+
//[Fact]
451487
public async Task Can_create_purchase_order()
452488
{
453489

454-
var odooClient = new OdooClient(Config);
490+
var odooClient = new OdooClient(TestConfig);
455491

456492
var partnerResult = await odooClient.GetAsync<StockPickingTypeOdooDto>();
457493

@@ -483,9 +519,9 @@ public void OnChange_test1()
483519
{
484520
using (var client = new WebClient())
485521
{
486-
client.Credentials = new NetworkCredential(Config.UserName, Config.Password);
522+
client.Credentials = new NetworkCredential(TestConfig.UserName, TestConfig.Password);
487523
var json = "{\"jsonrpc\":\"2.0\",\"method\":\"GUI.ShowNotification\",\"params\":{\"title\":\"This is the title of the message\",\"message\":\"This is the body of the message\"},\"id\":1}";
488-
var response = client.UploadString(Config.ApiUrlJson, "POST", json);
524+
var response = client.UploadString(TestConfig.ApiUrlJson, "POST", json);
489525
}
490526
}
491527
catch (Exception e)
@@ -506,9 +542,9 @@ public async Task CreatePurchaseOrderAsync()
506542
{
507543
var odooCompanyId = 32;
508544

509-
var accountTaxOdooRepository = new OdooRepository<AccountTaxOdooModel>(Config);
510-
var purchaseOrderOdooRepository = new OdooRepository<PurchaseOrderOdooModel>(Config);
511-
var purchaseOrderLineOdooRepository = new OdooRepository<PurchaseOrderLineOdooModel>(Config);
545+
var accountTaxOdooRepository = new OdooRepository<AccountTaxOdooModel>(TestConfig);
546+
var purchaseOrderOdooRepository = new OdooRepository<PurchaseOrderOdooModel>(TestConfig);
547+
var purchaseOrderLineOdooRepository = new OdooRepository<PurchaseOrderLineOdooModel>(TestConfig);
512548

513549
var odooCompanyTaxes = await accountTaxOdooRepository.Query()
514550
.Where(x => x.CompanyId, OdooOperator.EqualsTo, odooCompanyId)

0 commit comments

Comments
 (0)