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 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)); }