public void ApplyStylesToAllElements()
        {
            var elementDictionary = new Dictionary<IElement, StyleClass>();

            var tableDomObject1 = new HtmlParser().Parse("<table id=\"tabletest1\" class=\"test1\" bgcolor=\"\"></table>");
            var tableDomObject2 = new HtmlParser().Parse("<table id=\"tabletest2\" class=\"test2\" bgcolor=\"\" width=\"\"></table>");
            var tableDomObject3 = new HtmlParser().Parse("<table id=\"tabletest3\" class=\"test3\" bgcolor=\"\" height=\"\"></table>");
            var tableDomObject4 = new HtmlParser().Parse("<table id=\"tabletest4\" class=\"test4\" bgcolor=\"\" width=\"\"></table>");

            var styleClassBgColor = new StyleClass();
            styleClassBgColor.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008001");

            var styleClassWidth = new StyleClass();
            styleClassWidth.Attributes["width"] = CssAttribute.FromRule("width: 10px");

            var styleClassHeight = new StyleClass();
            styleClassHeight.Attributes["height"] = CssAttribute.FromRule("height: 10px");

            var styleClassBgAndWidth = new StyleClass();
            styleClassBgAndWidth.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008003");
            styleClassBgAndWidth.Attributes["width"] = CssAttribute.FromRule("width: 10px");
            
            elementDictionary.Add(tableDomObject1.Body.FirstElementChild, styleClassBgColor);
            elementDictionary.Add(tableDomObject2.Body.FirstElementChild, styleClassWidth);
            elementDictionary.Add(tableDomObject3.Body.FirstElementChild, styleClassHeight);
            elementDictionary.Add(tableDomObject4.Body.FirstElementChild, styleClassBgAndWidth);

            var result = StyleClassApplier.ApplyAllStyles(elementDictionary);

            Assert.AreEqual("<table id=\"tabletest1\" class=\"test1\" bgcolor=\"#008001\" style=\"background-color: #008001\"></table>", result.ElementAt(0).Key.OuterHtml);
            Assert.AreEqual("<table id=\"tabletest2\" class=\"test2\" bgcolor=\"\" width=\"10px\" style=\"width: 10px\"></table>", result.ElementAt(1).Key.OuterHtml);
            Assert.AreEqual("<table id=\"tabletest3\" class=\"test3\" bgcolor=\"\" height=\"10px\" style=\"height: 10px\"></table>", result.ElementAt(2).Key.OuterHtml);
            Assert.AreEqual("<table id=\"tabletest4\" class=\"test4\" bgcolor=\"#008003\" width=\"10px\" style=\"background-color: #008003;width: 10px\"></table>", result.ElementAt(3).Key.OuterHtml);
        }
        public void ApplyStylesToAllElements()
        {
            var elementDictionary = new Dictionary<IDomObject, StyleClass>();

            var tableDomObject1 = CQ.CreateFragment("<td id=\"tabletest1\" class=\"test1\" bgcolor=\"\"></td>");
            var tableDomObject2 = CQ.CreateFragment("<td id=\"tabletest2\" class=\"test2\" bgcolor=\"\" width=\"\"></td>");
            var tableDomObject3 = CQ.CreateFragment("<td id=\"tabletest3\" class=\"test3\" bgcolor=\"\" height=\"\"></td>");
            var tableDomObject4 = CQ.CreateFragment("<td id=\"tabletest4\" class=\"test4\" bgcolor=\"\" width=\"\"></td>");

            var styleClassBgColor = new StyleClass();
            styleClassBgColor.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008001");

            var styleClassWidth = new StyleClass();
            styleClassWidth.Attributes["width"] = CssAttribute.FromRule("width: 10px");

            var styleClassHeight = new StyleClass();
            styleClassHeight.Attributes["height"] = CssAttribute.FromRule("height: 10px");

            var styleClassBgAndWidth = new StyleClass();
            styleClassBgAndWidth.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008003");
            styleClassBgAndWidth.Attributes["width"] = CssAttribute.FromRule("width: 10px");
            
            elementDictionary.Add(tableDomObject1.FirstElement(), styleClassBgColor);
            elementDictionary.Add(tableDomObject2.FirstElement(), styleClassWidth);
            elementDictionary.Add(tableDomObject3.FirstElement(), styleClassHeight);
            elementDictionary.Add(tableDomObject4.FirstElement(), styleClassBgAndWidth);

            var result = StyleClassApplier.ApplyAllStyles(elementDictionary);

            Assert.AreEqual("<td class=\"test1\" style=\"background-color: #008001\" id=\"tabletest1\" bgcolor=\"#008001\"></td>", result.ElementAt(0).Key.ToString());
            Assert.AreEqual("<td class=\"test2\" style=\"width: 10px\" id=\"tabletest2\" bgcolor width=\"10px\"></td>", result.ElementAt(1).Key.ToString());
            Assert.AreEqual("<td class=\"test3\" style=\"height: 10px\" id=\"tabletest3\" bgcolor height=\"10px\"></td>", result.ElementAt(2).Key.ToString());
            Assert.AreEqual("<td class=\"test4\" style=\"background-color: #008003;width: 10px\" id=\"tabletest4\" bgcolor=\"#008003\" width=\"10px\"></td>", result.ElementAt(3).Key.ToString());
        }
