Пример #1
0
        /// <summary>
        /// Helper method for creating a list of ktExaminedGroup
        /// from an Excel worksheet.
        /// </summary>
        public bool LoadUIGroupOrder(Worksheet worksheet, SharedStringTable sharedString)
        {
            Result = new List <ktUIGroupOrder>();
            //Linq query to get the column headers on the sheet
            Row columnRow =
                (from row in worksheet.Descendants <Row>()
                 where row.RowIndex == 1
                 select row).First();

            IEnumerable <String> headerValues =
                from cell in columnRow.Descendants <Cell>()
                where cell.CellValue != null
                select
                    (cell.DataType != null &&
                    cell.DataType.HasValue &&
                    cell.DataType == CellValues.SharedString
                    ?sharedString.ChildElements[
                        int.Parse(cell.CellValue.InnerText)].InnerText
                    : cell.CellValue.InnerText);

            foreach (string header in headerValues)
            {
                ColumnNames.Add(header);
            }

            if (CheckColumnNames(ColumnNames))
            {
                //LINQ query to skip first row with column names.
                IEnumerable <Row> dataRows =
                    from row in worksheet.Descendants <Row>()
                    where row.RowIndex > 1
                    select row;

                if (CheckDataInSheets(dataRows))
                {
                    foreach (Row row in dataRows)
                    {
                        //LINQ query to return the row's cell values.
                        //Where clause filters out any cells that do not contain a value.
                        //Select returns the value of a cell unless the cell contains
                        //  a Shared String.
                        //If the cell contains a Shared String, its value will be a
                        //  reference id which will be used to look up the value in the
                        //  Shared String table.
                        IEnumerable <String> textValues =
                            from cell in row.Descendants <Cell>()
                            where cell.CellValue != null
                            select
                                (cell.DataType != null &&
                                cell.DataType.HasValue &&
                                cell.DataType == CellValues.SharedString
                                ?sharedString.ChildElements[
                                    int.Parse(cell.CellValue.InnerText)].InnerText
                                : cell.CellValue.InnerText)
                        ;

                        //Check to verify the row contained data.
                        if (textValues.Count() > 0)
                        {
                            //Create a ktExaminedGroup and add it to the list.

                            var            textArray  = textValues.ToArray();
                            ktUIGroupOrder groupOrder = new ktUIGroupOrder();
                            groupOrder.DepartmentID = textArray[0];
                            groupOrder.PageTypeID   = textArray[1];
                            groupOrder.GroupTypeID  = textArray[2];
                            groupOrder.GroupOrder   = Convert.ToDouble(textArray[3], CultureInfo.InvariantCulture);
                            Result.Add(groupOrder);
                        }
                        else
                        {
                            //If no cells, then you have reached the end of the table.
                            break;
                        }
                    }
                }
                else
                {
                    return(false);
                }
                return(true);
            }
            return(false);
        }
