public async Task Verify_that_person_can_be_Posted() { var cdpServicesDal = new CdpServicesDal(); var dtos = await cdpServicesDal.Open(this.credentials, this.cancelationTokenSource.Token); var siteDirectory = (CDP4Common.DTO.SiteDirectory)dtos.Single(x => x.ClassKind == ClassKind.SiteDirectory); var context = siteDirectory.Route; var operationContainer = new OperationContainer(context, siteDirectory.RevisionNumber); var person = new CDP4Common.DTO.Person(Guid.NewGuid(), 1); person.ShortName = Guid.NewGuid().ToString(); person.Surname = Guid.NewGuid().ToString(); person.GivenName = Guid.NewGuid().ToString(); person.AddContainer(ClassKind.SiteDirectory, siteDirectory.Iid); var operation1 = new Operation(null, person, OperationKind.Create); operationContainer.AddOperation(operation1); var siteDirectoryClone = siteDirectory.DeepClone <CDP4Common.DTO.SiteDirectory>(); siteDirectoryClone.Person.Add(person.Iid); var operation2 = new Operation(siteDirectory, siteDirectoryClone, OperationKind.Update); operationContainer.AddOperation(operation2); var result = await cdpServicesDal.Write(operationContainer); var resultPerson = (CDP4Common.DTO.Person)result.Single(x => x.Iid == person.Iid); Assert.NotNull(resultPerson); }
public void VerifyThatWritingMultipleOperationContainersIsNotSupported() { var dal = new CdpServicesDal(); this.SetDalToBeOpen(dal); var contextOne = $"/EngineeringModel/{Guid.NewGuid()}/iteration/{Guid.NewGuid()}"; var contextTwo = $"/EngineeringModel/{Guid.NewGuid()}/iteration/{Guid.NewGuid()}"; var operationContainerOne = new OperationContainer(contextOne); var operationContainerTwo = new OperationContainer(contextTwo); var operationContainers = new List <OperationContainer> { operationContainerOne, operationContainerTwo }; Assert.Throws <NotSupportedException>(() => dal.Write(operationContainers)); Assert.Throws <NotSupportedException>(() => dal.Write(operationContainers)); }
public async Task Vefify_that_when_OperationContainer_is_empty_an_empty_is_returned() { var dal = new CdpServicesDal(); this.SetDalToBeOpen(dal); var context = $"/EngineeringModel/{Guid.NewGuid()}/iteration/{Guid.NewGuid()}"; var operationContainer = new OperationContainer(context); Assert.That(await dal.Write(operationContainer), Is.Empty); }
public async Task VerifyThatFileCanBeUploaded() { this.dal = new CdpServicesDal { 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)); }