Exemple #3
0
        private void FillStyleClass(string s)
        {
            StyleClass sc = null;
            string[] parts = s.Split('{');
            string styleName = CleanUp(parts[0]).Trim();

            if (this._scc.ContainsKey(styleName))
            {
                sc = this._scc[styleName];
                this._scc.Remove(styleName);
            }
            else
            {
                sc = new StyleClass();
            }

            sc.Name = styleName;

            string[] atrs = CleanUp(parts[1]).Replace("}", "").Split(';');
            foreach (string a in atrs)
            {
                if (a.Contains(":"))
                {
                    string _key = a.Split(':')[0].Trim();
                    if (sc.Attributes.ContainsKey(_key))
                    {
                        sc.Attributes.Remove(_key);
                    }
                    sc.Attributes.Add(_key, a.Split(':')[1].Trim());
                }
            }
            this._scc.Add(sc.Name, sc);
        }
        public void SingleAttribute_ShouldNotAppendSemiColonToString()
        {
            var clazz = new StyleClass();
            clazz.Attributes["color"] = CssAttribute.FromRule("color: red");

            Assert.AreEqual("color: red", clazz.ToString());
        }
        public void MultipleAttributes_ShouldJoinAttributesWithSemiColonInString()
        {
            var clazz = new StyleClass();
            clazz.Attributes["color"] = CssAttribute.FromRule("color: red");
            clazz.Attributes["height"] = CssAttribute.FromRule("height: 100%");

            Assert.AreEqual("color: red;height: 100%", clazz.ToString());
        }
        public void FindEquivalentStyles()
        {
            var tableDomObject = CQ.CreateFragment("<td id=\"tabletest\" class=\"test\" bgcolor=\"\"></td>");
            var nodewithoutselector = tableDomObject.FirstElement();

            var clazz = new StyleClass();
            clazz.Attributes["background-color"] = CssAttribute.FromRule("background-color: red");

            var result = CssStyleEquivalence.FindEquivalent(nodewithoutselector, clazz);

            Assert.AreEqual(1, result.Count);
        }
        public void FindEquivalentStyles()
        {
            var tableDomObject = new HtmlParser().Parse("<table id=\"tabletest\" class=\"test\" bgcolor=\"\"></table>");
            var nodewithoutselector = (IElement)tableDomObject.Body.FirstChild;

            var clazz = new StyleClass();
            clazz.Attributes["background-color"] = CssAttribute.FromRule("background-color: red");

            var result = CssStyleEquivalence.FindEquivalent(nodewithoutselector, clazz);

            Assert.AreEqual(1, result.Count);
        }
        public void Merge_ShouldAddNonExistingAttributesToClass()
        {
            var target = new StyleClass();
            var donator = new StyleClass();

            target.Attributes["color"] = CssAttribute.FromRule("color: red");
            donator.Attributes["height"] = CssAttribute.FromRule("height: 100%");

            target.Merge(donator, true);

            Assert.IsTrue(target.Attributes.ContainsKey("height"));
            Assert.AreEqual("100%", target.Attributes["height"].Value);
        }
        public void GetAllStylesForElement()
        {
            var tableDomObject = new HtmlParser().Parse("<table id=\"tabletest\" class=\"test\" bgcolor=\"\"></table>");
            var nodewithoutselector = (IElement)tableDomObject.Body.FirstChild;

            var clazz = new StyleClass();
            clazz.Attributes["background-color"] = CssAttribute.FromRule("background-color: red");

            var result = CssElementStyleResolver.GetAllStyles(nodewithoutselector, clazz);

            Assert.AreEqual(2, result.Count());
            Assert.AreEqual("style", result.ElementAt(0).AttributeName);
            Assert.AreEqual("bgcolor", result.ElementAt(1).AttributeName);
        }
        public void GetAllStylesForElement()
        {
            var tableDomObject = CQ.CreateFragment("<td id=\"tabletest\" class=\"test\" bgcolor=\"\"></td>");
            var nodewithoutselector = tableDomObject.FirstElement();

            var clazz = new StyleClass();
            clazz.Attributes["background-color"] = CssAttribute.FromRule("background-color: red");

            var result = CssElementStyleResolver.GetAllStyles(nodewithoutselector, clazz);

            Assert.AreEqual(2, result.Count());
            Assert.AreEqual("style", result.ElementAt(0).AttributeName);
            Assert.AreEqual("bgcolor", result.ElementAt(1).AttributeName);
        }
        public void Merge_ShouldNotOverrideExistingImportantEntriesIfNewEntryIsNotImportant()
        {
            var target = new StyleClass();
            var donator = new StyleClass();

            target.Attributes["color"] = CssAttribute.FromRule("color: red");
            target.Attributes["height"] = CssAttribute.FromRule("height: 50% !important");
            donator.Attributes["height"] = CssAttribute.FromRule("height: 100%");

            target.Merge(donator, true);

            Assert.IsTrue(target.Attributes.ContainsKey("height"));
            Assert.AreEqual("50%", target.Attributes["height"].Value);
        }
        private static StyleClass Map(string s)
        {
            var parts = s.Split('{');
            var styleName = CleanUp(parts[0]).Trim().ToLower();

            var sc = new StyleClass { Name = styleName };

            var atrs = CleanUp(parts[1]).Replace("}", "").Split(';');
            foreach (var a in atrs)
            {
                if (!a.Contains(":")) continue;

                var key = a.Split(':')[0].Trim().ToLower();
                if (sc.Attributes.ContainsKey(key))
                {
                    sc.Attributes.Remove(key);
                }
                sc.Attributes.Add(key, a.Split(':')[1].Trim().ToLower());
            }

            return sc;
        }
        public void ApplyStylesToAllElements()
        {
            var elementDictionary = new Dictionary <IDomObject, StyleClass>();

            var tableDomObject1 = CQ.CreateFragment("<td id=\"tabletest1\" class=\"test1\" bgcolor=\"\"></td>");
            var tableDomObject2 = CQ.CreateFragment("<td id=\"tabletest2\" class=\"test2\" bgcolor=\"\" width=\"\"></td>");
            var tableDomObject3 = CQ.CreateFragment("<td id=\"tabletest3\" class=\"test3\" bgcolor=\"\" height=\"\"></td>");
            var tableDomObject4 = CQ.CreateFragment("<td id=\"tabletest4\" class=\"test4\" bgcolor=\"\" width=\"\"></td>");

            var styleClassBgColor = new StyleClass();

            styleClassBgColor.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008001");

            var styleClassWidth = new StyleClass();

            styleClassWidth.Attributes["width"] = CssAttribute.FromRule("width: 10px");

            var styleClassHeight = new StyleClass();

            styleClassHeight.Attributes["height"] = CssAttribute.FromRule("height: 10px");

            var styleClassBgAndWidth = new StyleClass();

            styleClassBgAndWidth.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008003");
            styleClassBgAndWidth.Attributes["width"]            = CssAttribute.FromRule("width: 10px");

            elementDictionary.Add(tableDomObject1.FirstElement(), styleClassBgColor);
            elementDictionary.Add(tableDomObject2.FirstElement(), styleClassWidth);
            elementDictionary.Add(tableDomObject3.FirstElement(), styleClassHeight);
            elementDictionary.Add(tableDomObject4.FirstElement(), styleClassBgAndWidth);

            var result = StyleClassApplier.ApplyAllStyles(elementDictionary);

            Assert.AreEqual("<td class=\"test1\" style=\"background-color: #008001\" id=\"tabletest1\" bgcolor=\"#008001\"></td>", result.ElementAt(0).Key.ToString());
            Assert.AreEqual("<td class=\"test2\" style=\"width: 10px\" id=\"tabletest2\" bgcolor width=\"10px\"></td>", result.ElementAt(1).Key.ToString());
            Assert.AreEqual("<td class=\"test3\" style=\"height: 10px\" id=\"tabletest3\" bgcolor height=\"10px\"></td>", result.ElementAt(2).Key.ToString());
            Assert.AreEqual("<td class=\"test4\" style=\"background-color: #008003;width: 10px\" id=\"tabletest4\" bgcolor=\"#008003\" width=\"10px\"></td>", result.ElementAt(3).Key.ToString());
        }
