1+ // -------------------------------------------------------------------------------------------------
2+ // <copyright file="RestClientTestFixture.cs" company="RHEA System S.A.">
3+ //
4+ // Copyright 2022 RHEA System S.A.
5+ //
6+ // Licensed under the Apache License, Version 2.0 (the "License");
7+ // you may not use this file except in compliance with the License.
8+ // You may obtain a copy of the License at
9+ //
10+ // http://www.apache.org/licenses/LICENSE-2.0
11+ //
12+ // Unless required by applicable law or agreed to in writing, software
13+ // distributed under the License is distributed on an "AS IS" BASIS,
14+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ // See the License for the specific language governing permissions and
16+ // limitations under the License.
17+ //
18+ // </copyright>
19+ // ------------------------------------------------------------------------------------------------
20+
21+ namespace SySML2 . NET . REST . Tests
22+ {
23+ using System ;
24+ using System . Linq ;
25+ using System . Net . Http ;
26+ using System . Threading ;
27+ using System . Threading . Tasks ;
28+
29+ using SysML2 . NET . Serializer . Json ;
30+
31+ using NUnit . Framework ;
32+
33+ /// <summary>
34+ /// Suite of tests for the <see cref="RestClient"/> class
35+ /// </summary>
36+ public class RestClientTestFixture
37+ {
38+ private string baseUri ;
39+
40+ private CancellationTokenSource cancellationTokenSource ;
41+
42+ private IRestClient restClient ;
43+
44+ private Guid projectId ;
45+
46+ private Guid branchId ;
47+
48+ private Guid commitId ;
49+
50+ private Guid tagId ;
51+
52+ private Guid elementId ;
53+
54+ [ SetUp ]
55+ public void Setup ( )
56+ {
57+ this . baseUri = "http://sysml2-sst.intercax.com:9000" ;
58+
59+ this . cancellationTokenSource = new CancellationTokenSource ( ) ;
60+
61+ var httpClient = new HttpClient ( ) ;
62+ var deserializer = new DeSerializer ( ) ;
63+ var serializer = new Serializer ( ) ;
64+
65+ this . projectId = Guid . Parse ( "2e912d1b-a31c-4f93-b082-2c0aff296ea0" ) ;
66+ this . branchId = Guid . Parse ( "047c94c7-e8dc-420a-a0fb-0b19fc57c998" ) ;
67+ this . commitId = Guid . Parse ( "c5c5f0a2-5cce-4a2c-a083-97f39a576b53" ) ;
68+ this . tagId = Guid . Parse ( "79722f63-0592-40e8-941f-cbf60c14243e" ) ;
69+ this . elementId = Guid . Parse ( "00730052-0ac7-4344-8a90-a3d70da21ccb" ) ;
70+
71+ this . restClient = new RestClient ( httpClient , deserializer , serializer ) ;
72+ }
73+
74+ [ Test ]
75+ public async Task Verify_that_RestClient_can_be_opened_and_that_projects_are_returned ( )
76+ {
77+ var projects = await this . restClient . Open ( "john" , "doe" , this . baseUri , this . cancellationTokenSource . Token ) ;
78+
79+ Assert . That ( projects , Is . Not . Empty ) ;
80+ }
81+
82+ [ Test ]
83+ public async Task Verify_that_projects_can_be_requested ( )
84+ {
85+ Assert . DoesNotThrowAsync ( async ( ) => await this . restClient . Open ( "john" , "doe" , this . baseUri , this . cancellationTokenSource . Token ) ) ;
86+
87+ var projects = await this . restClient . RequestProjects ( null , null , this . cancellationTokenSource . Token ) ;
88+
89+ Assert . That ( projects , Is . Not . Empty ) ;
90+
91+ projects = await this . restClient . RequestProjects ( this . projectId , null , this . cancellationTokenSource . Token ) ;
92+
93+ var project = projects . Single ( ) ;
94+
95+ Assert . That ( project . Name , Is . EqualTo ( "Spacecraft project with branches and tags - 2022-08-12 16:03:49.344073" ) ) ;
96+ }
97+
98+ [ Test ]
99+ public async Task Verify_that_branches_in_a_project_can_be_requested ( )
100+ {
101+ Assert . DoesNotThrowAsync ( async ( ) => await this . restClient . Open ( "john" , "doe" , this . baseUri , this . cancellationTokenSource . Token ) ) ;
102+
103+ var branches = await this . restClient . RequestBranches ( this . projectId , null , null , this . cancellationTokenSource . Token ) ;
104+
105+ Assert . That ( branches , Is . Not . Empty ) ;
106+
107+ branches = await this . restClient . RequestBranches ( this . projectId , this . branchId , null , this . cancellationTokenSource . Token ) ;
108+
109+ var branch = branches . Single ( ) ;
110+
111+ Assert . That ( branch . Name , Is . EqualTo ( "main" ) ) ;
112+ Assert . That ( branch . Head , Is . EqualTo ( Guid . Parse ( "7aaae0dd-63f2-445f-b494-43e3305d3394" ) ) ) ;
113+ Assert . That ( branch . OwningProject , Is . EqualTo ( this . projectId ) ) ;
114+ }
115+
116+ [ Test ]
117+ public async Task Verify_that_commits_in_a_project_can_be_requested ( )
118+ {
119+ Assert . DoesNotThrowAsync ( async ( ) => await this . restClient . Open ( "john" , "doe" , this . baseUri , this . cancellationTokenSource . Token ) ) ;
120+
121+ var commits = await this . restClient . RequestCommits ( this . projectId , null , null , this . cancellationTokenSource . Token ) ;
122+
123+ Assert . That ( commits , Is . Not . Empty ) ;
124+
125+ Assert . Warn ( "deserializer is too strict for the pilot implementation response" ) ;
126+
127+ return ;
128+
129+ commits = await this . restClient . RequestCommits ( this . projectId , this . commitId , null , this . cancellationTokenSource . Token ) ;
130+
131+ var commit = commits . Single ( ) ;
132+
133+ Assert . That ( commit . PreviousCommit , Is . EqualTo ( Guid . Parse ( "7aaae0dd-63f2-445f-b494-43e3305d3394" ) ) ) ;
134+ Assert . That ( commit . OwningProject , Is . EqualTo ( this . projectId ) ) ;
135+ }
136+
137+ [ Test ]
138+ public async Task Verify_that_tags_in_a_project_can_be_requested ( )
139+ {
140+ Assert . DoesNotThrowAsync ( async ( ) => await this . restClient . Open ( "john" , "doe" , this . baseUri , this . cancellationTokenSource . Token ) ) ;
141+
142+ var tags = await this . restClient . RequestTags ( this . projectId , null , null , this . cancellationTokenSource . Token ) ;
143+
144+ Assert . That ( tags , Is . Not . Empty ) ;
145+
146+ tags = await this . restClient . RequestTags ( this . projectId , this . tagId , null , this . cancellationTokenSource . Token ) ;
147+
148+ var tag = tags . Single ( ) ;
149+
150+ Assert . That ( tag . Name , Is . EqualTo ( "Spacecraft Internal Release 0.2 build 1" ) ) ;
151+ Assert . That ( tag . OwningProject , Is . EqualTo ( this . projectId ) ) ;
152+ }
153+
154+ [ Test ]
155+ public async Task Verify_that_elements_in_a_project_commit_can_be_requested ( )
156+ {
157+ Assert . DoesNotThrowAsync ( async ( ) => await this . restClient . Open ( "john" , "doe" , this . baseUri , this . cancellationTokenSource . Token ) ) ;
158+
159+ Assert . Warn ( "deserializer is too strict for the pilot implementation response" ) ;
160+
161+ return ;
162+
163+ var elements = await this . restClient . RequestElements ( this . projectId , this . commitId , null , null , this . cancellationTokenSource . Token ) ;
164+
165+ Assert . That ( elements , Is . Not . Empty ) ;
166+
167+ elements = await this . restClient . RequestElements ( this . projectId , this . commitId , this . elementId , null , this . cancellationTokenSource . Token ) ;
168+
169+ var element = elements . Single ( ) ;
170+
171+ Assert . That ( element . Name , Is . EqualTo ( "Propulsion System" ) ) ;
172+ }
173+ }
174+ }
0 commit comments