public async Task VerifyThatIterationIsDeletedWhenSetupIsDeleted()
        {
            var assembler = new Assembler(this.uri);

            var model = new EngineeringModel(Guid.NewGuid(), assembler.Cache, this.uri);
            var it1   = new Iteration(Guid.NewGuid(), assembler.Cache, this.uri);
            var it2   = new Iteration(Guid.NewGuid(), assembler.Cache, this.uri);

            model.Iteration.Add(it1);
            model.Iteration.Add(it2);

            var sitedir    = new SiteDirectory(Guid.NewGuid(), assembler.Cache, this.uri);
            var modelsetup = new EngineeringModelSetup(Guid.NewGuid(), assembler.Cache, this.uri)
            {
                EngineeringModelIid = model.Iid
            };
            var iterationsetup1 = new IterationSetup(Guid.NewGuid(), assembler.Cache, this.uri)
            {
                IterationIid = it1.Iid
            };
            var iterationsetup2 = new IterationSetup(Guid.NewGuid(), assembler.Cache, this.uri)
            {
                IterationIid = it2.Iid
            };

            sitedir.Model.Add(modelsetup);
            modelsetup.IterationSetup.Add(iterationsetup1);
            modelsetup.IterationSetup.Add(iterationsetup2);

            assembler.Cache.TryAdd(new CacheKey(sitedir.Iid, null), new Lazy <Thing>(() => sitedir));
            assembler.Cache.TryAdd(new CacheKey(modelsetup.Iid, null), new Lazy <Thing>(() => modelsetup));
            assembler.Cache.TryAdd(new CacheKey(iterationsetup1.Iid, null), new Lazy <Thing>(() => iterationsetup1));
            assembler.Cache.TryAdd(new CacheKey(iterationsetup2.Iid, null), new Lazy <Thing>(() => iterationsetup2));
            assembler.Cache.TryAdd(new CacheKey(model.Iid, null), new Lazy <Thing>(() => model));
            assembler.Cache.TryAdd(new CacheKey(it1.Iid, null), new Lazy <Thing>(() => it1));
            assembler.Cache.TryAdd(new CacheKey(it2.Iid, null), new Lazy <Thing>(() => it2));

            var sitedirdto = new Dto.SiteDirectory(sitedir.Iid, 1);

            sitedirdto.Model.Add(modelsetup.Iid);

            var itdto = (Dto.IterationSetup)iterationsetup1.ToDto();

            itdto.IsDeleted = true;

            Assert.IsTrue(assembler.Cache.ContainsKey(new CacheKey(it1.Iid, null)));
            await assembler.Synchronize(new List <Dto.Thing> {
                sitedirdto, itdto
            });

            Assert.IsFalse(assembler.Cache.ContainsKey(new CacheKey(it1.Iid, null)));
        }
        private void InitSessionThings()
        {
            // Site Directory
            this.siteDirectory = new SiteDirectory(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri);

            this.domain = new DomainOfExpertise(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri)
            {
                Name = "domain"
            };
            this.siteDirectory.Domain.Add(domain);

            this.person = new Person(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri)
            {
                ShortName     = credentials.UserName,
                GivenName     = credentials.UserName,
                Password      = credentials.Password,
                DefaultDomain = domain,
                IsActive      = true
            };
            this.siteDirectory.Person.Add(this.person);

            var participant = new Participant(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri)
            {
                Person = person
            };

            participant.Domain.Add(domain);

            // Site Rld
            var siteReferenceDataLibrary =
                new SiteReferenceDataLibrary(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri)
            {
                ShortName = "Generic_RDL"
            };
            var quantityKindParamType = new SimpleQuantityKind(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri)
            {
                Name      = "m",
                ShortName = "m"
            };

            siteReferenceDataLibrary.ParameterType.Add(quantityKindParamType);

            // Model Rdl
            var modelReferenceDataLibrary =
                new ModelReferenceDataLibrary(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri)
            {
                RequiredRdl = siteReferenceDataLibrary
            };

            this.siteDirectory.SiteReferenceDataLibrary.Add(siteReferenceDataLibrary);

            // Iteration
            this.iteration = new Iteration(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri);
            var iterationSetup = new IterationSetup(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri);

            this.iteration.IterationSetup = iterationSetup;

            // Engineering Model & Setup
            var engineeringModel = new EngineeringModel(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri);

            engineeringModel.Iteration.Add(this.iteration);

            this.engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.session.Object.Assembler.Cache, this.session.Object.Credentials.Uri)
            {
                EngineeringModelIid = engineeringModel.Iid
            };
            engineeringModel.EngineeringModelSetup = this.engineeringModelSetup;
            this.engineeringModelSetup.RequiredRdl.Add(modelReferenceDataLibrary);
            this.engineeringModelSetup.IterationSetup.Add(iterationSetup);
            this.engineeringModelSetup.Participant.Add(participant);

            this.siteDirectory.Model.Add(engineeringModelSetup);

            this.sessionThings = new Dictionary <Guid, CDP4Common.DTO.Thing>
            {
                { this.siteDirectory.Iid, this.siteDirectory.ToDto() },
                { this.domain.Iid, this.domain.ToDto() },
                { this.person.Iid, this.person.ToDto() },
                { participant.Iid, participant.ToDto() },
                { siteReferenceDataLibrary.Iid, siteReferenceDataLibrary.ToDto() },
                { quantityKindParamType.Iid, quantityKindParamType.ToDto() },
                { modelReferenceDataLibrary.Iid, modelReferenceDataLibrary.ToDto() },
                { this.engineeringModelSetup.Iid, this.engineeringModelSetup.ToDto() },
                { this.iteration.Iid, this.iteration.ToDto() },
                { iterationSetup.Iid, iterationSetup.ToDto() },
                { engineeringModel.Iid, engineeringModel.ToDto() }
            };

            this.session.Object.Assembler.Cache.TryAdd(new CacheKey(this.siteDirectory.Iid, null),
                                                       new Lazy <Thing>(() => this.siteDirectory));
            this.session.Object.Assembler.Cache.TryAdd(new CacheKey(this.domain.Iid, null),
                                                       new Lazy <Thing>(() => this.domain));
            this.session.Object.Assembler.Cache.TryAdd(new CacheKey(this.person.Iid, null),
                                                       new Lazy <Thing>(() => this.person));
            this.session.Object.Assembler.Cache.TryAdd(new CacheKey(participant.Iid, null),
                                                       new Lazy <Thing>(() => participant));
            this.session.Object.Assembler.Cache.TryAdd(new CacheKey(siteReferenceDataLibrary.Iid, null),
                                                       new Lazy <Thing>(() => siteReferenceDataLibrary));
            this.session.Object.Assembler.Cache.TryAdd(new CacheKey(quantityKindParamType.Iid, null),
                                                       new Lazy <Thing>(() => quantityKindParamType));
            this.session.Object.Assembler.Cache.TryAdd(new CacheKey(modelReferenceDataLibrary.Iid, null),
                                                       new Lazy <Thing>(() => modelReferenceDataLibrary));
            this.session.Object.Assembler.Cache.TryAdd(new CacheKey(this.engineeringModelSetup.Iid, null),
                                                       new Lazy <Thing>(() => this.engineeringModelSetup));
            this.session.Object.Assembler.Cache.TryAdd(new CacheKey(this.iteration.Iid, null),
                                                       new Lazy <Thing>(() => this.iteration));
            this.session.Object.Assembler.Cache.TryAdd(new CacheKey(iterationSetup.Iid, null),
                                                       new Lazy <Thing>(() => iterationSetup));
            this.session.Object.Assembler.Cache.TryAdd(new CacheKey(engineeringModel.Iid, null),
                                                       new Lazy <Thing>(() => engineeringModel));
        }