Exemple #14
0
        public void ApplyStylesToAllElements()
        {
            var elementDictionary = new Dictionary <IElement, StyleClass>();

            var tableDomObject1 = new HtmlParser().ParseDocument("<table id=\"tabletest1\" class=\"test1\" bgcolor=\"\"></table>");
            var tableDomObject2 = new HtmlParser().ParseDocument("<table id=\"tabletest2\" class=\"test2\" bgcolor=\"\" width=\"\"></table>");
            var tableDomObject3 = new HtmlParser().ParseDocument("<table id=\"tabletest3\" class=\"test3\" bgcolor=\"\" height=\"\"></table>");
            var tableDomObject4 = new HtmlParser().ParseDocument("<table id=\"tabletest4\" class=\"test4\" bgcolor=\"\" width=\"\"></table>");

            var styleClassBgColor = new StyleClass();

            styleClassBgColor.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008001");

            var styleClassWidth = new StyleClass();

            styleClassWidth.Attributes["width"] = CssAttribute.FromRule("width: 10px");

            var styleClassHeight = new StyleClass();

            styleClassHeight.Attributes["height"] = CssAttribute.FromRule("height: 10px");

            var styleClassBgAndWidth = new StyleClass();

            styleClassBgAndWidth.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008003");
            styleClassBgAndWidth.Attributes["width"]            = CssAttribute.FromRule("width: 10px");

            elementDictionary.Add(tableDomObject1.Body.FirstElementChild, styleClassBgColor);
            elementDictionary.Add(tableDomObject2.Body.FirstElementChild, styleClassWidth);
            elementDictionary.Add(tableDomObject3.Body.FirstElementChild, styleClassHeight);
            elementDictionary.Add(tableDomObject4.Body.FirstElementChild, styleClassBgAndWidth);

            var result = StyleClassApplier.ApplyAllStyles(elementDictionary);

            Assert.Equal("<table id=\"tabletest1\" class=\"test1\" bgcolor=\"#008001\" style=\"background-color: #008001\"></table>", result.ElementAt(0).Key.OuterHtml);
            Assert.Equal("<table id=\"tabletest2\" class=\"test2\" bgcolor=\"\" width=\"10px\" style=\"width: 10px\"></table>", result.ElementAt(1).Key.OuterHtml);
            Assert.Equal("<table id=\"tabletest3\" class=\"test3\" bgcolor=\"\" height=\"10px\" style=\"height: 10px\"></table>", result.ElementAt(2).Key.OuterHtml);
            Assert.Equal("<table id=\"tabletest4\" class=\"test4\" bgcolor=\"#008003\" width=\"10px\" style=\"background-color: #008003;width: 10px\"></table>", result.ElementAt(3).Key.OuterHtml);
        }
        public void TestAddStyleClassWorksOnMissingStyleClass()
        {
            Mock <IStyleClassRepository> mockStyleClassRepository = new Mock <IStyleClassRepository>();
            IStyleClassManagementService styleClassLogic          = new StyleClassManagementService
            {
                StyleClassRepository = mockStyleClassRepository.Object
            };

            StyleClass fakeStyleClass = new StyleClass
            {
                Name = "Al Bacalao"
            };

            mockStyleClassRepository
            .Setup(wl => wl.Exists(fakeStyleClass.Name))
            .Returns(false);

            StyleClass result = styleClassLogic.Add(fakeStyleClass);

            mockStyleClassRepository.VerifyAll();
            Assert.IsNotNull(result);
            Assert.AreEqual(fakeStyleClass, result);
        }
Exemple #16
0
        public IHttpActionResult Add([FromBody] AddStyleClass styleClass)
        {
            if (IsTokenValid() && authenticationService.IsAllowedToAddStyleClasses(GetTokenUserEmail()))
            {
                try
                {
                    StyleClass     newStyleClass      = styleClassManagementService.Add(AddStyleClass.ToEntity(styleClass));
                    BaseStyleClass modelNewStyleClass = BaseStyleClass.ToModel(newStyleClass);

                    return(CreatedAtRoute("AddStyleClass", new { styleclassname = modelNewStyleClass.Name }, modelNewStyleClass));
                }
                catch (MissingStyleClassException e)
                {
                    return(BadRequest(e.Message));
                }
                catch (Exceptions e)
                {
                    return(BadRequest(e.Message));
                }
            }

            return(Unauthorized());
        }
