public void Setup()
        {
            this.npgsqlTransaction = null;
            this.fileService       = new Mock <IFileService>();
            this.fileRevision      = new FileRevision(Guid.NewGuid(), 0);
            this.file = new File(Guid.NewGuid(), 0);

            this.fileStore = new DomainFileStore
            {
                Iid  = Guid.NewGuid(),
                File =
                {
                    this.file.Iid
                }
            };

            this.fileService = new Mock <IFileService>();

            this.domainFileStoreService = new Mock <IDomainFileStoreService>();

            this.sideEffect = new FileRevisionSideEffect
            {
                DomainFileStoreService = this.domainFileStoreService.Object,
                FileService            = this.fileService.Object,
            };
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DomainFileStoreRowViewModel"/> class
 /// </summary>
 /// <param name="store">The associated <see cref="DomainFileStore"/></param>
 /// <param name="session">The <see cref="ISession"/></param>
 /// <param name="containerViewModel">The container view-model</param>
 public DomainFileStoreRowViewModel(DomainFileStore store, ISession session, IViewModelBase <Thing> containerViewModel)
     : base(store, session, containerViewModel)
 {
     this.folderCache = new Dictionary <Folder, FolderRowViewModel>();
     this.fileCache   = new Dictionary <File, FileRowViewModel>();
     this.UpdateProperties();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Allows derived classes to override and execute additional logic after a successful update operation.
        /// </summary>
        /// <param name="thing">
        /// The <see cref="Thing"/> instance that will be inspected.
        /// </param>
        /// <param name="container">
        /// The container instance of the <see cref="Thing"/> that is inspected.
        /// </param>
        /// <param name="originalThing">
        /// The original Thing.
        /// </param>
        /// <param name="transaction">
        /// The current transaction to the database.
        /// </param>
        /// <param name="partition">
        /// The database partition (schema) where the requested resource will be stored.
        /// </param>
        /// <param name="securityContext">
        /// The security Context used for permission checking.
        /// </param>
        public override void AfterUpdate(EngineeringModelSetup thing, Thing container, EngineeringModelSetup originalThing, NpgsqlTransaction transaction, string partition, ISecurityContext securityContext)
        {
            var newEngineeringModelPartition = this.RequestUtils.GetEngineeringModelPartitionString(thing.EngineeringModelIid);
            var newIterationPartition        = newEngineeringModelPartition.Replace(Utils.EngineeringModelPartition, Utils.IterationSubPartition);
            var iterationSetups = this.IterationSetupService.GetShallow(transaction, partition, thing.IterationSetup, securityContext).Cast <IterationSetup>();
            var iterations      = this.IterationService.GetShallow(transaction, newEngineeringModelPartition, iterationSetups.Select(i => i.IterationIid), securityContext).Cast <Iteration>();

            // determine which domains have been added and removed
            var removedDomains = originalThing.ActiveDomain.Except(thing.ActiveDomain).ToList();
            var addedDomains   = thing.ActiveDomain.Except(originalThing.ActiveDomain).ToList();

            foreach (var iteration in iterations)
            {
                var domainFileStores = this.DomainFileStoreService.GetShallow(transaction, newIterationPartition, iteration.DomainFileStore, securityContext).Cast <DomainFileStore>().ToList();

                // if domain was removed, remove the DomainFileStore as well
                foreach (var removedDomain in removedDomains)
                {
                    // see if one already exists
                    var domainFileStore = domainFileStores.SingleOrDefault(dfs => dfs.Owner.Equals(removedDomain));

                    if (domainFileStore == null)
                    {
                        // indicates that the model is in a broken state (no DomainFileStore for the given DomainOfExpertise). Be forgiving and allow the code to return to a steady state.
                        continue;
                    }

                    if (!this.DomainFileStoreService.DeleteConcept(transaction, newIterationPartition, domainFileStore, iteration))
                    {
                        throw new InvalidOperationException($"There was a problem deleting the DomainFileStore: {domainFileStore.Iid} contained by Iteration: {iteration.Iid}");
                    }
                }

                // create domain file store for every added domain
                foreach (var addedDomain in addedDomains)
                {
                    // see if one already exists
                    if (domainFileStores.Any(dfs => dfs.Owner.Equals(addedDomain)))
                    {
                        // indicates the model is in a broken state (a DomainFileStore was not cleaned up previously). Be forgiving and allow the domain to relink to it.
                        continue;
                    }

                    var newDomainFileStore = new DomainFileStore(Guid.NewGuid(), 1)
                    {
                        Owner     = addedDomain,
                        CreatedOn = DateTime.UtcNow
                    };

                    if (!this.DomainFileStoreService.CreateConcept(transaction, newIterationPartition, newDomainFileStore, iteration))
                    {
                        throw new InvalidOperationException($"There was a problem creating the new DomainFileStore: {newDomainFileStore.Iid} contained by Iteration: {iteration.Iid}");
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create a new <see cref="EngineeringModel"/> from scratch
        /// </summary>
        /// <param name="thing">The <see cref="EngineeringModelSetup"/></param>
        /// <param name="container">The container</param>
        /// <param name="transaction">The current transaction</param>
        /// <param name="partition">The partition</param>
        /// <param name="securityContext">The security context</param>
        private void CreateDefaultEngineeringModel(EngineeringModelSetup thing, Thing container, NpgsqlTransaction transaction, string partition, ISecurityContext securityContext)
        {
            // No need to create a model RDL for the created EngineeringModelSetup since is handled in the client. It happens in the same transaction as the creation of the EngineeringModelSetup itself
            var firstIterationSetup = this.CreateIterationSetup(thing, transaction, partition);

            this.CreateParticipant(thing, (SiteDirectory)container, transaction, partition);

            // The EngineeringModel schema (for the new EngineeringModelSetup) is already created from the DAO at this point, get its partition name
            var newEngineeringModelPartition = this.RequestUtils.GetEngineeringModelPartitionString(thing.EngineeringModelIid);

            // Create the engineering model in the newEngineeringModelPartition
            var engineeringModel = new EngineeringModel(thing.EngineeringModelIid, 1)
            {
                EngineeringModelSetup = thing.Iid
            };

            if (!this.EngineeringModelService.CreateConcept(transaction, newEngineeringModelPartition, engineeringModel, container))
            {
                var errorMessage = $"There was a problem creating the new EngineeringModel: {engineeringModel.Iid} from EngineeringModelSetup: {thing.Iid}";
                Logger.Error(errorMessage);
                throw new InvalidOperationException(errorMessage);
            }

            // Create the first iteration in the newEngineeringModelPartition
            var firstIteration = new Iteration(firstIterationSetup.IterationIid, 1)
            {
                IterationSetup = firstIterationSetup.Iid
            };

            if (!this.IterationService.CreateConcept(transaction, newEngineeringModelPartition, firstIteration, engineeringModel))
            {
                var errorMessage = $"There was a problem creating the new Iteration: {firstIteration.Iid} contained by EngineeringModel: {engineeringModel.Iid}";
                Logger.Error(errorMessage);
                throw new InvalidOperationException(errorMessage);
            }

            // switch to iteration partition:
            var newIterationPartition = newEngineeringModelPartition.Replace(Utils.EngineeringModelPartition, Utils.IterationSubPartition);

            // Create a Domain FileStore for the current domain in the first iteration
            var newDomainFileStore = new DomainFileStore(Guid.NewGuid(), 1)
            {
                Owner     = thing.ActiveDomain.Single(),
                CreatedOn = DateTime.UtcNow
            };

            if (!this.DomainFileStoreService.CreateConcept(transaction, newIterationPartition, newDomainFileStore, firstIteration))
            {
                var errorMessage = $"There was a problem creating the new DomainFileStore: {newDomainFileStore.Iid} contained by Iteration: {firstIteration.Iid}";
                Logger.Error(errorMessage);
                throw new InvalidOperationException(errorMessage);
            }

            this.CreateDefaultOption(firstIteration, transaction, newIterationPartition);
        }
        public void Setup()
        {
            this.npgsqlTransaction = null;
            this.securityContext   = new Mock <ISecurityContext>();

            // There is a chain a -> b -> c
            this.folderD = new Folder {
                Iid = Guid.NewGuid()
            };
            this.folderC = new Folder {
                Iid = Guid.NewGuid()
            };
            this.folderB = new Folder {
                Iid = Guid.NewGuid(), ContainingFolder = this.folderC.Iid
            };
            this.folderA = new Folder {
                Iid = Guid.NewGuid(), ContainingFolder = this.folderB.Iid
            };

            this.fileStore = new DomainFileStore
            {
                Iid    = Guid.NewGuid(),
                Folder =
                {
                    this.folderA.Iid, this.folderB.Iid, this.folderC.Iid
                }
            };

            this.domainFileStoreService = new Mock <IDomainFileStoreService>();
            this.folderService          = new Mock <IFolderService>();

            this.folderService
            .Setup(
                x => x.Get(
                    this.npgsqlTransaction,
                    It.IsAny <string>(),
                    new List <Guid> {
                this.folderA.Iid, this.folderB.Iid, this.folderC.Iid
            },
                    It.IsAny <ISecurityContext>()))
            .Returns(new List <Folder> {
                this.folderA, this.folderB, this.folderC
            });

            this.sideEffect = new FolderSideEffect
            {
                FolderService          = this.folderService.Object,
                DomainFileStoreService = this.domainFileStoreService.Object
            };
        }
Ejemplo n.º 6
0
        public void VerifyUpdateFolderRowsAddsNewFolders()
        {
            this.store = new DomainFileStore(Guid.NewGuid(), this.assembler.Cache, this.uri);
            var newTopLevelFolder = new Folder();

            newTopLevelFolder.Name = "TopLevelFolder";
            var newContainedFolder = new Folder();

            newContainedFolder.Name             = "ContainedFolder";
            newContainedFolder.ContainingFolder = newTopLevelFolder;
            this.store.Folder.Add(newTopLevelFolder);
            this.store.Folder.Add(newContainedFolder);
            var row = new DomainFileStoreRowViewModel(store, session.Object, null);

            Assert.AreSame(newTopLevelFolder.Name, ((FolderRowViewModel)row.ContainedRows.FirstOrDefault()).Name);
            Assert.AreSame(newContainedFolder.Name, ((FolderRowViewModel)row.ContainedRows.FirstOrDefault().ContainedRows.FirstOrDefault()).Name);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Serialize the <see cref="DomainFileStore"/>
        /// </summary>
        /// <param name="domainFileStore">The <see cref="DomainFileStore"/> to serialize</param>
        /// <returns>The <see cref="JObject"/></returns>
        private JObject Serialize(DomainFileStore domainFileStore)
        {
            var jsonObject = new JObject();

            jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), domainFileStore.ClassKind)));
            jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](domainFileStore.CreatedOn));
            jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](domainFileStore.ExcludedDomain.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](domainFileStore.ExcludedPerson.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("file", this.PropertySerializerMap["file"](domainFileStore.File.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("folder", this.PropertySerializerMap["folder"](domainFileStore.Folder.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("iid", this.PropertySerializerMap["iid"](domainFileStore.Iid));
            jsonObject.Add("isHidden", this.PropertySerializerMap["isHidden"](domainFileStore.IsHidden));
            jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](domainFileStore.ModifiedOn));
            jsonObject.Add("name", this.PropertySerializerMap["name"](domainFileStore.Name));
            jsonObject.Add("owner", this.PropertySerializerMap["owner"](domainFileStore.Owner));
            jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](domainFileStore.RevisionNumber));
            jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](domainFileStore.ThingPreference));
            return(jsonObject);
        }
