Skip to content

Commit

Permalink
SLVS-1447 More renaming of BindingDto to BindingJsonModel
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriela-trutan-sonarsource committed Sep 27, 2024
1 parent c11f25c commit 54b1484
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<BindingDtoConverter, IBindingDtoConverter>();
MefTestHelpers.CheckTypeCanBeImported<BindingJsonModelConverter, IBindingJsonModelConverter>();
}

[TestMethod]
public void MefCtor_CheckIsSingleton()
{
MefTestHelpers.CheckIsSingletonMefComponent<BindingDtoConverter>();
MefTestHelpers.CheckIsSingletonMefComponent<BindingJsonModelConverter>();
}

[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<Language, ApplicableQualityProfile>(),
Expand All @@ -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<Language, ApplicableQualityProfile>()
};

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<Language, ApplicableQualityProfile>()
};

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<ICredentials>();
var bindingDto = new BindingJsonModel
var bindingModel = new BindingJsonModel
{
Organization = new SonarQubeOrganization("org", "my org"),
ServerUri = new Uri("http://localhost"),
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
"""
Expand All @@ -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(
"""
Expand All @@ -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<BindingJsonModel>(serialized);
var deserializeBindingModel = JsonConvert.DeserializeObject<BindingJsonModel>(serialized);

var convertedFromJsonToLegacy = bindingDtoConverter.ConvertFromDtoToLegacy(deserializeBindingDto, null);
var convertedFromJsonToLegacy = bindingJsonModelConverter.ConvertFromModelToLegacy(deserializeBindingModel, null);

convertedFromJsonToLegacy.Should().BeEquivalentTo(boundSonarQubeProject);
}
Expand All @@ -149,7 +149,7 @@ public void Legacy_ToJson_ToLegacyDirectly_And_ToJsonModel_ToLegacy_IsCorrect()
var legacyDirect = JsonConvert.DeserializeObject<BoundSonarQubeProject>(serializedLegacy);
var deserializedBindingModel = JsonConvert.DeserializeObject<BindingJsonModel>(serializedLegacy);

var convertedFromJsonToLegacy = bindingDtoConverter.ConvertFromDtoToLegacy(deserializedBindingModel, null);
var convertedFromJsonToLegacy = bindingJsonModelConverter.ConvertFromModelToLegacy(deserializedBindingModel, null);

convertedFromJsonToLegacy.Should().BeEquivalentTo(legacyDirect);
}
Expand All @@ -169,19 +169,19 @@ public void JsonModel_ToJson_ToJsonModel_ToLegacy_IsCorrect()
var serializedBindingModel = JsonConvert.SerializeObject(bindingJsonModel);
var deserializedBindingModel = JsonConvert.DeserializeObject<BindingJsonModel>(serializedBindingModel);

var convertedFromJsonToLegacy = bindingDtoConverter.ConvertFromDtoToLegacy(deserializedBindingModel, null);
var convertedFromJsonToLegacy = bindingJsonModelConverter.ConvertFromModelToLegacy(deserializedBindingModel, null);

convertedFromJsonToLegacy.Should().BeEquivalentTo(boundSonarQubeProject);
}

[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<BindingJsonModel>(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);
Expand All @@ -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<BindingJsonModel>(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();
Expand All @@ -206,25 +206,25 @@ 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<BindingJsonModel>(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);
}

[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<BindingJsonModel>(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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading

0 comments on commit 54b1484

Please sign in to comment.