Exemplo n.º 1
0
        public void DeletePersonalization_Invoke_ExecutesDelete()
        {
            // Arrange
            var listId = Guid.NewGuid();
            var webId  = Guid.NewGuid();
            var siteId = Guid.NewGuid();

            // Act
            MyPersonalization.DeletePersonalization(DummyString, One, listId, webId, siteId, ExampleUrl);

            // Assert
            this.ShouldSatisfyAllConditions(
                () => _connectedToDb.ShouldBeTrue(),
                () => _unconnectedFromDb.ShouldBeTrue(),
                () => _sqlCommands.ShouldContain("DELETE FROM PERSONALIZATIONS WHERE [Key] = @key AND UserId = @userId AND ListId = @listId AND WebId = @webId AND SiteId = @siteId"),
                () => _parameters.ShouldContainKey("@key"),
                () => _parameters.ShouldContainKey("@listId"),
                () => _parameters.ShouldContainKey("@webId"),
                () => _parameters.ShouldContainKey("@siteId"),
                () => _parameters["@key"].ShouldBe(DummyString),
                () => _parameters["@listId"].ShouldBe(listId),
                () => _parameters["@webId"].ShouldBe(webId),
                () => _parameters["@siteId"].ShouldBe(siteId),
                () => _didExecuteNonQuery.ShouldBeTrue());
        }
Exemplo n.º 2
0
        public void SetPersonalizations_ContainsKeyValuePair_ExecutesUpdate()
        {
            // Arrange
            var keyValuePair = new Dictionary <string, string>
            {
                { DummyString, One }
            };

            // Act
            MyPersonalization.SetPersonalizations(keyValuePair, DummyString, Id, _listId, _webId, _siteId, ExampleUrl);

            // Assert
            this.ShouldSatisfyAllConditions(
                () => _connectedToDb.ShouldBeTrue(),
                () => _unconnectedFromDb.ShouldBeTrue(),
                () => _sqlCommands.Any(c => c.Contains("UPDATE PERSONALIZATIONS SET Value = @value WHERE [Key] = @key AND UserId = @username")).ShouldBeTrue(),
                () => _parameters.ShouldContainKey("@key"),
                () => _parameters.ShouldContainKey("@value"),
                () => _parameters.ShouldContainKey("@username"),
                () => _parameters.ShouldContainKey("@itemId"),
                () => _parameters.ShouldContainKey("@listId"),
                () => _parameters.ShouldContainKey("@webId"),
                () => _parameters.ShouldContainKey("@siteId"),
                () => _parameters["@key"].ShouldBe(DummyString),
                () => _parameters["@value"].ShouldBe(One),
                () => _parameters["@username"].ShouldBe(DummyString),
                () => _parameters["@itemId"].ShouldBe(Id),
                () => _parameters["@listId"].ShouldBe(_listId),
                () => _parameters["@webId"].ShouldBe(_webId),
                () => _parameters["@siteId"].ShouldBe(_siteId),
                () => _didExecuteNonQuery.ShouldBeTrue());
        }
Exemplo n.º 3
0
        public void GetPersonalizationValue_Invoke_ExecutesSelectAndReturnsResult()
        {
            // Arrange
            var keyValuePair = new Dictionary <string, string>
            {
                { DummyString, One }
            };

            // Act
            var result = MyPersonalization.GetPersonalizationValue(DummyString, new ShimSPWeb(), new ShimSPList());

            // Assert
            this.ShouldSatisfyAllConditions(
                () => _connectedToDb.ShouldBeTrue(),
                () => _unconnectedFromDb.ShouldBeTrue(),
                () => _sqlCommands.ShouldContain("SELECT VALUE FROM PERSONALIZATIONS where userid=@userid and [key]=@key and listid=@listid"),
                () => _parameters.ShouldContainKey("@userid"),
                () => _parameters.ShouldContainKey("@key"),
                () => _parameters.ShouldContainKey("@listid"),
                () => _parameters["@userid"].ShouldBe(One),
                () => _parameters["@key"].ShouldBe(DummyString),
                () => _parameters["@listid"].ShouldBe(_listId),
                () => _didExecuteNonQuery.ShouldBeTrue(),
                () => result.ShouldBe(DummyResult));
        }
Exemplo n.º 4
0
        public void SetMyPersonalization_Set_ReturnsXml()
        {
            // Arrange
            ShimUtils.ValidateItemListWebAndSiteXElement = _ => { };

            // Act
            var result = MyPersonalization.SetMyPersonalization(GetMyPersonalizationsXmlData());

            // Assert
            this.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNull(),
                () => result.ShouldBe("<MyPersonalization />"));
        }