Ejemplo n.º 8
0
        public void SetUp()
        {
            this.session = new Mock <ISession>();

            this.person = new Person(Guid.NewGuid(), this.cache, this.uri)
            {
                ShortName = "person",
                GivenName = "John",
                Surname   = "Doe"
            };

            this.participant = new Participant(Guid.NewGuid(), this.cache, this.uri)
            {
                Person   = this.person,
                IsActive = true,
            };

            this.store = new DomainFileStore(Guid.NewGuid(), this.cache, this.uri);
            this.file  = new File(Guid.NewGuid(), this.cache, this.uri);

            this.fileRevision1 = new FileRevision(Guid.NewGuid(), this.cache, this.uri)
            {
                Name      = "1",
                Creator   = this.participant,
                CreatedOn = new DateTime(1, 1, 1)
            };

            this.fileRevision2 = new FileRevision(Guid.NewGuid(), this.cache, this.uri)
            {
                Name      = "1.1",
                Creator   = this.participant,
                CreatedOn = new DateTime(1, 1, 2)
            };

            this.fileStoreFileAndFolderHandler = new Mock <IFileStoreFileAndFolderHandler>();
        }
Ejemplo n.º 9
0
        public void VerifyUpdateFileRowsAddsNewFiles()
        {
            this.store   = new DomainFileStore(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.folder1 = new Folder(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "1",
                CreatedOn = new DateTime(1, 1, 1),
                Creator   = this.participant
            };
            this.store.Folder.Add(this.folder1);
            this.file.FileRevision.Add(this.fileRevision1);
            this.file1.FileRevision.Add(this.file1Revision1);
            this.file.FileRevision.First().ContainingFolder = this.folder1;

            this.store.File.Add(this.file);
            this.store.File.Add(file1);

            var row = new DomainFileStoreRowViewModel(store, session.Object, null);

            Assert.AreEqual(2, row.ContainedRows.Count);
            Assert.AreEqual(folder1.Name, ((FolderRowViewModel)row.ContainedRows.FirstOrDefault()).Name);
            Assert.AreEqual(1, ((FolderRowViewModel)row.ContainedRows.FirstOrDefault()).ContainedRows.Count);
            Assert.IsInstanceOf <FileRowViewModel>(row.ContainedRows[1]);
        }
Ejemplo n.º 10
0
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.session = new Mock <ISession>();
            this.panelNavigationService       = new Mock <IPanelNavigationService>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.permissionService            = new Mock <IPermissionService>();
            this.dialogNavigationService      = new Mock <IDialogNavigationService>();
            this.serviceLocator      = new Mock <IServiceLocator>();
            this.downloadFileService = new Mock <IDownloadFileService>();

            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IDownloadFileService>()).Returns(this.downloadFileService.Object);

            this.assembler = new Assembler(this.uri);
            this.session.Setup(x => x.Assembler).Returns(this.assembler);
            this.session.Setup(x => x.DataSourceUri).Returns(this.uri.ToString);
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);

            this.sitedir = new SiteDirectory(Guid.NewGuid(), this.assembler.Cache, this.uri);

            this.engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name = "model"
            };

            this.iterationSetup = new IterationSetup(Guid.NewGuid(), this.assembler.Cache, this.uri);

            this.person = new Person(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                ShortName = "person",
                GivenName = "person",
            };

            this.participant = new Participant(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Person   = this.person,
                IsActive = true,
            };

            this.domain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "domain",
                ShortName = "d"
            };

            this.session.Setup(x => x.QueryDomainOfExpertise(It.IsAny <Iteration>())).Returns(new List <DomainOfExpertise>()
            {
                this.domain
            });
            this.srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri);

            this.mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                RequiredRdl = this.srdl
            };

            this.sitedir.Model.Add(this.engineeringModelSetup);
            this.engineeringModelSetup.IterationSetup.Add(this.iterationSetup);
            this.sitedir.Person.Add(this.person);
            this.sitedir.Domain.Add(this.domain);
            this.engineeringModelSetup.RequiredRdl.Add(this.mrdl);
            this.sitedir.SiteReferenceDataLibrary.Add(this.srdl);
            this.engineeringModelSetup.Participant.Add(this.participant);
            this.participant.Domain.Add(this.domain);

            this.model = new EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                EngineeringModelSetup = this.engineeringModelSetup
            };

            this.iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                IterationSetup = this.iterationSetup
            };

            this.model.Iteration.Add(this.iteration);

            var lazyIteration = new Lazy <Thing>(() => this.iteration);

            this.assembler.Cache.GetOrAdd(new CacheKey(this.iteration.Iid, null), lazyIteration);

            this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true);
            this.permissionService.Setup(x => x.CanWrite(It.IsAny <ClassKind>(), It.IsAny <Thing>())).Returns(true);

            this.session.Setup(x => x.QuerySelectedDomainOfExpertise(this.iteration)).Returns(this.domain);
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
            this.session.Setup(x => x.ActivePerson).Returns(this.person);

            this.store = new DomainFileStore(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Owner = this.domain
            };

            this.folder1 = new Folder(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "1",
                CreatedOn = new DateTime(1, 1, 1),
                Creator   = this.participant,
                Owner     = this.domain
            };

            this.folder2 = new Folder(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "2",
                CreatedOn = new DateTime(1, 1, 1),
                Creator   = this.participant,
                Owner     = this.domain
            };

            this.file = new File(Guid.NewGuid(), this.assembler.Cache, this.uri);

            this.fileRevision1 = new FileRevision(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "1",
                Creator   = this.participant,
                CreatedOn = new DateTime(1, 1, 1)
            };

            this.fileRevision2 = new FileRevision(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "1",
                Creator   = this.participant,
                CreatedOn = new DateTime(1, 1, 2)
            };

            this.downloadFileService.Setup(x => x.ExecuteDownloadFile(It.IsAny <IDownloadFileViewModel>(), It.IsAny <File>())).Returns(Task.Delay(100));

            this.vm = new DomainFileStoreBrowserViewModel(
                this.iteration,
                this.session.Object,
                this.thingDialogNavigationService.Object,
                this.panelNavigationService.Object,
                this.dialogNavigationService.Object,
                null);
        }