Exemple #17
0
 public StyleClass Add(StyleClass styleClass)
 {
     if (styleClass == null)
     {
         throw new InvalidStyleClassException("The style class is null.");
     }
     if (!StyleClassRepository.Exists(styleClass.Name))
     {
         if (NoRedundantDependency(styleClass))
         {
             StyleClassRepository.Add(styleClass);
             return(styleClass);
         }
         else
         {
             throw new RedundantStyleClassException("This style class has redundant dependencies");
         }
     }
     else
     {
         throw new ExistingStyleClassException("This style class already exists on the database.");
     }
 }
        public void IntegrationTest()
        {
            Guid token          = Guid.NewGuid();
            var  requestMessage = new HttpRequestMessage();

            requestMessage.Headers.Add("Token", token + "");
            mockUserAuthorizationLogic.Setup(b1 => b1.IsAValidToken(token)).Returns(true);
            mockUserAuthorizationLogic.Setup(b1 => b1.IsAdmin(token)).Returns(true);

            IStyleDataAccess         styleDA              = new StyleDataAccess();
            IStyleBusinessLogic      styleBL              = new StyleBusinessLogic(styleDA);
            IStyleClassDataAccess    styleClassDA         = new StyleClassDataAccess();
            IStyleClassBusinessLogic styleClassBL         = new StyleClassBusinessLogic(styleClassDA, styleBL);
            StyleClassController     styleClassController = new StyleClassController(styleClassBL, mockUserAuthorizationLogic.Object);

            styleClassController.Request = requestMessage;

            StyleClass      styleClassA = Utils.CreateStyleClassForTest();
            StyleClassModel styleClassM = StyleClassModel.ToModel(styleClassA);

            styleClassM.InheritedPlusProperStyles = new List <StyleModel>();
            styleClassController.Post(styleClassM);
        }
        public void TestAddStyleClassFailsOnRedundantDependency()
        {
            Mock <IStyleClassRepository> mockStyleClassRepository = new Mock <IStyleClassRepository>();
            IStyleClassManagementService styleClassLogic          = new StyleClassManagementService
            {
                StyleClassRepository = mockStyleClassRepository.Object
            };

            StyleClass fakeStyleClass = new StyleClass
            {
                Name = "Al Bacalao"
            };

            fakeStyleClass.BasedOn = fakeStyleClass;

            mockStyleClassRepository
            .Setup(wl => wl.Exists(fakeStyleClass.Name))
            .Returns(false);

            StyleClass result = styleClassLogic.Add(fakeStyleClass);

            mockStyleClassRepository.VerifyAll();
        }
Exemple #20
0
        private void addStyleToImportedFormat(XmlNode styleClassInformation, ImportedFormatModel importedFormat)
        {
            List <StyleClass> styleClassesForCurrentFormat = importedFormat.ImportedStyleClasses.ToList();
            List <Style>      stylesForClassesAndFormat    = importedFormat.ImportedStyles.ToList();

            StyleClass styleClassToAdd = new StyleClass
            {
                Name    = styleClassInformation.Name,
                BasedOn = null
            };

            XmlNode stylesInClass;

            try {
                stylesInClass = styleClassInformation.SelectSingleNode("descendant::Estilos");
            } catch (XPathException e)
            {
                throw new InvalidDataException("The format for this style class is invalid.");
            }

            if (stylesInClass.InnerText != null || stylesInClass.InnerText != "...")
            {
                XmlNodeList         selectedClassStyles = stylesInClass.ChildNodes;
                IEnumerable <Style> newStyles;
                newStyles = XMLStyleBuilder.buildStylesFromXml(selectedClassStyles);
                foreach (Style newStyle in newStyles)
                {
                    newStyle.StyleClass = styleClassToAdd;
                    newStyle.Format     = importedFormat.ImportedFormat;
                    stylesForClassesAndFormat.Add(newStyle);
                }
            }

            styleClassesForCurrentFormat.Add(styleClassToAdd);
            importedFormat.ImportedStyleClasses = styleClassesForCurrentFormat.AsEnumerable();
            importedFormat.ImportedStyles       = stylesForClassesAndFormat.AsEnumerable();
        }
