public async Task VerifyThatReadRdlNotWorksWithoutActivePerson() { var siteDirectoryPoco = new CDP4Common.SiteDirectoryData.SiteDirectory(this.sieSiteDirectoryDto.Iid, this.session.Assembler.Cache, this.uri); var johnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; siteDirectoryPoco.Person.Add(johnDoe); var rdlDto = new CDP4Common.DTO.SiteReferenceDataLibrary { Iid = Guid.NewGuid() }; var rdlPoco = new CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary { Iid = rdlDto.Iid, Name = rdlDto.Name, ShortName = rdlDto.ShortName, Container = siteDirectoryPoco }; this.session.GetType().GetProperty("ActivePerson")?.SetValue(this.session, null, null); await this.session.Assembler.Synchronize(new List <Thing> { rdlDto }); Assert.ThrowsAsync <InvalidOperationException>(async() => await this.session.Read(rdlPoco)); }
/// <summary> /// Allow the API user to update the copyright information with custom data /// </summary> /// <param name="person">The <see cref="CDP4Common.SiteDirectoryData.Person"/> that is used to create the <see cref="ExchangeFileHeader"/></param> /// <param name="headerCopyright">Header copyright text</param> /// <param name="headerRemark">Header remark text</param> public void UpdateExchangeFileHeader(CDP4Common.SiteDirectoryData.Person person, string headerCopyright = null, string headerRemark = null) { var exchangeFileHeader = JsonFileDalUtils.CreateExchangeFileHeader(person); exchangeFileHeader.Remark = headerRemark ?? exchangeFileHeader.Remark; exchangeFileHeader.Copyright = headerCopyright ?? exchangeFileHeader.Copyright; this.FileHeader = exchangeFileHeader; }
public async Task VerifyThatWriteWorksWithoutEventHandler() { var context = $"/SiteDirectory/{Guid.NewGuid()}"; var johnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; this.session.GetType().GetProperty("ActivePerson")?.SetValue(this.session, johnDoe, null); await this.session.Write(new OperationContainer(context)); this.mockedDal.Verify(x => x.Write(It.IsAny <OperationContainer>(), It.IsAny <IEnumerable <string> >()), Times.Exactly(1)); }
public void Setup() { this.session = new Mock <ISession>(); this.assembler = new Assembler(this.uri); this.permissionService = new Mock <IPermissionService>(); this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object); this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>(); this.panelNavigationService = new Mock <IPanelNavigationService>(); this.dropinfo = new Mock <IDropInfo>(); this.cache = this.assembler.Cache; this.sitedir = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri); this.modelsetup = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri) { Name = "model" }; this.iterationsetup = new IterationSetup(Guid.NewGuid(), this.cache, this.uri); this.person = new Person(Guid.NewGuid(), this.cache, this.uri); this.domain = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri) { Name = "domain" }; this.participant = new Participant(Guid.NewGuid(), this.cache, this.uri) { Person = this.person, SelectedDomain = this.domain }; this.sitedir.Model.Add(this.modelsetup); this.sitedir.Person.Add(this.person); this.sitedir.Domain.Add(this.domain); this.modelsetup.IterationSetup.Add(this.iterationsetup); this.modelsetup.Participant.Add(this.participant); this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri) { EngineeringModelSetup = this.modelsetup }; this.iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri) { IterationSetup = this.iterationsetup }; this.model.Iteration.Add(this.iteration); this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.sitedir); this.session.Setup(x => x.ActivePerson).Returns(this.person); this.session.Setup(x => x.OpenIterations).Returns(new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> >()); this.session.Setup(x => x.Assembler).Returns(this.assembler); this.cache.TryAdd(new CacheKey(this.iteration.Iid, null), new Lazy <Thing>(() => this.iteration)); }
public void VerifyThatSessionNameIsProperlyNamed() { var siteDirectoryPoco = new CDP4Common.SiteDirectoryData.SiteDirectory(this.sieSiteDirectoryDto.Iid, this.session.Assembler.Cache, this.uri); var johnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { Surname = "Doe", GivenName = "John" }; siteDirectoryPoco.Person.Add(johnDoe); this.session.GetType().GetProperty("ActivePerson")?.SetValue(this.session, johnDoe, null); Assert.AreEqual("http://www.rheagroup.com/ - John Doe", this.session.Name); }
public async Task VerifyThatOpenSiteRDLUpdatesListInSession() { var siteDir = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), null, null); var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; var rdlDto = new CDP4Common.DTO.SiteReferenceDataLibrary { Iid = Guid.NewGuid() }; var siteDirDto = new CDP4Common.DTO.SiteDirectory() { Iid = Guid.NewGuid() }; var requiredPocoDto = new CDP4Common.DTO.SiteReferenceDataLibrary() { Iid = Guid.NewGuid() }; var requiredPocoRdl = new CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary(requiredPocoDto.Iid, null, null); rdlDto.RequiredRdl = requiredPocoDto.Iid; var credentials = new Credentials("admin", "pass", new Uri("http://www.rheagroup.com")); var session2 = new Session(this.mockedDal.Object, credentials); var rdlPoco = new CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary { Iid = rdlDto.Iid, Name = rdlDto.Name, ShortName = rdlDto.ShortName, Container = siteDir, RequiredRdl = requiredPocoRdl }; var thingsToAdd = new List <Thing>() { siteDirDto, requiredPocoDto, rdlDto }; session2.GetType().GetProperty("ActivePerson").SetValue(session2, JohnDoe, null); await session2.Assembler.Synchronize(thingsToAdd); Assert.IsEmpty(session2.OpenReferenceDataLibraries); await session2.Read(rdlPoco); Assert.AreEqual(2, session2.OpenReferenceDataLibraries.ToList().Count()); await session2.Close(); Assert.IsEmpty(session2.OpenReferenceDataLibraries); }
public void VerifyThatCancelWriteWorks() { var context = $"/SiteDirectory/{Guid.NewGuid()}"; var johnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; this.session.GetType().GetProperty("ActivePerson")?.SetValue(this.session, johnDoe, null); this.session.BeforeWrite += (o, args) => { args.Cancelled = true; }; Assert.ThrowsAsync <OperationCanceledException>(async() => await this.session.Write(new OperationContainer(context))); this.mockedDal.Verify(x => x.Write(It.IsAny <OperationContainer>(), It.IsAny <IEnumerable <string> >()), Times.Exactly(0)); }
public async Task VerifyThatWriteWithEmptyResponseSendsMessages() { var beginUpdateReceived = false; var endUpdateReceived = false; var writeWithNoResultsTaskCompletionSource = new TaskCompletionSource <IEnumerable <Thing> >(); writeWithNoResultsTaskCompletionSource.SetResult(new List <Thing>()); this.mockedDal.Setup(x => x.Open(It.IsAny <Credentials>(), It.IsAny <CancellationToken>())).Returns(writeWithNoResultsTaskCompletionSource.Task); CDPMessageBus.Current.Listen <SessionEvent>() .Subscribe(x => { if (x.Status == SessionStatus.BeginUpdate) { beginUpdateReceived = true; return; } if (x.Status == SessionStatus.EndUpdate) { endUpdateReceived = true; } }); var context = $"/SiteDirectory/{Guid.NewGuid()}"; var johnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; this.session.GetType().GetProperty("ActivePerson").SetValue(session, johnDoe, null); await this.session.Write(new OperationContainer(context)); Assert.IsTrue(beginUpdateReceived); Assert.IsTrue(endUpdateReceived); }
public async Task VerifyThatReadRdlWorks() { var siteDir = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; this.session.Assembler.Cache.TryAdd(new CacheKey(siteDir.Iid, null), new Lazy <CDP4Common.CommonData.Thing>(() => siteDir)); var sitedirDto = new SiteDirectory(siteDir.Iid, 1); var rdl = new CDP4Common.DTO.SiteReferenceDataLibrary(Guid.NewGuid(), 1); sitedirDto.SiteReferenceDataLibrary.Add(rdl.Iid); var readOutput = new List <Thing> { sitedirDto, rdl }; var readTaskCompletionSource = new TaskCompletionSource <IEnumerable <Thing> >(); readTaskCompletionSource.SetResult(readOutput); this.mockedDal.Setup(x => x.Read(It.IsAny <Thing>(), It.IsAny <CancellationToken>(), It.IsAny <IQueryAttributes>())).Returns(readTaskCompletionSource.Task); var srdl = new SiteReferenceDataLibrary(rdl.Iid, null, null); srdl.Container = siteDir; this.session.GetType().GetProperty("ActivePerson").SetValue(this.session, JohnDoe, null); await this.session.Read(srdl); Assert.AreEqual(1, this.session.OpenReferenceDataLibraries.Count()); Assert.IsTrue(siteDir.SiteReferenceDataLibrary.Any()); }
public async Task VerifyThatReadIterationWorks() { var siteDir = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; var modelSetup = new CDP4Common.SiteDirectoryData.EngineeringModelSetup(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); var iterationSetup = new CDP4Common.SiteDirectoryData.IterationSetup(Guid.NewGuid(), this.session.Assembler.Cache, this.uri) { FrozenOn = DateTime.Now, IterationIid = Guid.NewGuid() }; var mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); var srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); var activeDomain = new DomainOfExpertise(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); mrdl.RequiredRdl = srdl; modelSetup.RequiredRdl.Add(mrdl); modelSetup.IterationSetup.Add(iterationSetup); siteDir.Model.Add(modelSetup); siteDir.SiteReferenceDataLibrary.Add(srdl); siteDir.Domain.Add(activeDomain); siteDir.Person.Add(JohnDoe); this.session.Assembler.Cache.TryAdd(new CacheKey(siteDir.Iid, null), new Lazy <CDP4Common.CommonData.Thing>(() => siteDir)); this.session.Assembler.Cache.TryAdd(new CacheKey(JohnDoe.Iid, null), new Lazy <CDP4Common.CommonData.Thing>(() => JohnDoe)); this.session.Assembler.Cache.TryAdd(new CacheKey(modelSetup.Iid, null), new Lazy <CDP4Common.CommonData.Thing>(() => modelSetup)); this.session.Assembler.Cache.TryAdd(new CacheKey(mrdl.Iid, null), new Lazy <CDP4Common.CommonData.Thing>(() => mrdl)); this.session.Assembler.Cache.TryAdd(new CacheKey(srdl.Iid, null), new Lazy <CDP4Common.CommonData.Thing>(() => srdl)); this.session.Assembler.Cache.TryAdd(new CacheKey(siteDir.Iid, null), new Lazy <CDP4Common.CommonData.Thing>(() => siteDir)); this.session.Assembler.Cache.TryAdd(new CacheKey(iterationSetup.Iid, null), new Lazy <CDP4Common.CommonData.Thing>(() => iterationSetup)); this.session.GetType().GetProperty("ActivePerson").SetValue(this.session, JohnDoe, null); var participant = new CDP4Common.SiteDirectoryData.Participant(Guid.NewGuid(), this.session.Assembler.Cache, this.uri) { Person = this.session.ActivePerson }; modelSetup.Participant.Add(participant); var model = new EngineeringModel(Guid.NewGuid(), 1); var iteration = new Iteration(iterationSetup.IterationIid, 10) { IterationSetup = iterationSetup.Iid }; model.Iteration.Add(iteration.Iid); model.EngineeringModelSetup = modelSetup.Iid; var readOutput = new List <Thing> { model, iteration }; var readTaskCompletionSource = new TaskCompletionSource <IEnumerable <Thing> >(); readTaskCompletionSource.SetResult(readOutput); this.mockedDal.Setup(x => x.Read(It.IsAny <Iteration>(), It.IsAny <CancellationToken>(), It.IsAny <IQueryAttributes>())).Returns(readTaskCompletionSource.Task); var iterationToOpen = new CDP4Common.EngineeringModelData.Iteration(iteration.Iid, null, null); var modelToOpen = new CDP4Common.EngineeringModelData.EngineeringModel(model.Iid, null, null); iterationToOpen.Container = modelToOpen; await this.session.Read(iterationToOpen, activeDomain); this.mockedDal.Verify(x => x.Read(It.Is <Iteration>(i => i.Iid == iterationToOpen.Iid), It.IsAny <CancellationToken>(), It.IsAny <IQueryAttributes>()), Times.Once); var pair = this.session.OpenIterations.Single(); Assert.AreEqual(pair.Value.Item1, activeDomain); await this.session.Read(iterationToOpen, activeDomain); this.mockedDal.Verify(x => x.Read(It.Is <Iteration>(i => i.Iid == iterationToOpen.Iid), It.IsAny <CancellationToken>(), It.IsAny <IQueryAttributes>()), Times.Exactly(2)); pair = this.session.OpenIterations.Single(); Assert.AreEqual(pair.Value.Item1, activeDomain); var selectedDomain = this.session.QuerySelectedDomainOfExpertise(iterationToOpen); Assert.AreEqual(activeDomain.Iid, selectedDomain.Iid); this.mockedDal.Setup(x => x.Read(It.IsAny <Thing>(), It.IsAny <CancellationToken>(), It.IsAny <IQueryAttributes>())).Returns <Thing, CancellationToken, IQueryAttributes>( (x, y, z) => { // the method with iteration is called var xvariable = x; return(readTaskCompletionSource.Task); }); await this.session.Refresh(); this.mockedDal.Verify(x => x.Read <Thing>(It.IsAny <Thing>(), It.IsAny <CancellationToken>(), It.IsAny <IQueryAttributes>()), Times.Exactly(1)); Assert.ThrowsAsync <InvalidOperationException>(async() => await this.session.Read(iterationToOpen, null)); }
public async Task VerifyThatCloseModelRdlWorks() { var siteDir = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), null, null); var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; var modelRdlDto = new CDP4Common.DTO.ModelReferenceDataLibrary() { Iid = Guid.NewGuid() }; var siteDirDto = new CDP4Common.DTO.SiteDirectory() { Iid = Guid.NewGuid() }; var requiredPocoDto = new CDP4Common.DTO.SiteReferenceDataLibrary() { Iid = Guid.NewGuid() }; var requiredPocoRdl = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null); var containerEngModelSetupDto = new EngineeringModelSetup() { Iid = Guid.NewGuid() }; var containerEngModelSetup = new CDP4Common.SiteDirectoryData.EngineeringModelSetup() { Iid = containerEngModelSetupDto.Iid }; siteDir.Model.Add(containerEngModelSetup); modelRdlDto.RequiredRdl = requiredPocoDto.Iid; siteDir.Person.Add(JohnDoe); var credentials = new Credentials("admin", "pass", new Uri("http://www.rheagroup.com")); var session2 = new Session(this.mockedDal.Object, credentials); session2.GetType().GetProperty("ActivePerson").SetValue(session2, JohnDoe, null); var modelRdlPoco = new ModelReferenceDataLibrary { Iid = modelRdlDto.Iid, Name = modelRdlDto.Name, ShortName = modelRdlDto.ShortName, Container = containerEngModelSetup, RequiredRdl = requiredPocoRdl }; var thingsToAdd = new List <Thing>() { siteDirDto, requiredPocoDto, containerEngModelSetupDto, modelRdlDto }; await session2.Assembler.Synchronize(thingsToAdd); await session2.Read(modelRdlPoco); Assert.AreEqual(2, session2.OpenReferenceDataLibraries.ToList().Count()); Lazy <CDP4Common.CommonData.Thing> rdlPocoToClose; session2.Assembler.Cache.TryGetValue(new CacheKey(modelRdlPoco.Iid, null), out rdlPocoToClose); Assert.NotNull(rdlPocoToClose); await session2.CloseModelRdl((ModelReferenceDataLibrary)rdlPocoToClose.Value); // Checkt that closing a modelRDL doesn't close it's required SiteRDL Assert.AreEqual(1, session2.OpenReferenceDataLibraries.ToList().Count()); Assert.AreEqual(ClassKind.SiteReferenceDataLibrary, session2.OpenReferenceDataLibraries.First().ClassKind); }
public async Task VerifyThatCloseRdlWorks() { var siteDirectoryPoco = new CDP4Common.SiteDirectoryData.SiteDirectory(this.sieSiteDirectoryDto.Iid, this.session.Assembler.Cache, this.uri); var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; siteDirectoryPoco.Person.Add(JohnDoe); var rdlDto = new CDP4Common.DTO.SiteReferenceDataLibrary { Iid = Guid.NewGuid() }; var rdlPoco = new CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary { Iid = rdlDto.Iid, Name = rdlDto.Name, ShortName = rdlDto.ShortName, Container = siteDirectoryPoco }; var requiredSiteReferenceDataLibraryDto = new CDP4Common.DTO.SiteReferenceDataLibrary() { Iid = Guid.NewGuid() }; var requiredSiteReferenceDataLibraryPoco = new CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary(requiredSiteReferenceDataLibraryDto.Iid, this.session.Assembler.Cache, this.uri); rdlDto.RequiredRdl = requiredSiteReferenceDataLibraryDto.Iid; rdlPoco.RequiredRdl = requiredSiteReferenceDataLibraryPoco; var thingsToAdd = new List <Thing>() { requiredSiteReferenceDataLibraryDto, rdlDto }; session.GetType().GetProperty("ActivePerson").SetValue(session, JohnDoe, null); await session.Assembler.Synchronize(thingsToAdd); await session.Read(rdlPoco); Assert.AreEqual(2, session.OpenReferenceDataLibraries.ToList().Count()); Lazy <CDP4Common.CommonData.Thing> rdlPocoToClose; session.Assembler.Cache.TryGetValue(new CacheKey(rdlPoco.Iid, null), out rdlPocoToClose); await session.CloseRdl((CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary) rdlPocoToClose.Value); Assert.AreEqual(1, session.OpenReferenceDataLibraries.ToList().Count()); await session.Read(rdlPoco); Assert.AreEqual(2, session.OpenReferenceDataLibraries.ToList().Count()); session.Assembler.Cache.TryGetValue(new CacheKey(rdlPoco.Iid, null), out rdlPocoToClose); Lazy <CDP4Common.CommonData.Thing> requiredRdlToClose; session.Assembler.Cache.TryGetValue(new CacheKey(requiredSiteReferenceDataLibraryPoco.Iid, null), out requiredRdlToClose); await session.CloseRdl((CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary) requiredRdlToClose.Value); Assert.AreEqual(0, session.OpenReferenceDataLibraries.ToList().Count()); await session.CloseRdl((CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary) rdlPocoToClose.Value); Assert.AreEqual(0, session.OpenReferenceDataLibraries.ToList().Count()); }