Skip to content

Commit

Permalink
SLVS-1592 Update TaintStore with taints from SLCore
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource committed Nov 11, 2024
1 parent 12fa01e commit 0a003b8
Show file tree
Hide file tree
Showing 9 changed files with 696 additions and 800 deletions.
214 changes: 107 additions & 107 deletions src/IssueViz.Security.UnitTests/Taint/TaintIssuesBindingMonitorTests.cs
Original file line number Diff line number Diff line change
@@ -1,107 +1,107 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.Core.Binding;
using SonarLint.VisualStudio.TestInfrastructure;
using SonarLint.VisualStudio.IssueVisualization.Security.Taint;

namespace SonarLint.VisualStudio.IssueVisualization.Security.UnitTests.Taint
{
[TestClass]
public class TaintIssuesBindingMonitorTests
{
[TestMethod]
public void MefCtor_CheckIsExported()
{
MefTestHelpers.CheckTypeCanBeImported<TaintIssuesBindingMonitor, ITaintIssuesBindingMonitor>(
MefTestHelpers.CreateExport<IActiveSolutionBoundTracker>(),
MefTestHelpers.CreateExport<IFolderWorkspaceMonitor>(),
MefTestHelpers.CreateExport<ITaintIssuesSynchronizer>());
}

[TestMethod]
public void Ctor_SubscribeToSolutionBindingUpdated()
{
var synchronizer = new Mock<ITaintIssuesSynchronizer>();
var activeSolutionBoundTracker = new Mock<IActiveSolutionBoundTracker>();
var folderWorkspaceInitialized = new Mock<IFolderWorkspaceMonitor>();

new TaintIssuesBindingMonitor(activeSolutionBoundTracker.Object, folderWorkspaceInitialized.Object, synchronizer.Object);
synchronizer.Invocations.Clear();

activeSolutionBoundTracker.Raise(x=> x.SolutionBindingUpdated += null, EventArgs.Empty);

synchronizer.Verify(x=> x.SynchronizeWithServer(), Times.Once);
}

[TestMethod]
public void Ctor_SubscribeToSolutionBindingChanged()
{
var synchronizer = new Mock<ITaintIssuesSynchronizer>();
var activeSolutionBoundTracker = new Mock<IActiveSolutionBoundTracker>();
var folderWorkspaceInitialized = new Mock<IFolderWorkspaceMonitor>();

new TaintIssuesBindingMonitor(activeSolutionBoundTracker.Object, folderWorkspaceInitialized.Object, synchronizer.Object);
synchronizer.Invocations.Clear();
activeSolutionBoundTracker.Raise(x => x.SolutionBindingChanged += null, new ActiveSolutionBindingEventArgs(BindingConfiguration.Standalone));

synchronizer.Verify(x => x.SynchronizeWithServer(), Times.Once);
}

[TestMethod]
public void Ctor_SubscribeToFolderInitialized()
{
var synchronizer = new Mock<ITaintIssuesSynchronizer>();
var activeSolutionBoundTracker = new Mock<IActiveSolutionBoundTracker>();
var folderWorkspaceInitialized = new Mock<IFolderWorkspaceMonitor>();

new TaintIssuesBindingMonitor(activeSolutionBoundTracker.Object, folderWorkspaceInitialized.Object, synchronizer.Object);
synchronizer.Invocations.Clear();

folderWorkspaceInitialized.Raise(x => x.FolderWorkspaceInitialized += null, EventArgs.Empty);

synchronizer.Verify(x => x.SynchronizeWithServer(), Times.Once);
}

[TestMethod]
public void Dispose_UnsubscribeFromEvents()
{
var synchronizer = new Mock<ITaintIssuesSynchronizer>();
var activeSolutionBoundTracker = new Mock<IActiveSolutionBoundTracker>();
var folderWorkspaceInitialized = new Mock<IFolderWorkspaceMonitor>();

var testSubject = new TaintIssuesBindingMonitor(activeSolutionBoundTracker.Object, folderWorkspaceInitialized.Object, synchronizer.Object);
testSubject.Dispose();
synchronizer.Invocations.Clear();

folderWorkspaceInitialized.Raise(x => x.FolderWorkspaceInitialized += null, EventArgs.Empty);
activeSolutionBoundTracker.Raise(x => x.SolutionBindingUpdated += null, EventArgs.Empty);
activeSolutionBoundTracker.Raise(x => x.SolutionBindingChanged += null, new ActiveSolutionBindingEventArgs(BindingConfiguration.Standalone));

synchronizer.Invocations.Count.Should().Be(0);
}
}
}
// /*
// * SonarLint for Visual Studio
// * Copyright (C) 2016-2024 SonarSource SA
// * mailto:info AT sonarsource DOT com
// *
// * This program is free software; you can redistribute it and/or
// * modify it under the terms of the GNU Lesser General Public
// * License as published by the Free Software Foundation; either
// * version 3 of the License, or (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// * Lesser General Public License for more details.
// *
// * You should have received a copy of the GNU Lesser General Public License
// * along with this program; if not, write to the Free Software Foundation,
// * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// */
//
// using System;
// using FluentAssertions;
// using Microsoft.VisualStudio.TestTools.UnitTesting;
// using Moq;
// using SonarLint.VisualStudio.Core;
// using SonarLint.VisualStudio.Core.Binding;
// using SonarLint.VisualStudio.TestInfrastructure;
// using SonarLint.VisualStudio.IssueVisualization.Security.Taint;
//
// namespace SonarLint.VisualStudio.IssueVisualization.Security.UnitTests.Taint
// {
// [TestClass]
// public class TaintIssuesBindingMonitorTests
// {
// [TestMethod]
// public void MefCtor_CheckIsExported()
// {
// MefTestHelpers.CheckTypeCanBeImported<TaintIssuesBindingMonitor, ITaintIssuesBindingMonitor>(
// MefTestHelpers.CreateExport<IActiveSolutionBoundTracker>(),
// MefTestHelpers.CreateExport<IFolderWorkspaceMonitor>(),
// MefTestHelpers.CreateExport<ITaintIssuesSynchronizer>());
// }
//
// [TestMethod]
// public void Ctor_SubscribeToSolutionBindingUpdated()
// {
// var synchronizer = new Mock<ITaintIssuesSynchronizer>();
// var activeSolutionBoundTracker = new Mock<IActiveSolutionBoundTracker>();
// var folderWorkspaceInitialized = new Mock<IFolderWorkspaceMonitor>();
//
// new TaintIssuesBindingMonitor(activeSolutionBoundTracker.Object, folderWorkspaceInitialized.Object, synchronizer.Object);
// synchronizer.Invocations.Clear();
//
// activeSolutionBoundTracker.Raise(x=> x.SolutionBindingUpdated += null, EventArgs.Empty);
//
// synchronizer.Verify(x=> x.SynchronizeWithServer(), Times.Once);
// }
//
// [TestMethod]
// public void Ctor_SubscribeToSolutionBindingChanged()
// {
// var synchronizer = new Mock<ITaintIssuesSynchronizer>();
// var activeSolutionBoundTracker = new Mock<IActiveSolutionBoundTracker>();
// var folderWorkspaceInitialized = new Mock<IFolderWorkspaceMonitor>();
//
// new TaintIssuesBindingMonitor(activeSolutionBoundTracker.Object, folderWorkspaceInitialized.Object, synchronizer.Object);
// synchronizer.Invocations.Clear();
//
// activeSolutionBoundTracker.Raise(x => x.SolutionBindingChanged += null, new ActiveSolutionBindingEventArgs(BindingConfiguration.Standalone));
//
// synchronizer.Verify(x => x.SynchronizeWithServer(), Times.Once);
// }
//
// [TestMethod]
// public void Ctor_SubscribeToFolderInitialized()
// {
// var synchronizer = new Mock<ITaintIssuesSynchronizer>();
// var activeSolutionBoundTracker = new Mock<IActiveSolutionBoundTracker>();
// var folderWorkspaceInitialized = new Mock<IFolderWorkspaceMonitor>();
//
// new TaintIssuesBindingMonitor(activeSolutionBoundTracker.Object, folderWorkspaceInitialized.Object, synchronizer.Object);
// synchronizer.Invocations.Clear();
//
// folderWorkspaceInitialized.Raise(x => x.FolderWorkspaceInitialized += null, EventArgs.Empty);
//
// synchronizer.Verify(x => x.SynchronizeWithServer(), Times.Once);
// }
//
// [TestMethod]
// public void Dispose_UnsubscribeFromEvents()
// {
// var synchronizer = new Mock<ITaintIssuesSynchronizer>();
// var activeSolutionBoundTracker = new Mock<IActiveSolutionBoundTracker>();
// var folderWorkspaceInitialized = new Mock<IFolderWorkspaceMonitor>();
//
// var testSubject = new TaintIssuesBindingMonitor(activeSolutionBoundTracker.Object, folderWorkspaceInitialized.Object, synchronizer.Object);
// testSubject.Dispose();
// synchronizer.Invocations.Clear();
//
// folderWorkspaceInitialized.Raise(x => x.FolderWorkspaceInitialized += null, EventArgs.Empty);
// activeSolutionBoundTracker.Raise(x => x.SolutionBindingUpdated += null, EventArgs.Empty);
// activeSolutionBoundTracker.Raise(x => x.SolutionBindingChanged += null, new ActiveSolutionBindingEventArgs(BindingConfiguration.Standalone));
//
// synchronizer.Invocations.Count.Should().Be(0);
// }
// }
// }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
Expand Down Expand Up @@ -694,48 +694,6 @@ public void SetSelectedIssue_ValueIsTheSame_SelectionServiceNotCalled()
selectionService.VerifyNoOtherCalls();
}