Exemple #21
0
 public static string InsUpdDelStyle(char Event, StyleClass obj, out int returnId)
 {
     returnId = 0;
     try
     {
         var cmd = new SqlCommand();
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.CommandText = "USP_IUD_tbl_Style";
         cmd.Connection  = DL_CCommon.ConnectionForCommonDb();
         cmd.Parameters.AddWithValue("@EVENT", Event);
         cmd.Parameters.AddWithValue("@ID", obj.Id);
         cmd.Parameters.AddWithValue("@Style", obj.Style);
         cmd.Parameters.AddWithValue("@Description", obj.Description);
         var outparameter = new SqlParameter("@MSG", SqlDbType.NVarChar, 200)
         {
             Direction = ParameterDirection.Output
         };
         cmd.Parameters.Add(outparameter);
         var outId = new SqlParameter("@RETURNOUTID", SqlDbType.NVarChar, 100)
         {
             Direction = ParameterDirection.Output
         };
         cmd.Parameters.Add(outId);
         cmd.ExecuteNonQuery();
         var msg = cmd.Parameters[outparameter.ParameterName].Value;
         returnId = Convert.ToInt32(cmd.Parameters[outId.ParameterName].Value);
         return(Convert.ToString(msg));
     }
     catch (Exception ex)
     {
         throw new ArgumentException(ex.Message);
     }
     finally
     {
         DL_CCommon.ConnectionForCommonDb().Close();
     }
 }
 private void btnDeleteClass_Click(object sender, EventArgs e)
 {
     if (lbxStyleClasses.SelectedItem != null)
     {
         try
         {
             StyleClass selectedStyleClass = (StyleClass)lbxStyleClasses.SelectedItem;
             styleClassManager.Delete(selectedStyleClass.Name);
             LoadFormatsAndStyleClasses();
         }
         catch (MissingStyleClassException exception)
         {
             MessageBox.Show(exception.Message);
         }
         catch (InvalidStyleClassException exception)
         {
             MessageBox.Show(exception.Message);
         }
     }
     else
     {
         MessageBox.Show("Please select a style class first.");
     }
 }
        public void integration()
        {
            var                         requestMessage = new HttpRequestMessage();
            IUserDataAccess             da             = new UserDataAccess();
            IUserBusinessLogic          userBL         = new UserBusinessLogic(new UserDataAccess());
            IAuthorizationBusinessLogic auth           = new AuthorizationBusinessLogic(da);
            IStyleDataAccess            styleDA        = new StyleDataAccess();
            IStyleBusinessLogic         styleBL        = new StyleBusinessLogic(styleDA);
            IStyleClassDataAccess       styleClassDA   = new StyleClassDataAccess();
            IStyleClassBusinessLogic    styleClassBL   = new StyleClassBusinessLogic(styleClassDA, styleBL);
            IFormatDataAccess           formatDA       = new FormatDataAccess();
            IFormatBusinessLogic        formatBL       = new FormatBusinessLogic(formatDA, styleClassBL);
            FormatController            formatC        = new FormatController(formatBL, auth);

            formatC.Request = requestMessage;
            StyleClass  styleClassA  = Utils.CreateStyleClassInDataBaseForTest();
            Format      formatA      = Utils.CreateFormatForTest();
            FormatModel formatModelA = FormatModel.ToModel(formatA);

            formatC.Post(formatModelA);
            formatC.AddStyleClassToFormat(formatA.Id, StyleClassModel.ToModel(styleClassA));
            IHttpActionResult statusObtained = formatC.Get(formatA.Id);
            int a = 2;
        }
 private void btnSubmitStyleClass_Click(object sender, EventArgs e)
 {
     if (tbxStyleClassName.Text != "")
     {
         try
         {
             StyleClass newClass = new StyleClass()
             {
                 Name = tbxStyleClassName.Text
             };
             if (((string)cbxStyleClassBasedOn.SelectedItem) != "---None---")
             {
                 StyleClass parentClass = styleClassManager.GetByName((string)cbxStyleClassBasedOn.SelectedItem);
                 newClass.BasedOn = parentClass;
             }
             styleClassManager.Add(newClass);
             MessageBox.Show("The new Style Class was successfully added.");
             this.Close();
         } catch (ExistingStyleClassException exception)
         {
             MessageBox.Show(exception.Message);
         }
     }
 }
        private void SetDefaultButtonStyle()
        {
            var brushT = new LinearGradientBrush();

            ButtonStyle = new StyleClass();
            ButtonStyle.BackNormalBrush = BaseStyle.PanelUpperBrush;

            brushT            = new LinearGradientBrush();
            brushT.StartPoint = new System.Windows.Point(0, 0);
            brushT.EndPoint   = new System.Windows.Point(0, 1);
            brushT.GradientStops.Add(new GradientStop(Color.FromArgb(0, 0, 0, 0), 0));
            brushT.GradientStops.Add(new GradientStop(Color.FromArgb(200, 0, 0, 0), 0.75));
            brushT.GradientStops.Add(new GradientStop(Color.FromArgb(0, 0, 0, 0), 1));


            ButtonStyle.BorderBrush = brushT;

            brushT            = new LinearGradientBrush();
            brushT.StartPoint = new System.Windows.Point(0, 0);
            brushT.EndPoint   = new System.Windows.Point(0, 1);
            brushT.GradientStops.Add(new GradientStop(Color.FromArgb(0, 0, 0, 0), 0));
            brushT.GradientStops.Add(new GradientStop(Color.FromArgb(200, 0, 0, 0), 0.75));
            brushT.GradientStops.Add(new GradientStop(Color.FromArgb(0, 0, 0, 0), 1));

            ButtonStyle.BorderMouseoverBrush = brushT;
            brushT            = new LinearGradientBrush();
            brushT.StartPoint = new System.Windows.Point(0, 0);
            brushT.EndPoint   = new System.Windows.Point(0, 1);
            brushT.GradientStops.Add(new GradientStop(Color.FromArgb(0, 0, 0, 0), 0));
            brushT.GradientStops.Add(new GradientStop(Color.FromArgb(100, 0, 0, 0), 0.85));
            brushT.GradientStops.Add(new GradientStop(Color.FromArgb(0, 0, 0, 0), 1));

            ButtonStyle.BorderPressedBrush = brushT;

            brushT            = new LinearGradientBrush();
            brushT.StartPoint = new System.Windows.Point(0, 0);
            brushT.EndPoint   = new System.Windows.Point(0, 1);
            brushT.GradientStops.Add(new GradientStop(Color.FromArgb(0, 0, 0, 0), 0));
            brushT.GradientStops.Add(new GradientStop(Color.FromArgb(200, 0, 0, 0), 0.85));
            brushT.GradientStops.Add(new GradientStop(Color.FromArgb(0, 0, 0, 0), 1));

            ButtonStyle.BorderDisabledBrush = brushT;


            brushT            = new LinearGradientBrush();
            brushT.StartPoint = new System.Windows.Point(0, 0);
            brushT.EndPoint   = new System.Windows.Point(0, 1);
            brushT.GradientStops.Add(new GradientStop(Color.FromRgb(65, 65, 65), 0));
            brushT.GradientStops.Add(new GradientStop(Color.FromRgb(150, 150, 150), 0.75));
            brushT.GradientStops.Add(new GradientStop(Color.FromRgb(65, 65, 65), 1));

            ButtonStyle.BackMouseoverBrush = brushT;

            brushT            = new LinearGradientBrush();
            brushT.StartPoint = new System.Windows.Point(0, 0);
            brushT.EndPoint   = new System.Windows.Point(0, 1);
            brushT.GradientStops.Add(new GradientStop(Color.FromRgb(33, 33, 33), 0));
            brushT.GradientStops.Add(new GradientStop(Color.FromRgb(75, 75, 75), 0.85));
            brushT.GradientStops.Add(new GradientStop(Color.FromRgb(33, 33, 33), 1));

            ButtonStyle.BackPressedBrush = brushT;

            ButtonStyle.BaseBorderThickness.Bottom = 0;
            ButtonStyle.BaseBorderThickness.Top    = 0;

            ButtonStyle.PressedTranslation = new System.Windows.Point(0, 2);


            brushT            = new LinearGradientBrush();
            brushT.StartPoint = new System.Windows.Point(0, 0);
            brushT.EndPoint   = new System.Windows.Point(0, 1);
            brushT.GradientStops.Add(new GradientStop(Color.FromRgb(30, 30, 30), 0));
            brushT.GradientStops.Add(new GradientStop(Color.FromRgb(70, 70, 70), 0.85));
            brushT.GradientStops.Add(new GradientStop(Color.FromRgb(30, 30, 30), 1));

            ButtonStyle.BackDisabledBrush = brushT;
        }
 /// <summary>
 /// Exposes properties representing an object and its color.  This is a convenience wrapper around
 /// the StyleClass type, so you don't have to provide the type argument each time.
 /// </summary>
 /// <param name="target">The object to be styled.</param>
 /// <param name="color">The color to be applied to the target.</param>
 public Formatter(object target, Color color)
 {
     backingClass = new StyleClass<object>(target, color);
 }
        protected override UpdateFooter SetModel(Footer footer)
        {
            StyleClass = footer.StyleClass;

            return(this);
        }
        public void TestParagraphsDontExistsAfterDeleteDocumentFromDatabase()
        {
            User userP1 = new User
            {
                UserName      = "******",
                Password      = "******",
                Name          = "nameP1",
                LastName      = "lastnameP1",
                Email         = "emailP1",
                Administrator = true
            };

            UserRepository.Add(userP1);

            StyleClass StyleClassP1 = new StyleClass
            {
                Name    = "StyleClassP1",
                BasedOn = null
            };

            StyleClassRepository.Add(StyleClassP1);

            StyleClass StyleClassP2 = new StyleClass
            {
                Name    = "StyleClassP2",
                BasedOn = null
            };

            StyleClassRepository.Add(StyleClassP2);

            Document document = new Document
            {
                Id               = Guid.NewGuid(),
                Title            = "title1",
                Creator          = userP1,
                CreationDate     = DateTime.Now,
                LastModification = DateTime.Now,
                StyleClass       = StyleClassP1
            };

            DocumentRepository.Add(document);

            Content content = new Content
            {
                Id = Guid.NewGuid(),
            };

            ContentRepository.Add(content);

            Paragraph paragraph1 = new Paragraph
            {
                Id                  = Guid.NewGuid(),
                Content             = content,
                DocumentThatBelongs = document,
                StyleClass          = StyleClassP1,
                Position            = 0
            };

            ParagraphRepository.Add(paragraph1);

            Paragraph paragraph2 = new Paragraph
            {
                Id                  = Guid.NewGuid(),
                Content             = content,
                DocumentThatBelongs = document,
                StyleClass          = StyleClassP2,
                Position            = 1
            };

            ParagraphRepository.Add(paragraph2);

            bool existsBeforeDeleteDocument1 = ParagraphRepository.Exists(paragraph1.Id);
            bool existsBeforeDeleteDocument2 = ParagraphRepository.Exists(paragraph2.Id);

            DocumentRepository.Delete(document.Id);

            bool existsAfterDeleteDocument1  = ParagraphRepository.Exists(paragraph1.Id);
            bool existsAftereDeleteDocument2 = ParagraphRepository.Exists(paragraph2.Id);

            StyleClassRepository.Delete(StyleClassP1.Name);
            StyleClassRepository.Delete(StyleClassP2.Name);
            UserRepository.Delete(userP1.Email);
            ContentRepository.Delete(content);

            Assert.IsTrue(existsBeforeDeleteDocument1);
            Assert.IsTrue(existsBeforeDeleteDocument2);
            Assert.IsFalse(existsAfterDeleteDocument1);
            Assert.IsFalse(existsAftereDeleteDocument2);
        }
        public void TestParagraphIsUpdatedCorrectlyFromDatabase()
        {
            User userP1 = new User
            {
                UserName      = "******",
                Password      = "******",
                Name          = "nameP1",
                LastName      = "lastnameP1",
                Email         = "emailP1",
                Administrator = true
            };

            UserRepository.Add(userP1);

            StyleClass StyleClassP1 = new StyleClass
            {
                Name    = "StyleClassP1",
                BasedOn = null
            };

            StyleClassRepository.Add(StyleClassP1);

            StyleClass StyleClassP2 = new StyleClass
            {
                Name    = "StyleClassP2",
                BasedOn = null
            };

            StyleClassRepository.Add(StyleClassP2);

            Document document = new Document
            {
                Id               = Guid.NewGuid(),
                Title            = "title1",
                Creator          = userP1,
                CreationDate     = DateTime.Now,
                LastModification = DateTime.Now,
                StyleClass       = StyleClassP1
            };

            DocumentRepository.Add(document);

            Content content = new Content
            {
                Id = Guid.NewGuid(),
            };

            ContentRepository.Add(content);

            Paragraph paragraph1 = new Paragraph
            {
                Id                  = Guid.NewGuid(),
                Content             = content,
                DocumentThatBelongs = document,
                StyleClass          = StyleClassP1,
                Position            = 0
            };

            ParagraphRepository.Add(paragraph1);

            Paragraph updatedParagraph = new Paragraph
            {
                Id                  = paragraph1.Id,
                Content             = content,
                DocumentThatBelongs = document,
                StyleClass          = StyleClassP2,
                Position            = 1
            };

            ParagraphRepository.Update(updatedParagraph);

            Paragraph fromDatabase = ParagraphRepository.GetById(updatedParagraph.Id);

            StyleClassRepository.Delete(StyleClassP1.Name);
            StyleClassRepository.Delete(StyleClassP2.Name);
            DocumentRepository.Delete(document.Id);
            UserRepository.Delete(userP1.Email);
            ContentRepository.Delete(content);

            Assert.AreEqual(updatedParagraph.Id, fromDatabase.Id);
            Assert.AreEqual(updatedParagraph.Content.Id, fromDatabase.Content.Id);
            Assert.AreEqual(updatedParagraph.StyleClass.Name, fromDatabase.StyleClass.Name);
            Assert.AreEqual(updatedParagraph.DocumentThatBelongs.Id, fromDatabase.DocumentThatBelongs.Id);
            Assert.AreEqual(updatedParagraph.Position, fromDatabase.Position);
        }
 public void TestInitialize()
 {
     styleClassDataAccess = new StyleClassDataAccess();
     styleClass           = Utils.CreateStyleClassForTest();
 }
