Ejemplo n.º 1
0
        public void ScheduleToPlainTextStringWithThreeItemsInListReturnsFormattedStringTest()
        {
            // arrange
            var scheduleDiff = new ScheduleDiff[]
            {
                new ScheduleDiff
                {
                    Schedule = ScheduleA,
                    Status   = ScheduleStatus.Added
                },
                new ScheduleDiff
                {
                    Schedule = ScheduleB,
                    Status   = ScheduleStatus.Removed
                },
                new ScheduleDiff
                {
                    Schedule = ScheduleC,
                    Status   = ScheduleStatus.Unchanged
                }
            };

            // act
            var result = sut.ScheduleToPlainTextString(scheduleDiff);

            // assert
            string expected = "";

            expected += "+ 08-04 08:05-17:05 Jacob" + Environment.NewLine;
            expected += "- 08-01 10:05-12:05 New York" + Environment.NewLine;
            expected += "= 08-04 08:30-22:00 Madrid" + Environment.NewLine;
            Assert.That(result, Is.EqualTo(expected));
        }
Ejemplo n.º 2
0
        public async Task ScheduleToPlainTextStringWithThreeItemsInListReturnsFormattedStringTest()
        {
            // arrange
            var scheduleDiff = new ScheduleDiff[]
            {
                new ScheduleDiff
                {
                    SingleShift = _singleShiftA,
                    Status      = ScheduleStatus.Added,
                },
                new ScheduleDiff
                {
                    SingleShift = _singleShiftB,
                    Status      = ScheduleStatus.Removed,
                },
                new ScheduleDiff
                {
                    SingleShift = _singleShiftC,
                    Status      = ScheduleStatus.Unchanged,
                },
            };

            // act
            var result = Sut.ScheduleToPlainTextString(scheduleDiff);

            // assert
            await Verifier.Verify(result);
        }