Exemplo n.º 5
0
        public void GetMyPersonalization_Get_ReturnsXml()
        {
            // Arrange
            ShimUtils.ValidateItemListWebAndSiteXElement = _ => { };

            // Act
            var result = MyPersonalization.GetMyPersonalization(GetXmlData());

            // Assert
            this.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNull(),
                () => result.ShouldContainWithoutWhitespace("<MyPersonalization>"),
                () => result.ShouldContainWithoutWhitespace($"<Personalizations Username=\"{DummyResult}\" ItemID=\"{One}\" ListID=\"{_listId}\" WebID=\"{_webId}\" SiteID=\"{_siteId}\" SiteURL=\"{ExampleUrl}\""),
                () => result.ShouldContainWithoutWhitespace($"<Personalization ID=\"{One}\" Key=\"{DummyString}\" Value=\"0\" />"),
                () => result.ShouldContainWithoutWhitespace("</Personalizations>"),
                () => result.ShouldContainWithoutWhitespace("</MyPersonalization>"));
        }
Exemplo n.º 6
0
        public void GetMyPersonalization_ValidateException_Throws()
        {
            // Arrange
            var data = GetXmlData();

            ShimUtils.ValidateItemListWebAndSiteXElement = _ => { throw new InvalidOperationException(DummyString); };

            // Act
            var action = new Action(() => MyPersonalization.GetMyPersonalization(data));

            // Assert
            var exception = action.ShouldThrow <APIException>();

            this.ShouldSatisfyAllConditions(
                () => exception.ExceptionNumber.ShouldBe(5005),
                () => exception.Message.ShouldBe(DummyString));
        }
Exemplo n.º 7
0
        public void SetPersonalizations_DoesNotContainKeyValuePair_ExecutesInsert()
        {
            // Arrange
            var keyValuePair = new Dictionary <string, string>
            {
                { One, One }
            };

            // Act
            MyPersonalization.SetPersonalizations(keyValuePair, DummyString, Id, _listId, _webId, _siteId, ExampleUrl);

            // Assert
            this.ShouldSatisfyAllConditions(
                () => _connectedToDb.ShouldBeTrue(),
                () => _unconnectedFromDb.ShouldBeTrue(),
                () => _sqlCommands.Any(c => c.Contains("INSERT INTO PERSONALIZATIONS ([Key], Value, UserId, ItemID, ListID, WebID, SiteID)")).ShouldBeTrue(),
                () => _didExecuteNonQuery.ShouldBeTrue());
        }
