public void GetUserGroups_WhenUserNotInDataSet_ReturnsDefaultGroup()
        {
            TestGroupsDataSet loadedDataSet = new TestGroupsDataSet(TestResourceName);

            loadedDataSet.Load(GetCorrectData());

            // Expecting a user to be in 'all' group
            Assert.True(loadedDataSet.GetUserGroups("*****@*****.**").Count() == 1, "Expected 1 group for [email protected]");
            Assert.True(loadedDataSet.GetUserGroups("*****@*****.**").Contains("all"), "Expected groups for [email protected] to contain group 'all'");
        }
        public void GetUserGroups_InputInDifferentCasing_ReturnsCorrectResult()
        {
            TestGroupsDataSet testGroupsDataSet = new TestGroupsDataSet(TestResourceName);

            if (!testGroupsDataSet.Load(GetCorrectData()))
            {
                Assert.True(false, GetDataSetLoadingErrors(testGroupsDataSet));
            }

            Assert.True(testGroupsDataSet.GetUserGroups("*****@*****.**").Count() == 3, "Expected GetUserGroups search to be case insensitive");
        }
        public void Load_ValidTestGroupsXml_LoadsDataSet()
        {
            TestGroupsDataSet testGroupsDataSet = new TestGroupsDataSet(TestResourceName);

            // Expecting DataSet to be loaded and no errors
            if (!testGroupsDataSet.Load(GetCorrectData()))
            {
                Assert.Empty(GetDataSetLoadingErrors(testGroupsDataSet));
            }

            Assert.True(testGroupsDataSet.IsHealthy, "DataSet reports to be healthy");
        }
        public void GetUserGroups_WhenDataSetIsEmpty_ReturnsDefaultGroup()
        {
            FailOnErrors = false;

            TestGroupsDataSet emptyDataSet = new TestGroupsDataSet(TestResourceName);

            emptyDataSet.Load(GetIncorrectData());

            // Expecting a user to be in 'all' group in empty DataSet
            Assert.True(emptyDataSet.GetUserGroups("*****@*****.**").Count() == 1, "Expected 1 group for [email protected]");
            Assert.True(emptyDataSet.GetUserGroups("*****@*****.**").Contains("all"), "Expected groups for [email protected] to contain group 'all'");
        }
        /// <summary>
        /// Verifies that DataSet loads with one parsing error from given resource
        /// </summary>
        /// <param name="resourceString">resource content as a string</param>
        private void LoadDataSetWithOneError(string resourceString)
        {
            FailOnErrors = false;

            IDictionary <string, IResourceDetails> resources =
                new Dictionary <string, IResourceDetails>(1, StringComparer.OrdinalIgnoreCase)
            {
                { TestResourceName, EmbeddedResources.CreateResourceDetails(resourceString) }
            };

            TestGroupsDataSet testGroupsDataSet = new TestGroupsDataSet(TestResourceName);

            // Expecting DataSet load to return false
            Assert.False(testGroupsDataSet.Load(resources), "Expecting DataSet load to return false.");
            // Expecting DataSet to be loaded
            Assert.False(testGroupsDataSet.IsHealthy, "Expecting DataSet to be not healthy.");
            // Expecting one error
            Assert.Equal(1, testGroupsDataSet.Errors.Count);
        }
        public void Load_ValidTestGroupsXml_LoadsUserGroups()
        {
            TestGroupsDataSet testGroupsDataSet = new TestGroupsDataSet(TestResourceName);

            if (!testGroupsDataSet.Load(GetCorrectData()))
            {
                Assert.Empty(GetDataSetLoadingErrors(testGroupsDataSet));
            }

            //Expecting correct groups returned for emails
            Assert.True(testGroupsDataSet.GetUserGroups("*****@*****.**").Count() == 3, "Expected 3 groups for [email protected]");
            Assert.True(testGroupsDataSet.GetUserGroups("*****@*****.**").Contains("Test"), "Expected groups for [email protected] to contain Test");
            Assert.True(testGroupsDataSet.GetUserGroups("*****@*****.**").Contains("Automation"), "Expected groups for [email protected] to contain Automation");
            Assert.True(testGroupsDataSet.GetUserGroups("*****@*****.**").Contains("all"), "Expected groups for [email protected] to contain group 'all'");

            Assert.True(testGroupsDataSet.GetUserGroups("*****@*****.**").Count() == 2, "Expected 2 groups for [email protected]");
            Assert.True(testGroupsDataSet.GetUserGroups("*****@*****.**").Contains("Test"), "Expected groups for [email protected] to contain Test");
            Assert.True(testGroupsDataSet.GetUserGroups("*****@*****.**").Contains("all"), "Expected groups for [email protected] to contain group 'all'");

            Assert.True(testGroupsDataSet.GetUserGroups("*****@*****.**").Count() == 2, "Expected 2 groups for [email protected]");
            Assert.True(testGroupsDataSet.GetUserGroups("*****@*****.**").Contains("Automation"), "Expected groups for [email protected] to contain Automation");
            Assert.True(testGroupsDataSet.GetUserGroups("*****@*****.**").Contains("all"), "Expected groups for [email protected] to contain group 'all'");

            //Expecting correct users returned for groups
            Assert.True(testGroupsDataSet.GetGroupUsers("Test").Count() == 4, "Expected 4 users for Test group");
            Assert.True(testGroupsDataSet.GetGroupUsers("Test").Contains("*****@*****.**", StringComparer.OrdinalIgnoreCase), "Expected [email protected] to be in Test");
            Assert.True(testGroupsDataSet.GetGroupUsers("Test").Contains("*****@*****.**", StringComparer.OrdinalIgnoreCase), "Expected [email protected] to be in Test");

            Assert.True(testGroupsDataSet.GetGroupUsers("Automation").Count() == 2, "Expected 2 users for Automation group");
            Assert.True(testGroupsDataSet.GetGroupUsers("Automation").Contains("*****@*****.**", StringComparer.OrdinalIgnoreCase), "Expected [email protected] to be in Automation");
            Assert.True(testGroupsDataSet.GetGroupUsers("Automation").Contains("*****@*****.**", StringComparer.OrdinalIgnoreCase), "Expected [email protected] to be in Automation");

            Assert.True(testGroupsDataSet.GetGroupUsers("all").Count() == 6, "Expected 6 users for 'all' group");
            Assert.True(testGroupsDataSet.GetGroupUsers("all").Contains("*****@*****.**", StringComparer.OrdinalIgnoreCase), "Expected [email protected] to be in 'all'");
            Assert.True(testGroupsDataSet.GetGroupUsers("all").Contains("*****@*****.**", StringComparer.OrdinalIgnoreCase), "Expected [email protected] to be in 'all'");
            Assert.True(testGroupsDataSet.GetGroupUsers("all").Contains("*****@*****.**", StringComparer.OrdinalIgnoreCase), "Expected [email protected] to be in 'all'");
        }