public void IntegrationSettings_SetValue_Int() { // Arrange const string propertyKey = "key1"; const string collection = SonarLintSettings.SettingsRoot; SonarLintSettings testSubject = this.CreateTestSubject(); // Sanity this.settingsStore.AssertCollectionPropertyCount(collection, 0); // Test case 1: new property // Act testSubject.SetValue(propertyKey, 1); // Assert this.settingsStore.AssertCollectionPropertyCount(collection, 1); this.settingsStore.AssertInt(collection, propertyKey, 1); // Test case 2: overwrite existing property // Act testSubject.SetValue(propertyKey, 2); // Assert this.settingsStore.AssertCollectionPropertyCount(collection, 1); this.settingsStore.AssertInt(collection, propertyKey, 2); }
public void IntegrationSettings_GetValueOrDefault_Bool() { // Arrange SonarLintSettings testSubject = this.CreateTestSubject(); // Test case 1: exists -> value // Arrange bool expected1 = false; this.settingsStore.SetBoolean(SonarLintSettings.SettingsRoot, "key1", expected1); // Act bool actual1 = testSubject.GetValueOrDefault("key1", true); // Assert actual1.Should().Be(expected1, "Did not load existing value"); // Test case 2: does NOT exist -> default // Arrange bool expected2 = true; // Act bool actual2 = testSubject.GetValueOrDefault("key2", expected2); // Assert actual2.Should().Be(expected2, "Did not return default value"); }
public void IntegrationSettings_Ctor_InitializesStore() { // Sanity - should be empty store this.settingsStore.AssertCollectionDoesNotExist(SonarLintSettings.SettingsRoot); // Act SonarLintSettings testSubject = this.CreateTestSubject(); // Assert this.settingsStore.AssertCollectionExists(SonarLintSettings.SettingsRoot); }
public void IntegrationSettings_GetValueOrDefault_Int() { // Arrange SonarLintSettings testSubject = this.CreateTestSubject(); // Test case 1: exists -> value // Arrange int expected1 = 1; this.settingsStore.SetInt32(SonarLintSettings.SettingsRoot, "key1", expected1); // Act int actual1 = testSubject.GetValueOrDefault("key1", 0); // Assert actual1.Should().Be(expected1, "Did not load existing value"); // Test case 2: does NOT exist -> default // Arrange int expected2 = 2; // Act int actual2 = testSubject.GetValueOrDefault("key2", expected2); // Assert actual2.Should().Be(expected2, "Did not return default value"); // Test case 3: invalid type // Arrange int expected3 = 3; this.settingsStore.SetBoolean(SonarLintSettings.SettingsRoot, "key3", true); // Act int actual3 = testSubject.GetValueOrDefault("key3", expected3); // Assert actual3.Should().Be(expected3, "Did not return default value"); }