Пример #1
0
        /// <summary>
        /// Resolve the properties of the current <see cref="IterationSetup"/> from its <see cref="DTO.Thing"/> counter-part
        /// </summary>
        /// <param name="dtoThing">The source <see cref="DTO.Thing"/></param>
        internal override void ResolveProperties(DTO.Thing dtoThing)
        {
            if (dtoThing == null)
            {
                throw new ArgumentNullException("dtoThing");
            }

            var dto = dtoThing as DTO.IterationSetup;

            if (dto == null)
            {
                throw new InvalidOperationException(string.Format("The DTO type {0} does not match the type of the current IterationSetup POCO.", dtoThing.GetType()));
            }

            this.CreatedOn   = dto.CreatedOn;
            this.Description = dto.Description;
            this.ExcludedDomain.ResolveList(dto.ExcludedDomain, dto.IterationContainerId, this.Cache);
            this.ExcludedPerson.ResolveList(dto.ExcludedPerson, dto.IterationContainerId, this.Cache);
            this.FrozenOn             = dto.FrozenOn;
            this.IsDeleted            = dto.IsDeleted;
            this.IterationIid         = dto.IterationIid;
            this.IterationNumber      = dto.IterationNumber;
            this.ModifiedOn           = dto.ModifiedOn;
            this.RevisionNumber       = dto.RevisionNumber;
            this.SourceIterationSetup = (dto.SourceIterationSetup.HasValue) ? this.Cache.Get <IterationSetup>(dto.SourceIterationSetup.Value, dto.IterationContainerId) : null;
            this.ThingPreference      = dto.ThingPreference;

            this.ResolveExtraProperties();
        }
        public async Task VerifyThatCloseModelWorks()
        {
            var siteDir     = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), null, null);
            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 containerEngModelSetupDto = new EngineeringModelSetup {
                Iid = Guid.NewGuid()
            };
            var containerEngModelSetup = new CDP4Common.SiteDirectoryData.EngineeringModelSetup {
                Iid = containerEngModelSetupDto.Iid
            };
            var iterationDto = new Iteration {
                Iid = Guid.NewGuid()
            };
            var iteration = new CDP4Common.EngineeringModelData.Iteration {
                Iid = iterationDto.Iid
            };
            var iterationSetupDto = new CDP4Common.DTO.IterationSetup {
                Iid = Guid.NewGuid(), IterationIid = iterationDto.Iid
            };

            iterationDto.IterationSetup = iterationSetupDto.IterationIid;
            siteDir.Model.Add(containerEngModelSetup);
            modelRdlDto.RequiredRdl = requiredPocoDto.Iid;

            var credentials = new Credentials("admin", "pass", new Uri("http://www.rheagroup.com"));
            var session2    = new Session(this.mockedDal.Object, credentials);

            var iterationSetup = new CDP4Common.SiteDirectoryData.IterationSetup {
                Iid = iterationSetupDto.Iid, Container = containerEngModelSetup, IterationIid = iteration.Iid
            };
            var thingsToAdd = new List <Thing> {
                siteDirDto, requiredPocoDto, containerEngModelSetupDto, modelRdlDto, iterationSetupDto
            };

            await session2.Assembler.Synchronize(thingsToAdd);

            var lazyiteration = new Lazy <CDP4Common.CommonData.Thing>(() => iteration);

            session2.Assembler.Cache.GetOrAdd(new CacheKey(iterationDto.Iid, null), lazyiteration);

            CDP4Common.CommonData.Thing changedObject = null;
            CDPMessageBus.Current.Listen <ObjectChangedEvent>(typeof(CDP4Common.EngineeringModelData.Iteration)).Subscribe(x => changedObject = x.ChangedThing);
            await session2.CloseIterationSetup(iterationSetup);

            Assert.NotNull(changedObject);
        }
Пример #3
0
        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 Verify_that_when_active_person_is_null_Iteration_is_not_read()
        {
            var iterationSetup = new CDP4Common.SiteDirectoryData.IterationSetup(Guid.NewGuid(), null, null)
            {
                FrozenOn = DateTime.Now, IterationIid = Guid.NewGuid()
            };
            var activeDomain = new DomainOfExpertise(Guid.NewGuid(), null, null);
            var model        = new EngineeringModel(Guid.NewGuid(), 1);
            var iteration    = new Iteration(Guid.NewGuid(), 10)
            {
                IterationSetup = iterationSetup.Iid
            };

            var iterationToOpen = new CDP4Common.EngineeringModelData.Iteration(iteration.Iid, null, null);
            var modelToOpen     = new CDP4Common.EngineeringModelData.EngineeringModel(model.Iid, null, null);

            iterationToOpen.Container = modelToOpen;

            Assert.ThrowsAsync <InvalidOperationException>(async() => await this.session.Read(iterationToOpen, activeDomain));
        }
        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));
        }