Exemple #31
0
        public void TestStyleClass()
        {
            StyleClass styleClass = new StyleClass();

            Assert.IsNotNull(styleClass);
        }
Exemple #32
0
 public static string InsUpdDelStyle(char Event, StyleClass obj, out int id)
 {
     id = 0;
     return(DlStyle.InsUpdDelStyle(Event, obj, out id));
 }
        public void Merge_ShouldOverrideExistingEntriesIfSpecifiedIgnoringCasing()
        {
            var target = new StyleClass();
            var donator = new StyleClass();

            target.Attributes["color"] = CssAttribute.FromRule("color: red");
            target.Attributes["HEight"] = CssAttribute.FromRule("height: 50%");
            donator.Attributes["height"] = CssAttribute.FromRule("height: 100%");

            target.Merge(donator, true);

            Assert.IsTrue(target.Attributes.ContainsKey("height"));
            Assert.AreEqual("100%", target.Attributes["height"].Value);
        }
        public void TestFooterIsUpdatedCorrectlyFromDatabase()
        {
            User user = new User
            {
                UserName      = "******",
                Password      = "******",
                Name          = "name",
                LastName      = "lastname",
                Email         = Guid.NewGuid().ToString(),
                Administrator = true
            };

            UserRepository.Add(user);

            StyleClass StyleClassF1 = new StyleClass
            {
                Name    = "StyleClassF1",
                BasedOn = null
            };

            StyleClassRepository.Add(StyleClassF1);

            Document document = new Document
            {
                Id               = Guid.NewGuid(),
                Title            = "title1",
                Creator          = user,
                CreationDate     = DateTime.Now,
                LastModification = DateTime.Now,
                StyleClass       = StyleClassF1
            };

            DocumentRepository.Add(document);

            Content content = new Content
            {
                Id = Guid.NewGuid(),
            };

            ContentRepository.Add(content);

            Footer footer = new Footer
            {
                Id                  = Guid.NewGuid(),
                Content             = content,
                DocumentThatBelongs = document,
                StyleClass          = StyleClassF1
            };

            FooterRepository.Add(footer);

            Footer updatedFooter = new Footer
            {
                Id                  = footer.Id,
                Content             = content,
                DocumentThatBelongs = document,
                StyleClass          = null
            };

            FooterRepository.Update(updatedFooter);

            Footer fromDatabase = FooterRepository.GetById(updatedFooter.Id);

            StyleClassRepository.Delete(StyleClassF1.Name);
            DocumentRepository.Delete(document.Id);
            UserRepository.Delete(user.Email);
            ContentRepository.Delete(content);

            Assert.AreEqual(updatedFooter.Id, fromDatabase.Id);
            Assert.AreEqual(updatedFooter.Content.Id, fromDatabase.Content.Id);
            Assert.IsNull(updatedFooter.StyleClass);
            Assert.AreEqual(updatedFooter.DocumentThatBelongs.Id, fromDatabase.DocumentThatBelongs.Id);
        }
 internal FontSubfamily(StyleClass style, WeightClass weight, WidthClass width)
 {
     Style  = style;
     Weight = weight;
     Width  = width;
 }
        protected override AddHeader SetModel(Header header)
        {
            StyleClass = header.StyleClass;

            return(this);
        }
