public async Task GetInstanceSettingsAsync_QueryReturnsEmpty_ThrowsException()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlSettingsRepository(cxn.Object);

            InstanceSettings[] result = { };
            cxn.SetupQueryAsync("GetInstanceSettings", null, result);

            // Act
            await repository.GetInstanceSettingsAsync();

            // Assert
            cxn.Verify();
        }
        public async Task GetFederatedAuthentication_QueryReturnsEmpty_ReturnsNull()
        {
            // Arrange
            var     cxn        = new SqlConnectionWrapperMock();
            var     repository = new SqlSettingsRepository(cxn.Object);
            dynamic result     = new dynamic[] { };

            cxn.SetupQueryAsync("GetFederatedAuthentications", null, result);

            // Act
            var settings = await repository.GetFederatedAuthenticationSettingsAsync();

            // Assert
            cxn.Verify();
            Assert.AreEqual(null, settings);
        }
        public async Task GetInstanceSettingsAsync_QueryReturnsSettings_ReturnsFirst()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlSettingsRepository(cxn.Object);

            InstanceSettings[] result = { new InstanceSettings {
                                              UseDefaultConnection = true
                                          } };
            cxn.SetupQueryAsync("GetInstanceSettings", null, result);

            // Act
            InstanceSettings settings = await repository.GetInstanceSettingsAsync();

            // Assert
            cxn.Verify();
            Assert.AreEqual(result.First(), settings);
        }
        public async Task GetUserManagementSettingsAsync_PasswordExpirationInDaysIsGreaterThanZero_IsPasswordExpirationEnabledIsTrue()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlSettingsRepository(cxn.Object);
            var result     = new[] { new InstanceSettings {
                                         PasswordExpirationInDays = 90
                                     } };

            cxn.SetupQueryAsync("GetInstanceSettings", null, result);

            // Act
            var settings = await repository.GetUserManagementSettingsAsync();

            // Assert
            cxn.Verify();
            Assert.AreEqual(settings.IsPasswordExpirationEnabled, true);
        }
        public async Task GetLdapSettingsAsync_QueryReturnsSettings_ReturnsSettings()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlSettingsRepository(cxn.Object);

            LdapSettings[] result = { new LdapSettings {
                                          Id = 1
                                      } };
            cxn.SetupQueryAsync("GetLdapSettings", null, result);

            // Act
            IEnumerable <LdapSettings> settings = await repository.GetLdapSettingsAsync();

            // Assert
            cxn.Verify();
            CollectionAssert.AreEquivalent(result, settings.ToList());
        }
        public async Task GetUserManagementSettingsAsync_FederatedAuthEnabled_IsFederatedAuthenticationEnabledIsTrue()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlSettingsRepository(cxn.Object);
            var result     = new[] { new InstanceSettings {
                                         IsSamlEnabled = true
                                     } };

            cxn.SetupQueryAsync("GetInstanceSettings", null, result);

            // Act
            var settings = await repository.GetUserManagementSettingsAsync();

            // Assert
            cxn.Verify();
            Assert.AreEqual(settings.IsFederatedAuthenticationEnabled, true);
        }
        public async Task GetFederatedAuthentication_QueryReturnsSettings_ReturnsFirst()
        {
            // Arrange
            var     cxn        = new SqlConnectionWrapperMock();
            var     repository = new SqlSettingsRepository(cxn.Object);
            var     xml        = SerializationHelper.Serialize(new FederatedAuthenticationSettings.FASettings());
            dynamic dbObject   = new ExpandoObject();

            dbObject.Settings    = xml;
            dbObject.Certificate = null;
            var expectedFedAuthSettings = new FederatedAuthenticationSettings(xml, null);
            var result = new[] { dbObject };

            cxn.SetupQueryAsync("GetFederatedAuthentications", null, result);

            // Act
            var settings = await repository.GetFederatedAuthenticationSettingsAsync();

            // Assert
            cxn.Verify();
            Assert.IsTrue(Equals(expectedFedAuthSettings, settings));
        }