Esempio n. 1
0
        public void GetDeviceServiceSettings_WhenBaseUrlDoesNotEndWithForwardSlash_ShouldReturnBaseUrlEndingWithForwardSlash()
        {
            // Arrange
            var baseUrl         = "http://api.matlus.com";
            var expectedBaseUrl = baseUrl + "/";
            var generatedDeviceServiceSettings = new DeviceServiceSettingsBuilder()
                                                 .Set(x => x.BaseUrl, baseUrl)
                                                 .Build();

            var appSettings = new AppSettings {
                HttpProxyUrl = ProxyUrl
            };
            var configurationProvider = InitializeConfigurationProvider(generatedDeviceServiceSettings, appSettings);

            var expectedDeviceServiceSettings = new DeviceServiceSettingsBuilder()
                                                .Set(x => x.BaseUrl, expectedBaseUrl)
                                                .Set(x => x.HttpProxyUrl, appSettings.HttpProxyUrl)
                                                .With(generatedDeviceServiceSettings);

            // Act
            var actualDeviceServiceSettings = configurationProvider.GetDeviceServiceSettings();

            // Assert
            ObjectComparer.AssertAreEqual(expectedDeviceServiceSettings, actualDeviceServiceSettings);
        }
Esempio n. 2
0
        public void GetDeviceServiceSettings_WhenAccessTokenIsNull_ShouldThrow()
        {
            // Arrange
            var expectedExceptionMessage =
                @"The property: ""DeviceServiceSettings.AccessToken"" must be a valid DeviceServiceSettings.AccessToken and can not be Empty
";
            var deviceServiceSettings = new DeviceServiceSettingsBuilder()
                                        .Set(x => x.AccessToken, null)
                                        .Build();

            var appSettings = new AppSettings {
                HttpProxyUrl = ProxyUrl
            };
            var configurationProvider = InitializeConfigurationProvider(deviceServiceSettings, appSettings);

            try
            {
                // Act
                _ = configurationProvider.GetDeviceServiceSettings();
                Assert.Fail("We were expectiing an Excption of type: ConfigurationSettingMissingException, but no exception was thrown");
            }
            catch (ConfigurationSettingMissingException e)
            {
                // Assert
                Assert.AreEqual(expectedExceptionMessage, e.Message);
            }
        }
Esempio n. 3
0
        public void GetDeviceServiceSettings_WhenDevicesNull_ShouldThrowWithMessageSayingDevicesIsEmpty()
        {
            // Arrange
            var expectedExceptionMessage =
                @"The property: ""DeviceServiceSettings.Devices"" collection is Empty. The collection must contain at least 1 item.
";
            var deviceServiceSettings = new DeviceServiceSettingsBuilder()
                                        .Set(x => x.Devices, null)
                                        .Build();

            var appSettings = new AppSettings {
                HttpProxyUrl = ProxyUrl
            };
            var configurationProvider = InitializeConfigurationProvider(deviceServiceSettings, appSettings);

            try
            {
                // Act
                _ = configurationProvider.GetDeviceServiceSettings();
                Assert.Fail("We were expectiing an Excption of type: ConfigurationSettingMissingException, but no exception was thrown");
            }
            catch (ConfigurationSettingMissingException e)
            {
                // Assert
                Assert.AreEqual(expectedExceptionMessage, e.Message);
            }
        }
Esempio n. 4
0
        public void GetDeviceServiceSettings_WhenAllPropertiesAreNull_ShouldThrowWithMessageMentioningAllProperties()
        {
            // Arrange
            var expectedExceptionMessage =
                @"The property: ""DeviceServiceSettings.BaseUrl"" must be a valid DeviceServiceSettings.BaseUrl and can not be Empty
The property: ""DeviceServiceSettings.AccessToken"" must be a valid DeviceServiceSettings.AccessToken and can not be Empty
The property: ""DeviceServiceSettings.Devices"" collection is Empty. The collection must contain at least 1 item.
";
            var deviceServiceSettings = new DeviceServiceSettingsBuilder()
                                        .BuildWithDefaults();

            var appSettings = new AppSettings {
                HttpProxyUrl = ProxyUrl
            };
            var configurationProvider = InitializeConfigurationProvider(deviceServiceSettings, appSettings);

            try
            {
                // Act
                _ = configurationProvider.GetDeviceServiceSettings();
                Assert.Fail("We were expectiing an Excption of type: ConfigurationSettingMissingException, but no exception was thrown");
            }
            catch (ConfigurationSettingMissingException e)
            {
                // Assert
                Assert.AreEqual(expectedExceptionMessage, e.Message);
            }
        }
Esempio n. 5
0
        public void GetDeviceServiceSettings_WhenAllSeetingsArePresentAndCorrect_ShouldReturnExpectedSettings()
        {
            // Arrange
            var generatedWebExSettings = new DeviceServiceSettingsBuilder().Build();
            var appSettings            = new AppSettings {
                HttpProxyUrl = ProxyUrl
            };
            var configurationProvider = InitializeConfigurationProvider(generatedWebExSettings, appSettings);

            var expectedWebExSettings = new DeviceServiceSettingsBuilder()
                                        .Set(x => x.HttpProxyUrl, appSettings.HttpProxyUrl)
                                        .With(generatedWebExSettings);

            // Act
            var actualDeviceServiceSettings = configurationProvider.GetDeviceServiceSettings();

            // Assert
            ObjectComparer.AssertAreEqual(expectedWebExSettings, actualDeviceServiceSettings);
        }