Ejemplo n.º 11
0
        public void Setup()
        {
            this.session   = new Mock <ISession>();
            this.assembler = new Assembler(this.uri);

            this.domain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "domain",
                ShortName = "d"
            };

            this.store = new DomainFileStore(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.rev.SetValue(this.store, 2);

            this.file = new File(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Container = this.store
            };

            this.file1 = new File(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Container = this.store
            };

            this.person = new Person(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                ShortName = "person",
                GivenName = "person",
            };

            this.participant = new Participant(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Person   = this.person,
                IsActive = true,
            };

            this.fileRevision1 = new FileRevision(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "1",
                Creator   = this.participant,
                CreatedOn = new DateTime(1, 1, 1)
            };

            this.file1Revision1 = new FileRevision(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "11",
                Creator   = this.participant,
                CreatedOn = new DateTime(1, 1, 1)
            };

            this.domain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "domain",
                ShortName = "d"
            };

            this.participant.Domain.Add(this.domain);

            this.folder1 = new Folder(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "1",
                CreatedOn = new DateTime(1, 1, 1),
                Creator   = this.participant
            };

            this.iteration = new Iteration(Guid.NewGuid(), null, this.uri);
            this.iteration.DomainFileStore.Add(this.store);

            this.store.Container = this.iteration;

            this.session
            .Setup(x => x.OpenIterations)
            .Returns(
                new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> >
            {
                {
                    this.iteration,
                    new Tuple <DomainOfExpertise, Participant>(
                        this.domain,
                        this.participant)
                }
            });
        }