Пример #2
0
        public void AddOneGroup()
        {
            //Create a new group
            string        pageTypeID     = "15";
            string        engTransText   = "New group";
            string        danTransText   = "Ny gruppe";
            List <string> departmentList = new List <string>();

            departmentList.Add("-1");
            _wvm.CreateGroup(pageTypeID, engTransText, danTransText, departmentList);

            //Export excel with the new group in it
            _exExcel.CreateNewExcel(_exportPath);

            //Import the new excel file
            _impExcel.ImportExcelConfiguration(_exportPath);

            #region ktExaminedGroup tests

            //Get the new group in ktExaminedGroup
            List <ktExaminedGroup> examinedGroups =
                _impExcel._workSheetktExaminedGroup.ExaminedGroupList.Where(
                    x => x.GroupType.Equals("Newgroup1")).ToList();

            //Check if there only is one item of "New Group" in ktExaminedGroup
            Assert.AreEqual(examinedGroups.Count(), 1);
            ktExaminedGroup newGroup = examinedGroups[0];

            //Does the old list contain the new group?
            CollectionAssert.DoesNotContain(_oldExGroup, newGroup);

            #endregion

            #region ktUIOrder tests

            //Get the new group in ktUIOrder
            List <ktUIOrder> orders =
                _impExcel._workSheetktUIOrder.ktUIOrderList.Where(
                    x => x.GroupTypeID.Equals(newGroup.ID)).ToList();

            //Check if there are no items of "New Group" in ktExaminedGroup
            //There should be 0, because there are no items in the group
            Assert.AreEqual(orders.Count(), 0);

            #endregion

            #region ktUIGroupOrder tests

            //Get the new group in ktUIGroupOrder
            List <ktUIGroupOrder> groupOrders =
                _impExcel._workSheetktUIGroupOrder.ktUIGroupOrderList.Where(
                    x => x.GroupTypeID.Equals(newGroup.ID)).ToList();

            //Check if there only is one item of "New Group" in ktUIGroupOrder
            Assert.AreEqual(groupOrders.Count(), 1);
            ktUIGroupOrder newGroupOrder = groupOrders[0];

            //Does the old list contain the new group?
            CollectionAssert.DoesNotContain(_oldGroupOrder, newGroupOrder);

            //Does the new group have the right parameters on ktUIGroupOrder?
            Assert.AreEqual(newGroupOrder.PageTypeID, pageTypeID);

            #endregion

            #region ktResources tests

            //Get the new group in ktResources
            List <ktResources> resources =
                _impExcel._workSheetktResources.ktResourceList.Where(
                    x => x.ResourceResxID.Equals("Newgroup1")).ToList();

            //Check if there only is one item of "New Group" in ktResources
            Assert.AreEqual(resources.Count(), 1);
            ktResources newResource = resources[0];

            //Check if new group has a ResourceTypeID equal to 1.
            //Means that the group is a group
            Assert.AreEqual(newResource.ResourceTypeID, "1");

            //Does the old list contain the new group?
            CollectionAssert.DoesNotContain(_oldResources, newResource);

            #endregion

            #region ktUIResourceTranslation tests

            //Get the new group in ktResourceTranslation
            List <ktResourceTranslation> resourceTranslations =
                _impExcel._workSheetktResourceTranslation.ktResourceTranslationList.Where(
                    x => x.ResourceID.Equals(newResource.ResourceID)).ToList();

            //Check if there only is two item of "New Group" in ktResourceTranslation
            Assert.AreEqual(resourceTranslations.Count(), 2);

            //Check if the translation texts are right for the "New Group"
            foreach (ktResourceTranslation rt in resourceTranslations)
            {
                if (rt.LanguageID.Equals("1"))
                {
                    Assert.AreEqual(rt.TranslationText, engTransText);
                }
                else
                {
                    Assert.AreEqual(rt.TranslationText, danTransText);
                }

                //Does the "New Group" exist in the old list
                CollectionAssert.DoesNotContain(_oldResTranslation, rt);
            }

            #endregion
        }