[TestMethod]
public void AnalysisInformation_NoAnalysisInformation_Null()
{
var store = new Mock<ITaintStore>();
SetupAnalysisInformation(store, null);

var testSubject = CreateTestSubject(store: store);

testSubject.AnalysisInformation.Should().BeNull();
}

[TestMethod]
public void AnalysisInformation_HasAnalysisInformation_PropertySet()
{
var store = new Mock<ITaintStore>();
var analysisInformation = new AnalysisInformation("some branch", default);
SetupAnalysisInformation(store, analysisInformation);

var testSubject = CreateTestSubject(store: store);

testSubject.AnalysisInformation.Should().BeSameAs(analysisInformation);
}

[TestMethod]
public void AnalysisInformation_IssuesChanged_RaisesPropertyChanged()
{
var store = new Mock<ITaintStore>();
var testSubject = CreateTestSubject(store: store);

var eventHandler = new Mock<PropertyChangedEventHandler>();
testSubject.PropertyChanged += eventHandler.Object;

var analysisInformation = new AnalysisInformation("some branch", default);

SetupAnalysisInformation(store, analysisInformation);
RaiseStoreIssuesChangedEvent(store);

VerifyPropertyChangedWasRaised(eventHandler, nameof(testSubject.AnalysisInformation));

testSubject.AnalysisInformation.Should().BeSameAs(analysisInformation);
}

[TestMethod]
[DataRow(null, ServerType.SonarCloud, nameof(ServerType.SonarCloud), true)]
[DataRow(null, null, "", false)]
Expand Down Expand Up @@ -1011,10 +969,5 @@ private void VerifyPropertyChangedWasRaised(Mock<PropertyChangedEventHandler> ev
It.Is((PropertyChangedEventArgs e) => e.PropertyName == expectedProperty)),
Times.Once);
}

private void SetupAnalysisInformation(Mock<ITaintStore> store, AnalysisInformation analysisInformation)
{
store.Setup(x => x.GetAnalysisInformation()).Returns(analysisInformation);
}
}
}
Loading

0 comments on commit 0a003b8

Please sign in to comment.