Example #1
0
        public void Set_NullSettingValue_Removes()
        {
            // arrange
            var memorySettings = new MemorySettings();

            // act
            memorySettings.Set("String Setting", "Value 1");
            memorySettings.Set("String Setting", (string)null);
            var retrieved = memorySettings.Get("String Setting", out string actualValue);

            // assert
            Assert.False(retrieved);
        }
Example #2
0
        public void Set_EmptySettingValue_ReturnSame()
        {
            // arrange
            var memorySettings = new MemorySettings();
            var expectedValue  = string.Empty;

            // act
            memorySettings.Set("String Setting", "Value 1");
            memorySettings.Set("String Setting", expectedValue);
            var retrieved = memorySettings.Get("String Setting", out string actualValue);

            // assert
            Assert.True(retrieved);
            Assert.Equal(expectedValue, actualValue);
        }
Example #3
0
        public void Set_MultipleSettings_ReturnsSame()
        {
            // arrange
            var memorySettings = new MemorySettings();
            var expectedValueA = "Cat";
            var expectedValueB = "Dog";
            var expectedValueC = "Bird";
            var settings       = new[]
            {
                new KeyValuePair <string, string>("Setting A", expectedValueA),
                new KeyValuePair <string, string>("Setting B", expectedValueB),
                new KeyValuePair <string, string>("Setting C", expectedValueC)
            };

            // act
            memorySettings.Set(settings);

            var retrievedA = memorySettings.Get("Setting A", out string actualValueA);
            var retrievedB = memorySettings.Get("Setting B", out string actualValueB);
            var retrievedC = memorySettings.Get("Setting C", out string actualValueC);

            // assert
            Assert.True(retrievedA);
            Assert.Equal(expectedValueA, actualValueA);

            Assert.True(retrievedB);
            Assert.Equal(expectedValueB, actualValueB);

            Assert.True(retrievedC);
            Assert.Equal(expectedValueC, actualValueC);
        }
Example #4
0
        public void Set_NullSettingName_ThrowsException()
        {
            // arrange
            var memorySettings = new MemorySettings();
            var expected       = default(bool);

            // act
            Action actual = () => memorySettings.Set(null, "some setting value");

            // assert
            Assert.Throws <ArgumentNullException>(actual);
        }
Example #5
0
        public void Set_IntegerNumber_ReturnsSame(string setting, int expected)
        {
            // arrange
            var memorySettings = new MemorySettings();

            // act
            memorySettings.Set(setting, expected);
            var retrieved = memorySettings.Get(setting, out int actual);

            // assert
            Assert.True(retrieved);
            Assert.Equal(expected, actual);
        }
Example #6
0
        public void Get_DoubleNumber_ReturnsSame()
        {
            // arrange
            var memorySettings = new MemorySettings();
            var expected       = Math.PI;

            // act
            memorySettings.Set("PI", expected);
            var retrieved = memorySettings.Get("PI", out double actual);

            // assert
            Assert.True(retrieved);
            Assert.Equal(expected, actual);
        }