Exemplo n.º 8
0
        // Private Methods (1) 

        /// <summary>
        /// Hides the slide out.
        /// </summary>
        /// <param name="slideOutId"></param>
        private void HideSlideOut(string slideOutId)
        {
            try
            {
                SPSite spSite = SPContext.Current.Site;

                MyPersonalization.SetPersonalizations(
                    new Dictionary <string, string> {
                    { "ContextualSlideOutId", slideOutId }
                },
                    SPContext.Current.Web.CurrentUser.ID.ToString(), 0, Guid.Empty, Guid.Empty,
                    spSite.ID, spSite.Url);

                Data = "Success";
            }
            catch (Exception e)
            {
                Data = e.Message;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public string GetData(string data)
        {
            try
            {
                string           response;
                NumberFormatInfo providerEn = new System.Globalization.NumberFormatInfo();
                providerEn.NumberDecimalSeparator = ".";
                providerEn.NumberGroupSeparator   = ",";
                providerEn.NumberGroupSizes       = new int[] { 3 };

                XElement dataRootElement = XDocument.Parse(data).Root;

                if (dataRootElement == null)
                {
                    throw new APIException((int)Errors.GetDataRootElementNotFound,
                                           "Cannot find the Root AssignmentPlanner element.");
                }

                using (var workEngineAPI = new WorkEngineAPI())
                {
                    response = workEngineAPI.Execute("Reporting_GetMyWorkData",
                                                     new XElement("GetMyWorkReportingData",
                                                                  dataRootElement.Element("Params")).ToString());
                }

                XDocument myWorkDataXml = XDocument.Parse(response);

                ValidateMyWorkDataResponse(myWorkDataXml);

                var gridSafeFields = new Dictionary <string, string>();

                var bElement         = new XElement("B");
                var resourcesElement = new XElement("Resources");
                var footElement      = new XElement("Foot");

                var resources = new Dictionary <int, string>();

                SPRegionalSettings spRegionalSettings = _spWeb.CurrentUser.RegionalSettings ??
                                                        _spWeb.Site.RootWeb.RegionalSettings;

                var workDayStartHour = (short)(spRegionalSettings.WorkDayStartHour / 60);
                var workDayEndHour   = (short)(spRegionalSettings.WorkDayEndHour / 60);

                string siteUrl = _spWeb.Site.Url;
                string safeServerRelativeUrl = _spWeb.SafeServerRelativeUrl();

                foreach (
                    XElement resourceElement in
                    myWorkDataXml.Element("Result").Element("GetMyWorkData").Element("Data").Elements("Resource"))
                {
                    XElement resultElement = resourceElement.Element("Result");

                    if (!resultElement.Attribute("Status").Value.Equals("0"))
                    {
                        continue;
                    }

                    int    resourceId   = 0;
                    string resourceName = string.Empty;

                    foreach (XElement itemElement in resourceElement.Element("Data").Elements("Item"))
                    {
                        var iElement = new XElement("I");

                        int    itemId = 0;
                        Guid   listId = Guid.Empty;
                        Guid   webId  = Guid.Empty;
                        Guid   siteId = Guid.Empty;
                        string value  = string.Empty;
                        float  floatFieldValue;

                        foreach (XElement fieldElement in itemElement.Elements("Field"))
                        {
                            string field = fieldElement.Attribute("Name").Value;

                            if (!gridSafeFields.ContainsKey(field))
                            {
                                gridSafeFields.Add(field, Utils.ToGridSafeFieldName(field));
                            }

                            if (float.TryParse(fieldElement.Value.ToString(), out floatFieldValue))
                            {
                                value = floatFieldValue.ToString(providerEn);
                            }
                            else
                            {
                                value = fieldElement.Value;
                            }

                            string fieldName = field.ToLower();

                            if (fieldName.Equals("id"))
                            {
                                itemId = Convert.ToInt32(value);
                            }
                            else if (fieldName.Equals("listid"))
                            {
                                listId = new Guid(value);
                            }
                            else if (fieldName.Equals("webid"))
                            {
                                webId = new Guid(value);
                            }
                            else if (fieldName.Equals("siteid"))
                            {
                                siteId = new Guid(value);
                            }
                            else if (fieldName.Equals("assignedtoid"))
                            {
                                resourceId = Convert.ToInt32(value);
                            }
                            else if (fieldName.Equals("assignedtotext"))
                            {
                                resourceName = value;
                            }
                            else if (fieldElement.Attribute("Type").Value.Equals("System.DateTime") &&
                                     !string.IsNullOrEmpty(value))
                            {
                                DateTime localTime = SPUtility.CreateDateTimeFromISO8601DateTimeString(value);

                                if (fieldName.Equals("startdate") &&
                                    (localTime.Hour < workDayStartHour || localTime.Hour > workDayEndHour))
                                {
                                    localTime = new DateTime(localTime.Year, localTime.Month, localTime.Day,
                                                             workDayStartHour, 0, 0);
                                }
                                else if (fieldName.Equals("duedate") &&
                                         (localTime.Hour < workDayStartHour || localTime.Hour > workDayEndHour))
                                {
                                    localTime = new DateTime(localTime.Year, localTime.Month, localTime.Day,
                                                             workDayEndHour, 0, 0);
                                }

                                value = SPUtility.CreateISO8601DateTimeFromSystemDateTime(localTime);
                            }

                            iElement.Add(new XAttribute(gridSafeFields[field], value));
                        }

                        string flagQuery =
                            string.Format(
                                @"<MyPersonalization>
                                        <Keys>AssignmentPlannerFlag</Keys>
                                        <Item ID=""{0}""/>
                                        <List ID=""{1}""/>
                                        <Web ID=""{2}""/>
                                        <Site ID=""{3}"" URL=""{4}""/>
                                </MyPersonalization>",
                                itemId, listId, webId, siteId, siteUrl);

                        XDocument flagResponse = XDocument.Parse(MyPersonalization.GetMyPersonalization(flagQuery));

                        string flag = null;

                        XElement personalizationRootElement = flagResponse.Element("MyPersonalization");

                        if (personalizationRootElement != null)
                        {
                            flag = (from e in personalizationRootElement.Descendants("Personalization")
                                    let keyAttribute = e.Attribute("Key")
                                                       where keyAttribute != null && keyAttribute.Value.Equals("AssignmentPlannerFlag")
                                                       let valueAttribute = e.Attribute("Value")
                                                                            where valueAttribute != null
                                                                            select valueAttribute.Value).FirstOrDefault();
                        }

                        var flagValue = flag ?? "0";
                        var flagUrl   = safeServerRelativeUrl + "/_layouts/epmlive/images/mywork/flagged.png";
                        if (flagValue.Equals("0"))
                        {
                            flagUrl = safeServerRelativeUrl + "/_layouts/epmlive/images/mywork/unflagged.png";
                        }

                        iElement.Add(new XAttribute("Duration", string.Empty),
                                     new XAttribute("Flag", string.Format(@"<img src=""{0}"" class=""AP_Flag""/>", flagUrl)),
                                     new XAttribute("FlagValue", flagValue), new XAttribute("Height", 23));

                        if (resourceId == 0 || string.IsNullOrEmpty(resourceName))
                        {
                            continue;
                        }

                        bElement.Add(iElement);
                        if (!resources.ContainsKey(resourceId))
                        {
                            resources.Add(resourceId, resourceName);
                        }
                    }
                }

                foreach (var keyValuePair in resources)
                {
                    resourcesElement.Add(new XElement("R", new XAttribute("Name", keyValuePair.Value),
                                                      new XAttribute("Availability", 8), new XAttribute("Type", 1)));

                    footElement.Add(new XElement("I", new XAttribute("id", string.Format("-{0}", keyValuePair.Key)),
                                                 new XAttribute("Def", "Resource"),
                                                 new XAttribute("Title", keyValuePair.Value)));
                }

                return(new XElement("Grid", new XElement("Body", bElement), resourcesElement, footElement).ToString());
            }
            catch (APIException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new APIException((int)Errors.GetData, e.Message);
            }
        }