Ejemplo n.º 12
0
        public void Verify_that_serialization_of_Post_Operation_returns_expected_result()
        {
            var expected = @"{""_delete"":[],""_create"":[{""category"":[],""classKind"":""File"",""excludedDomain"":[],""excludedPerson"":[],""fileRevision"":[""cb54801a-9a08-495f-996c-6467a86ed9cc""],""iid"":""643e6154-a035-4445-a4f2-2c7ff5d2fdbd"",""lockedBy"":null,""modifiedOn"":""0001-01-01T00:00:00.000Z"",""owner"":""0e92edde-fdff-41db-9b1d-f2e484f12535"",""revisionNumber"":0},{""classKind"":""FileRevision"",""containingFolder"":null,""contentHash"":""F73747371CFD9473C19A0A7F99BCAB008474C4CA"",""createdOn"":""0001-01-01T00:00:00.000Z"",""creator"":""284334dd-e8e5-42d6-bc8a-715c507a7f02"",""excludedDomain"":[],""excludedPerson"":[],""fileType"":[{""k"":1,""v"":""b16894e4-acb5-4e81-a118-16c00eb86d8f""}],""iid"":""cb54801a-9a08-495f-996c-6467a86ed9cc"",""modifiedOn"":""0001-01-01T00:00:00.000Z"",""name"":""testfile"",""revisionNumber"":0}],""_update"":[{""classKind"":""DomainFileStore"",""iid"":""da7dddaa-02aa-4897-9935-e8d66c811a96"",""file"":[""643e6154-a035-4445-a4f2-2c7ff5d2fdbd""]}]}";

            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.Parse("643e6154-a035-4445-a4f2-2c7ff5d2fdbd");
            var fileRevisionIid      = Guid.Parse("cb54801a-9a08-495f-996c-6467a86ed9cc");
            var domainOfExpertiseIid = Guid.Parse("0e92edde-fdff-41db-9b1d-f2e484f12535");
            var fileTypeIid          = Guid.Parse("b16894e4-acb5-4e81-a118-16c00eb86d8f");
            var participantIid       = Guid.Parse("284334dd-e8e5-42d6-bc8a-715c507a7f02");

            var originalDomainFileStore = new DomainFileStore(domainFileStoreIid, 0);

            originalDomainFileStore.AddContainer(ClassKind.Iteration, iterationIid);
            originalDomainFileStore.AddContainer(ClassKind.EngineeringModel, engineeringModelIid);

            var modifiedDomainFileStore = originalDomainFileStore.DeepClone <DomainFileStore>();

            modifiedDomainFileStore.File.Add(fileIid);

            var file = new CDP4Common.DTO.File(fileIid, 0);

            file.Owner = domainOfExpertiseIid;
            file.FileRevision.Add(fileRevisionIid);
            file.AddContainer(ClassKind.DomainFileStore, domainFileStoreIid);
            file.AddContainer(ClassKind.Iteration, iterationIid);
            file.AddContainer(ClassKind.EngineeringModel, engineeringModelIid);

            var fileRevision = new FileRevision(fileRevisionIid, 0);

            fileRevision.Name        = "testfile";
            fileRevision.ContentHash = "F73747371CFD9473C19A0A7F99BCAB008474C4CA";
            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, null);

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

            var postOperation = new WspPostOperation(new MetaDataProvider());

            foreach (var operation in operationContainer.Operations)
            {
                postOperation.ConstructFromOperation(operation);
            }

            using (var stream = new MemoryStream())
                using (var streamReader = new StreamReader(stream))
                {
                    this.serializer.SerializeToStream(postOperation, stream);

                    stream.Position = 0;
                    Assert.AreEqual(expected, streamReader.ReadToEnd());
                }
        }
 /// <summary>
 /// Add an Domain File Store row view model to the list of <see cref="DomainFileStore"/>
 /// </summary>
 /// <param name="domainFileStore">
 /// The <see cref="DomainFileStore"/> that is to be added
 /// </param>
 private DomainFileStoreRowViewModel AddDomainFileStoreRowViewModel(DomainFileStore domainFileStore)
 {
     return(new DomainFileStoreRowViewModel(domainFileStore, this.Session, this));
 }
        /// <summary>
        /// Persist the DTO composition to the ORM layer.
        /// </summary>
        /// <param name="transaction">
        /// The transaction object.
        /// </param>
        /// <param name="partition">
        /// The database partition (schema) where the requested resource will be stored.
        /// </param>
        /// <param name="domainFileStore">
        /// The domainFileStore instance to persist.
        /// </param>
        /// <returns>
        /// True if the persistence was successful.
        /// </returns>
        private bool CreateContainment(NpgsqlTransaction transaction, string partition, DomainFileStore domainFileStore)
        {
            var results = new List <bool>();

            foreach (var folder in this.ResolveFromRequestCache(domainFileStore.Folder))
            {
                results.Add(this.FolderService.CreateConcept(transaction, partition, folder, domainFileStore));
            }

            foreach (var file in this.ResolveFromRequestCache(domainFileStore.File))
            {
                results.Add(this.FileService.CreateConcept(transaction, partition, file, domainFileStore));
            }

            return(results.All(x => x));
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DomainFileStoreDialogViewModel"/> class.
 /// </summary>
 /// <param name="fileStore">
 /// The <see cref="DomainFileStore"/> that is the subject of the current view-model. This is the object
 /// that will be either created, or edited.
 /// </param>
 /// <param name=""></param>
 /// <param name="transaction">
 /// The <see cref="ThingTransaction"/> that contains the log of recorded changes.
 /// </param>
 /// <param name="session">
 /// The <see cref="ISession"/> in which the current <see cref="Thing"/> is to be added or updated
 /// </param>
 /// <param name="isRoot">
 /// Assert if this <see cref="DomainFileStoreDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/>
 /// </param>
 /// <param name="dialogKind">
 /// The kind of operation this <see cref="DomainFileStoreDialogViewModel"/> performs
 /// </param>
 /// <param name="thingDialogNavigationService">
 /// The <see cref="IThingDialogNavigationService"/>
 /// </param>
 /// <param name="container">
 /// The Container <see cref="Thing"/> of the created <see cref="Thing"/>
 /// </param>
 /// <param name="chainOfContainers">
 /// The optional chain of containers that contains the <paramref name="container"/> argument
 /// </param>
 public DomainFileStoreDialogViewModel(DomainFileStore fileStore, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind,
                                       IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null)
     : base(fileStore, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers)
 {
 }
Ejemplo n.º 16
0
        public void SetUp()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.session = new Mock <ISession>();

            this.domainOfExpertise = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "system", ShortName = "SYS"
            };

            this.participant = new Participant(Guid.NewGuid(), this.cache, this.uri);
            this.participant.Domain.Add(this.domainOfExpertise);

            var engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri);

            engineeringModelSetup.ActiveDomain.Add(this.domainOfExpertise);
            var srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "testRDL", ShortName = "test"
            };
            var category = new Category(Guid.NewGuid(), this.cache, this.uri)
            {
                Name = "test Category", ShortName = "testCategory"
            };

            category.PermissibleClass.Add(ClassKind.ElementDefinition);
            srdl.DefinedCategory.Add(category);
            var mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                RequiredRdl = srdl
            };

            engineeringModelSetup.RequiredRdl.Add(mrdl);
            srdl.DefinedCategory.Add(new Category(Guid.NewGuid(), this.cache, this.uri));
            this.engineeringModel = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri);
            this.engineeringModel.EngineeringModelSetup = engineeringModelSetup;
            var iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri)
            {
                IterationSetup = new IterationSetup()
            };

            this.engineeringModel.Iteration.Add(iteration);
            this.folder          = new Folder(Guid.NewGuid(), this.cache, this.uri);
            this.domainFileStore = new DomainFileStore(Guid.NewGuid(), this.cache, this.uri);
            this.domainFileStore.Folder.Add(this.folder);
            iteration.DomainFileStore.Add(this.domainFileStore);

            this.cache.TryAdd(new CacheKey(iteration.Iid, null), new Lazy <Thing>(() => iteration));

            this.domainFileStoreClone = this.domainFileStore.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.domainFileStore);

            this.thingTransaction = new ThingTransaction(transactionContext, this.domainFileStoreClone);

            var dal = new Mock <IDal>();

            this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0));
            this.session.Setup(x => x.Dal).Returns(dal.Object);

            var openIterations = new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> >();

            openIterations.Add(iteration, new Tuple <DomainOfExpertise, Participant>(this.domainOfExpertise, this.participant));

            this.session.Setup(x => x.OpenIterations).Returns(openIterations);
            this.session.Setup(x => x.QuerySelectedDomainOfExpertise(It.IsAny <Iteration>())).Returns(this.domainOfExpertise);

            dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider());
        }
        public void Setup()
        {
            this.domainFileStoreDao = new Mock <IDomainFileStoreDao>();
            this.iterationService   = new Mock <IIterationService>();
            this.permissionService  = new Mock <IPermissionService>();
            this.transaction        = new Mock <IDbTransaction>();
            this.transactionManager = new Mock <ICdp4TransactionManager>();

            this.domainFileStoreService = new DomainFileStoreService
            {
                IterationService   = this.iterationService.Object,
                PermissionService  = this.permissionService.Object,
                DomainFileStoreDao = this.domainFileStoreDao.Object,
                TransactionManager = this.transactionManager.Object
            };

            this.iterationPartitionName = "Iteration_" + Guid.NewGuid();

            domainFileStore.IsHidden = false;

            domainFileStore.File.Clear();
            domainFileStore.File.Add(file.Iid);

            domainFileStore.Folder.Clear();
            domainFileStore.Folder.Add(folder.Iid);

            this.iteration = new Iteration(Guid.NewGuid(), 0)
            {
                DomainFileStore = new List <Guid>
                {
                    domainFileStore.Iid
                }
            };

            this.iterationService
            .Setup(x => x.GetActiveIteration(It.IsAny <NpgsqlTransaction>(), It.IsAny <string>(), It.IsAny <ISecurityContext>()))
            .Returns(this.iteration);

            this.permissionService.Setup(x => x.IsOwner(It.IsAny <NpgsqlTransaction>(), domainFileStore)).Returns(true);
            this.permissionService.Setup(x => x.IsOwner(It.IsAny <NpgsqlTransaction>(), folder)).Returns(true);
            this.permissionService.Setup(x => x.IsOwner(It.IsAny <NpgsqlTransaction>(), file)).Returns(true);

            this.permissionService.Setup(x => x.Credentials)
            .Returns(
                new Credentials
            {
                Person = new AuthenticationPerson(Guid.NewGuid(), 0)
                {
                    UserName = "******"
                }
            });

            // Without a domainFileStoreSelector, SingleOrDefault(domainFileStoreSelector) could fail, because multiple <see cref="DomainFileStore"/>s could exist.
            // Also if a new DomainFileStore including Files and Folders are created in the same webservice call, then GetShallow for the new DomainFileStores might not return
            // the to be created <see cref="DomainFileStore"/>. The isHidden check will then be ignored.
            var extraDomainFileStoreToTestDomainFileStoreSelectors = new DomainFileStore(Guid.NewGuid(), 0);

            this.domainFileStoreDao
            .Setup(
                x => x.Read(It.IsAny <NpgsqlTransaction>(), this.iterationPartitionName, It.IsAny <IEnumerable <Guid> >(), It.IsAny <bool>()))
            .Returns(new[] { domainFileStore, extraDomainFileStoreToTestDomainFileStoreSelectors });

            this.transactionManager.Setup(x => x.IsFullAccessEnabled()).Returns(true);
        }
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.session = new Mock <ISession>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.permissionService            = new Mock <IPermissionService>();
            this.fileDialogService            = new Mock <IOpenSaveFileDialogService>();
            this.downloadFileService          = new Mock <IDownloadFileService>();
            this.thingSelectorDialogService   = new Mock <IThingSelectorDialogService>();
            this.serviceLocator = new Mock <IServiceLocator>();
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IOpenSaveFileDialogService>()).Returns(this.fileDialogService.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IThingSelectorDialogService>()).Returns(this.thingSelectorDialogService.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IDownloadFileService>()).Returns(this.downloadFileService.Object);

            this.assembler = new Assembler(this.uri);
            this.session.Setup(x => x.Assembler).Returns(this.assembler);
            this.session.Setup(x => x.DataSourceUri).Returns(this.uri.ToString);
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);

            var dal = new Mock <IDal>();

            dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider());
            this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0));
            this.session.Setup(x => x.Dal).Returns(dal.Object);

            this.sitedir = new SiteDirectory(Guid.NewGuid(), this.assembler.Cache, this.uri);

            this.engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name = "model"
            };

            this.iterationSetup = new IterationSetup(Guid.NewGuid(), this.assembler.Cache, this.uri);

            this.person = new Person(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                ShortName = "person",
                GivenName = "person",
            };

            this.participant = new Participant(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Person   = this.person,
                IsActive = true,
            };

            this.domain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "domain",
                ShortName = "d"
            };

            this.session.Setup(x => x.QueryDomainOfExpertise(It.IsAny <Iteration>())).Returns(new List <DomainOfExpertise>()
            {
                this.domain
            });

            this.fileType1 = new FileType(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Extension = "jpg"
            };
            this.fileType2 = new FileType(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Extension = "zip"
            };

            this.thingSelectorDialogService.Setup(x => x.SelectThing(It.IsAny <IEnumerable <FileType> >(), It.IsAny <IEnumerable <string> >())).Returns(this.fileType1);

            this.srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri);

            this.mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                RequiredRdl = this.srdl,
                FileType    = { this.fileType1, this.fileType2 }
            };

            this.session.Setup(x => x.OpenReferenceDataLibraries).Returns(new ReferenceDataLibrary[] { this.srdl, this.mrdl });

            this.sitedir.Model.Add(this.engineeringModelSetup);
            this.engineeringModelSetup.IterationSetup.Add(this.iterationSetup);
            this.sitedir.Person.Add(this.person);
            this.sitedir.Domain.Add(this.domain);
            this.engineeringModelSetup.RequiredRdl.Add(this.mrdl);
            this.sitedir.SiteReferenceDataLibrary.Add(this.srdl);
            this.engineeringModelSetup.Participant.Add(this.participant);
            this.participant.Domain.Add(this.domain);

            this.model = new EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                EngineeringModelSetup = this.engineeringModelSetup
            };

            this.iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                IterationSetup = this.iterationSetup,
                Container      = this.engineeringModelSetup
            };

            this.model.Iteration.Add(this.iteration);

            this.permissionService.Setup(x => x.CanWrite(It.IsAny <ClassKind>(), It.IsAny <Thing>())).Returns(true);
            this.permissionService.Setup(x => x.CanRead(It.IsAny <Thing>())).Returns(true);

            this.session.Setup(x => x.OpenIterations)
            .Returns(new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> >
            {
                { this.iteration, new Tuple <DomainOfExpertise, Participant>(this.domain, this.participant) }
            });

            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);

            this.session.Setup(x => x.ActivePerson).Returns(this.person);

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.sitedir);

            this.store = new DomainFileStore(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Container = this.iteration
            };

            this.file = new File(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Container = this.store,
                Owner     = this.domain
            };

            this.fileRevision = new FileRevision(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.file.FileRevision.Add(this.fileRevision);

            this.storeClone = this.store.Clone(false);
            this.fileClone  = this.file.Clone(false);

            this.assembler.Cache.TryAdd(new CacheKey(this.store.Iid, this.iteration.Iid), new Lazy <Thing>(() => this.storeClone));
            this.assembler.Cache.TryAdd(new CacheKey(this.file.Iid, null), new Lazy <Thing>(() => this.fileClone));

            var transactionContext = TransactionContextResolver.ResolveContext(this.iteration);

            this.thingTransaction = new ThingTransaction(transactionContext, this.file);
        }
        public void Setup()
        {
            this.messageBoxService = new Mock <IMessageBoxService>();
            this.serviceLocator    = new Mock <IServiceLocator>();
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IMessageBoxService>()).Returns(this.messageBoxService.Object);

            this.fileStoreFileAndFolderHandler = new Mock <IFileStoreFileAndFolderHandler>();
            this.session   = new Mock <ISession>();
            this.assembler = new Assembler(this.uri);

            this.domain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "domain",
                ShortName = "d"
            };

            this.store = new DomainFileStore(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.rev.SetValue(this.store, 2);

            this.file = new File(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Container = this.store
            };

            this.fileRevision1 = new FileRevision(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "1",
                Creator   = this.participant,
                CreatedOn = new DateTime(1, 1, 1)
            };

            this.file.FileRevision.Add(this.fileRevision1);

            this.person = new Person(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                ShortName = "person",
                GivenName = "person",
            };

            this.participant = new Participant(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Person   = this.person,
                IsActive = true,
            };

            this.domain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "domain",
                ShortName = "d"
            };

            this.participant.Domain.Add(this.domain);

            this.folder1 = new Folder(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "1",
                CreatedOn = new DateTime(1, 1, 1),
                Creator   = this.participant,
                Container = this.store
            };

            this.iteration = new Iteration(Guid.NewGuid(), null, this.uri);
            this.iteration.DomainFileStore.Add(this.store);

            this.store.Container = this.iteration;

            this.session
            .Setup(x => x.OpenIterations)
            .Returns(
                new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> >
            {
                {
                    this.iteration,
                    new Tuple <DomainOfExpertise, Participant>(
                        this.domain,
                        this.participant)
                }
            });
        }
        public void Setup()
        {
            var configurationFilePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "config.json");

            AppConfig.Load(configurationFilePath);

            this.authenticatedPerson = new AuthenticationPerson(Guid.NewGuid(), 1)
            {
                DefaultDomain = Guid.NewGuid()
            };
            this.credentials = new Credentials()
            {
                Person = this.authenticatedPerson
            };
            this.cdp4RequestContext = new Mock <ICdp4RequestContext>();
            this.cdp4RequestContext.Setup(x => x.AuthenticatedCredentials).Returns(this.credentials);
            this.requestUtils.Context = this.cdp4RequestContext.Object;

            this.iterationService             = new Mock <IIterationService>();
            this.iterationSetupService        = new Mock <IIterationSetupService>();
            this.engineeringModelService      = new Mock <IEngineeringModelService>();
            this.engineeringModelSetupService = new Mock <IEngineeringModelSetupService>();
            this.domainFileStoreService       = new Mock <IDomainFileStoreService>();
            this.participantService           = new Mock <IParticipantService>();
            this.optionService       = new Mock <IOptionService>();
            this.securityContext     = new Mock <ISecurityContext>();
            this.revisionService     = new Mock <IRevisionService>();
            this.personResolver      = new Mock <IPersonResolver>();
            this.permissionService   = new Mock <IPermissionService>();
            this.engineeringModelDao = new Mock <IEngineeringModelDao>();
            this.npgsqlTransaction   = null;

            this.modelCreatorManager = new ModelCreatorManager();
            this.modelCreatorManager.RevisionService = this.revisionService.Object;

            this.engineeringModelSetupSideEffect = new EngineeringModelSetupSideEffect
            {
                EngineeringModelService      = this.engineeringModelService.Object,
                EngineeringModelSetupService = this.engineeringModelSetupService.Object,
                IterationService             = this.iterationService.Object,
                IterationSetupService        = this.iterationSetupService.Object,
                ParticipantService           = this.participantService.Object,
                DomainFileStoreService       = this.domainFileStoreService.Object,
                OptionService       = this.optionService.Object,
                RequestUtils        = this.requestUtils,
                ModelCreatorManager = this.modelCreatorManager,
                PersonResolver      = this.personResolver.Object,
                PermissionService   = this.permissionService.Object,
                RevisionService     = this.revisionService.Object,
                EngineeringModelDao = this.engineeringModelDao.Object
            };

            this.siteDirectory         = new SiteDirectory(Guid.NewGuid(), 1);
            this.engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), 1);
            var domainOfExpertise  = new DomainOfExpertise(Guid.NewGuid(), 1);
            var domainOfExpertise1 = new DomainOfExpertise(Guid.NewGuid(), 1);
            var domainFileStore    = new DomainFileStore(Guid.NewGuid(), 1);

            domainFileStore.Owner = domainOfExpertise.Iid;
            var domainFileStore1 = new DomainFileStore(Guid.NewGuid(), 1);

            domainFileStore1.Owner = domainOfExpertise1.Iid;
            var option = new Option(Guid.NewGuid(), 1)
            {
                Name      = "Option 1",
                ShortName = "optioin_1"
            };

            this.engineeringModelSetup.ActiveDomain.Add(domainOfExpertise.Iid);
            var engineeringModel = new EngineeringModel(this.engineeringModelSetup.EngineeringModelIid, 1);
            var iteration        = new Iteration(Guid.NewGuid(), 1);

            iteration.DomainFileStore.Add(domainFileStore.Iid);

            var orderedOption = new OrderedItem
            {
                K = 1,
                V = option.Iid
            };

            iteration.Option.Add(orderedOption);

            var iterationSetup = new IterationSetup(Guid.NewGuid(), 1);

            this.engineeringModelSetup.IterationSetup.Add(iterationSetup.Iid);

            var participant = new Participant(Guid.NewGuid(), 1);

            this.engineeringModelSetup.Participant.Add(participant.Iid);

            engineeringModel.Iteration.Add(iteration.Iid);
            iterationSetup.IterationIid = iteration.Iid;
            this.siteDirectory.Model.Add(this.engineeringModelSetup.Iid);
            this.siteDirectory.DefaultParticipantRole = Guid.NewGuid();

            this.engineeringModelService.Setup(x => x.CreateConcept(It.IsAny <NpgsqlTransaction>(), It.IsAny <string>(), It.IsAny <EngineeringModel>(), It.IsAny <Thing>(), -1)).Returns(true);
            this.engineeringModelService.Setup(x => x.DeleteConcept(It.IsAny <NpgsqlTransaction>(), It.IsAny <string>(), It.IsAny <EngineeringModel>(), null)).Returns(true);
            this.engineeringModelService.Setup(x => x.GetShallow(It.IsAny <NpgsqlTransaction>(), It.IsAny <string>(), It.IsAny <IEnumerable <Guid> >(), this.securityContext.Object)).Returns(new[] { engineeringModel });

            this.engineeringModelSetupService.Setup(x => x.UpdateConcept(It.IsAny <NpgsqlTransaction>(), It.IsAny <string>(), It.IsAny <EngineeringModelSetup>(), It.IsAny <Thing>())).Returns(true);

            this.iterationService.Setup(x => x.CreateConcept(It.IsAny <NpgsqlTransaction>(), It.IsAny <string>(), It.IsAny <Iteration>(), It.IsAny <EngineeringModel>(), -1)).Returns(true);
            this.iterationService.Setup(
                x =>
                x.GetShallow(
                    It.IsAny <NpgsqlTransaction>(),
                    It.IsAny <string>(),
                    It.IsAny <IEnumerable <Guid> >(),
                    this.securityContext.Object)).Returns(new[] { iteration });
            this.iterationSetupService.Setup(x => x.CreateConcept(It.IsAny <NpgsqlTransaction>(), It.IsAny <string>(), It.IsAny <IterationSetup>(), It.IsAny <EngineeringModelSetup>(), -1)).Returns(true);
            this.iterationSetupService.Setup(
                x =>
                x.GetShallow(
                    It.IsAny <NpgsqlTransaction>(),
                    It.IsAny <string>(),
                    It.IsAny <IEnumerable <Guid> >(),
                    this.securityContext.Object)).Returns(new[] { iterationSetup });

            this.participantService.Setup(x => x.CreateConcept(It.IsAny <NpgsqlTransaction>(), It.IsAny <string>(), It.IsAny <Participant>(), It.IsAny <EngineeringModelSetup>(), -1)).Returns(true);
            this.participantService.Setup(
                x =>
                x.GetShallow(
                    It.IsAny <NpgsqlTransaction>(),
                    It.IsAny <string>(),
                    It.IsAny <IEnumerable <Guid> >(),
                    this.securityContext.Object)).Returns(new[] { participant });

            this.domainFileStoreService.Setup(x => x.CreateConcept(It.IsAny <NpgsqlTransaction>(), It.IsAny <string>(), It.IsAny <DomainFileStore>(), It.IsAny <Iteration>(), -1)).Returns(true);
            this.domainFileStoreService.Setup(
                x =>
                x.GetShallow(
                    It.IsAny <NpgsqlTransaction>(),
                    It.IsAny <string>(),
                    It.IsAny <IEnumerable <Guid> >(),
                    this.securityContext.Object)).Returns(new[] { domainFileStore });

            this.domainFileStoreService.Setup(x => x.DeleteConcept(It.IsAny <NpgsqlTransaction>(), It.IsAny <string>(), It.IsAny <DomainFileStore>(), It.IsAny <Iteration>())).Returns(true);

            this.optionService.Setup(x => x.CreateConcept(It.IsAny <NpgsqlTransaction>(), It.IsAny <string>(), It.IsAny <Option>(), It.IsAny <Iteration>(), -1)).Returns(true);
            this.optionService.Setup(x => x.GetShallow(
                                         It.IsAny <NpgsqlTransaction>(),
                                         It.IsAny <string>(),
                                         It.IsAny <IEnumerable <Guid> >(),
                                         this.securityContext.Object)).Returns(new[] { option });

            this.revisionService.Setup(
                x => x.SaveRevisions(
                    It.IsAny <NpgsqlTransaction>(),
                    It.IsAny <string>(),
                    It.IsAny <Guid>(),
                    It.IsAny <int>())).Returns(new List <Thing>());

            this.engineeringModelDao.Setup(x => x.GetNextIterationNumber(It.IsAny <NpgsqlTransaction>(), It.IsAny <string>())).Returns(1);
        }
