diff --git a/.github/workflows/build-project.yml b/.github/workflows/build-project.yml
index d1cb4bed..c01810af 100644
--- a/.github/workflows/build-project.yml
+++ b/.github/workflows/build-project.yml
@@ -68,12 +68,9 @@ jobs:
with:
vs-version: '[17.0, )'
- - name: Restore NuGet packages
- run: nuget restore ${{ inputs.solution-file-path }}
-
- name: Build
run: |
- msbuild ${{ inputs.solution-file-path }} /p:configuration=Release /p:DeployExtension=false /p:ZipPackageCompressionLevel=normal /v:m
+ msbuild ${{ inputs.solution-file-path }} /p:configuration=Release /p:DeployExtension=false /p:ZipPackageCompressionLevel=normal /t:restore /p:RestoreLockedMode=true /v:m
shell: powershell
- name: Upload build artifacts
diff --git a/.github/workflows/security-scan-upload.yml b/.github/workflows/security-scan-upload.yml
index 32ef7bf0..0cc2c00a 100644
--- a/.github/workflows/security-scan-upload.yml
+++ b/.github/workflows/security-scan-upload.yml
@@ -14,7 +14,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Restore dependencies
- run: dotnet restore /home/runner/work/snyk-visual-studio-plugin/snyk-visual-studio-plugin
+ run: dotnet restore /home/runner/work/snyk-visual-studio-plugin/snyk-visual-studio-plugin --locked-mode
- name: Run snyk monitor
uses: snyk/actions/dotnet@master
continue-on-error: true
diff --git a/README.md b/README.md
index 5edd9c61..843a7326 100644
--- a/README.md
+++ b/README.md
@@ -48,4 +48,4 @@ Continue by following the instructions in the other Visual Studio extension docs
For troubleshooting and known issues, see [Troubleshooting and known issues with Visual Studio extension](https://docs.snyk.io/scm-ide-and-ci-cd-integrations/snyk-ide-plugins-and-extensions/visual-studio-extension/troubleshooting-and-known-issues-with-visual-studio-extension).
-If you need help, submit a request to [Snyk Support](https://support.snyk.io/hc/en-us/requests/new).
+If you need help, submit a request to [Snyk Support](https://support.snyk.io).
diff --git a/Snyk.VisualStudio.Extension.2022/Language/SnykLanguageClientCustomTarget.cs b/Snyk.VisualStudio.Extension.2022/Language/SnykLanguageClientCustomTarget.cs
index 564ecdee..99d4d9ae 100644
--- a/Snyk.VisualStudio.Extension.2022/Language/SnykLanguageClientCustomTarget.cs
+++ b/Snyk.VisualStudio.Extension.2022/Language/SnykLanguageClientCustomTarget.cs
@@ -116,7 +116,7 @@ public async Task OnHasAuthenticated(JToken arg)
{
if (arg?["token"] == null)
{
- await serviceProvider.Options.HandleFailedAuthentication("Authentication failed");
+ await serviceProvider.GeneralOptionsDialogPage.HandleFailedAuthentication("Authentication failed");
return;
}
@@ -134,7 +134,7 @@ public async Task OnHasAuthenticated(JToken arg)
serviceProvider.Options.ApiToken = new AuthenticationToken(serviceProvider.Options.AuthenticationMethod, token);
- await serviceProvider.Options.HandleAuthenticationSuccess(token, apiUrl);
+ await serviceProvider.GeneralOptionsDialogPage.HandleAuthenticationSuccess(token, apiUrl);
serviceProvider.FeatureFlagService.RefreshAsync(SnykVSPackage.Instance.DisposalToken).FireAndForget();
if (serviceProvider.Options.AutoScan)
diff --git a/Snyk.VisualStudio.Extension.2022/Service/ISnykServiceProvider.cs b/Snyk.VisualStudio.Extension.2022/Service/ISnykServiceProvider.cs
index 96541f42..41fcb079 100644
--- a/Snyk.VisualStudio.Extension.2022/Service/ISnykServiceProvider.cs
+++ b/Snyk.VisualStudio.Extension.2022/Service/ISnykServiceProvider.cs
@@ -46,6 +46,7 @@ public interface ISnykServiceProvider
/// Gets (Settings) implementation instance.
///
ISnykOptions Options { get; }
+ ISnykGeneralOptionsDialogPage GeneralOptionsDialogPage { get; }
///
/// Gets Visual Studio Settiings Manager instance.
diff --git a/Snyk.VisualStudio.Extension.2022/Service/SnykService.cs b/Snyk.VisualStudio.Extension.2022/Service/SnykService.cs
index 53705e9e..3112722f 100644
--- a/Snyk.VisualStudio.Extension.2022/Service/SnykService.cs
+++ b/Snyk.VisualStudio.Extension.2022/Service/SnykService.cs
@@ -59,6 +59,8 @@ public SnykService(IAsyncServiceProvider serviceProvider, string vsVersion = "")
///
public ISnykOptions Options => this.Package.Options;
+ public ISnykGeneralOptionsDialogPage GeneralOptionsDialogPage => this.Package.SnykGeneralOptionsDialogPage;
+
///
/// Gets solution service.
///
diff --git a/Snyk.VisualStudio.Extension.2022/Service/SnykTasksService.cs b/Snyk.VisualStudio.Extension.2022/Service/SnykTasksService.cs
index 08def074..a51b638a 100644
--- a/Snyk.VisualStudio.Extension.2022/Service/SnykTasksService.cs
+++ b/Snyk.VisualStudio.Extension.2022/Service/SnykTasksService.cs
@@ -306,7 +306,7 @@ public async Task IsFolderTrustedAsync()
try
{
this.serviceProvider.WorkspaceTrustService.AddFolderToTrusted(solutionFolderPath);
- this.serviceProvider.Options.FireSettingsChangedEvent();
+ this.serviceProvider.Options.InvokeSettingsChangedEvent();
Logger.Information("Workspace folder was trusted: {SolutionFolderPath}", solutionFolderPath);
return true;
}
diff --git a/Snyk.VisualStudio.Extension.2022/Settings/ISnykGeneralOptionsDialogPage.cs b/Snyk.VisualStudio.Extension.2022/Settings/ISnykGeneralOptionsDialogPage.cs
new file mode 100644
index 00000000..3f5a0606
--- /dev/null
+++ b/Snyk.VisualStudio.Extension.2022/Settings/ISnykGeneralOptionsDialogPage.cs
@@ -0,0 +1,12 @@
+using Snyk.VisualStudio.Extension.Service;
+using System.Threading.Tasks;
+
+namespace Snyk.VisualStudio.Extension.Settings;
+
+public interface ISnykGeneralOptionsDialogPage
+{
+ void Initialize(ISnykServiceProvider provider);
+ Task HandleAuthenticationSuccess(string token, string apiUrl);
+ Task HandleFailedAuthentication(string errorMessage);
+ void Authenticate();
+}
\ No newline at end of file
diff --git a/Snyk.VisualStudio.Extension.2022/Settings/ISnykOptions.cs b/Snyk.VisualStudio.Extension.2022/Settings/ISnykOptions.cs
index 38db1f5e..fe1e05c7 100644
--- a/Snyk.VisualStudio.Extension.2022/Settings/ISnykOptions.cs
+++ b/Snyk.VisualStudio.Extension.2022/Settings/ISnykOptions.cs
@@ -3,7 +3,6 @@
using System.Threading.Tasks;
using Snyk.VisualStudio.Extension.Authentication;
using Snyk.VisualStudio.Extension.Language;
-using Snyk.VisualStudio.Extension.Service;
namespace Snyk.VisualStudio.Extension.Settings
{
@@ -12,7 +11,6 @@ namespace Snyk.VisualStudio.Extension.Settings
///
public interface ISnykOptions
{
- void Initialize(ISnykServiceProvider provider);
string Application { get; set; }
string ApplicationVersion { get; set; }
string IntegrationName { get; }
@@ -24,8 +22,8 @@ public interface ISnykOptions
bool AutoScan { get; set; }
bool ConsistentIgnoresEnabled { get; set; }
- public bool OpenIssuesEnabled { get; set; }
- public bool IgnoredIssuesEnabled { get; set; }
+ bool OpenIssuesEnabled { get; set; }
+ bool IgnoredIssuesEnabled { get; set; }
///
/// Gets or sets a value indicating whether Snyk user API token.
@@ -35,7 +33,7 @@ public interface ISnykOptions
///
/// Gets Value of Authentication Token Type.
///
- AuthenticationType AuthenticationMethod { get; }
+ AuthenticationType AuthenticationMethod { get; set; }
///
/// Gets or sets a value indicating whether CLI custom endpoint parameter.
@@ -60,18 +58,18 @@ public interface ISnykOptions
///
/// Gets a value indicating whether is Oss scan enabled.
///
- bool OssEnabled { get; }
- bool IacEnabled { get; }
+ bool OssEnabled { get; set; }
+ bool IacEnabled { get; set; }
///
/// Gets a value indicating whether is Oss scan enabled.
///
- bool SnykCodeSecurityEnabled { get; }
+ bool SnykCodeSecurityEnabled { get; set; }
///
/// Gets a value indicating whether is Oss scan enabled.
///
- bool SnykCodeQualityEnabled { get; }
+ bool SnykCodeQualityEnabled { get; set; }
///
/// Gets or sets a value indicating whether the CLI should be automatically updated.
@@ -86,8 +84,8 @@ public interface ISnykOptions
string CliDownloadUrl { get; set; }
ISet TrustedFolders { get; set; }
- public bool EnableDeltaFindings { get; set; }
- public List FolderConfigs { get; set; }
+ bool EnableDeltaFindings { get; set; }
+ List FolderConfigs { get; set; }
///
/// Settings changed event.
@@ -108,18 +106,10 @@ public interface ISnykOptions
/// representing the asynchronous operation.
Task IsScanAllProjectsAsync();
- ///
- /// Attempts to pull the token from the CLI config storage, and validates the token.
- /// If the token is invalid, attempts to run the authentication command.
- ///
- /// Returns true if authenticated successfully, or if a valid token was loaded from storage.
- void Authenticate();
- public string CurrentCliVersion { get; set; }
-
+ string CurrentCliVersion { get; set; }
SastSettings SastSettings { get; set; }
bool AnalyticsPluginInstalledSent { get; set; }
- Task HandleAuthenticationSuccess(string token, string apiUrl);
- Task HandleFailedAuthentication(string errorMessage);
- void FireSettingsChangedEvent();
+ void InvokeSettingsChangedEvent();
+ void SaveSettings();
}
}
\ No newline at end of file
diff --git a/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralOptionsDialogPage.cs b/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralOptionsDialogPage.cs
index de0918a2..62586245 100644
--- a/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralOptionsDialogPage.cs
+++ b/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralOptionsDialogPage.cs
@@ -1,12 +1,12 @@
using System;
-using System.Collections.Generic;
+using System.ComponentModel;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
+using System.Windows.Controls;
using System.Windows.Forms;
using Microsoft.VisualStudio.Shell;
using Serilog;
-using Snyk.VisualStudio.Extension.Authentication;
using Snyk.VisualStudio.Extension.CLI;
using Snyk.VisualStudio.Extension.Language;
using Snyk.VisualStudio.Extension.Service;
@@ -18,192 +18,46 @@ namespace Snyk.VisualStudio.Extension.Settings
///
[Guid("d45468c1-33d2-4dca-9780-68abaedf95e7")]
[ComVisible(true)]
- public class SnykGeneralOptionsDialogPage : DialogPage, ISnykOptions
+ public class SnykGeneralOptionsDialogPage : DialogPage, ISnykGeneralOptionsDialogPage
{
- public string Application { get; set; }
- public string ApplicationVersion { get; set; }
- public string IntegrationName { get; } = SnykExtension.IntegrationName;
- public string IntegrationVersion { get; } = SnykExtension.Version;
- public string IntegrationEnvironment { get; set; }
- public string IntegrationEnvironmentVersion { get; set;}
-
- public string DeviceId
- {
- get => this.userStorageSettingsService.DeviceId;
- set => this.userStorageSettingsService.DeviceId = value;
- }
-
private ISnykServiceProvider serviceProvider;
-
- private IUserStorageSettingsService userStorageSettingsService;
-
private SnykGeneralSettingsUserControl generalSettingsUserControl;
-
private static readonly ILogger Logger = LogManager.ForContext();
- public ISet TrustedFolders
- {
- get => this.userStorageSettingsService.TrustedFolders;
- set
- {
- if (this.userStorageSettingsService == null || this.userStorageSettingsService.TrustedFolders == value)
- return;
- this.userStorageSettingsService.TrustedFolders = value;
- }
- }
-
- public bool EnableDeltaFindings
- {
- get => this.userStorageSettingsService.EnableDeltaFindings;
- set
- {
- if (this.userStorageSettingsService == null || this.userStorageSettingsService.EnableDeltaFindings == value)
- return;
- this.userStorageSettingsService.EnableDeltaFindings = value;
- userStorageSettingsService.SaveSettings();
- }
- }
-
- public List FolderConfigs
- {
- get => this.userStorageSettingsService.FolderConfigs;
- set
- {
- if (this.userStorageSettingsService == null)
- return;
- this.userStorageSettingsService.FolderConfigs = value;
- userStorageSettingsService.SaveSettings();
- FireSettingsChangedEvent();
- }
- }
-
- ///
- public event EventHandler SettingsChanged;
-
- ///
- /// Gets a value indicating whether service provider.
- ///
- public ISnykServiceProvider ServiceProvider => this.serviceProvider;
-
- public bool ConsistentIgnoresEnabled { get; set; }
-
- public bool OpenIssuesEnabled
- {
- get => this.userStorageSettingsService.OpenIssuesEnabled;
- set
- {
- if (this.userStorageSettingsService == null || this.userStorageSettingsService.OpenIssuesEnabled == value)
- return;
- this.userStorageSettingsService.OpenIssuesEnabled = value;
- }
- }
-
- public bool IgnoredIssuesEnabled
+ protected override void OnActivate(CancelEventArgs e)
{
- get => this.userStorageSettingsService.IgnoredIssuesEnabled;
- set
- {
- if (this.userStorageSettingsService == null || this.userStorageSettingsService.IgnoredIssuesEnabled == value)
- return;
- this.userStorageSettingsService.IgnoredIssuesEnabled = value;
- }
- }
+ base.OnActivate(e);
- ///
- /// Gets or sets a value indicating whether API token.
- ///
- public AuthenticationToken ApiToken
- {
- get => CreateAuthenticationToken(this.userStorageSettingsService.Token);
- set
- {
- var tokenAsString = value.ToString();
- if (this.userStorageSettingsService == null || this.userStorageSettingsService.Token == tokenAsString)
- return;
- this.userStorageSettingsService.Token = tokenAsString;
- userStorageSettingsService.SaveSettings();
- FireSettingsChangedEvent();
- }
- }
-
- public AuthenticationType AuthenticationMethod
- {
- get => this.userStorageSettingsService.AuthenticationMethod;
- set
- {
- if (this.userStorageSettingsService == null || this.userStorageSettingsService.AuthenticationMethod == value)
- return;
- this.userStorageSettingsService.AuthenticationMethod = value;
- this.GeneralSettingsUserControl.InvalidateApiToken();
- ApiToken = AuthenticationToken.EmptyToken;
- userStorageSettingsService.SaveSettings();
- FireSettingsChangedEvent();
- }
+ ResetScrollbarSettings();
}
- public bool AutoScan
- {
- get => this.userStorageSettingsService.AutoScan;
- set
- {
- if (this.userStorageSettingsService == null)
- return;
- this.userStorageSettingsService.AutoScan = value;
- }
- }
-
- private AuthenticationToken CreateAuthenticationToken(string token)
+ protected override void OnClosed(EventArgs e)
{
- var tokenObj = new AuthenticationToken(this.AuthenticationMethod, token);
- return tokenObj;
+ ResetScrollbarSettings();
}
- ///
- /// Gets or sets a value indicating whether Custom endpoint.
- ///
- public string CustomEndpoint
+ private void ResetScrollbarSettings()
{
- get => this.userStorageSettingsService.CustomEndpoint;
- set
- {
- if (!Uri.IsWellFormedUriString(value, UriKind.Absolute))
- {
- Logger.Warning("Custom endpoint value is not a well-formed URI. Setting custom endpoint to empty string");
- value = string.Empty;
- }
-
- var newApiEndpoint = ApiEndpointResolver.TranslateOldApiToNewApiEndpoint(value);
- if (this.userStorageSettingsService == null || this.userStorageSettingsService.CustomEndpoint == newApiEndpoint)
- {
- return;
- }
+ if (this.generalSettingsUserControl == null)
+ return;
- this.userStorageSettingsService.CustomEndpoint = newApiEndpoint;
- ApiToken = AuthenticationToken.EmptyToken;
- userStorageSettingsService.SaveSettings();
- FireSettingsChangedEvent();
- }
+ // Reset the scroll position
+ this.generalSettingsUserControl.GetPanel().AutoScrollPosition = new System.Drawing.Point(0, 0);
+ this.generalSettingsUserControl.GetPanel().Top = 0;
+ this.generalSettingsUserControl.Top = 0;
+ // Force a refresh if needed
+ this.generalSettingsUserControl.Invalidate(true);
+ this.generalSettingsUserControl.Update();
}
- ///
- public string SnykCodeSettingsUrl => $"{this.GetBaseAppUrl()}/manage/snyk-code";
-
- private SastSettings sastSettings;
- public SastSettings SastSettings
+ public void Initialize(ISnykServiceProvider provider)
{
- get => this.sastSettings;
-
- set
- {
- this.sastSettings = value;
- }
+ this.serviceProvider = provider;
+ this.SnykOptions = provider.Options;
+ SnykOptions.SettingsChanged += SnykGeneralOptionsDialogPage_SettingsChanged;
}
- public bool AnalyticsPluginInstalledSent
- {
- get => this.userStorageSettingsService.AnalyticsPluginInstalledSent;
- set => this.userStorageSettingsService.AnalyticsPluginInstalledSent = value;
- }
+ public ISnykOptions SnykOptions { get; set; }
public async Task HandleAuthenticationSuccess(string token, string apiUrl)
{
@@ -214,183 +68,27 @@ public async Task HandleFailedAuthentication(string errorMessage)
{
await this.GeneralSettingsUserControl.HandleFailedAuthentication(errorMessage);
}
- ///
- /// Gets or sets a value indicating whether organization.
- ///
- public string Organization
- {
- get => this.userStorageSettingsService.Organization;
- set
- {
- if (this.userStorageSettingsService == null || this.userStorageSettingsService.Organization == value)
- {
- return;
- }
- this.userStorageSettingsService.Organization = value;
- userStorageSettingsService.SaveSettings();
- FireSettingsChangedEvent();
- }
- }
-
- ///
- /// Gets or sets a value indicating whether ignore unknown CA.
- ///
- public bool IgnoreUnknownCA
- {
- get => this.userStorageSettingsService.IgnoreUnknownCa;
- set
- {
- if (this.userStorageSettingsService == null || this.userStorageSettingsService.IgnoreUnknownCa == value)
- {
- return;
- }
- this.userStorageSettingsService.IgnoreUnknownCa = value;
- userStorageSettingsService.SaveSettings();
- FireSettingsChangedEvent();
- }
- }
-
- ///
- public bool OssEnabled
- {
- get => this.userStorageSettingsService.OssEnabled;
- set
- {
- if (this.userStorageSettingsService == null || userStorageSettingsService.OssEnabled == value)
- {
- return;
- }
-
- this.userStorageSettingsService.OssEnabled = value;
- }
- }
-
- public bool IacEnabled
- {
- get => this.userStorageSettingsService.IacEnabled;
- set
- {
- if (this.userStorageSettingsService == null || userStorageSettingsService.IacEnabled == value)
- {
- return;
- }
-
- this.userStorageSettingsService.IacEnabled = value;
- }
- }
-
- ///
- public bool SnykCodeSecurityEnabled
- {
- get => this.userStorageSettingsService.SnykCodeSecurityEnabled;
- set
- {
- if (this.userStorageSettingsService == null || userStorageSettingsService.SnykCodeSecurityEnabled == value)
- {
- return;
- }
-
- this.userStorageSettingsService.SnykCodeSecurityEnabled = value;
- }
- }
-
- ///
- public bool SnykCodeQualityEnabled
- {
- get => this.userStorageSettingsService.SnykCodeQualityEnabled;
- set
- {
- if (this.userStorageSettingsService == null || userStorageSettingsService.SnykCodeQualityEnabled == value)
- {
- return;
- }
-
- this.userStorageSettingsService.SnykCodeQualityEnabled = value;
- }
- }
-
- public bool BinariesAutoUpdate
- {
- get => this.userStorageSettingsService.BinariesAutoUpdate;
- set
- {
- if (this.userStorageSettingsService == null || this.userStorageSettingsService.BinariesAutoUpdate == value)
- {
- return;
- }
- this.userStorageSettingsService.BinariesAutoUpdate = value;
- }
- }
- public string CliCustomPath
- {
- get => this.userStorageSettingsService.CliCustomPath;
- set
- {
- if (this.userStorageSettingsService == null || this.userStorageSettingsService.CliCustomPath == value)
- {
- return;
- }
- this.userStorageSettingsService.CliCustomPath = value;
- }
- }
+ protected override IWin32Window Window => GeneralSettingsUserControl;
- public string CliReleaseChannel
- {
- get => this.userStorageSettingsService.CliReleaseChannel;
- set
- {
- if (this.userStorageSettingsService == null || this.userStorageSettingsService.CliReleaseChannel == value)
- {
- return;
- }
- this.userStorageSettingsService.CliReleaseChannel = value;
- }
- }
- public string CliDownloadUrl
+ public SnykGeneralSettingsUserControl GeneralSettingsUserControl
{
- get => this.userStorageSettingsService.CliDownloadUrl;
- set
- {
- if (this.userStorageSettingsService == null || this.userStorageSettingsService.CliDownloadUrl == value)
- {
- return;
- }
- this.userStorageSettingsService.CliDownloadUrl = value;
- }
- }
-
- public string CurrentCliVersion
- {
- get => this.userStorageSettingsService.CurrentCliVersion;
- set
+ get
{
- if (this.userStorageSettingsService == null || this.userStorageSettingsService.CurrentCliVersion == value)
+ if (generalSettingsUserControl == null)
{
- return;
+ generalSettingsUserControl = new SnykGeneralSettingsUserControl(serviceProvider);
}
- this.userStorageSettingsService.CurrentCliVersion = value;
+ return generalSettingsUserControl;
}
}
- ///
- /// Gets a value indicating whether General Settings control.
- ///
- protected override IWin32Window Window => this.GeneralSettingsUserControl;
-
// This method is used when the user clicks "Ok"
public override void SaveSettingsToStorage()
{
HandleCliDownload();
- this.userStorageSettingsService?.SaveSettings();
- this.FireSettingsChangedEvent();
- }
-
- protected override void OnClosed(EventArgs e)
- {
- if (generalSettingsUserControl == null)
- return;
- ResetControlScrollSettings(generalSettingsUserControl);
+ this.SnykOptions.SaveSettings();
+ this.SnykOptions.InvokeSettingsChangedEvent();
}
private void HandleCliDownload()
@@ -400,94 +98,43 @@ private void HandleCliDownload()
var manageBinariesAutomatically = generalSettingsUserControl.GetManageBinariesAutomatically();
if (!manageBinariesAutomatically)
{
- this.userStorageSettingsService.CurrentCliVersion = string.Empty;
- this.BinariesAutoUpdate = false;
+ this.SnykOptions.CurrentCliVersion = string.Empty;
+ this.SnykOptions.BinariesAutoUpdate = false;
serviceProvider.TasksService.CancelDownloadTask();
// Language Server restart will happen on DownloadCancelled Event.
return;
}
- if (this.CliReleaseChannel != releaseChannel || this.CliDownloadUrl != downloadUrl || this.BinariesAutoUpdate != manageBinariesAutomatically)
+ if (this.SnykOptions.CliReleaseChannel != releaseChannel || this.SnykOptions.CliDownloadUrl != downloadUrl || this.SnykOptions.BinariesAutoUpdate != manageBinariesAutomatically)
{
- this.CliDownloadUrl = downloadUrl;
- this.CliReleaseChannel = releaseChannel;
- this.BinariesAutoUpdate = manageBinariesAutomatically;
+ this.SnykOptions.CliDownloadUrl = downloadUrl;
+ this.SnykOptions.CliReleaseChannel = releaseChannel;
+ this.SnykOptions.BinariesAutoUpdate = manageBinariesAutomatically;
serviceProvider.TasksService.CancelDownloadTask();
this.serviceProvider.TasksService.Download();
}
}
- private void ResetControlScrollSettings(UserControl control)
- {
- control.VerticalScroll.Value = 0;
- control.HorizontalScroll.Value = 0;
- control.AutoScroll = true;
- }
-
- private SnykGeneralSettingsUserControl GeneralSettingsUserControl
- {
- get
- {
- if (this.generalSettingsUserControl == null)
- {
- this.generalSettingsUserControl = new SnykGeneralSettingsUserControl()
- {
- OptionsDialogPage = this,
- };
-
- this.generalSettingsUserControl.Initialize();
- }
-
- return this.generalSettingsUserControl;
- }
- }
-
- ///
- /// Gets a value indicating whether additional options.
- /// Get this data using .
- ///
- /// representing the asynchronous operation.
- public async Task GetAdditionalOptionsAsync() => await this.serviceProvider.UserStorageSettingsService.GetAdditionalOptionsAsync();
-
- ///
- /// Gets a value indicating whether is scan all projects enabled via .
- /// Get this data using .
- ///
- /// representing the asynchronous operation.
- public async Task IsScanAllProjectsAsync() => await this.userStorageSettingsService.GetIsAllProjectsEnabledAsync();
-
- ///
- /// Initialize .
- ///
- /// Snyk service provider.
- public void Initialize(ISnykServiceProvider provider)
- {
- this.serviceProvider = provider;
- SettingsChanged += SnykGeneralOptionsDialogPage_SettingsChanged;
- this.userStorageSettingsService = this.serviceProvider.UserStorageSettingsService;
- }
-
private void SnykGeneralOptionsDialogPage_SettingsChanged(object sender, SnykSettingsChangedEventArgs e)
{
ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
if (LanguageClientHelper.IsLanguageServerReady())
{
- await ServiceProvider.LanguageClientManager.DidChangeConfigurationAsync(SnykVSPackage
+ await serviceProvider.LanguageClientManager.DidChangeConfigurationAsync(SnykVSPackage
.Instance.DisposalToken);
- if (AutoScan)
- await ServiceProvider.LanguageClientManager.InvokeWorkspaceScanAsync(SnykVSPackage
+ if (this.SnykOptions.AutoScan)
+ await serviceProvider.LanguageClientManager.InvokeWorkspaceScanAsync(SnykVSPackage
.Instance.DisposalToken);
}
}).FireAndForget();
}
- ///
public void Authenticate()
{
Logger.Information("Enter Authenticate method");
- if (!SnykCli.IsCliFileFound(this.CliCustomPath))
+ if (!SnykCli.IsCliFileFound(this.SnykOptions.CliCustomPath))
{
- ThrowFileNotFoundException();
+ throw new FileNotFoundException("CLI not found");
}
try
{
@@ -496,16 +143,16 @@ public void Authenticate()
Logger.Error("Language Server is not initialized yet.");
return;
}
- if (ApiToken.IsValid())
+ if (this.SnykOptions.ApiToken.IsValid())
return;
-
+
Logger.Information("Api token is invalid. Attempting to authenticate via snyk auth");
ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
- await ServiceProvider.LanguageClientManager.InvokeLogout(SnykVSPackage.Instance
+ await serviceProvider.LanguageClientManager.InvokeLogout(SnykVSPackage.Instance
.DisposalToken);
- await ServiceProvider.LanguageClientManager.InvokeLogin(SnykVSPackage.Instance
+ await serviceProvider.LanguageClientManager.InvokeLogin(SnykVSPackage.Instance
.DisposalToken);
}).FireAndForget();
@@ -521,28 +168,5 @@ await ServiceProvider.LanguageClientManager.InvokeLogin(SnykVSPackage.Instance
}
}
- public void FireSettingsChangedEvent() => this.SettingsChanged?.Invoke(this, new SnykSettingsChangedEventArgs());
-
- public string GetCustomApiEndpoint()
- {
- return string.IsNullOrEmpty(CustomEndpoint) ? ApiEndpointResolver.DefaultApiEndpoint : ApiEndpointResolver.TranslateOldApiToNewApiEndpoint(CustomEndpoint);
- }
-
- public string GetBaseAppUrl()
- {
- if (string.IsNullOrEmpty(CustomEndpoint))
- return ApiEndpointResolver.DefaultAppEndpoint;
-
- var result = ApiEndpointResolver.GetCustomEndpointUrlFromSnykApi(GetCustomApiEndpoint(), "app");
-
- return string.IsNullOrEmpty(result) ? ApiEndpointResolver.DefaultAppEndpoint : result;
- }
-
- private void ThrowFileNotFoundException()
- {
- const string cliNotFound = "CLI not found";
- Logger.Information(cliNotFound);
- throw new FileNotFoundException(cliNotFound);
- }
}
}
diff --git a/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.Designer.cs b/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.Designer.cs
index b4fbf67e..0de34f58 100644
--- a/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.Designer.cs
+++ b/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.Designer.cs
@@ -86,12 +86,14 @@ private void InitializeComponent()
this.cliReleaseChannelLabel = new System.Windows.Forms.Label();
this.cliBaseDownloadUrl = new System.Windows.Forms.Label();
this.cliDownloadUrlTextBox = new System.Windows.Forms.TextBox();
+ this.mainPanel = new System.Windows.Forms.Panel();
((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
this.generalSettingsGroupBox.SuspendLayout();
this.productSelectionGroupBox.SuspendLayout();
this.ignoreGroupbox.SuspendLayout();
this.userExperienceGroupBox.SuspendLayout();
this.ExecutablesGroupBox.SuspendLayout();
+ this.mainPanel.SuspendLayout();
this.SuspendLayout();
//
// customEndpointTextBox
@@ -234,7 +236,7 @@ private void InitializeComponent()
this.generalSettingsGroupBox.Controls.Add(this.organizationLabel);
this.generalSettingsGroupBox.Controls.Add(this.ignoreUnknownCACheckBox);
this.generalSettingsGroupBox.Controls.Add(this.organizationTextBox);
- this.generalSettingsGroupBox.Location = new System.Drawing.Point(13, 12);
+ this.generalSettingsGroupBox.Location = new System.Drawing.Point(29, 10);
this.generalSettingsGroupBox.Margin = new System.Windows.Forms.Padding(11, 10, 11, 10);
this.generalSettingsGroupBox.Name = "generalSettingsGroupBox";
this.generalSettingsGroupBox.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
@@ -391,7 +393,7 @@ private void InitializeComponent()
this.productSelectionGroupBox.Controls.Add(this.codeQualityEnabledCheckBox);
this.productSelectionGroupBox.Controls.Add(this.ossEnabledCheckBox);
this.productSelectionGroupBox.Controls.Add(this.codeSecurityEnabledCheckBox);
- this.productSelectionGroupBox.Location = new System.Drawing.Point(13, 711);
+ this.productSelectionGroupBox.Location = new System.Drawing.Point(29, 709);
this.productSelectionGroupBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.productSelectionGroupBox.Name = "productSelectionGroupBox";
this.productSelectionGroupBox.Padding = new System.Windows.Forms.Padding(11, 10, 11, 10);
@@ -571,7 +573,7 @@ private void InitializeComponent()
// userExperienceGroupBox
//
this.userExperienceGroupBox.Controls.Add(this.autoScanCheckBox);
- this.userExperienceGroupBox.Location = new System.Drawing.Point(13, 957);
+ this.userExperienceGroupBox.Location = new System.Drawing.Point(29, 955);
this.userExperienceGroupBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.userExperienceGroupBox.Name = "userExperienceGroupBox";
this.userExperienceGroupBox.Padding = new System.Windows.Forms.Padding(11, 10, 11, 10);
@@ -627,7 +629,7 @@ private void InitializeComponent()
this.ExecutablesGroupBox.Controls.Add(this.CliPathBrowseButton);
this.ExecutablesGroupBox.Controls.Add(this.ManageBinariesAutomaticallyCheckbox);
this.ExecutablesGroupBox.Controls.Add(this.CliPathTextBox);
- this.ExecutablesGroupBox.Location = new System.Drawing.Point(13, 428);
+ this.ExecutablesGroupBox.Location = new System.Drawing.Point(29, 426);
this.ExecutablesGroupBox.Margin = new System.Windows.Forms.Padding(4);
this.ExecutablesGroupBox.Name = "ExecutablesGroupBox";
this.ExecutablesGroupBox.Padding = new System.Windows.Forms.Padding(4);
@@ -683,15 +685,25 @@ private void InitializeComponent()
this.cliDownloadUrlTextBox.Size = new System.Drawing.Size(399, 22);
this.cliDownloadUrlTextBox.TabIndex = 21;
//
+ // mainPanel
+ //
+ this.mainPanel.AutoScroll = true;
+ this.mainPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.mainPanel.Controls.Add(this.generalSettingsGroupBox);
+ this.mainPanel.Controls.Add(this.ExecutablesGroupBox);
+ this.mainPanel.Controls.Add(this.productSelectionGroupBox);
+ this.mainPanel.Controls.Add(this.userExperienceGroupBox);
+ this.mainPanel.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.mainPanel.Location = new System.Drawing.Point(0, 0);
+ this.mainPanel.Name = "mainPanel";
+ this.mainPanel.Size = new System.Drawing.Size(1060, 1041);
+ this.mainPanel.TabIndex = 20;
+ //
// SnykGeneralSettingsUserControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.AutoScroll = true;
- this.Controls.Add(this.ExecutablesGroupBox);
- this.Controls.Add(this.userExperienceGroupBox);
- this.Controls.Add(this.productSelectionGroupBox);
- this.Controls.Add(this.generalSettingsGroupBox);
+ this.Controls.Add(this.mainPanel);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.MinimumSize = new System.Drawing.Size(1060, 923);
this.Name = "SnykGeneralSettingsUserControl";
@@ -707,6 +719,7 @@ private void InitializeComponent()
this.userExperienceGroupBox.PerformLayout();
this.ExecutablesGroupBox.ResumeLayout(false);
this.ExecutablesGroupBox.PerformLayout();
+ this.mainPanel.ResumeLayout(false);
this.ResumeLayout(false);
}
@@ -765,5 +778,6 @@ private void InitializeComponent()
private Label label3;
private ComboBox cbDelta;
private Label label4;
+ private Panel mainPanel;
}
}
diff --git a/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.cs b/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.cs
index cfd02ea6..0c4eb93e 100644
--- a/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.cs
+++ b/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -25,39 +24,40 @@ namespace Snyk.VisualStudio.Extension.Settings
///
public partial class SnykGeneralSettingsUserControl : UserControl
{
- private static readonly ILogger logger = LogManager.ForContext();
+ private readonly ISnykServiceProvider serviceProvider;
+ private static readonly ILogger Logger = LogManager.ForContext();
///
/// Instance of SnykGeneralOptionsDialogPage.
///
- [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Reviewed.")]
- internal SnykGeneralOptionsDialogPage OptionsDialogPage;
+ private readonly ISnykOptions snykOptions;
private static readonly int TwoSecondsDelay = 2000;
- private static readonly int MaxSastRequestAttempts = 20;
+ private const int MaxSastRequestAttempts = 20;
- private Timer snykCodeEnableTimer = new Timer();
+ private readonly Timer snykCodeEnableTimer = new Timer();
///
/// Initializes a new instance of the class.
///
- /// Snyk API service instance.
- public SnykGeneralSettingsUserControl()
+ ///
+ public SnykGeneralSettingsUserControl(ISnykServiceProvider serviceProvider)
{
+ this.serviceProvider = serviceProvider;
+ snykOptions = this.serviceProvider.Options;
this.InitializeComponent();
+ this.Initialize();
}
-
- private ISnykServiceProvider ServiceProvider => this.OptionsDialogPage.ServiceProvider;
-
+
///
/// Initialize elements and actions.
///
- public void Initialize()
+ private void Initialize()
{
- logger.Information("Enter Initialize method");
+ Logger.Information("Enter Initialize method");
this.UpdateViewFromOptionsDialog();
- this.OptionsDialogPage.SettingsChanged += this.OptionsDialogPageOnSettingsChanged;
+ snykOptions.SettingsChanged += this.OptionsDialogPageOnSettingsChanged;
this.Load += this.SnykGeneralSettingsUserControl_Load;
if (LanguageClientHelper.LanguageClientManager() != null)
@@ -65,8 +65,8 @@ public void Initialize()
LanguageClientHelper.LanguageClientManager().OnLanguageClientNotInitializedAsync += OnOnLanguageClientNotInitializedAsync;
LanguageClientHelper.LanguageClientManager().OnLanguageServerReadyAsync += OnOnLanguageServerReadyAsync;
}
- this.ServiceProvider.ToolWindow.Show();
- logger.Information("Leave Initialize method");
+ this.serviceProvider.ToolWindow.Show();
+ Logger.Information("Leave Initialize method");
}
private async Task OnOnLanguageServerReadyAsync(object sender, SnykLanguageServerEventArgs args)
@@ -84,21 +84,21 @@ private async Task OnOnLanguageClientNotInitializedAsync(object sender, SnykLang
private void UpdateViewFromOptionsDialog()
{
this.authenticateButton.Enabled = LanguageClientHelper.IsLanguageServerReady();
- this.customEndpointTextBox.Text = this.OptionsDialogPage.CustomEndpoint;
- this.organizationTextBox.Text = this.OptionsDialogPage.Organization;
- this.ignoreUnknownCACheckBox.Checked = this.OptionsDialogPage.IgnoreUnknownCA;
- this.ossEnabledCheckBox.Checked = this.OptionsDialogPage.OssEnabled;
- this.iacEnabledCheckbox.Checked = this.OptionsDialogPage.IacEnabled;
- this.ManageBinariesAutomaticallyCheckbox.Checked = this.OptionsDialogPage.BinariesAutoUpdate;
- this.autoScanCheckBox.Checked = this.OptionsDialogPage.AutoScan;
- this.cliDownloadUrlTextBox.Text = this.OptionsDialogPage.CliDownloadUrl;
- this.tokenTextBox.Text = this.OptionsDialogPage.ApiToken.ToString();
- this.cbIgnoredIssues.Checked = this.OptionsDialogPage.IgnoredIssuesEnabled;
- this.cbOpenIssues.Checked = this.OptionsDialogPage.OpenIssuesEnabled;
-
- var cliPath = string.IsNullOrEmpty(this.OptionsDialogPage.CliCustomPath)
+ this.customEndpointTextBox.Text = snykOptions.CustomEndpoint;
+ this.organizationTextBox.Text = snykOptions.Organization;
+ this.ignoreUnknownCACheckBox.Checked = snykOptions.IgnoreUnknownCA;
+ this.ossEnabledCheckBox.Checked = snykOptions.OssEnabled;
+ this.iacEnabledCheckbox.Checked = snykOptions.IacEnabled;
+ this.ManageBinariesAutomaticallyCheckbox.Checked = snykOptions.BinariesAutoUpdate;
+ this.autoScanCheckBox.Checked = snykOptions.AutoScan;
+ this.cliDownloadUrlTextBox.Text = snykOptions.CliDownloadUrl;
+ this.tokenTextBox.Text = snykOptions.ApiToken.ToString();
+ this.cbIgnoredIssues.Checked = snykOptions.IgnoredIssuesEnabled;
+ this.cbOpenIssues.Checked = snykOptions.OpenIssuesEnabled;
+
+ var cliPath = string.IsNullOrEmpty(snykOptions.CliCustomPath)
? SnykCli.GetSnykCliDefaultPath()
- : this.OptionsDialogPage.CliCustomPath;
+ : snykOptions.CliCustomPath;
this.CliPathTextBox.Text = cliPath;
if (releaseChannel.DataSource == null)
@@ -118,11 +118,12 @@ private void UpdateViewFromOptionsDialog()
this.authType.ValueMember = "Value";
}
- this.releaseChannel.SelectedItem = this.OptionsDialogPage.CliReleaseChannel;
- this.authType.SelectedValue = this.OptionsDialogPage.AuthenticationMethod;
- this.cbDelta.SelectedItem = this.OptionsDialogPage.EnableDeltaFindings ? "Net new issues" : "All issues";
+ this.releaseChannel.SelectedItem = snykOptions.CliReleaseChannel;
+ this.authType.SelectedValue = snykOptions.AuthenticationMethod;
+ this.cbDelta.SelectedItem = snykOptions.EnableDeltaFindings ? "Net new issues" : "All issues";
}
+
private IEnumerable
public ISnykOptions Options { get; private set; }
+ public ISnykGeneralOptionsDialogPage SnykGeneralOptionsDialogPage { get; private set; }
///
/// Gets instance.
@@ -279,17 +280,7 @@ private async Task InitializeGeneralOptionsAsync()
{
Logger.Information(
"Call GetDialogPage to create. await JoinableTaskFactory.SwitchToMainThreadAsync().");
-
- await JoinableTaskFactory.SwitchToMainThreadAsync();
-
- Logger.Information("GeneralOptionsDialogPage not created yet. Call GetDialogPage to create.");
-
- Options =
- (SnykGeneralOptionsDialogPage) GetDialogPage(typeof(SnykGeneralOptionsDialogPage));
-
- Logger.Information("Call generalOptionsDialogPage.Initialize()");
-
- Options.Initialize(this.serviceProvider);
+ Options = new SnykOptions(this.serviceProvider);
var readableVsVersion = await this.GetReadableVsVersionAsync();
var vsMajorMinorVersion = await this.GetVsMajorMinorVersionAsync();
Options.Application = readableVsVersion;
@@ -297,6 +288,18 @@ private async Task InitializeGeneralOptionsAsync()
Options.IntegrationEnvironment = readableVsVersion;
Options.IntegrationEnvironmentVersion = vsMajorMinorVersion;
}
+
+ if (SnykGeneralOptionsDialogPage == null)
+ {
+ await JoinableTaskFactory.SwitchToMainThreadAsync();
+
+ Logger.Information("GeneralOptionsDialogPage not created yet. Call GetDialogPage to create.");
+
+ SnykGeneralOptionsDialogPage =
+ (SnykGeneralOptionsDialogPage)GetDialogPage(typeof(SnykGeneralOptionsDialogPage));
+ Logger.Information("Call generalOptionsDialogPage.Initialize()");
+ SnykGeneralOptionsDialogPage.Initialize(this.serviceProvider);
+ }
}
private async Task GetVsVersionAsync()
diff --git a/Snyk.VisualStudio.Extension.2022/UI/Toolwindow/MessagePanel.xaml.cs b/Snyk.VisualStudio.Extension.2022/UI/Toolwindow/MessagePanel.xaml.cs
index 4a76492f..bef305cf 100644
--- a/Snyk.VisualStudio.Extension.2022/UI/Toolwindow/MessagePanel.xaml.cs
+++ b/Snyk.VisualStudio.Extension.2022/UI/Toolwindow/MessagePanel.xaml.cs
@@ -138,7 +138,7 @@ private async Task RunTestCodeNowAsync()
try
{
this.ServiceProvider.WorkspaceTrustService.AddFolderToTrusted(solutionFolderPath);
- this.ServiceProvider.Options.FireSettingsChangedEvent();
+ this.ServiceProvider.Options.InvokeSettingsChangedEvent();
Logger.Information("Workspace folder was trusted: {SolutionFolderPath}", solutionFolderPath);
}
catch (ArgumentException ex)
@@ -150,7 +150,7 @@ private async Task RunTestCodeNowAsync()
try
{
- this.ServiceProvider.Options.Authenticate();
+ this.ServiceProvider.GeneralOptionsDialogPage.Authenticate();
}
catch (FileNotFoundException)
{
diff --git a/Snyk.VisualStudio.Extension.2022/UI/Toolwindow/SnykToolWindowControl.xaml.cs b/Snyk.VisualStudio.Extension.2022/UI/Toolwindow/SnykToolWindowControl.xaml.cs
index 83e7b197..c920a09d 100644
--- a/Snyk.VisualStudio.Extension.2022/UI/Toolwindow/SnykToolWindowControl.xaml.cs
+++ b/Snyk.VisualStudio.Extension.2022/UI/Toolwindow/SnykToolWindowControl.xaml.cs
@@ -748,7 +748,7 @@ private void VulnerabilitiesTree_SelectetVulnerabilityChanged(object sender, Rou
new BranchSelectorDialogWindow(serviceProvider).ShowDialog();
return;
}
- catch (Exception ex)
+ catch (Exception)
{
}
diff --git a/Snyk.VisualStudio.Extension.Tests/Language/SnykLanguageClientCustomTargetTests.cs b/Snyk.VisualStudio.Extension.Tests/Language/SnykLanguageClientCustomTargetTests.cs
index 3cb87b60..9d68a4e6 100644
--- a/Snyk.VisualStudio.Extension.Tests/Language/SnykLanguageClientCustomTargetTests.cs
+++ b/Snyk.VisualStudio.Extension.Tests/Language/SnykLanguageClientCustomTargetTests.cs
@@ -19,6 +19,7 @@ public class SnykLanguageClientCustomTargetTests : PackageBaseTest
private readonly Mock optionsMock;
private readonly Mock userStorageSettingsServiceMock;
private readonly Mock languageClientManagerMock;
+ private readonly Mock generalSettingsPageMock;
private readonly SnykLanguageClientCustomTarget cut;
public SnykLanguageClientCustomTargetTests(GlobalServiceProvider gsp) : base(gsp)
@@ -26,6 +27,7 @@ public SnykLanguageClientCustomTargetTests(GlobalServiceProvider gsp) : base(gsp
var serviceProviderMock = new Mock();
tasksServiceMock = new Mock();
optionsMock = new Mock();
+ generalSettingsPageMock = new Mock();
userStorageSettingsServiceMock = new Mock();
languageClientManagerMock = new Mock();
@@ -36,6 +38,7 @@ public SnykLanguageClientCustomTargetTests(GlobalServiceProvider gsp) : base(gsp
serviceProviderMock.SetupGet(sp => sp.TasksService).Returns(tasksServiceMock.Object);
serviceProviderMock.SetupGet(sp => sp.Options).Returns(optionsMock.Object);
+ serviceProviderMock.SetupGet(sp => sp.GeneralOptionsDialogPage).Returns(generalSettingsPageMock.Object);
serviceProviderMock.SetupGet(sp => sp.UserStorageSettingsService).Returns(userStorageSettingsServiceMock.Object);
serviceProviderMock.SetupGet(sp => sp.FeatureFlagService).Returns(featureFlagServiceMock.Object);
serviceProviderMock.SetupGet(sp => sp.LanguageClientManager).Returns(languageClientManagerMock.Object);
@@ -112,13 +115,13 @@ public async Task OnHasAuthenticated_ShouldHandleFailedAuthentication_WhenTokenI
{
// Arrange
var arg = JObject.Parse("{}");
- optionsMock.Setup(o => o.HandleFailedAuthentication(It.IsAny())).Returns(Task.CompletedTask);
+ generalSettingsPageMock.Setup(o => o.HandleFailedAuthentication(It.IsAny())).Returns(Task.CompletedTask);
// Act
await cut.OnHasAuthenticated(arg);
// Assert
- optionsMock.Verify(o => o.HandleFailedAuthentication("Authentication failed"), Times.Once);
+ generalSettingsPageMock.Verify(o => o.HandleFailedAuthentication("Authentication failed"), Times.Once);
}
[Fact]
@@ -126,7 +129,7 @@ public async Task OnHasAuthenticated_ShouldHandleAuthenticationSuccess_WhenToken
{
// Arrange
var arg = JObject.Parse("{'token':'test-token','apiUrl':'https://api.snyk.io'}");
- optionsMock.Setup(o => o.HandleAuthenticationSuccess("test-token", "https://api.snyk.io")).Returns(Task.CompletedTask);
+ generalSettingsPageMock.Setup(o => o.HandleAuthenticationSuccess("test-token", "https://api.snyk.io")).Returns(Task.CompletedTask);
optionsMock.SetupGet(o => o.AuthenticationMethod).Returns(AuthenticationType.OAuth);
// Act
@@ -135,7 +138,7 @@ public async Task OnHasAuthenticated_ShouldHandleAuthenticationSuccess_WhenToken
// Assert
optionsMock.VerifySet(o => o.CustomEndpoint = "https://api.snyk.io");
optionsMock.VerifySet(o => o.ApiToken = It.Is(t => t.Type == AuthenticationType.OAuth && t.ToString() == "test-token"));
- optionsMock.Verify(o => o.HandleAuthenticationSuccess("test-token", "https://api.snyk.io"), Times.Once);
+ generalSettingsPageMock.Verify(o => o.HandleAuthenticationSuccess("test-token", "https://api.snyk.io"), Times.Once);
}
[Fact]
diff --git a/Snyk.VisualStudio.Extension.Tests/GeneralOptionsDialogPageTest.cs b/Snyk.VisualStudio.Extension.Tests/SnykOptionsTest.cs
similarity index 76%
rename from Snyk.VisualStudio.Extension.Tests/GeneralOptionsDialogPageTest.cs
rename to Snyk.VisualStudio.Extension.Tests/SnykOptionsTest.cs
index e9f6d572..f3af7bc6 100644
--- a/Snyk.VisualStudio.Extension.Tests/GeneralOptionsDialogPageTest.cs
+++ b/Snyk.VisualStudio.Extension.Tests/SnykOptionsTest.cs
@@ -8,18 +8,19 @@
namespace Snyk.VisualStudio.Extension.Tests
{
[Collection(MockedVS.Collection)]
- public class GeneralOptionsDialogPageTest
+ public class SnykOptionsTest
{
- private ISnykServiceProvider serviceProvider;
- public GeneralOptionsDialogPageTest(GlobalServiceProvider sp)
+ private readonly SnykOptions cut;
+ public SnykOptionsTest(GlobalServiceProvider sp)
{
sp.Reset();
var serviceProviderMock = new Mock();
var snykSolutionService = new SnykSolutionService();
serviceProviderMock.Setup(x => x.SolutionService).Returns(snykSolutionService);
- serviceProvider = serviceProviderMock.Object;
+ var serviceProvider = serviceProviderMock.Object;
var settingsFilePath = Path.Combine(SnykExtension.GetExtensionDirectoryPath(), "settings.json");
serviceProviderMock.Setup(x => x.UserStorageSettingsService).Returns(new SnykUserStorageSettingsService(settingsFilePath, serviceProvider));
+ cut = new SnykOptions(serviceProvider);
}
[Theory]
@@ -38,10 +39,8 @@ public GeneralOptionsDialogPageTest(GlobalServiceProvider sp)
[InlineData("https://api.eu.snyk.io", "https://app.eu.snyk.io/manage/snyk-code")]
public void SnykCodeSettingsUrl(string endpoint, string expected)
{
- var optionsDialogPage = new SnykGeneralOptionsDialogPage();
- optionsDialogPage.Initialize(this.serviceProvider);
- optionsDialogPage.CustomEndpoint = endpoint;
- Assert.Equal(expected, optionsDialogPage.SnykCodeSettingsUrl);
+ cut.CustomEndpoint = endpoint;
+ Assert.Equal(expected, cut.SnykCodeSettingsUrl);
}
[Theory]
@@ -56,10 +55,8 @@ public void SnykCodeSettingsUrl(string endpoint, string expected)
[InlineData("https://api.eu.snyk.io", "https://api.eu.snyk.io")]
public void TransformApiToNewSchema(string endpoint, string expected)
{
- var optionsDialogPage = new SnykGeneralOptionsDialogPage();
- optionsDialogPage.Initialize(this.serviceProvider);
- optionsDialogPage.CustomEndpoint = endpoint;
- Assert.Equal(expected, optionsDialogPage.GetCustomApiEndpoint());
+ cut.CustomEndpoint = endpoint;
+ Assert.Equal(expected, cut.GetCustomApiEndpoint());
}
[Theory]
@@ -73,10 +70,8 @@ public void TransformApiToNewSchema(string endpoint, string expected)
[InlineData("https://api.eu.snyk.io", "https://app.eu.snyk.io")]
public void GetBaseAppUrl(string endpoint, string expected)
{
- var optionsDialogPage = new SnykGeneralOptionsDialogPage();
- optionsDialogPage.Initialize(this.serviceProvider);
- optionsDialogPage.CustomEndpoint = endpoint;
- Assert.Equal(expected, optionsDialogPage.GetBaseAppUrl());
+ cut.CustomEndpoint = endpoint;
+ Assert.Equal(expected, cut.GetBaseAppUrl());
}
}
}
\ No newline at end of file