Exemple #1
0
        public void TimeregWorkPackageTest()
        {
            var timereg = new Timeregistration
            {
                CaseId             = 21,
                DoneDate           = new DateTime(2018, 5, 7),
                Duration           = "11:00-20:00",
                IsWorkPackage      = true,
                Team               = "Operations",
                ToolkitDisplayName = "ATEAM"
            };

            var toolkit = new Toolkit
            {
                CustomerName = "NCOPEATEAM",
                DisplayName  = "ATEAM",
                Url          = "https://goto.netcompany.com/cases/GTO539/NCOPEATEAM",
                UserId       = 43,
                Teams        = new List <Team> {
                    new Team {
                        Name = "Operations", UsesTimeslots = false
                    }
                }
            };

            var id = _sharepointClient.MakeTimeregistration(timereg, _toolkitUser, toolkit);

            Assert.AreNotEqual(-1, id);
        }
        public void CalculateHoursFromVariousDurationFormats()
        {
            //Arrange
            string duration1 = "08:00-08:30";
            string duration2 = "08.00-09.00";
            string duration3 = "08,00-09,30";
            string duration4 = "0800-1000";
            string duration5 = "2.5";
            string duration6 = "3,0";
            var    timereg1  = new Timeregistration {
                Duration = duration1
            };
            var timereg2 = new Timeregistration {
                Duration = duration2
            };
            var timereg3 = new Timeregistration {
                Duration = duration3
            };
            var timereg4 = new Timeregistration {
                Duration = duration4
            };
            var timereg5 = new Timeregistration {
                Duration = duration5
            };
            var timereg6 = new Timeregistration {
                Duration = duration6
            };

            //Act
            var result1 = timereg1.CouldConvertDurationToHours();
            var result2 = timereg2.CouldConvertDurationToHours();
            var result3 = timereg3.CouldConvertDurationToHours();
            var result4 = timereg4.CouldConvertDurationToHours();
            var result5 = timereg5.CouldConvertDurationToHours();
            var result6 = timereg6.CouldConvertDurationToHours();

            //Assert
            Assert.IsTrue(result1);
            Assert.AreEqual(0.5, timereg1.Hours);

            Assert.IsTrue(result2);
            Assert.AreEqual(1.0, timereg2.Hours);

            Assert.IsTrue(result3);
            Assert.AreEqual(1.5, timereg3.Hours);

            Assert.IsTrue(result4);
            Assert.AreEqual(2.0, timereg4.Hours);

            Assert.IsTrue(result5);
            Assert.AreEqual(2.5, timereg5.Hours);

            Assert.IsTrue(result6);
            Assert.AreEqual(3.0, timereg6.Hours);
        }
Exemple #3
0
        public virtual int MakeTimeregistration(Timeregistration timereg, ToolkitUser toolkitUser, Toolkit toolkit)
        {
            var clientContext = new ClientContext(toolkit.Url)
            {
                Credentials = new NetworkCredential(toolkitUser.Name, toolkitUser.SecurePassword, toolkitUser.Domain)
            };

            const string timeregList    = "tidsregistrering";
            var          sharepointList = clientContext.Web.Lists.GetByTitle(timeregList);

            clientContext.Load(sharepointList);
            clientContext.ExecuteQuery();

            var itemCreateInfo     = new ListItemCreationInformation();
            var sharepointListItem = sharepointList.AddItem(itemCreateInfo);

            var success = timereg.CouldConvertDurationToHours();

            if (!success)
            {
                return(-1);
            }

            var doneBy = new SPFieldLookupValue(toolkit.UserId, toolkitUser.Name);
            var author = new SPFieldLookupValue(toolkit.UserId, toolkitUser.Name);

            if (timereg.IsWorkPackage)
            {
                sharepointListItem["Case"] = FindRelatedCaseForWorkPackage(clientContext, timereg.CaseId);
                var toolkitWorkPackage = new SPFieldLookupValue(timereg.CaseId, "");
                sharepointListItem["WorkPackage"] = toolkitWorkPackage;
            }
            else
            {
                var toolkitCase = new SPFieldLookupValue(timereg.CaseId, $"{toolkit.CustomerName}-{timereg.CaseId}");
                sharepointListItem["Case"] = toolkitCase;
            }

            //sharepointListItem["Hours"] = timereg.Hours;
            sharepointListItem["Hours"]    = timereg.Hours;
            sharepointListItem["DoneBy"]   = doneBy;
            sharepointListItem["Author"]   = author;
            sharepointListItem["DoneDate"] = timereg.DoneDate;

            try
            {
                sharepointListItem.Update();
                clientContext.ExecuteQuery();
                return(sharepointListItem.Id);
            }
            catch
            {
                return(-1);
            }
        }
Exemple #4
0
        private Toolkit GetRelevantToolkit(Timeregistration timereg)
        {
            var toolkit = _toolkits.SingleOrDefault(tk => tk.DisplayName == timereg.ToolkitDisplayName);

            if (toolkit == null)
            {
                throw new Exception("Toolkit not found");
            }

            return(toolkit);
        }