diff --git a/src/ConnectedMode.UnitTests/Persistence/BindingDtoConverterTests.cs b/src/ConnectedMode.UnitTests/Persistence/BindingJsonModelConverterTests.cs similarity index 57% rename from src/ConnectedMode.UnitTests/Persistence/BindingDtoConverterTests.cs rename to src/ConnectedMode.UnitTests/Persistence/BindingJsonModelConverterTests.cs index fe194c3c8..c32905086 100644 --- a/src/ConnectedMode.UnitTests/Persistence/BindingDtoConverterTests.cs +++ b/src/ConnectedMode.UnitTests/Persistence/BindingJsonModelConverterTests.cs @@ -27,33 +27,33 @@ namespace SonarLint.VisualStudio.ConnectedMode.UnitTests.Persistence; [TestClass] -public class BindingDtoConverterTests +public class BindingJsonModelConverterTests { - private BindingDtoConverter testSubject; + private BindingJsonModelConverter testSubject; [TestInitialize] public void TestInitialize() { - testSubject = new BindingDtoConverter(); + testSubject = new BindingJsonModelConverter(); } [TestMethod] public void MefCtor_CheckIsExported() { - MefTestHelpers.CheckTypeCanBeImported(); + MefTestHelpers.CheckTypeCanBeImported(); } [TestMethod] public void MefCtor_CheckIsSingleton() { - MefTestHelpers.CheckIsSingletonMefComponent(); + MefTestHelpers.CheckIsSingletonMefComponent(); } [TestMethod] - public void ConvertFromDto_ConvertsCorrectly() + public void ConvertFromModel_ConvertsCorrectly() { const string localBindingKey = "solution123"; - var bindingDto = new BindingJsonModel + var bindingModel = new BindingJsonModel { ProjectKey = "project123", Profiles = new Dictionary(), @@ -64,55 +64,55 @@ public void ConvertFromDto_ConvertsCorrectly() }; var connection = new ServerConnection.SonarCloud("myorg"); - var boundServerProject = testSubject.ConvertFromDto(bindingDto, connection, localBindingKey); + var boundServerProject = testSubject.ConvertFromModel(bindingModel, connection, localBindingKey); boundServerProject.ServerConnection.Should().BeSameAs(connection); boundServerProject.LocalBindingKey.Should().BeSameAs(localBindingKey); - boundServerProject.ServerProjectKey.Should().BeSameAs(bindingDto.ProjectKey); - boundServerProject.Profiles.Should().BeSameAs(bindingDto.Profiles); + boundServerProject.ServerProjectKey.Should().BeSameAs(bindingModel.ProjectKey); + boundServerProject.Profiles.Should().BeSameAs(bindingModel.Profiles); } [TestMethod] - public void ConvertToDto_SonarCloudConnection_ConvertsCorrectly() + public void ConvertToModel_SonarCloudConnection_ConvertsCorrectly() { var boundServerProject = new BoundServerProject("localBinding", "serverProject", new ServerConnection.SonarCloud("myorg")) { Profiles = new Dictionary() }; - var bindingDto = testSubject.ConvertToDto(boundServerProject); + var bindingModel = testSubject.ConvertToModel(boundServerProject); - bindingDto.ProjectKey.Should().BeSameAs(boundServerProject.ServerProjectKey); - bindingDto.ProjectName.Should().BeNull(); - bindingDto.ServerUri.Should().BeEquivalentTo(boundServerProject.ServerConnection.ServerUri); - bindingDto.Organization.Key.Should().BeSameAs(((ServerConnection.SonarCloud)boundServerProject.ServerConnection).OrganizationKey); - bindingDto.ServerConnectionId.Should().BeSameAs(boundServerProject.ServerConnection.Id); - bindingDto.Profiles.Should().BeSameAs(boundServerProject.Profiles); + bindingModel.ProjectKey.Should().BeSameAs(boundServerProject.ServerProjectKey); + bindingModel.ProjectName.Should().BeNull(); + bindingModel.ServerUri.Should().BeEquivalentTo(boundServerProject.ServerConnection.ServerUri); + bindingModel.Organization.Key.Should().BeSameAs(((ServerConnection.SonarCloud)boundServerProject.ServerConnection).OrganizationKey); + bindingModel.ServerConnectionId.Should().BeSameAs(boundServerProject.ServerConnection.Id); + bindingModel.Profiles.Should().BeSameAs(boundServerProject.Profiles); } [TestMethod] - public void ConvertToDto_SonarQubeConnection_ConvertsCorrectly() + public void ConvertToModel_SonarQubeConnection_ConvertsCorrectly() { var boundServerProject = new BoundServerProject("localBinding", "serverProject", new ServerConnection.SonarQube(new Uri("http://mysq"))) { Profiles = new Dictionary() }; - var bindingDto = testSubject.ConvertToDto(boundServerProject); + var bindingModel = testSubject.ConvertToModel(boundServerProject); - bindingDto.ProjectKey.Should().BeSameAs(boundServerProject.ServerProjectKey); - bindingDto.ProjectName.Should().BeNull(); - bindingDto.ServerUri.Should().BeEquivalentTo(boundServerProject.ServerConnection.ServerUri); - bindingDto.Organization.Should().BeNull(); - bindingDto.ServerConnectionId.Should().BeSameAs(boundServerProject.ServerConnection.Id); - bindingDto.Profiles.Should().BeSameAs(boundServerProject.Profiles); + bindingModel.ProjectKey.Should().BeSameAs(boundServerProject.ServerProjectKey); + bindingModel.ProjectName.Should().BeNull(); + bindingModel.ServerUri.Should().BeEquivalentTo(boundServerProject.ServerConnection.ServerUri); + bindingModel.Organization.Should().BeNull(); + bindingModel.ServerConnectionId.Should().BeSameAs(boundServerProject.ServerConnection.Id); + bindingModel.Profiles.Should().BeSameAs(boundServerProject.Profiles); } [TestMethod] - public void ConvertFromDtoToLegacy_ConvertsCorrectly() + public void ConvertFromModelToLegacy_ConvertsCorrectly() { var credentials = Substitute.For(); - var bindingDto = new BindingJsonModel + var bindingModel = new BindingJsonModel { Organization = new SonarQubeOrganization("org", "my org"), ServerUri = new Uri("http://localhost"), @@ -122,12 +122,12 @@ public void ConvertFromDtoToLegacy_ConvertsCorrectly() ServerConnectionId = "ignored", }; - var legacyBinding = testSubject.ConvertFromDtoToLegacy(bindingDto, credentials); + var legacyBinding = testSubject.ConvertFromModelToLegacy(bindingModel, credentials); - legacyBinding.ProjectKey.Should().BeSameAs(bindingDto.ProjectKey); - legacyBinding.ProjectName.Should().BeSameAs(bindingDto.ProjectName); - legacyBinding.ServerUri.Should().BeSameAs(bindingDto.ServerUri); - legacyBinding.Organization.Should().BeSameAs(bindingDto.Organization); + legacyBinding.ProjectKey.Should().BeSameAs(bindingModel.ProjectKey); + legacyBinding.ProjectName.Should().BeSameAs(bindingModel.ProjectName); + legacyBinding.ServerUri.Should().BeSameAs(bindingModel.ServerUri); + legacyBinding.Organization.Should().BeSameAs(bindingModel.Organization); legacyBinding.Profiles.Should().BeSameAs(legacyBinding.Profiles); legacyBinding.Credentials.Should().BeSameAs(credentials); } diff --git a/src/ConnectedMode.UnitTests/Persistence/BindingJsonModelSerializationTests.cs b/src/ConnectedMode.UnitTests/Persistence/BindingJsonModelSerializationTests.cs index 1e3c03cf1..ac0bd7404 100644 --- a/src/ConnectedMode.UnitTests/Persistence/BindingJsonModelSerializationTests.cs +++ b/src/ConnectedMode.UnitTests/Persistence/BindingJsonModelSerializationTests.cs @@ -57,7 +57,7 @@ public class BindingJsonModelSerializationTests private readonly BoundServerProject boundSonarCloudServerProject = new("solution123", "my_project_123", new ServerConnection.SonarCloud("org_key_123")){ Profiles = QualityProfiles }; private readonly BoundServerProject boundSonarQubeServerProject = new("solution123", "my_project_123", new ServerConnection.SonarQube(new Uri("http://next.sonarqube.com/sonarqube"))){ Profiles = QualityProfiles }; - private readonly BindingDtoConverter bindingDtoConverter = new(); + private readonly BindingJsonModelConverter bindingJsonModelConverter = new(); [TestMethod] public void JsonModel_SerializedAsExpected() @@ -88,7 +88,7 @@ public void JsonModel_SerializedAsExpected() [TestMethod] public void JsonModel_FromSonarCloudBinding_SerializedAsExpected() { - var serializeObject = JsonConvert.SerializeObject(bindingDtoConverter.ConvertToDto(boundSonarCloudServerProject), Formatting.Indented); + var serializeObject = JsonConvert.SerializeObject(bindingJsonModelConverter.ConvertToModel(boundSonarCloudServerProject), Formatting.Indented); serializeObject.Should().BeEquivalentTo( """ @@ -113,7 +113,7 @@ public void JsonModel_FromSonarCloudBinding_SerializedAsExpected() [TestMethod] public void JsonModel_FromSonarQubeBinding_SerializedAsExpected() { - var serializeObject = JsonConvert.SerializeObject(bindingDtoConverter.ConvertToDto(boundSonarQubeServerProject), Formatting.Indented); + var serializeObject = JsonConvert.SerializeObject(bindingJsonModelConverter.ConvertToModel(boundSonarQubeServerProject), Formatting.Indented); serializeObject.Should().BeEquivalentTo( """ @@ -135,9 +135,9 @@ public void JsonModel_FromSonarQubeBinding_SerializedAsExpected() public void Legacy_ToJson_ToJsonModel_ToLegacy_IsCorrect() { var serialized = JsonConvert.SerializeObject(boundSonarQubeProject); - var deserializeBindingDto = JsonConvert.DeserializeObject(serialized); + var deserializeBindingModel = JsonConvert.DeserializeObject(serialized); - var convertedFromJsonToLegacy = bindingDtoConverter.ConvertFromDtoToLegacy(deserializeBindingDto, null); + var convertedFromJsonToLegacy = bindingJsonModelConverter.ConvertFromModelToLegacy(deserializeBindingModel, null); convertedFromJsonToLegacy.Should().BeEquivalentTo(boundSonarQubeProject); } @@ -149,7 +149,7 @@ public void Legacy_ToJson_ToLegacyDirectly_And_ToJsonModel_ToLegacy_IsCorrect() var legacyDirect = JsonConvert.DeserializeObject(serializedLegacy); var deserializedBindingModel = JsonConvert.DeserializeObject(serializedLegacy); - var convertedFromJsonToLegacy = bindingDtoConverter.ConvertFromDtoToLegacy(deserializedBindingModel, null); + var convertedFromJsonToLegacy = bindingJsonModelConverter.ConvertFromModelToLegacy(deserializedBindingModel, null); convertedFromJsonToLegacy.Should().BeEquivalentTo(legacyDirect); } @@ -169,7 +169,7 @@ public void JsonModel_ToJson_ToJsonModel_ToLegacy_IsCorrect() var serializedBindingModel = JsonConvert.SerializeObject(bindingJsonModel); var deserializedBindingModel = JsonConvert.DeserializeObject(serializedBindingModel); - var convertedFromJsonToLegacy = bindingDtoConverter.ConvertFromDtoToLegacy(deserializedBindingModel, null); + var convertedFromJsonToLegacy = bindingJsonModelConverter.ConvertFromModelToLegacy(deserializedBindingModel, null); convertedFromJsonToLegacy.Should().BeEquivalentTo(boundSonarQubeProject); } @@ -177,11 +177,11 @@ public void JsonModel_ToJson_ToJsonModel_ToLegacy_IsCorrect() [TestMethod] public void CurrentSonarCloud_ToJsonModel_ToJson_ToJsonModel_ToLegacy_IsCorrect() { - var convertedBindingJsonFromLegacy = bindingDtoConverter.ConvertToDto(boundSonarCloudServerProject); + var convertedBindingJsonFromLegacy = bindingJsonModelConverter.ConvertToModel(boundSonarCloudServerProject); var serializedBindingModel = JsonConvert.SerializeObject(convertedBindingJsonFromLegacy); var deserializedBindingModel = JsonConvert.DeserializeObject(serializedBindingModel); - var legacyBinding = bindingDtoConverter.ConvertFromDtoToLegacy(deserializedBindingModel, null); + var legacyBinding = bindingJsonModelConverter.ConvertFromModelToLegacy(deserializedBindingModel, null); legacyBinding.Should().BeEquivalentTo(boundSonarQubeProject, options => options.Excluding(x => x.ProjectName).Excluding(x => x.ServerUri).Excluding(x => x.Organization.Name)); legacyBinding.ServerUri.Should().BeEquivalentTo(boundSonarCloudServerProject.ServerConnection.ServerUri); @@ -192,11 +192,11 @@ public void CurrentSonarCloud_ToJsonModel_ToJson_ToJsonModel_ToLegacy_IsCorrect( [TestMethod] public void CurrentSonarQube_ToJsonModel_ToJson_ToJsonModel_ToLegacy_IsCorrect() { - var convertedBindingJsonFromLegacy = bindingDtoConverter.ConvertToDto(boundSonarQubeServerProject); + var convertedBindingJsonFromLegacy = bindingJsonModelConverter.ConvertToModel(boundSonarQubeServerProject); var serializedBindingModel = JsonConvert.SerializeObject(convertedBindingJsonFromLegacy); var deserializedBindingModel = JsonConvert.DeserializeObject(serializedBindingModel); - var legacyBinding = bindingDtoConverter.ConvertFromDtoToLegacy(deserializedBindingModel, null); + var legacyBinding = bindingJsonModelConverter.ConvertFromModelToLegacy(deserializedBindingModel, null); legacyBinding.Should().BeEquivalentTo(boundSonarQubeProject, options => options.Excluding(x => x.ProjectName).Excluding(x => x.Organization)); legacyBinding.ProjectName.Should().BeNull(); @@ -206,12 +206,12 @@ public void CurrentSonarQube_ToJsonModel_ToJson_ToJsonModel_ToLegacy_IsCorrect() [TestMethod] public void CurrentSonarCloud_ToJsonModel_ToJson_ToJsonModel_ToCurrent_IsCorrect() { - var convertedBindingJsonFromLegacy = bindingDtoConverter.ConvertToDto(boundSonarCloudServerProject); + var convertedBindingJsonFromLegacy = bindingJsonModelConverter.ConvertToModel(boundSonarCloudServerProject); var serializedBindingModel = JsonConvert.SerializeObject(convertedBindingJsonFromLegacy); var deserializedBindingModel = JsonConvert.DeserializeObject(serializedBindingModel); deserializedBindingModel.ServerConnectionId.Should().BeEquivalentTo(boundSonarCloudServerProject.ServerConnection.Id); - var binding = bindingDtoConverter.ConvertFromDto(deserializedBindingModel, boundSonarCloudServerProject.ServerConnection, "solution123"); + var binding = bindingJsonModelConverter.ConvertFromModel(deserializedBindingModel, boundSonarCloudServerProject.ServerConnection, "solution123"); binding.Should().BeEquivalentTo(boundSonarCloudServerProject); } @@ -219,12 +219,12 @@ public void CurrentSonarCloud_ToJsonModel_ToJson_ToJsonModel_ToCurrent_IsCorrect [TestMethod] public void CurrentSonarQube_ToJsonModel_ToJson_ToJsonModel_ToCurrent_IsCorrect() { - var convertedBindingJsonFromLegacy = bindingDtoConverter.ConvertToDto(boundSonarQubeServerProject); + var convertedBindingJsonFromLegacy = bindingJsonModelConverter.ConvertToModel(boundSonarQubeServerProject); var serializedBindingModel = JsonConvert.SerializeObject(convertedBindingJsonFromLegacy); var deserializedBindingModel = JsonConvert.DeserializeObject(serializedBindingModel); deserializedBindingModel.ServerConnectionId.Should().BeEquivalentTo(boundSonarQubeServerProject.ServerConnection.Id); - var binding = bindingDtoConverter.ConvertFromDto(deserializedBindingModel, boundSonarQubeServerProject.ServerConnection, "solution123"); + var binding = bindingJsonModelConverter.ConvertFromModel(deserializedBindingModel, boundSonarQubeServerProject.ServerConnection, "solution123"); binding.Should().BeEquivalentTo(boundSonarQubeServerProject); } diff --git a/src/ConnectedMode.UnitTests/Persistence/BoundSonarQubeProjectTests.cs b/src/ConnectedMode.UnitTests/Persistence/BoundSonarQubeProjectTests.cs index 8ff0e8389..1318f7cdd 100644 --- a/src/ConnectedMode.UnitTests/Persistence/BoundSonarQubeProjectTests.cs +++ b/src/ConnectedMode.UnitTests/Persistence/BoundSonarQubeProjectTests.cs @@ -50,7 +50,7 @@ public void BoundProject_Serialization() } [TestMethod] - public void BoundProject_BindingDto_Serialization() + public void BoundProject_BindingJsonModel_Serialization() { // Arrange var serverUri = new Uri("https://finding-nemo.org"); diff --git a/src/ConnectedMode.UnitTests/Persistence/SolutionBindingRepositoryTests.cs b/src/ConnectedMode.UnitTests/Persistence/SolutionBindingRepositoryTests.cs index cfcdade33..68a46629b 100644 --- a/src/ConnectedMode.UnitTests/Persistence/SolutionBindingRepositoryTests.cs +++ b/src/ConnectedMode.UnitTests/Persistence/SolutionBindingRepositoryTests.cs @@ -31,7 +31,7 @@ namespace SonarLint.VisualStudio.ConnectedMode.UnitTests.Persistence; public class SolutionBindingRepositoryTests { private IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider; - private IBindingDtoConverter bindingDtoConverter; + private IBindingJsonModelConverter bindingJsonModelConverter; private IServerConnectionsRepository serverConnectionsRepository; private ISolutionBindingCredentialsLoader credentialsLoader; private ISolutionBindingFileLoader solutionBindingFileLoader; @@ -49,13 +49,13 @@ public class SolutionBindingRepositoryTests public void TestInitialize() { unintrusiveBindingPathProvider = Substitute.For(); - bindingDtoConverter = Substitute.For(); + bindingJsonModelConverter = Substitute.For(); serverConnectionsRepository = Substitute.For(); credentialsLoader = Substitute.For(); solutionBindingFileLoader = Substitute.For(); logger = new TestLogger(); - testSubject = new SolutionBindingRepository(unintrusiveBindingPathProvider, bindingDtoConverter, serverConnectionsRepository, solutionBindingFileLoader, credentialsLoader, logger); + testSubject = new SolutionBindingRepository(unintrusiveBindingPathProvider, bindingJsonModelConverter, serverConnectionsRepository, solutionBindingFileLoader, credentialsLoader, logger); mockCredentials = new BasicAuthCredentials("user", "pwd".ToSecureString()); @@ -72,13 +72,13 @@ public void MefCtor_CheckIsExported() { MefTestHelpers.CheckTypeCanBeImported( MefTestHelpers.CreateExport(), - MefTestHelpers.CreateExport(), + MefTestHelpers.CreateExport(), MefTestHelpers.CreateExport(), MefTestHelpers.CreateExport(), MefTestHelpers.CreateExport()); MefTestHelpers.CheckTypeCanBeImported( MefTestHelpers.CreateExport(), - MefTestHelpers.CreateExport(), + MefTestHelpers.CreateExport(), MefTestHelpers.CreateExport(), MefTestHelpers.CreateExport(), MefTestHelpers.CreateExport()); @@ -119,7 +119,7 @@ public void Read_ProjectIsNotNull_ReadsConnectionRepositoryForConnection() }); solutionBindingFileLoader.Load(MockFilePath).Returns(bindingJsonModel); unintrusiveBindingPathProvider.GetBindingKeyFromPath(MockFilePath).Returns(boundServerProject.LocalBindingKey); - bindingDtoConverter.ConvertFromDto(bindingJsonModel, serverConnection, boundServerProject.LocalBindingKey).Returns(boundServerProject); + bindingJsonModelConverter.ConvertFromModel(bindingJsonModel, serverConnection, boundServerProject.LocalBindingKey).Returns(boundServerProject); var actual = testSubject.Read(MockFilePath); @@ -184,7 +184,7 @@ public void Write_EventTriggered_DependingOnFileWriteStatus(bool triggered) { var eventHandler = Substitute.For(); testSubject.BindingUpdated += eventHandler; - bindingDtoConverter.ConvertToDto(boundServerProject).Returns(bindingJsonModel); + bindingJsonModelConverter.ConvertToModel(boundServerProject).Returns(bindingJsonModel); solutionBindingFileLoader.Save(MockFilePath, bindingJsonModel).Returns(triggered); testSubject.Write(MockFilePath, boundServerProject); @@ -196,7 +196,7 @@ public void Write_EventTriggered_DependingOnFileWriteStatus(bool triggered) [TestMethod] public void Write_FileWritten_NoOnSaveCallback_NoException() { - bindingDtoConverter.ConvertToDto(boundServerProject).Returns(bindingJsonModel); + bindingJsonModelConverter.ConvertToModel(boundServerProject).Returns(bindingJsonModel); solutionBindingFileLoader.Save(MockFilePath, bindingJsonModel).Returns(true); Action act = () => testSubject.Write(MockFilePath, boundServerProject); @@ -285,7 +285,7 @@ public void LegacyRead_ValidBinding_LoadsCredentials() bindingJsonModel.ServerUri = new Uri("http://localhost/"); credentialsLoader.Load(bindingJsonModel.ServerUri).Returns(mockCredentials); solutionBindingFileLoader.Load(MockFilePath).Returns(bindingJsonModel); - bindingDtoConverter.ConvertFromDtoToLegacy(bindingJsonModel, mockCredentials).Returns(boundSonarQubeProject); + bindingJsonModelConverter.ConvertFromModelToLegacy(bindingJsonModel, mockCredentials).Returns(boundSonarQubeProject); ((ILegacySolutionBindingRepository)testSubject).Read(MockFilePath).Should().BeSameAs(boundSonarQubeProject); credentialsLoader.Received().Load(bindingJsonModel.ServerUri); @@ -301,7 +301,7 @@ private BoundServerProject SetUpBinding(string solution, ServerConnection connec } var bound = new BoundServerProject(solution, "any", connection); unintrusiveBindingPathProvider.GetBindingKeyFromPath(bindingConfig).Returns(solution); - bindingDtoConverter.ConvertFromDto(dto, connection, solution).Returns(bound); + bindingJsonModelConverter.ConvertFromModel(dto, connection, solution).Returns(bound); return bound; } diff --git a/src/ConnectedMode/Persistence/BindingDtoConverter.cs b/src/ConnectedMode/Persistence/BindingJsonModelConverter.cs similarity index 71% rename from src/ConnectedMode/Persistence/BindingDtoConverter.cs rename to src/ConnectedMode/Persistence/BindingJsonModelConverter.cs index ca60c14a3..763724a04 100644 --- a/src/ConnectedMode/Persistence/BindingDtoConverter.cs +++ b/src/ConnectedMode/Persistence/BindingJsonModelConverter.cs @@ -24,24 +24,24 @@ namespace SonarLint.VisualStudio.ConnectedMode.Persistence; -internal interface IBindingDtoConverter +internal interface IBindingJsonModelConverter { - BoundServerProject ConvertFromDto(BindingJsonModel bindingJsonModel, ServerConnection connection, string localBindingKey); - BindingJsonModel ConvertToDto(BoundServerProject binding); - BoundSonarQubeProject ConvertFromDtoToLegacy(BindingJsonModel bindingJsonModel, ICredentials credentials); + BoundServerProject ConvertFromModel(BindingJsonModel bindingJsonModel, ServerConnection connection, string localBindingKey); + BindingJsonModel ConvertToModel(BoundServerProject binding); + BoundSonarQubeProject ConvertFromModelToLegacy(BindingJsonModel bindingJsonModel, ICredentials credentials); } -[Export(typeof(IBindingDtoConverter))] +[Export(typeof(IBindingJsonModelConverter))] [PartCreationPolicy(CreationPolicy.Shared)] -internal class BindingDtoConverter : IBindingDtoConverter +internal class BindingJsonModelConverter : IBindingJsonModelConverter { - public BoundServerProject ConvertFromDto(BindingJsonModel bindingJsonModel, ServerConnection connection, string localBindingKey) => + public BoundServerProject ConvertFromModel(BindingJsonModel bindingJsonModel, ServerConnection connection, string localBindingKey) => new(localBindingKey, bindingJsonModel.ProjectKey, connection) { Profiles = bindingJsonModel.Profiles }; - public BindingJsonModel ConvertToDto(BoundServerProject binding) => + public BindingJsonModel ConvertToModel(BoundServerProject binding) => new() { ProjectKey = binding.ServerProjectKey, @@ -54,7 +54,7 @@ public BindingJsonModel ConvertToDto(BoundServerProject binding) => : null }; - public BoundSonarQubeProject ConvertFromDtoToLegacy(BindingJsonModel bindingJsonModel, ICredentials credentials) => + public BoundSonarQubeProject ConvertFromModelToLegacy(BindingJsonModel bindingJsonModel, ICredentials credentials) => new(bindingJsonModel.ServerUri, bindingJsonModel.ProjectKey, bindingJsonModel.ProjectName, diff --git a/src/ConnectedMode/Persistence/SolutionBindingRepository.cs b/src/ConnectedMode/Persistence/SolutionBindingRepository.cs index 0c8bc04de..bdeea600e 100644 --- a/src/ConnectedMode/Persistence/SolutionBindingRepository.cs +++ b/src/ConnectedMode/Persistence/SolutionBindingRepository.cs @@ -35,17 +35,17 @@ internal class SolutionBindingRepository : ISolutionBindingRepository, ILegacySo private readonly ISolutionBindingCredentialsLoader credentialsLoader; private readonly IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider; private readonly IServerConnectionsRepository serverConnectionsRepository; - private readonly IBindingDtoConverter bindingDtoConverter; + private readonly IBindingJsonModelConverter bindingJsonModelConverter; private readonly ILogger logger; [ImportingConstructor] public SolutionBindingRepository(IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider, - IBindingDtoConverter bindingDtoConverter, + IBindingJsonModelConverter bindingJsonModelConverter, IServerConnectionsRepository serverConnectionsRepository, ICredentialStoreService credentialStoreService, ILogger logger) : this(unintrusiveBindingPathProvider, - bindingDtoConverter, + bindingJsonModelConverter, serverConnectionsRepository, new SolutionBindingFileLoader(logger), new SolutionBindingCredentialsLoader(credentialStoreService), @@ -54,7 +54,7 @@ public SolutionBindingRepository(IUnintrusiveBindingPathProvider unintrusiveBind } internal /* for testing */ SolutionBindingRepository(IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider, - IBindingDtoConverter bindingDtoConverter, + IBindingJsonModelConverter bindingJsonModelConverter, IServerConnectionsRepository serverConnectionsRepository, ISolutionBindingFileLoader solutionBindingFileLoader, ISolutionBindingCredentialsLoader credentialsLoader, @@ -62,7 +62,7 @@ public SolutionBindingRepository(IUnintrusiveBindingPathProvider unintrusiveBind { this.unintrusiveBindingPathProvider = unintrusiveBindingPathProvider; this.serverConnectionsRepository = serverConnectionsRepository; - this.bindingDtoConverter = bindingDtoConverter; + this.bindingJsonModelConverter = bindingJsonModelConverter; this.solutionBindingFileLoader = solutionBindingFileLoader ?? throw new ArgumentNullException(nameof(solutionBindingFileLoader)); this.credentialsLoader = credentialsLoader ?? throw new ArgumentNullException(nameof(credentialsLoader)); this.logger = logger; @@ -70,11 +70,11 @@ public SolutionBindingRepository(IUnintrusiveBindingPathProvider unintrusiveBind BoundSonarQubeProject ILegacySolutionBindingRepository.Read(string configFilePath) { - var bindingDto = ReadBindingFile(configFilePath); - return bindingDto switch + var bindingJsonModel = ReadBindingFile(configFilePath); + return bindingJsonModel switch { null => null, - not null => bindingDtoConverter.ConvertFromDtoToLegacy(bindingDto, credentialsLoader.Load(bindingDto.ServerUri)) + not null => bindingJsonModelConverter.ConvertFromModelToLegacy(bindingJsonModel, credentialsLoader.Load(bindingJsonModel.ServerUri)) }; } @@ -92,7 +92,7 @@ public bool Write(string configFilePath, BoundServerProject binding) return false; } - if (!solutionBindingFileLoader.Save(configFilePath, bindingDtoConverter.ConvertToDto(binding))) + if (!solutionBindingFileLoader.Save(configFilePath, bindingJsonModelConverter.ConvertToModel(binding))) { return false; } @@ -115,21 +115,21 @@ public IEnumerable List() foreach (var bindingConfigPath in bindingConfigPaths) { - var bindingDto = ReadBindingFile(bindingConfigPath); + var bindingJsonModel = ReadBindingFile(bindingConfigPath); - if (bindingDto == null) + if (bindingJsonModel == null) { logger.LogVerbose($"Skipped {bindingConfigPath} because it could not be read"); continue; } - if (connections.FirstOrDefault(c => c.Id == bindingDto.ServerConnectionId) is not {} serverConnection) + if (connections.FirstOrDefault(c => c.Id == bindingJsonModel.ServerConnectionId) is not {} serverConnection) { - logger.LogVerbose($"Skipped {bindingConfigPath} because connection {bindingDto.ServerConnectionId} doesn't exist"); + logger.LogVerbose($"Skipped {bindingConfigPath} because connection {bindingJsonModel.ServerConnectionId} doesn't exist"); continue; } - var boundServerProject = Convert(bindingDto, serverConnection, bindingConfigPath); + var boundServerProject = Convert(bindingJsonModel, serverConnection, bindingConfigPath); yield return boundServerProject; } @@ -157,5 +157,5 @@ private BoundServerProject Convert(BindingJsonModel bindingJsonModel, string con : null; private BoundServerProject Convert(BindingJsonModel bindingJsonModel, ServerConnection connection, string configFilePath) => - bindingDtoConverter.ConvertFromDto(bindingJsonModel, connection, unintrusiveBindingPathProvider.GetBindingKeyFromPath(configFilePath)); + bindingJsonModelConverter.ConvertFromModel(bindingJsonModel, connection, unintrusiveBindingPathProvider.GetBindingKeyFromPath(configFilePath)); }