Exemple #37
0
        public void TestHeaderIsUpdatedCorrectlyFromDatabase()
        {
            User userH1 = new User
            {
                UserName      = "******",
                Password      = "******",
                Name          = "nameH1",
                LastName      = "lastnameH1",
                Email         = "emailH1",
                Administrator = true
            };

            UserRepository.Add(userH1);

            StyleClass StyleClassH1 = new StyleClass
            {
                Name    = "StyleClassH1",
                BasedOn = null
            };

            StyleClassRepository.Add(StyleClassH1);

            StyleClass StyleClassH2 = new StyleClass
            {
                Name    = "StyleClassH2",
                BasedOn = null
            };

            StyleClassRepository.Add(StyleClassH2);

            Document document = new Document
            {
                Id               = Guid.NewGuid(),
                Title            = "title1",
                Creator          = userH1,
                CreationDate     = DateTime.Now,
                LastModification = DateTime.Now,
                StyleClass       = StyleClassH1
            };

            DocumentRepository.Add(document);

            Content content = new Content
            {
                Id = Guid.NewGuid(),
            };

            ContentRepository.Add(content);

            Header header = new Header
            {
                Id                  = Guid.NewGuid(),
                Content             = content,
                DocumentThatBelongs = document,
                StyleClass          = StyleClassH1
            };

            HeaderRepository.Add(header);

            Header updatedHeader = new Header
            {
                Id                  = header.Id,
                Content             = content,
                DocumentThatBelongs = document,
                StyleClass          = StyleClassH2
            };

            HeaderRepository.Update(updatedHeader);

            Header fromDatabase = HeaderRepository.GetById(updatedHeader.Id);

            StyleClassRepository.Delete(StyleClassH1.Name);
            StyleClassRepository.Delete(StyleClassH2.Name);
            DocumentRepository.Delete(document.Id);
            UserRepository.Delete(userH1.Email);
            ContentRepository.Delete(content);

            Assert.AreEqual(updatedHeader.Id, fromDatabase.Id);
            Assert.AreEqual(updatedHeader.Content.Id, fromDatabase.Content.Id);
            Assert.AreEqual(updatedHeader.StyleClass.Name, fromDatabase.StyleClass.Name);
            Assert.AreEqual(updatedHeader.DocumentThatBelongs.Id, fromDatabase.DocumentThatBelongs.Id);
        }
        private StyleClass GetStyleClassForDocumentPart(string ownStyleClassName, Format format, StyleClass styleClassInherited)
        {
            StyleClass styleClassForDocumentPart = styleClassInherited;
            StyleClass ownStyleClass             = format.GetStyleClass(ownStyleClassName);

            if (ownStyleClass != null)
            {
                ownStyleClass.SetInheritedStyleClass(styleClassInherited);
                styleClassForDocumentPart = ownStyleClass;
            }
            return(styleClassForDocumentPart);
        }
