Exemplo n.º 1
0
        public void ShouldPreparePlugin()
        {
            const long pluginId  = 123;
            const long projectId = 432;
            const long userId    = 523;

            var pluginObject = _plugin.Object;

            var settingsDictionary = new Dictionary <string, string>
            {
                { "param1", "value1" }
            };

            _pluginActivator
            .Setup(_ => _.Activate(pluginId))
            .Returns(pluginObject);

            _pluginSettingProvider
            .Setup(_ => _.GetSettingsForPlugin(pluginId, projectId, userId))
            .Returns(settingsDictionary);

            var result = _target.Prepare(pluginId, projectId, userId);

            result.Should().NotBeNull();
            result.IsSameOrEqualTo(pluginObject);

            _plugin.Verify(_ => _.LoadSettingValues(settingsDictionary), Times.Once);
        }
Exemplo n.º 2
0
        private IVersionControlPlugin GetPlugin([CanBeNull] Projects project)
        {
            if (project?.VcsPluginId == null)
            {
                return(null);
            }

            var plugin = _pluginFactory.Prepare(project.VcsPluginId.Value, project.Id);

            var vcsPlugin = plugin as IVersionControlPlugin;

            return(vcsPlugin);
        }
Exemplo n.º 3
0
        public BranchDto[] GetBranches(long projectId)
        {
            var project = _projectRepository.GetById(projectId);

            if (project == null)
            {
                return(new BranchDto[0]);
            }

            var projectVcsPluginId = project.VcsPluginId;

            var userId = _userPrincipal.Info.Id;

            if (projectVcsPluginId == null)
            {
                throw new Exception();
            }

            var vcsPlugin = _pluginFactory.Prepare(projectVcsPluginId.Value, projectId, userId) as IVersionControlPlugin;

            var branches = vcsPlugin?.GetBranches().ToArray();

            if (branches == null)
            {
                return(new BranchDto[0]);
            }

            var branchDtos = branches.Select(_ => _.ToDto()).ToArray();

            foreach (var branch in branchDtos)
            {
                branch.IsDefault           = branch.Id == project.DefaultBranchName;
                branch.LastScanFinishedUtc = _taskRepository.GetLast(projectId, branch.Name)?.Finished;
            }

            return(branchDtos);
        }
 /// <summary>
 ///   Gets the plugin.
 /// </summary>
 /// <typeparam name="TPlugin">The type of the plugin.</typeparam>
 /// <param name="pluginId">The plugin identifier.</param>
 /// <param name="userId">The user identifier.</param>
 /// <param name="projectId">The project identifier.</param>
 /// <returns>The plugin instance.</returns>
 public TPlugin GetPlugin <TPlugin>(long pluginId, long userId, long projectId)
     where TPlugin : class, ICorePlugin
 => (userId == _userPrincipal.Info.Id
                         ? _pluginFactory.Prepare(pluginId, projectId)
     : _pluginFactory.Prepare(pluginId, projectId, userId)) as TPlugin;