Ejemplo n.º 21
0
        public void Setup()
        {
            this.session = new Mock <ISession>();
            this.panelNavigationService       = new Mock <IPanelNavigationService>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.permissionService            = new Mock <IPermissionService>();
            this.dialogNavigationService      = new Mock <IDialogNavigationService>();
            this.fileDialogService            = new Mock <IOpenSaveFileDialogService>();
            this.serviceLocator = new Mock <IServiceLocator>();
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IOpenSaveFileDialogService>()).Returns(this.fileDialogService.Object);

            this.assembler = new Assembler(this.uri);
            this.session.Setup(x => x.Assembler).Returns(this.assembler);
            this.session.Setup(x => x.DataSourceUri).Returns(this.uri.ToString);
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);

            this.sitedir = new SiteDirectory(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name = "model"
            };
            this.iterationSetup = new IterationSetup(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.person         = new Person(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                ShortName = "person",
                GivenName = "person",
            };
            this.participant = new Participant(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Person   = this.person,
                IsActive = true,
            };

            this.domain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "domain",
                ShortName = "d"
            };
            this.srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                RequiredRdl = this.srdl
            };

            this.sitedir.Model.Add(this.engineeringModelSetup);
            this.engineeringModelSetup.IterationSetup.Add(this.iterationSetup);
            this.sitedir.Person.Add(this.person);
            this.sitedir.Domain.Add(this.domain);
            this.engineeringModelSetup.RequiredRdl.Add(this.mrdl);
            this.sitedir.SiteReferenceDataLibrary.Add(this.srdl);
            this.engineeringModelSetup.Participant.Add(this.participant);
            this.participant.Domain.Add(this.domain);

            this.model = new EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                EngineeringModelSetup = this.engineeringModelSetup
            };
            this.iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                IterationSetup = this.iterationSetup
            };

            this.model.Iteration.Add(this.iteration);

            this.permissionService.Setup(x => x.CanWrite(It.IsAny <ClassKind>(), It.IsAny <Thing>())).Returns(true);
            this.session.Setup(x => x.OpenIterations)
            .Returns(new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> >
            {
                { this.iteration, new Tuple <DomainOfExpertise, Participant>(this.domain, this.participant) }
            });

            this.session.Setup(x => x.ActivePerson).Returns(this.person);

            this.store   = new DomainFileStore(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.folder1 = new Folder(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "1",
                CreatedOn = new DateTime(1, 1, 1),
                Creator   = this.participant
            };
            this.folder2 = new Folder(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "2",
                CreatedOn = new DateTime(1, 1, 1),
                Creator   = this.participant
            };
            this.file          = new File(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.fileRevision1 = new FileRevision(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "1",
                Creator   = this.participant,
                CreatedOn = new DateTime(1, 1, 1)
            };
            this.fileRevision2 = new FileRevision(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name      = "1",
                Creator   = this.participant,
                CreatedOn = new DateTime(1, 1, 2)
            };
        }