Skip to content

Commit

Permalink
SLVS-1396 Rename method
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriela-trutan-sonarsource committed Sep 25, 2024
1 parent 5e49a4b commit 51a2485
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public async Task MigrateBindingToServerConnectionIfNeeded_RunsOnBackgroundThrea
[TestMethod]
public async Task MigrateBindingToServerConnectionIfNeeded_ConnectionsStorageFileExists_ShouldNotMigrate()
{
serverConnectionsRepository.IsConnectionsFileExisting().Returns(true);
serverConnectionsRepository.ConnectionsFileExists().Returns(true);

await testSubject.MigrateAllBindingsToServerConnectionsIfNeededAsync();

serverConnectionsRepository.Received(1).IsConnectionsFileExisting();
serverConnectionsRepository.Received(1).ConnectionsFileExists();
serverConnectionsRepository.DidNotReceiveWithAnyArgs().TryAdd(default);
unintrusiveBindingPathProvider.DidNotReceive().GetBindingPaths();
}
Expand All @@ -113,7 +113,7 @@ public async Task MigrateBindingToServerConnectionIfNeeded_ConnectionsStorageDoe

Received.InOrder(() =>
{
serverConnectionsRepository.IsConnectionsFileExisting();
serverConnectionsRepository.ConnectionsFileExists();
logger.WriteLine(MigrationStrings.ConnectionMigration_StartMigration);
unintrusiveBindingPathProvider.GetBindingPaths();
serverConnectionsRepository.TryAdd(Arg.Any<ServerConnection>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public async Task Migrate_ConnectionDoesNotExist_CannotAdd_DoesNotCreateConnecti
var unintrusiveBindingController = new Mock<IUnintrusiveBindingController>();
var convertedConnection = ServerConnection.FromBoundSonarQubeProject(AnyBoundProject);
var serverConnectionsRepositoryMock = new Mock<IServerConnectionsRepository>();
serverConnectionsRepositoryMock.Setup(x => x.IsConnectionsFileExisting()).Returns(true);
serverConnectionsRepositoryMock.Setup(x => x.ConnectionsFileExists()).Returns(true);
serverConnectionsRepositoryMock.Setup(x => x.TryAdd(convertedConnection)).Returns(false);
var testSubject = CreateTestSubject(unintrusiveBindingController: unintrusiveBindingController.Object, serverConnectionsRepository: serverConnectionsRepositoryMock.Object);

Expand All @@ -371,7 +371,7 @@ public async Task Migrate_ConnectionDoesNotExist_Throws_DoesNotCreateConnection(
var unintrusiveBindingController = new Mock<IUnintrusiveBindingController>();
var convertedConnection = ServerConnection.FromBoundSonarQubeProject(AnyBoundProject);
var serverConnectionsRepositoryMock = new Mock<IServerConnectionsRepository>();
serverConnectionsRepositoryMock.Setup(x => x.IsConnectionsFileExisting()).Returns(true);
serverConnectionsRepositoryMock.Setup(x => x.ConnectionsFileExists()).Returns(true);
serverConnectionsRepositoryMock.Setup(x => x.TryAdd(convertedConnection)).Throws(new Exception());
var testSubject = CreateTestSubject(unintrusiveBindingController: unintrusiveBindingController.Object, serverConnectionsRepository: serverConnectionsRepositoryMock.Object);

Expand Down Expand Up @@ -400,7 +400,7 @@ public async Task Migrate_ConnectionsJsonFileDoesNotExistAndNewBindingsExist_Doe
unintrusiveBindingController: unintrusiveBindingControllerMock.Object,
unintrusiveBindingPathProvider: bindingPathProvider.Object,
logger:logger.Object);
serverConnectionsRepositoryMock.Setup(mock => mock.IsConnectionsFileExisting()).Returns(false);
serverConnectionsRepositoryMock.Setup(mock => mock.ConnectionsFileExists()).Returns(false);
bindingPathProvider.Setup(mock => mock.GetBindingPaths()).Returns(["binding1"]);

await testSubject.MigrateAsync(AnyBoundProject, Mock.Of<IProgress<MigrationProgress>>(), false, CancellationToken.None);
Expand Down Expand Up @@ -428,7 +428,7 @@ public async Task Migrate_ConnectionsJsonFileDoesNotExistAndNoNewBindingsExist_M
unintrusiveBindingController: unintrusiveBindingControllerMock.Object,
unintrusiveBindingPathProvider:bindingPathProvider.Object,
logger: logger.Object);
serverConnectionsRepositoryMock.Setup(mock => mock.IsConnectionsFileExisting()).Returns(false);
serverConnectionsRepositoryMock.Setup(mock => mock.ConnectionsFileExists()).Returns(false);
bindingPathProvider.Setup(mock => mock.GetBindingPaths()).Returns([]);

await testSubject.MigrateAsync(AnyBoundProject, Mock.Of<IProgress<MigrationProgress>>(), false, CancellationToken.None);
Expand Down Expand Up @@ -550,7 +550,7 @@ private static Mock<IServerConnectionsRepository> CreateServerConnectionsReposit
{
var serverConnectionsRepositoryMock = new Mock<IServerConnectionsRepository>();
serverConnectionsRepositoryMock.Setup(x => x.TryAdd(It.IsAny<ServerConnection>())).Returns(true);
serverConnectionsRepositoryMock.Setup(x => x.IsConnectionsFileExisting()).Returns(true);
serverConnectionsRepositoryMock.Setup(x => x.ConnectionsFileExists()).Returns(true);

return serverConnectionsRepositoryMock;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,11 @@ public void TryUpdateCredentialsById_SonarQubeConnectionExists_UpdatesCredential
[TestMethod]
[DataRow(true)]
[DataRow(false)]
public void IsConnectionsFileExisting_ReturnsTrueOnlyIfTheConnectionsFileExists(bool fileExists)
public void ConnectionsFileExists_ReturnsTrueOnlyIfTheConnectionsFileExists(bool fileExists)
{
fileSystem.File.Exists(Arg.Any<string>()).Returns(fileExists);

var result = testSubject.IsConnectionsFileExisting();
var result = testSubject.ConnectionsFileExists();

result.Should().Be(fileExists);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Task MigrateAllBindingsToServerConnectionsIfNeededAsync()

private void MigrateBindingToServerConnectionIfNeeded()
{
if (serverConnectionsRepository.IsConnectionsFileExisting())
if (serverConnectionsRepository.ConnectionsFileExists())
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ConnectedMode/Migration/ConnectedModeMigration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ private ServerConnection GetServerConnectionWithMigration(BoundSonarQubeProject
// if the file doesn't exist, creating it now will prevent the migration of all existing bindings.
// The order being important, we throw an exception. For more info see IBindingToConnectionMigration
// But if there are no bindings in the new format, then creating the connections file is safe, because the new migration did not do anything in this case
if (!serverConnectionsRepository.IsConnectionsFileExisting() && unintrusiveBindingPathProvider.GetBindingPaths().Any())
if (!serverConnectionsRepository.ConnectionsFileExists() && unintrusiveBindingPathProvider.GetBindingPaths().Any())
{
logger.WriteLine(MigrationStrings.ConnectionsJson_DoesNotExist);
return proposedConnection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public bool TryUpdateCredentialsById(string connectionId, ICredentials credentia
return false;
}

public bool IsConnectionsFileExisting() => fileSystem.File.Exists(connectionsStorageFilePath);
public bool ConnectionsFileExists() => fileSystem.File.Exists(connectionsStorageFilePath);

private bool TryAddConnection(List<ServerConnection> connections, ServerConnection connection)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Binding/IServerConnectionsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public interface IServerConnectionsRepository
bool TryDelete(string connectionId);
bool TryUpdateSettingsById(string connectionId, ServerConnectionSettings connectionSettings);
bool TryUpdateCredentialsById(string connectionId, ICredentials credentials);
bool IsConnectionsFileExisting();
bool ConnectionsFileExists();
}

0 comments on commit 51a2485

Please sign in to comment.