Ejemplo n.º 3
0
 private static string StatusToString(ScheduleDiff item)
 {
     return(item.Status switch
     {
         ScheduleStatus.Added => "+",
         ScheduleStatus.Removed => "-",
         ScheduleStatus.Unchanged => "=",
         _ => string.Empty
     });
Ejemplo n.º 4
0
        public void ScheduleToPlainTextStringWithEmptyListReturnsEmptyStringTest()
        {
            // arrange
            var scheduleDiff = new ScheduleDiff[] { };

            // act
            var result = sut.ScheduleToPlainTextString(scheduleDiff);

            // assert
            Assert.That(result, Is.Empty);
        }
        private static string ScheduleItemToString(ScheduleDiff item)
        {
            var s = ScheduleStatusToString(item);

            s += " ";
            s += item.Schedule.StartDateTime.ToString("dd-MM HH:mm");
            s += "-";
            s += item.Schedule.EndDateTime.ToString("HH:mm");
            s += " ";
            s += item.Schedule.Location;
            return(s);
        }
Ejemplo n.º 6
0
        private static IList <ScheduleDiff> GetDiffs(ICollection <Schedule> dbSchedules, ICollection <ScheduleItem> parsedSchedules, Week week)
        {
            var diffResult = new List <ScheduleDiff>(parsedSchedules.Count + dbSchedules.Count);

            foreach (var item in dbSchedules)
            {
                var diffResultItem = new ScheduleDiff
                {
                    Schedule = item,
                };

                var selectItem = parsedSchedules
                                 .FirstOrDefault(x =>
                                                 x.Start == item.StartDateTime && x.End == item.EndDateTime && x.Location == item.Location);

                if (selectItem != null)
                {
                    diffResultItem.Status = ScheduleStatus.Unchanged;
                    parsedSchedules.Remove(selectItem);
                }
                else
                {
                    diffResultItem.Status = ScheduleStatus.Removed;
                }

                diffResult.Add(diffResultItem);
            }


            foreach (var parsedSchedule in parsedSchedules)
            {
                var schedule = new Schedule
                {
                    WeekId        = week.Id,
                    Week          = week,
                    Location      = parsedSchedule.Location,
                    StartDateTime = parsedSchedule.Start,
                    EndDateTime   = parsedSchedule.End
                };

                diffResult.Add(new ScheduleDiff
                {
                    Schedule = schedule,
                    Status   = ScheduleStatus.Added
                });
            }

            return(diffResult);
        }
Ejemplo n.º 7
0
        private IList <ScheduleDiff> GetDiffs(ICollection <SingleShift> dbSchedules, ICollection <ScheduleItem> parsedSchedules)
        {
            var diffResult = new List <ScheduleDiff>(parsedSchedules.Count + dbSchedules.Count);

            foreach (SingleShift item in dbSchedules)
            {
                var diffResultItem = new ScheduleDiff
                {
                    SingleShift = item,
                };

                ScheduleItem selectItem = parsedSchedules.FirstOrDefault(scheduleItem =>
                                                                         scheduleItem.Start == item.StartDateTime
                                                                         &&
                                                                         scheduleItem.End == item.EndDateTime
                                                                         &&
                                                                         scheduleItem.Location == item.Location);

                if (selectItem != null)
                {
                    diffResultItem.Status = ScheduleStatus.Unchanged;
                    _ = parsedSchedules.Remove(selectItem);
                }
                else
                {
                    diffResultItem.Status = ScheduleStatus.Removed;
                }

                diffResult.Add(diffResultItem);
            }

            foreach (ScheduleItem parsedSchedule in parsedSchedules)
            {
                var schedule = new SingleShift
                {
                    Location      = parsedSchedule.Location,
                    StartDateTime = parsedSchedule.Start,
                    EndDateTime   = parsedSchedule.End,
                };

                diffResult.Add(new ScheduleDiff
                {
                    SingleShift = schedule,
                    Status      = ScheduleStatus.Added,
                });
            }

            return(diffResult);
        }
Ejemplo n.º 8
0
        private static string StatusToString(ScheduleDiff item)
        {
            switch (item.Status)
            {
            case ScheduleStatus.Added:
                return("+");

            case ScheduleStatus.Removed:
                return("-");

            case ScheduleStatus.Unchanged:
                return("=");

            default:
                return(String.Empty);
            }
        }
Ejemplo n.º 9
0
        public void ScheduleToHtmlStringWithThreeItemsInListReturnsFormattedStringTest()
        {
            // arrange
            var scheduleDiff = new ScheduleDiff[]
            {
                new ScheduleDiff
                {
                    Schedule = ScheduleA,
                    Status   = ScheduleStatus.Added
                },
                new ScheduleDiff
                {
                    Schedule = ScheduleB,
                    Status   = ScheduleStatus.Removed
                },
                new ScheduleDiff
                {
                    Schedule = ScheduleC,
                    Status   = ScheduleStatus.Unchanged
                }
            };

            // act
            var result = sut.ScheduleToHtmlString(scheduleDiff);

            // assert
            var expected = @"
<p>Hier is je rooster voor week 23:</p>
<table style='border: 1px solid black; border-collapse:collapse;'>
<tr style='text-align:left; padding:0px 5px; border: 1px solid black;'>
<td style='text-align:center; padding:0px 5px; border: 1px solid black;'></td>
<td colspan=2 style='text-align:left; padding:0px 5px; border: 1px solid black;'><b>Dag</b></td>
<td colspan=3 style='text-align:left; padding:0px 5px; border: 1px solid black;'><b>Tijd</b></td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black;'><b>Locatie</b></td>
</tr>
<tr style='text-align:left; padding:0px 5px; border: 1px solid black;'>
<td style='text-align:center; padding:0px 5px; border: 1px solid black;'>+</td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black; border-right:hidden;'>zo</td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black;'>08-04</td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black; text-align: right; padding-right:0px;'>08:05</td>
<td style='text-align:center; padding:0px 5px; border: 1px solid black; border-left: hidden; border-right: hidden;'>-</td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black; padding-left:0px;'>17:05</td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black;'>Jacob</td>
</tr>
<tr style='text-align:left; padding:0px 5px; border: 1px solid black;'>
<td style='text-align:center; padding:0px 5px; border: 1px solid black;'>-</td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black;text-decoration: line-through; border-right:hidden;'>zo</td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black;text-decoration: line-through;'>08-01</td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black;text-decoration: line-through; text-align: right; padding-right:0px;'>10:05</td>
<td style='text-align:center; padding:0px 5px; border: 1px solid black; border-left: hidden; border-right: hidden;'>-</td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black;text-decoration: line-through; padding-left:0px;'>12:05</td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black;text-decoration: line-through;'>New York</td>
</tr>
<tr style='text-align:left; padding:0px 5px; border: 1px solid black;'>
<td style='text-align:center; padding:0px 5px; border: 1px solid black;'>=</td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black; border-right:hidden;'>zo</td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black;'>08-04</td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black; text-align: right; padding-right:0px;'>08:30</td>
<td style='text-align:center; padding:0px 5px; border: 1px solid black; border-left: hidden; border-right: hidden;'>-</td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black; padding-left:0px;'>22:00</td>
<td style='text-align:left; padding:0px 5px; border: 1px solid black;'>Madrid</td>
</tr>
</table>
</p>";

            Assert.That(result.Trim(), Is.EqualTo(expected.Trim()));
        }