Пример #1
0
        public bool SaveResource(ResourceDTO <string> resourceToSave)
        {
            try
            {
                var career       = _careerRepository.GetMany(x => x.Name == resourceToSave.NameCareer);
                var typeresource = _typeResourceRepository.GetMany(x => x.TypeName == resourceToSave.NameTypeResource);

                if (career.FirstOrDefault() == null || !career.Any())
                {
                    return(false);
                }
                if (typeresource.FirstOrDefault() == null || !typeresource.Any())
                {
                    return(false);
                }
                var newResource = new Resource()
                {
                    Author        = resourceToSave.Author,
                    IdCareer      = career.FirstOrDefault().IdCareer,
                    Description   = resourceToSave.Description,
                    Link          = resourceToSave.ResourceLink,
                    Title         = resourceToSave.Title,
                    TypeResource  = typeresource.FirstOrDefault().IdResource,
                    ResourceImage = null
                };

                _resourceRepository.Add(newResource);
                _resourceRepository.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #2
0
        public void SubmitForm(ResourceInputDto resourceInputDto, string keyValue)
        {
            Resource resource = new Resource();

            if (!string.IsNullOrEmpty(keyValue))
            {
                var id = Convert.ToInt64(keyValue);
                resource = resourceRepository.Get(id);
                AutoMapper.Mapper.Map <ResourceInputDto, Resource>(resourceInputDto, resource);
                resource.LastModificationTime = DateTime.Now;
                resourceRepository.Update(resource);
            }
            else
            {
                AutoMapper.Mapper.Map <ResourceInputDto, Resource>(resourceInputDto, resource);
                resource.Id           = IdWorkerHelper.GenId64();
                resource.CreationTime = DateTime.Now;
                resource.DeletedMark  = false;
                resourceRepository.Add(resource);
            }
        }
Пример #3
0
        protected internal virtual void CreateResource(string name, byte[] bytes, DeploymentEntity deploymentEntity)
        {
            ResourceEntity resource = new ResourceEntity();

            resource.Name         = name;
            resource.Bytes        = bytes;
            resource.DeploymentId = deploymentEntity.Id;

            // Mark the resource as 'generated'
            resource.Generated = true;

            ResourceRepository.Add(resource);
        }
Пример #4
0
        public void AddResource(ResourceDTO resource, string currentUser)
        {
            Resource dbResource = new Resource()
            {
                Id          = resource.Id,
                Title       = resource.Title,
                Author      = resource.Author,
                Link        = resource.Link,
                ImageUrl    = resource.ImageUrl,
                DateCreated = DateTime.Now,
                LastUpdated = DateTime.Now,
                UserId      = _uRepo.GetUser(currentUser).First().Id
            };

            _rRepo.Add(dbResource);
        }
Пример #5
0
        public void CreateResource(Resource resource)
        {
            ResourceRepository resourceRepo = new ResourceRepository();

            try
            {
                var             max = -1;
                List <Resource> rl  = resourceRepo.GetAll().ToList();



                rl.ForEach(r =>
                {
                    var number  = Regex.Replace(r.UserName, "[^0-9]", "");;
                    var usrName = Regex.Replace(r.UserName, "[^a-zA-Z]", "");

                    if (resource.UserName == usrName)
                    {
                        var intUsername = Int32.Parse(number);
                        if (max < intUsername)
                        {
                            max = intUsername;
                        }
                    }
                });


                resource.UserName  += max + 1;
                resource.ResourceID = resourceRepo.GetMaxId() + 1;

                resourceRepo.Add(resource);
                GlobalUnitOfWork.Commit();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #6
0
        public void UpdateResource(Resource resource)
        {
            try
            {
                ResourceRepository resourceRepo = new ResourceRepository();

                var repo = resourceRepo.Get(resource.ResourceID);

                if (repo == null)
                {
                    resourceRepo.Add(resource);
                }
                else
                {
                    resourceRepo.Update(resource);
                }
            }
            catch (Exception ex) {
                throw ex;
            }

            GlobalUnitOfWork.Commit();
        }
        public void SchedulerViewModel_DeActivateSave_AttemptsSave()
        {
            //------------Setup for test--------------------------
            var resources = new ObservableCollection<IScheduledResource>();
            var scheduledResourceForTest = new ScheduledResourceForTest { Trigger = new ScheduleTrigger(TaskState.Ready, new Dev2DailyTrigger(new TaskServiceConvertorFactory(), new DailyTrigger()), new Dev2TaskService(new TaskServiceConvertorFactory()), new TaskServiceConvertorFactory()), IsDirty = true };
            resources.Add(scheduledResourceForTest);
            Dev2JsonSerializer serializer = new Dev2JsonSerializer();
            var serializeObject = serializer.SerializeToBuilder(resources);
            var mockEnvironmentModel = new Mock<IEnvironmentModel>();
            var mockConnection = new Mock<IEnvironmentConnection>();
            mockConnection.Setup(connection => connection.IsConnected).Returns(true);
            mockConnection.Setup(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>())).Returns(serializeObject);
            mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
            mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
            mockEnvironmentModel.Setup(model => model.IsConnected).Returns(true);
            ResourceRepository resourceRepo = new ResourceRepository(mockEnvironmentModel.Object);
            var setupResourceModelMock = Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow2");
            resourceRepo.Add(Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow1").Object);
            resourceRepo.Add(setupResourceModelMock.Object);
            resourceRepo.Add(Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow3").Object);
            mockEnvironmentModel.Setup(c => c.ResourceRepository).Returns(resourceRepo);
            var popup = new Mock<IPopupController>();
            popup.Setup(a => a.ShowSchedulerCloseConfirmation()).Returns(MessageBoxResult.Yes);
            var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, popup.Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object) { SelectedTask = scheduledResourceForTest };

            var auth = new Mock<IAuthorizationService>();
            mockEnvironmentModel.Setup(a => a.AuthorizationService).Returns(auth.Object);
            auth.Setup(a => a.IsAuthorized(AuthorizationContext.Administrator, null)).Returns(false).Verifiable();
            schedulerViewModel.CurrentEnvironment = mockEnvironmentModel.Object;
            //------------Execute Test---------------------------
            schedulerViewModel.DoDeactivate();
            //------------Assert Results-------------------------
            auth.Verify(a => a.IsAuthorized(AuthorizationContext.Administrator, null));
            Assert.AreEqual(@"Error while saving: You don't have permission to schedule on this server.
You need Administrator permission.", schedulerViewModel.Error);



        }
        public void SchedulerViewModel_DeActivateCancel_ReturnsFalse()
        {
            //------------Setup for test--------------------------
            var resources = new ObservableCollection<IScheduledResource>();
            var scheduledResourceForTest = new ScheduledResourceForTest { Trigger = new ScheduleTrigger(TaskState.Ready, new Dev2DailyTrigger(new TaskServiceConvertorFactory(), new DailyTrigger()), new Dev2TaskService(new TaskServiceConvertorFactory()), new TaskServiceConvertorFactory()), IsDirty = true };
            resources.Add(scheduledResourceForTest);
            Dev2JsonSerializer serializer = new Dev2JsonSerializer();
            var serializeObject = serializer.SerializeToBuilder(resources);
            var mockEnvironmentModel = new Mock<IEnvironmentModel>();
            var mockConnection = new Mock<IEnvironmentConnection>();
            mockConnection.Setup(connection => connection.IsConnected).Returns(true);
            mockConnection.Setup(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>())).Returns(serializeObject);
            mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
            mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
            mockEnvironmentModel.Setup(model => model.IsConnected).Returns(true);
            ResourceRepository resourceRepo = new ResourceRepository(mockEnvironmentModel.Object);
            var setupResourceModelMock = Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow2");
            resourceRepo.Add(Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow1").Object);
            resourceRepo.Add(setupResourceModelMock.Object);
            resourceRepo.Add(Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow3").Object);
            mockEnvironmentModel.Setup(c => c.ResourceRepository).Returns(resourceRepo);
            var popup = new Mock<IPopupController>();
            popup.Setup(a => a.ShowSchedulerCloseConfirmation()).Returns(MessageBoxResult.Cancel);
            var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, popup.Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object) { SelectedTask = scheduledResourceForTest, CurrentEnvironment = null };
            //------------Execute Test---------------------------
            Assert.IsFalse(schedulerViewModel.DoDeactivate());
            //------------Assert Results-------------------------

        }
        public void SchedulerViewModel_AddWorkflow_WithNewTaskNameSet_WorkflowNameChangedAndNameChanged()
        {
            //------------Setup for test--------------------------
            var resources = new ObservableCollection<IScheduledResource> { new ScheduledResource("New Task1", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "TestFlow1") { NumberOfHistoryToKeep = 1 } };
            var mockEnvironmentModel = new Mock<IEnvironmentModel>();
            var mockConnection = new Mock<IEnvironmentConnection>();
            mockConnection.Setup(connection => connection.IsConnected).Returns(true);
            mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
            mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
            mockEnvironmentModel.Setup(model => model.IsConnected).Returns(true);
            ResourceRepository resourceRepo = new ResourceRepository(mockEnvironmentModel.Object);
            var setupResourceModelMock = Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow2");
            var resId = Guid.NewGuid();
            setupResourceModelMock.Setup(c => c.ID).Returns(resId);
            resourceRepo.Add(Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow1").Object);
            resourceRepo.Add(setupResourceModelMock.Object);
            resourceRepo.Add(Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow3").Object);
            mockEnvironmentModel.Setup(c => c.ResourceRepository).Returns(resourceRepo);

            var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IPopupController>().Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object) { CurrentEnvironment = mockEnvironmentModel.Object };
            Mock<IResourcePickerDialog> mockResourcePickerDialog = new Mock<IResourcePickerDialog>();
            mockResourcePickerDialog.Setup(c => c.ShowDialog(It.IsAny<IEnvironmentModel>())).Returns(true);
            mockResourcePickerDialog.Setup(c => c.SelectedResource).Returns(setupResourceModelMock.Object);

            schedulerViewModel.ResourcePickerDialog = mockResourcePickerDialog.Object;

            Mock<IScheduledResourceModel> scheduledResourceModelMock = new Mock<IScheduledResourceModel>();
            scheduledResourceModelMock.Setup(c => c.ScheduledResources).Returns(resources);
            schedulerViewModel.ScheduledResourceModel = scheduledResourceModelMock.Object;
            //------------Execute Test---------------------------
            schedulerViewModel.TaskList[0].WorkflowName = "TestFlow3";
            schedulerViewModel.SelectedTask = schedulerViewModel.TaskList[0];

            var _nameChange = false;
            var _workflowNameChange = false;
            var _taskListChange = false;

            schedulerViewModel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs args)
            {
                switch(args.PropertyName)
                {
                    case "TaskList":
                        _taskListChange = true;
                        break;
                    case "Name":
                        _nameChange = true;
                        break;
                    case "WorkflowName":
                        _workflowNameChange = true;
                        break;
                }
            };

            schedulerViewModel.AddWorkflowCommand.Execute(null);
            //------------Assert Results-------------------------  
            Assert.IsTrue(_nameChange);
            Assert.IsTrue(_workflowNameChange);
            Assert.IsTrue(_taskListChange);
            Assert.IsTrue(schedulerViewModel.SelectedTask.IsDirty);
            Assert.AreEqual("TestFlow2", schedulerViewModel.Name);
            Assert.AreEqual("Category\\Testing", schedulerViewModel.WorkflowName);
            Assert.AreEqual(resId, schedulerViewModel.SelectedTask.ResourceId);
        }
Пример #10
0
        public void DeployViewModelDeployWithServerExpectedDoesNotDisconnectOtherServers()
        {
            var source = EnviromentRepositoryTest.CreateMockEnvironment();
            var sourceConn = Mock.Get(source.Object.Connection);
            sourceConn.Setup(c => c.Disconnect()).Verifiable();

            var e1 = EnviromentRepositoryTest.CreateMockEnvironment();
            var s1 = e1.Object;
            var c1 = Mock.Get(e1.Object.Connection);
            c1.Setup(c => c.Disconnect()).Verifiable();

            var resourceRepo1 = new ResourceRepository(e1.Object);
            e1.Setup(e => e.ResourceRepository).Returns(resourceRepo1);
            var r1 = new Mock<IContextualResourceModel>();
            r1.Setup(r => r.Category).Returns("test");
            r1.Setup(r => r.ResourceName).Returns("testResource");
            r1.Setup(r => r.Environment).Returns(e1.Object);
            resourceRepo1.Add(r1.Object);

            var e2 = EnviromentRepositoryTest.CreateMockEnvironment();
            var s2 = e2.Object;
            var c2 = Mock.Get(e2.Object.Connection);
            c2.Setup(c => c.Disconnect()).Verifiable();

            var resourceRepo2 = new ResourceRepository(e2.Object);
            e2.Setup(e => e.ResourceRepository).Returns(resourceRepo2);

            var serverProvider = new Mock<IEnvironmentModelProvider>();
            serverProvider.Setup(s => s.Load()).Returns(new List<IEnvironmentModel> { s1, s2 });

            var repo = new TestEnvironmentRespository(source.Object, e1.Object, e2.Object);

            var statsCalc = new Mock<IDeployStatsCalculator>();
            IAsyncWorker asyncWorker = new TestAsyncWorker();
            statsCalc.Setup(s => s.SelectForDeployPredicate(It.IsAny<ExplorerItemModel>())).Returns(true);
            Mock<IStudioResourceRepository> mockStudioResourceRepository = new Mock<IStudioResourceRepository>();
            mockStudioResourceRepository.Setup(repository => repository.FindItem(It.IsAny<Func<IExplorerItemModel, bool>>())).Returns(new ExplorerItemModel(mockStudioResourceRepository.Object, asyncWorker, new Mock<IConnectControlSingleton>().Object));
            IStudioResourceRepository studioResourceRepository = mockStudioResourceRepository.Object;
            var deployViewModel = new DeployViewModel(asyncWorker, serverProvider.Object, repo, new Mock<IEventAggregator>().Object, studioResourceRepository, new Mock<IConnectControlViewModel>().Object, new Mock<IConnectControlViewModel>().Object, statsCalc.Object, null, null, new Mock<IConnectControlSingleton>().Object)
            {
                SelectedSourceServer = s1,
                SelectedDestinationServer = s2
            };

            Assert.IsTrue(source.Object.IsConnected);
            Assert.IsTrue(s1.IsConnected);
            Assert.IsTrue(s2.IsConnected);

            deployViewModel.DeployCommand.Execute(null);

            sourceConn.Verify(c => c.Disconnect(), Times.Never());
            c1.Verify(c => c.Disconnect(), Times.Never());
            c2.Verify(c => c.Disconnect(), Times.Never());
        }
Пример #11
0
        public void ResourceCreate()
        {
            var resource = new Resource()
                               {
                                   Name = "Account",
                                   ResourceDocs = new List<ResourceDoc>()
                                              {
                                                  new ResourceDoc()
                                                      {
                                                          Language = "en",
                                                          Summary = "This is the default English summary"
                                                      },
                                                  new ResourceDoc()
                                                      {
                                                          Language = "fr",
                                                          Summary = "This is the French summary"
                                                      }
                                              }

                               };

            resource.Fields = new List<Field>()
                                  {
                                      new Field()
                                          {
                                              Name = "Reference",
                                              FieldType = "string",
                                              Resource = resource
                                          },
                                      new Field()
                                          {
                                              Name = "EndOn",
                                              FieldType = "datetime",
                                              Resource = resource
                                          }
                                  };

            using (var repository = new ResourceRepository())
            {
                repository.Add(resource);
                repository.SaveChanges();
            }

            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["api.docs.data"].ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("SELECT Id, Name FROM Resources", connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        Assert.IsTrue(reader.Read());
                        Assert.AreEqual(resource.Name, reader.GetString(1));
                        Assert.IsFalse(reader.Read());
                    }
                }

                using (var command = new SqlCommand("SELECT Id, ResourceId, Language, Summary FROM ResourceDocs", connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        int i = 0;
                        while (reader.Read())
                        {
                            var docs = new List<ResourceDoc>(resource.ResourceDocs);

                            Assert.AreEqual(resource.Id, reader.GetGuid(1));
                            Assert.AreEqual(docs[i].Language, reader.GetString(2));
                            Assert.AreEqual(docs[i].Summary, reader.GetString(3));
                            i++;
                        }
                        Assert.AreEqual(i, resource.ResourceDocs.Count);
                    }
                }

                using (var command = new SqlCommand("SELECT Id, ResourceId, Name, FieldType FROM Fields", connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        int i = 0;
                        while (reader.Read())
                        {
                            var fields = new List<Field>(resource.Fields);

                            Assert.AreEqual(resource.Id, reader.GetGuid(1));
                            Assert.AreEqual(fields[i].Name, reader.GetString(2));
                            Assert.AreEqual(fields[i].FieldType, reader.GetString(3));
                            i++;
                        }
                        Assert.AreEqual(i, resource.Fields.Count);
                    }
                }
            }
        }
Пример #12
0
        public void ResourceDelete()
        {
            var resource = new Resource()
            {
                Name = "Account",
                ResourceDocs = new List<ResourceDoc>()
                                              {
                                                  new ResourceDoc()
                                                      {
                                                          Language = "en",
                                                          Summary = "This is the default English summary"
                                                      },
                                                  new ResourceDoc()
                                                      {
                                                          Language = "fr",
                                                          Summary = "This is the French summary"
                                                      }
                                              }
            };

            using (var repository = new ResourceRepository())
            {
                repository.Add(resource);
                repository.SaveChanges();

                repository.DeleteById(resource.Id);
                repository.SaveChanges();
            }

            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["api.docs.data"].ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("SELECT Id, Name FROM Resources", connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        Assert.IsFalse(reader.Read(), "Resources table");
                    }
                }

                using (var command = new SqlCommand("SELECT Id, ResourceId, Language, Summary FROM ResourceDocs", connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        Assert.IsFalse(reader.Read(), "Docs table");
                    }
                }
            }

        }
Пример #13
0
        public void ResourceRead()
        {
            var resource = new Resource()
            {
                Name = "Account",
                ResourceDocs = new List<ResourceDoc>()
                                              {
                                                  new ResourceDoc()
                                                      {
                                                          Language = "en",
                                                          Summary = "This is the default English summary"
                                                      },
                                                  new ResourceDoc()
                                                      {
                                                          Language = "fr",
                                                          Summary = "This is the French summary"
                                                      }
                                              }
            };

            using (var repository = new ResourceRepository())
            {
                repository.Add(resource);
                repository.SaveChanges();

                var actual = repository.GetById(resource.Id);

                Assert.AreEqual(resource.Name, actual.Name);
                Assert.AreEqual(resource.ResourceDocs.Count, actual.ResourceDocs.Count);

                var docs = new List<ResourceDoc>(resource.ResourceDocs);
                var actualDocs = new List<ResourceDoc>(actual.ResourceDocs);

                for (int i = 0; i < docs.Count; i++)
                {
                    Assert.AreEqual(docs[i].Language, actualDocs[i].Language);
                    Assert.AreEqual(docs[i].Summary, actualDocs[i].Summary);
                }
            }
        }
Пример #14
0
 public void Add(Resource resource)
 {
     ResourceRepository.Add(resource);
 }
Пример #15
0
        // kantaan tallennus ja update samassa sql tasolla
        private void btnSave_Click(object sender, EventArgs e)
        {
            int        selectedItemType = cboItemTypeSelector.SelectedIndex;
            EntityBase selectedItem     = (EntityBase)dgvItems.SelectedRows[0].DataBoundItem;

            FormHelper.ClearErrors(currentLayout, errorProvider);

            if (FormHelper.ValidateTextFields(currentLayout, errorProvider))
            {
                switch (selectedItemType)
                {
                case 0:
                case 1:
                case 2:
                    rRepository.Add(new Resource {
                        Id   = editMode ? selectedItem.Id : default(int?),      //editmodessa id valitusta rivistä, muuten null
                        Name = tbResourceName.Text,
                        Type = cboItemTypeSelector.SelectedIndex + 1
                    });
                    break;

                case 3:
                    uRepository.Add(new User {
                        Id             = editMode ? selectedItem.Id : default(int?),
                        Name           = tbUserName.Text,
                        Address        = tbUserAddress.Text,
                        Zip            = tbUserZip.Text,
                        City           = tbUserCity.Text,
                        ResearchAreaId = (int)cboUserResearchArea.SelectedValue,
                        Key            = tbUserKey.Text
                    });
                    break;

                case 4:
                    wsRepository.Add(new WaterSystem {
                        Id   = editMode ? selectedItem.Id : default(int?),
                        Name = tbResourceName.Text
                    });
                    break;

                case 5:
                    faRepository.Add(new FishingArea {
                        Id             = editMode ? selectedItem.Id : default(int?),
                        Name           = tbFishingAreaName.Text,
                        ResearchAreaId = (int)cboFishingAreaResearchArea.SelectedValue
                    });
                    break;

                case 6:
                    raRepository.Add(new ResearchArea {
                        Id            = editMode ? selectedItem.Id : default(int?),
                        Name          = tbResearchAreaName.Text,
                        WaterSystemId = (int)cboResearchAreaWaterSystem.SelectedValue
                    });
                    break;

                default:
                    break;
                }

                FormHelper.ClearFields(currentLayout);
                SetEditMode(false);
                cboItemTypeSelector_SelectedIndexChanged(null, null);
            }
        }
Пример #16
0
 internal Resource Add(Resource resource)
 => _resourceRepository.Add(resource);