11// --------------------------------------------------------------------------------------------------------------------
2- // <copyright file="WSPDalTestFixture.cs" company="RHEA S.A.">
3- // Copyright (c) 2015 RHEA S.A.
2+ // <copyright file="WSPDalTestFixture.cs" company="RHEA System S.A.">
3+ // Copyright (c) 2015-2018 RHEA System S.A.
44// </copyright>
55// --------------------------------------------------------------------------------------------------------------------
66
@@ -24,7 +24,7 @@ namespace CDP4WspDal.Tests
2424 using CDP4Dal . Operations ;
2525 using CDP4WspDal ;
2626 using NUnit . Framework ;
27-
27+
2828 using File = System . IO . File ;
2929 using Thing = CDP4Common . CommonData . Thing ;
3030
@@ -48,7 +48,7 @@ public class WspDalTestFixture
4848 private IterationSetup iterationSetup ;
4949 private SiteReferenceDataLibrary siteReferenceDataLibrary ;
5050 private ModelReferenceDataLibrary modelReferenceDataLibrary ;
51-
51+
5252 [ SetUp ]
5353 public void SetUp ( )
5454 {
@@ -62,7 +62,7 @@ public void SetUp()
6262 this . siteDirectory = new SiteDirectory ( Guid . Parse ( "f13de6f8-b03a-46e7-a492-53b2f260f294" ) , this . session . Assembler . Cache , this . uri ) ;
6363 var lazySiteDirectory = new Lazy < Thing > ( ( ) => this . siteDirectory ) ;
6464 lazySiteDirectory . Value . Cache . TryAdd ( new Tuple < Guid , Guid ? > ( lazySiteDirectory . Value . Iid , null ) , lazySiteDirectory ) ;
65-
65+
6666 this . PopulateSiteDirectory ( ) ;
6767 }
6868
@@ -115,7 +115,7 @@ public async Task VerifyThatOpenReturnsDTOs()
115115
116116 Assert . AreEqual ( 60 , amountOfDtos ) ;
117117 }
118-
118+
119119 [ Test ]
120120 public async Task VerifThatAClosedDalCannotBeClosedAgain ( )
121121 {
@@ -131,7 +131,7 @@ public async Task VerifThatAClosedDalCannotBeClosedAgain()
131131 public async Task VerifyThatIfCredentialsAreNullExceptionIsThrown ( )
132132 {
133133 var dal = new WspDal ( ) ;
134-
134+
135135 Assert . That ( async ( ) => await dal . Open ( null , new CancellationToken ( ) ) , Throws . TypeOf < NullReferenceException > ( ) ) ;
136136 }
137137
@@ -142,10 +142,10 @@ public async Task VerifyThatIfNotHttpOrHttpsExceptionIsThrown()
142142 var invalidCredentials = new Credentials ( "John" , "a password" , uri ) ;
143143
144144 var dal = new WspDal ( ) ;
145-
145+
146146 Assert . That ( async ( ) => await dal . Open ( invalidCredentials , new CancellationToken ( ) ) , Throws . TypeOf < ArgumentException > ( ) ) ;
147147 }
148-
148+
149149 [ Test ]
150150 public async Task VerifyThatIfCredentialsAreNullOnReadExceptionIsThrown ( )
151151 {
@@ -154,10 +154,10 @@ public async Task VerifyThatIfCredentialsAreNullOnReadExceptionIsThrown()
154154 organizationDto . AddContainer ( ClassKind . SiteDirectory , Guid . Parse ( "eb77f3e1-a0f3-412d-8ed6-b8ce881c0145" ) ) ;
155155
156156 var dal = new WspDal ( ) ;
157-
157+
158158 Assert . That ( async ( ) => await dal . Read ( organizationDto , new CancellationToken ( ) ) , Throws . TypeOf < InvalidOperationException > ( ) ) ;
159159 }
160-
160+
161161 [ Test ]
162162 public void VerifyThatWriteThrowsException ( )
163163 {
@@ -238,7 +238,7 @@ public async Task IntegrationTest()
238238
239239 foreach ( var container in topcontainers )
240240 {
241- returned = await this . dal . Read ( container . Value . ToDto ( ) , this . cancelationTokenSource . Token , attributes ) ;
241+ returned = await this . dal . Read ( container . Value . ToDto ( ) , this . cancelationTokenSource . Token , attributes ) ;
242242 await assembler . Synchronize ( returned ) ;
243243 }
244244 }
@@ -251,7 +251,7 @@ public void VerifyThatWSPPostBodyIsCorrectlyResolves()
251251
252252 var context = "/SiteDirectory/f289023d-41e8-4aaf-aae5-1be1ecf24bac" ;
253253 var operationContainer = new OperationContainer ( context ) ;
254-
254+
255255 var testDtoOriginal = new CDP4Common . DTO . Alias ( iid : Guid . NewGuid ( ) , rev : 1 )
256256 {
257257 Content = "content" ,
@@ -260,7 +260,7 @@ public void VerifyThatWSPPostBodyIsCorrectlyResolves()
260260 } ;
261261 testDtoOriginal . AddContainer ( ClassKind . DomainOfExpertise , domainOfExpertiseIid ) ;
262262 testDtoOriginal . AddContainer ( ClassKind . SiteDirectory , siteDirecortoryIid ) ;
263-
263+
264264 var testDtoModified = new CDP4Common . DTO . Alias ( iid : testDtoOriginal . Iid , rev : 1 )
265265 {
266266 Content = "content2" ,
@@ -341,14 +341,14 @@ public void VerifyThatWSPPostBodyIsCorrectlyResolves()
341341 [ Category ( "WSP_dependent" ) ]
342342 public async Task VerifyThatReadIterationWorks ( )
343343 {
344- var dal = new WspDal { Session = this . session } ;
345- var credentials = new Credentials ( "admin" , "pass" , new Uri ( "https://cdp4services-public.rheagroup.com" ) ) ;
344+ var dal = new WspDal { Session = this . session } ;
345+ var credentials = new Credentials ( "admin" , "pass" , new Uri ( "https://cdp4services-public.rheagroup.com" ) ) ;
346346 var session = new Session ( dal , credentials ) ;
347-
347+
348348 var returned = await dal . Open ( credentials , this . cancelationTokenSource . Token ) ;
349349
350- session . Assembler . Synchronize ( returned ) ;
351-
350+ await session . Assembler . Synchronize ( returned ) ;
351+
352352 var siteDir = session . Assembler . RetrieveSiteDirectory ( ) ;
353353 var modelSetup = siteDir . Model . Single ( x => x . ShortName == "LOFT" ) ;
354354 var iterationSetup = modelSetup . IterationSetup . First ( ) ;
@@ -426,13 +426,13 @@ public async Task VerifyThatFileCanBeUploaded()
426426 var commonFileStoreModified = new CDP4Common . DTO . CommonFileStore ( commonFileStoreIid , 0 ) ;
427427 commonFileStoreModified . File . Add ( fileIid ) ;
428428 commonFileStoreModified . AddContainer ( ClassKind . EngineeringModel , engineeringModeliid ) ;
429-
429+
430430 var file = new CDP4Common . DTO . File ( Guid . NewGuid ( ) , 0 ) ;
431431 file . Owner = domainOfExpertiseIid ;
432432 file . FileRevision . Add ( fileRevisionIid ) ;
433433 file . AddContainer ( ClassKind . CommonFileStore , commonFileStoreIid ) ;
434434 file . AddContainer ( ClassKind . EngineeringModel , engineeringModeliid ) ;
435-
435+
436436 var fileRevision = new CDP4Common . DTO . FileRevision ( Guid . NewGuid ( ) , 0 ) ;
437437 fileRevision . Name = "testfile" ;
438438 fileRevision . ContentHash = contentHash ;
@@ -441,10 +441,10 @@ public async Task VerifyThatFileCanBeUploaded()
441441 fileRevision . AddContainer ( ClassKind . File , fileIid ) ;
442442 fileRevision . AddContainer ( ClassKind . CommonFileStore , commonFileStoreIid ) ;
443443 fileRevision . AddContainer ( ClassKind . EngineeringModel , engineeringModeliid ) ;
444-
444+
445445 var context = string . Format ( "/EngineeringModel/{0}/iteration/{1}" , engineeringModeliid , iterationiid ) ;
446446 var operationContainer = new OperationContainer ( context ) ;
447-
447+
448448 var updateCommonFileStoreOperation = new Operation ( commonFileStoreOriginal , commonFileStoreModified , OperationKind . Update ) ;
449449 operationContainer . AddOperation ( updateCommonFileStoreOperation ) ;
450450
@@ -473,9 +473,45 @@ public void VerifyThatWritingMultipleOperationContainersIsNotSupported()
473473
474474 Assert . Throws < NotSupportedException > ( ( ) => dal . Write ( operationContainers ) ) ;
475475
476- Assert . Throws < NotSupportedException > ( ( ) => dal . Write ( operationContainers ) ) ;
476+ Assert . Throws < NotSupportedException > ( ( ) => dal . Write ( operationContainers ) ) ;
477477 }
478-
478+
479+ [ Test ]
480+ [ Category ( "WSP_dependent" ) ]
481+ public async Task Verify_that_person_can_be_Posted ( )
482+ {
483+ var uri = new Uri ( "http://ocdt-dev.rheagroup.com" ) ;
484+ var credentials = new Credentials ( "admin" , "Dahubo12" , uri ) ;
485+
486+ var wspdal = new WspDal ( ) ;
487+ var dtos = await wspdal . Open ( credentials , this . cancelationTokenSource . Token ) ;
488+
489+ var siteDirectory = ( CDP4Common . DTO . SiteDirectory ) dtos . Single ( x => x . ClassKind == ClassKind . SiteDirectory ) ;
490+
491+ var context = siteDirectory . Route ;
492+ var operationContainer = new OperationContainer ( context , siteDirectory . RevisionNumber ) ;
493+
494+ var person = new CDP4Common . DTO . Person ( Guid . NewGuid ( ) , 1 ) ;
495+ person . ShortName = Guid . NewGuid ( ) . ToString ( ) ;
496+ person . Surname = Guid . NewGuid ( ) . ToString ( ) ;
497+ person . GivenName = Guid . NewGuid ( ) . ToString ( ) ;
498+ person . AddContainer ( ClassKind . SiteDirectory , Guid . Parse ( "eb77f3e1-a0f3-412d-8ed6-b8ce881c0145" ) ) ;
499+
500+ var operation1 = new Operation ( null , person , OperationKind . Create ) ;
501+ operationContainer . AddOperation ( operation1 ) ;
502+
503+ var siteDirectoryClone = siteDirectory . DeepClone < CDP4Common . DTO . SiteDirectory > ( ) ;
504+ siteDirectoryClone . Person . Add ( person . Iid ) ;
505+ var operation2 = new Operation ( siteDirectory , siteDirectoryClone , OperationKind . Update ) ;
506+ operationContainer . AddOperation ( operation2 ) ;
507+
508+ var result = await wspdal . Write ( operationContainer ) ;
509+
510+ var resultPerson = ( CDP4Common . DTO . Person ) result . Single ( x => x . Iid == person . Iid ) ;
511+
512+ Assert . NotNull ( resultPerson ) ;
513+ }
514+
479515 /// <summary>
480516 /// Set the credentials property so DAL appears to be open
481517 /// </summary>
@@ -501,4 +537,4 @@ private string GetAssemblyDirectory()
501537 return directory ;
502538 }
503539 }
504- }
540+ }
0 commit comments