Exemple #39
0
        protected override AddParagraph SetModel(Paragraph paragraph)
        {
            StyleClass = paragraph.StyleClass;

            return(this);
        }
Exemple #40
0
 private bool StyleClassIsNull(StyleClass styleClass)
 {
     return(styleClass == null || styleClass.Name == null || styleClass.InheritedPlusProperStyles == null ||
            styleClass.Observers == null || styleClass.ProperStyles == null);
 }
        public void Delete(string styleClassName)
        {
            using (DatabaseContext c = new DatabaseContext())
            {
                List <Document> documentsToNullifyStyleclass = c.Documents
                                                               .Where(q => q.StyleClass.Name == styleClassName)
                                                               .Include(s => s.StyleClass)
                                                               .ToList();

                foreach (Document document in documentsToNullifyStyleclass)
                {
                    if (document.StyleClass != null)
                    {
                        document.StyleClass     = null;
                        c.Entry(document).State = EntityState.Modified;
                    }
                }

                List <Header> headersToNullifyStyleclass = c.Headers
                                                           .Where(q => q.StyleClass.Name == styleClassName)
                                                           .Include(s => s.StyleClass)
                                                           .ToList();

                foreach (Header header in headersToNullifyStyleclass)
                {
                    if (header.StyleClass != null)
                    {
                        header.StyleClass     = null;
                        c.Entry(header).State = EntityState.Modified;
                    }
                }

                List <Footer> footersToNullifyStyleclass = c.Footers
                                                           .Where(q => q.StyleClass.Name == styleClassName)
                                                           .Include(s => s.StyleClass)
                                                           .ToList();

                foreach (Footer footer in footersToNullifyStyleclass)
                {
                    if (footer.StyleClass != null)
                    {
                        footer.StyleClass     = null;
                        c.Entry(footer).State = EntityState.Modified;
                    }
                }

                List <Paragraph> paragraphsToNullifyStyleclass = c.Paragraphs
                                                                 .Where(q => q.StyleClass.Name == styleClassName)
                                                                 .Include(s => s.StyleClass)
                                                                 .ToList();

                foreach (Paragraph paragraph in paragraphsToNullifyStyleclass)
                {
                    if (paragraph.StyleClass != null)
                    {
                        paragraph.StyleClass     = null;
                        c.Entry(paragraph).State = EntityState.Modified;
                    }
                }

                List <Text> textsToNullifyStyleClass = c.Texts
                                                       .Where(q => q.StyleClass.Name == styleClassName)
                                                       .Include(s => s.StyleClass)
                                                       .ToList();

                foreach (Text text in textsToNullifyStyleClass)
                {
                    if (text.StyleClass != null)
                    {
                        text.StyleClass     = null;
                        c.Entry(text).State = EntityState.Modified;
                    }
                }

                StyleClass toDelete = c.StyleClasses
                                      .Where(s => s.Name == styleClassName)
                                      .Include(b => b.BasedOn)
                                      .FirstOrDefault();

                if (toDelete.BasedOn != null)
                {
                    toDelete.BasedOn.BasedOn = null;

                    c.Entry(toDelete.BasedOn).State = EntityState.Unchanged;
                }

                c.StyleClasses.Remove(toDelete);

                c.SaveChanges();
            }
        }
        public void TestDocumentIsUpdatedCorrectlyFromDatabase()
        {
            User user = new User
            {
                UserName      = "******",
                Password      = "******",
                Name          = "name",
                LastName      = "lastname",
                Email         = "email",
                Administrator = true
            };

            UserRepository.Add(user);

            StyleClass StyleClass1 = new StyleClass
            {
                Name    = "StyleClass1",
                BasedOn = null
            };

            StyleClassRepository.Add(StyleClass1);

            StyleClass StyleClass2 = new StyleClass
            {
                Name    = "StyleClass2",
                BasedOn = null
            };

            StyleClassRepository.Add(StyleClass2);

            Guid documentId = Guid.NewGuid();

            Document document = new Document
            {
                Id               = documentId,
                Title            = "title1",
                Creator          = user,
                CreationDate     = DateTime.Now,
                LastModification = DateTime.Now,
                StyleClass       = StyleClass1
            };

            DocumentRepository.Add(document);

            Document updatedDocument = new Document
            {
                Id               = documentId,
                Title            = "UpdatedTitle",
                Creator          = user,
                CreationDate     = document.CreationDate,
                LastModification = DateTime.Now,
                StyleClass       = StyleClass2
            };

            DocumentRepository.Update(documentId, updatedDocument);

            Document fromDatabase = DocumentRepository.GetById(documentId);

            StyleClassRepository.Delete(StyleClass1.Name);
            StyleClassRepository.Delete(StyleClass2.Name);
            DocumentRepository.Delete(documentId);
            UserRepository.Delete(user.Email);

            Assert.AreEqual(updatedDocument.Id, fromDatabase.Id);
            Assert.AreEqual(updatedDocument.Title, fromDatabase.Title);
            Assert.AreEqual(updatedDocument.Creator.Email, fromDatabase.Creator.Email);
            Assert.AreEqual(updatedDocument.StyleClass.Name, fromDatabase.StyleClass.Name);
        }