/// <summary> /// Instantiate and deserialize the properties of a <paramref name="DomainFileStore"/> /// </summary> /// <param name="jObject">The <see cref="JObject"/> containing the data</param> /// <returns>The <see cref="DomainFileStore"/> to instantiate</returns> public static CDP4Common.DTO.DomainFileStore FromJsonObject(JObject jObject) { var iid = jObject["iid"].ToObject <Guid>(); var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject <int>(); var domainFileStore = new CDP4Common.DTO.DomainFileStore(iid, revisionNumber); if (!jObject["createdOn"].IsNullOrEmpty()) { domainFileStore.CreatedOn = jObject["createdOn"].ToObject <DateTime>(); } if (!jObject["excludedDomain"].IsNullOrEmpty()) { domainFileStore.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject <IEnumerable <Guid> >()); } if (!jObject["excludedPerson"].IsNullOrEmpty()) { domainFileStore.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject <IEnumerable <Guid> >()); } if (!jObject["file"].IsNullOrEmpty()) { domainFileStore.File.AddRange(jObject["file"].ToObject <IEnumerable <Guid> >()); } if (!jObject["folder"].IsNullOrEmpty()) { domainFileStore.Folder.AddRange(jObject["folder"].ToObject <IEnumerable <Guid> >()); } if (!jObject["isHidden"].IsNullOrEmpty()) { domainFileStore.IsHidden = jObject["isHidden"].ToObject <bool>(); } if (!jObject["modifiedOn"].IsNullOrEmpty()) { domainFileStore.ModifiedOn = jObject["modifiedOn"].ToObject <DateTime>(); } if (!jObject["name"].IsNullOrEmpty()) { domainFileStore.Name = jObject["name"].ToObject <string>(); } if (!jObject["owner"].IsNullOrEmpty()) { domainFileStore.Owner = jObject["owner"].ToObject <Guid>(); } if (!jObject["thingPreference"].IsNullOrEmpty()) { domainFileStore.ThingPreference = jObject["thingPreference"].ToObject <string>(); } return(domainFileStore); }
public async Task VerifyThatFileCanBeUploaded() { this.dal = new WspDal { Session = this.session }; var filename = @"TestData\testfile.pdf"; var directory = TestContext.CurrentContext.TestDirectory; var filepath = Path.Combine(directory, filename); var files = new List <string> { filepath }; var contentHash = "F73747371CFD9473C19A0A7F99BCAB008474C4CA"; var uri = new Uri("https://cdp4services-test.cdp4.org"); this.credentials = new Credentials("admin", "pass", uri); var returned = await this.dal.Open(this.credentials, this.cancelationTokenSource.Token); var engineeringModeliid = Guid.Parse("9ec982e4-ef72-4953-aa85-b158a95d8d56"); var iterationiid = Guid.Parse("e163c5ad-f32b-4387-b805-f4b34600bc2c"); var domainFileStoreIid = Guid.Parse("da7dddaa-02aa-4897-9935-e8d66c811a96"); var fileIid = Guid.NewGuid(); var fileRevisionIid = Guid.NewGuid(); var domainOfExpertiseIid = Guid.Parse("0e92edde-fdff-41db-9b1d-f2e484f12535"); var fileTypeIid = Guid.Parse("b16894e4-acb5-4e81-a118-16c00eb86d8f"); //PDF var participantIid = Guid.Parse("284334dd-e8e5-42d6-bc8a-715c507a7f02"); var originalDomainFileStore = new CDP4Common.DTO.DomainFileStore(domainFileStoreIid, 0); originalDomainFileStore.AddContainer(ClassKind.Iteration, iterationiid); originalDomainFileStore.AddContainer(ClassKind.EngineeringModel, engineeringModeliid); var modifiedDomainFileStore = new CDP4Common.DTO.DomainFileStore(domainFileStoreIid, 0); modifiedDomainFileStore.File.Add(fileIid); modifiedDomainFileStore.AddContainer(ClassKind.Iteration, iterationiid); modifiedDomainFileStore.AddContainer(ClassKind.EngineeringModel, engineeringModeliid); var file = new CDP4Common.DTO.File(fileIid, 0) { Owner = domainOfExpertiseIid }; file.FileRevision.Add(fileRevisionIid); file.AddContainer(ClassKind.DomainFileStore, domainFileStoreIid); file.AddContainer(ClassKind.Iteration, iterationiid); file.AddContainer(ClassKind.EngineeringModel, engineeringModeliid); var fileRevision = new CDP4Common.DTO.FileRevision(fileRevisionIid, 0); fileRevision.Name = "testfile"; fileRevision.ContentHash = contentHash; fileRevision.FileType.Add(new OrderedItem() { K = 1, V = fileTypeIid }); fileRevision.Creator = participantIid; fileRevision.AddContainer(ClassKind.File, fileIid); fileRevision.AddContainer(ClassKind.DomainFileStore, domainFileStoreIid); fileRevision.AddContainer(ClassKind.Iteration, iterationiid); fileRevision.AddContainer(ClassKind.EngineeringModel, engineeringModeliid); var context = $"/EngineeringModel/{engineeringModeliid}/iteration/{iterationiid}"; var operationContainer = new OperationContainer(context); var updateCommonFileStoreOperation = new Operation(originalDomainFileStore, modifiedDomainFileStore, OperationKind.Update); operationContainer.AddOperation(updateCommonFileStoreOperation); var createFileOperation = new Operation(null, file, OperationKind.Create); operationContainer.AddOperation(createFileOperation); var createFileRevisionOperation = new Operation(null, fileRevision, OperationKind.Create); operationContainer.AddOperation(createFileRevisionOperation); Assert.DoesNotThrowAsync(async() => await dal.Write(operationContainer, files)); }