Пример #3
0
        public void AddTwoGroupsWithSameName()
        {
            //Create a new group
            string        pageTypeID1     = "15";
            string        engTransText1   = "New group";
            string        danTransText1   = "Ny gruppe";
            List <string> departmentList1 = new List <string>();

            departmentList1.Add("-1");
            _wvm.CreateGroup(pageTypeID1, engTransText1, danTransText1, departmentList1);

            //_wvm.CreateGroup(pageTypeID1, languageID1, groupOrder1, engTransText1, danTransText1);

            //Create a new group
            string        pageTypeID2     = "15";
            string        engTransText2   = "New group";
            string        danTransText2   = "Ny gruppe";
            List <string> departmentList2 = new List <string>();

            departmentList2.Add("-1");
            _wvm.CreateGroup(pageTypeID2, engTransText2, danTransText2, departmentList2);

            //_wvm.CreateGroup(pageTypeID2, languageID2, groupOrder2, engTransText2, danTransText2);

            //Export excel with the new groups in it
            _exExcel.CreateNewExcel(_exportPath);

            //Import the new excel file
            _impExcel.ImportExcelConfiguration(_exportPath);

            #region ktExaminedGroup tests

            //Get the new group in ktExaminedGroup
            List <ktExaminedGroup> examinedGroups =
                _impExcel._workSheetktExaminedGroup.ExaminedGroupList.Where(
                    x => x.GroupType.Equals("Newgroup1") || x.GroupType.Equals("Newgroup2")).ToList();

            //Check if there are two items of "New Group" in ktExaminedGroup
            Assert.AreEqual(examinedGroups.Count(), 2);
            ktExaminedGroup newGroupOne = examinedGroups[0];
            ktExaminedGroup newGroupTwo = examinedGroups[1];

            //Does the old list contain the new groups?
            CollectionAssert.DoesNotContain(_oldExGroup, newGroupOne);
            CollectionAssert.DoesNotContain(_oldExGroup, newGroupTwo);

            #endregion

            #region ktUIOrder tests

            //Get the new groups in ktUIOrder
            List <ktUIOrder> orders =
                _impExcel._workSheetktUIOrder.ktUIOrderList.Where(
                    x => x.GroupTypeID.Equals(newGroupOne.ID) ||
                    x.GroupTypeID.Equals(newGroupTwo.ID)).ToList();

            //Check if there are no items of "New Group" in ktExaminedGroup
            //There should be 0, because there are no items in the groups
            Assert.AreEqual(orders.Count(), 0);

            #endregion

            #region ktUIGroupOrder tests

            //Get the new groups in ktUIGroupOrder
            List <ktUIGroupOrder> groupOrders =
                _impExcel._workSheetktUIGroupOrder.ktUIGroupOrderList.Where(
                    x => x.GroupTypeID.Equals(newGroupOne.ID) ||
                    x.GroupTypeID.Equals(newGroupTwo.ID)).ToList();

            //Check if there are two items of "New Group" in ktUIGroupOrder
            Assert.AreEqual(groupOrders.Count(), 2);
            ktUIGroupOrder newGroupOrderOne = groupOrders[0];
            ktUIGroupOrder newGroupOrderTwo = groupOrders[1];

            //Does the old list contain the new groups?
            CollectionAssert.DoesNotContain(_oldGroupOrder, newGroupOrderOne);
            CollectionAssert.DoesNotContain(_oldGroupOrder, newGroupOrderTwo);

            //Does the new groups have the right parameters on ktUIGroupOrder?
            foreach (ktUIGroupOrder go in groupOrders)
            {
                if (go.PageTypeID.Equals(pageTypeID1))
                {
                    Assert.AreEqual(newGroupOrderOne.PageTypeID, pageTypeID1);
                }
                else
                {
                    Assert.AreEqual(newGroupOrderTwo.PageTypeID, pageTypeID2);
                }
            }

            #endregion

            #region ktResources tests

            //Get the new groups in ktResources
            List <ktResources> resources1 =
                _impExcel._workSheetktResources.ktResourceList.Where(
                    x => x.ResourceResxID.Equals("Newgroup1")).ToList();

            List <ktResources> resources2 =
                _impExcel._workSheetktResources.ktResourceList.Where(
                    x => x.ResourceResxID.Equals("Newgroup2")).ToList();

            //Check if there only is one item of "New Group" in ktResources
            Assert.AreEqual(resources1.Count(), 1);
            Assert.AreEqual(resources2.Count(), 1);
            ktResources newResourceOne = resources1[0];
            ktResources newResourceTwo = resources2[0];

            //Check if new group has a ResourceTypeID equal to 1.
            //Means that the group is a group
            Assert.AreEqual(newResourceOne.ResourceTypeID, "1");
            Assert.AreEqual(newResourceTwo.ResourceTypeID, "1");

            //Does the old list contain the new groups?
            CollectionAssert.DoesNotContain(_oldResources, newResourceOne);
            CollectionAssert.DoesNotContain(_oldResources, newResourceTwo);

            #endregion

            #region ktUIResourceTranslation tests

            //Get the new groups in ktResourceTranslation
            List <ktResourceTranslation> resourceTranslationsOne =
                _impExcel._workSheetktResourceTranslation.ktResourceTranslationList.Where(
                    x => x.ResourceID.Equals(newResourceOne.ResourceID)).ToList();

            List <ktResourceTranslation> resourceTranslationsTwo =
                _impExcel._workSheetktResourceTranslation.ktResourceTranslationList.Where(
                    x => x.ResourceID.Equals(newResourceTwo.ResourceID)).ToList();

            //Check if there are four items of "New Group" in ktResourceTranslation
            Assert.AreEqual(resourceTranslationsOne.Count() + resourceTranslationsTwo.Count(), 4);

            //Check if the translation texts are right for the two "New Groups"
            foreach (ktResourceTranslation rt in resourceTranslationsOne)
            {
                if (rt.LanguageID.Equals("1"))
                {
                    Assert.AreEqual(rt.TranslationText, engTransText1);
                }
                else
                {
                    Assert.AreEqual(rt.TranslationText, danTransText1);
                }

                //Does the "New Group" exist in the old list
                CollectionAssert.DoesNotContain(_oldResTranslation, rt);
            }

            foreach (ktResourceTranslation rt in resourceTranslationsTwo)
            {
                if (rt.LanguageID.Equals("1"))
                {
                    Assert.AreEqual(rt.TranslationText, engTransText2);
                }
                else
                {
                    Assert.AreEqual(rt.TranslationText, danTransText2);
                }

                //Does the "New Group" exist in the old list
                CollectionAssert.DoesNotContain(_oldResTranslation, rt);
            }

            #endregion
        }
        /// <summary>
        /// Helper method for creating a list of ktExaminedGroup 
        /// from an Excel worksheet.
        /// </summary>
        public bool LoadUIGroupOrder(Worksheet worksheet, SharedStringTable sharedString)
        {
            Result = new List<ktUIGroupOrder>();
            //Linq query to get the column headers on the sheet
            Row columnRow =
               (from row in worksheet.Descendants<Row>()
                where row.RowIndex == 1
                select row).First();

            IEnumerable<String> headerValues =
                    from cell in columnRow.Descendants<Cell>()
                    where cell.CellValue != null
                    select
                        (cell.DataType != null
                         && cell.DataType.HasValue
                         && cell.DataType == CellValues.SharedString
                            ? sharedString.ChildElements[
                                int.Parse(cell.CellValue.InnerText)].InnerText
                            : cell.CellValue.InnerText);

            foreach (string header in headerValues)
            {
                ColumnNames.Add(header);
            }

            if (CheckColumnNames(ColumnNames))
            {
                //LINQ query to skip first row with column names.
                IEnumerable<Row> dataRows =
                    from row in worksheet.Descendants<Row>()
                    where row.RowIndex > 1
                    select row;

                if (CheckDataInSheets(dataRows))
                {
                    foreach (Row row in dataRows)
                    {
                        //LINQ query to return the row's cell values.
                        //Where clause filters out any cells that do not contain a value.
                        //Select returns the value of a cell unless the cell contains
                        //  a Shared String.
                        //If the cell contains a Shared String, its value will be a
                        //  reference id which will be used to look up the value in the
                        //  Shared String table.
                        IEnumerable<String> textValues =
                            from cell in row.Descendants<Cell>()
                            where cell.CellValue != null
                            select
                                (cell.DataType != null
                                 && cell.DataType.HasValue
                                 && cell.DataType == CellValues.SharedString
                                    ? sharedString.ChildElements[
                                        int.Parse(cell.CellValue.InnerText)].InnerText
                                    : cell.CellValue.InnerText)
                            ;

                        //Check to verify the row contained data.
                        if (textValues.Count() > 0)
                        {
                            //Create a ktExaminedGroup and add it to the list.

                            var textArray = textValues.ToArray();
                            ktUIGroupOrder groupOrder = new ktUIGroupOrder();
                            groupOrder.DepartmentID = textArray[0];
                            groupOrder.PageTypeID = textArray[1];
                            groupOrder.GroupTypeID = textArray[2];
                            groupOrder.GroupOrder = Convert.ToDouble(textArray[3], CultureInfo.InvariantCulture);
                            Result.Add(groupOrder);
                        }
                        else
                        {
                            //If no cells, then you have reached the end of the table.
                            break;
                        }
                    }
                }
                else
                {
                    return false;
                }
                return true;
            }
            return false;
        }