-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AggregatingCompilationDatabaseProviderTests
- Loading branch information
1 parent
872b2ab
commit 715e7da
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
src/CFamily.UnitTests/CompilationDatabase/AggregatingCompilationDatabaseProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* 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 NSubstitute.ReturnsExtensions; | ||
using SonarLint.VisualStudio.CFamily.CMake; | ||
using SonarLint.VisualStudio.CFamily.CompilationDatabase; | ||
using SonarLint.VisualStudio.Core.CFamily; | ||
using SonarLint.VisualStudio.TestInfrastructure; | ||
|
||
namespace SonarLint.VisualStudio.CFamily.UnitTests.CompilationDatabase; | ||
|
||
[TestClass] | ||
public class AggregatingCompilationDatabaseProviderTests | ||
{ | ||
private ICMakeCompilationDatabaseLocator cmake; | ||
private IVCXCompilationDatabaseProvider vcx; | ||
private AggregatingCompilationDatabaseProvider testSubject; | ||
|
||
[TestMethod] | ||
public void MefCtor_CheckIsExported() => | ||
MefTestHelpers.CheckTypeCanBeImported<AggregatingCompilationDatabaseProvider, IAggregatingCompilationDatabaseProvider>( | ||
MefTestHelpers.CreateExport<ICMakeCompilationDatabaseLocator>(), | ||
MefTestHelpers.CreateExport<IVCXCompilationDatabaseProvider>()); | ||
|
||
[TestMethod] | ||
public void MefCtor_CheckIsSingleton() => MefTestHelpers.CheckIsSingletonMefComponent<AggregatingCompilationDatabaseProvider>(); | ||
|
||
[TestInitialize] | ||
public void TestInitialize() | ||
{ | ||
cmake = Substitute.For<ICMakeCompilationDatabaseLocator>(); | ||
vcx = Substitute.For<IVCXCompilationDatabaseProvider>(); | ||
testSubject = new AggregatingCompilationDatabaseProvider(cmake, vcx); | ||
} | ||
|
||
[TestMethod] | ||
public void GetOrNull_CmakeAvailable_ReturnsCmakeLocation() | ||
{ | ||
var location = "some location"; | ||
cmake.Locate().Returns(location); | ||
|
||
var result = testSubject.GetOrNull("some path"); | ||
|
||
result.Should().Be(location); | ||
vcx.DidNotReceiveWithAnyArgs().CreateOrNull(default); | ||
} | ||
|
||
[TestMethod] | ||
public void GetOrNull_CmakeUnavailable_VcxAvailable_ReturnsVcxLocation() | ||
{ | ||
var sourcePath = "some path"; | ||
var location = "some location"; | ||
cmake.Locate().ReturnsNull(); | ||
vcx.CreateOrNull(sourcePath).Returns(location); | ||
|
||
var result = testSubject.GetOrNull(sourcePath); | ||
|
||
result.Should().Be(location); | ||
cmake.Received().Locate(); | ||
} | ||
|
||
[TestMethod] | ||
public void GetOrNull_Unavailable_ReturnsNull() | ||
{ | ||
cmake.Locate().ReturnsNull(); | ||
vcx.CreateOrNull(default).ReturnsNullForAnyArgs(); | ||
|
||
var result = testSubject.GetOrNull("some path"); | ||
|
||
result.Should().BeNull(); | ||
} | ||
} |