Example #1
0
        public void VerifyThatBrowserWorksWithNoStore()
        {
            var vm = new DomainFileStoreBrowserViewModel(this.iteration, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, this.dialogNavigationService.Object, null);

            Assert.IsEmpty(vm.ContainedRows);

            Assert.That(vm.Caption, Is.Not.Null.Or.Empty);
            Assert.That(vm.ToolTip, Is.Not.Null.Or.Empty);
            Assert.That(vm.DomainOfExpertise, Is.Not.Null.Or.Empty);
            Assert.AreEqual(this.engineeringModelSetup.Name, vm.CurrentModel);
            Assert.AreEqual(this.iterationSetup.IterationNumber, vm.CurrentIteration);

            Assert.IsTrue(vm.CanCreateStore);
            Assert.IsFalse(vm.CanCreateFolder);
        }
Example #2
0
        public void VerifyUploadFileCommand()
        {
            this.model.Iteration.FirstOrDefault().DomainFileStore.Add(this.store);

            this.fileDialogService.Setup(x => x.GetSaveFileDialog(string.Empty, string.Empty, string.Empty, string.Empty, 1)).Returns("test");
            var vm = new DomainFileStoreBrowserViewModel(this.iteration, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, this.dialogNavigationService.Object, null);

            Assert.AreEqual(1, vm.ContainedRows.Count);

            Assert.IsTrue(vm.UploadFileCommand.CanExecute(null));

            vm.UploadFileCommand.Execute(null);

            Assert.AreEqual(2, vm.ContainedRows.Count);

            this.fileDialogService.Setup(x => x.GetSaveFileDialog(string.Empty, string.Empty, string.Empty, string.Empty, 1)).Returns(string.Empty);

            vm.UploadFileCommand.Execute(null);

            Assert.AreEqual(2, vm.ContainedRows.Count);
        }
Example #3
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);
        }
Example #4
0
        public void VerifyThatRowsAreCreatedAndAddedCorrectly()
        {
            var vm = new DomainFileStoreBrowserViewModel(this.iteration, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, this.dialogNavigationService.Object, null);

            this.model.Iteration.FirstOrDefault().DomainFileStore.Add(this.store);
            this.rev.SetValue(this.iteration, 2);

            CDPMessageBus.Current.SendObjectChangeEvent(this.iteration, EventKind.Updated);

            vm.ComputePermission();

            Assert.IsFalse(vm.CanCreateStore);
            Assert.IsTrue(vm.CanCreateFolder);

            var storeRow = vm.ContainedRows.Single();

            Assert.IsEmpty(storeRow.ContainedRows);

            this.store.Folder.Add(this.folder1);
            this.store.Folder.Add(this.folder2);

            this.rev.SetValue(this.store, 2);

            this.folder2.ContainingFolder = this.folder1;

            CDPMessageBus.Current.SendObjectChangeEvent(this.store, EventKind.Updated);
            Assert.AreEqual(1, storeRow.ContainedRows.Count);

            var folder1Row = storeRow.ContainedRows.Single();
            var folder2Row = folder1Row.ContainedRows.Single();

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

            this.rev.SetValue(this.store, 5);
            CDPMessageBus.Current.SendObjectChangeEvent(this.store, EventKind.Updated);
            Assert.AreEqual(2, storeRow.ContainedRows.Count);

            this.fileRevision2.ContainingFolder = this.folder2;
            this.file.FileRevision.Add(this.fileRevision2);
            this.rev.SetValue(this.file, 3);
            CDPMessageBus.Current.SendObjectChangeEvent(this.file, EventKind.Updated);

            Assert.AreEqual(1, folder2Row.ContainedRows.Count);

            this.folder2.ContainingFolder = null;
            this.rev.SetValue(this.folder2, 5);
            CDPMessageBus.Current.SendObjectChangeEvent(this.folder2, EventKind.Updated);
            Assert.IsTrue(storeRow.ContainedRows.Contains(folder2Row));

            var folder3 = new Folder(Guid.NewGuid(), this.assembler.Cache, this.uri);

            folder3.ContainingFolder = this.folder1;
            folder3.Creator          = this.participant;

            this.store.Folder.Add(folder3);
            this.rev.SetValue(this.store, 10);
            CDPMessageBus.Current.SendObjectChangeEvent(this.store, EventKind.Updated);

            Assert.AreEqual(2, storeRow.ContainedRows.Count);
            Assert.AreEqual(1, folder1Row.ContainedRows.Count);

            folder3.ContainingFolder = this.folder2;
            this.rev.SetValue(folder3, 10);
            CDPMessageBus.Current.SendObjectChangeEvent(folder3, EventKind.Updated);

            Assert.AreEqual(2, folder2Row.ContainedRows.Count);
        }