1+ using Microsoft . Extensions . Logging ;
2+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
3+ using SenseNet . Client . TestsForDocs . Infrastructure ;
4+ using System . Threading . Channels ;
5+ using SenseNet . Extensions . DependencyInjection ;
6+
7+ namespace SenseNet . Client . TestsForDocs ;
8+
9+ [ TestClass ]
10+ public class Settings : ClientIntegrationTestBase
11+ {
12+ // ReSharper disable once InconsistentNaming
13+ private CancellationToken cancel => new CancellationTokenSource ( TimeSpan . FromSeconds ( 10 ) ) . Token ;
14+ // ReSharper disable once InconsistentNaming
15+ IRepository repository => GetRepositoryCollection ( ) . GetRepositoryAsync ( "local" , cancel )
16+ . GetAwaiter ( ) . GetResult ( ) ;
17+
18+ /* ====================================================================================== ???? */
19+
20+ /// <tab category="________" article="setings" example="read" />
21+ [ TestMethod ]
22+ public async Task Docs_Settings_Read ( )
23+ {
24+ await repository . UploadAsync ( new UploadRequest
25+ {
26+ ParentPath = "/Root/System/Settings" ,
27+ ContentName = "MySettings.settings" ,
28+ ContentType = "Settings"
29+ } , "{\" P1\" :\" V1\" }" , cancel ) ;
30+ // Ensure empty settings because an older test run can leave noisy data.
31+ await repository . GetResponseStringAsync ( new ODataRequest
32+ {
33+ Path = "/Root/Content" ,
34+ ActionName = "WriteSettings" ,
35+ PostData = new
36+ {
37+ name = "MySettings" ,
38+ settingsData = new { }
39+ }
40+ } , HttpMethod . Post , cancel ) ;
41+
42+ // ACT
43+ /*<doc>*/
44+ dynamic settings = await repository . GetResponseJsonAsync ( new ODataRequest
45+ {
46+ Path = "/Root/Content/IT" ,
47+ ActionName = "GetSettings" ,
48+ Parameters = { { "name" , "MySettings" } }
49+ } , HttpMethod . Get , cancel ) ;
50+ /*</doc>*/
51+
52+ // ASSERT
53+ Assert . IsNotNull ( settings ) ;
54+ Assert . AreEqual ( "V1" , settings . P1 . ToString ( ) ) ;
55+ }
56+
57+ /// <tab category="________" article="setings" example="write" />
58+ [ TestMethod ]
59+ public async Task Docs_Settings_Write ( )
60+ {
61+ await repository . UploadAsync ( new UploadRequest
62+ {
63+ ParentPath = "/Root/System/Settings" ,
64+ ContentName = "MySettings.settings" ,
65+ ContentType = "Settings"
66+ } , "{\" P1\" :\" V1\" }" , cancel ) ;
67+
68+ // ACT
69+ /*<doc>*/
70+ var response = await repository . GetResponseStringAsync ( new ODataRequest
71+ {
72+ Path = "/Root/Content" ,
73+ ActionName = "WriteSettings" ,
74+ PostData = new
75+ {
76+ name = "MySettings" ,
77+ settingsData = new { P1 = "V11" }
78+ }
79+ } , HttpMethod . Post , cancel ) ;
80+ /*</doc>*/
81+
82+ // ASSERT
83+ dynamic settings = await repository . GetResponseJsonAsync ( new ODataRequest
84+ {
85+ Path = "/Root/Content/IT" ,
86+ ActionName = "GetSettings" ,
87+ Parameters = { { "name" , "MySettings" } }
88+ } , HttpMethod . Get , cancel ) ;
89+ Assert . IsNotNull ( settings ) ;
90+ Assert . AreEqual ( "V11" , settings . P1 . ToString ( ) ) ;
91+ }
92+
93+ }
0 commit comments