예제 #1
0
            public void SmsNotification()
            {
                //Arrange
                var atTimes = new List <DateTime> {
                    DateTime.Now, DateTime.Now.AddHours(3)
                };
                var afterHours = new List <int> {
                    4, 5
                };

                var source = new SmsNotification();

                source.NotifyAfterHours.AddRange(afterHours);
                source.NotifyAtTimes.AddRange(atTimes);

                var expectedDto = new smsnotification
                {
                    afterhours = afterHours.ToArray(),
                    at         = atTimes.Select(a => new listedtime {
                        timeSpecified = true, time = a
                    }).ToArray()
                };

                //Act
                var actual = DataTransferObjectConverter.ToDataTransferObject(source);

                //Assert
                Comparator.AssertEqual(expectedDto, actual);
            }
예제 #2
0
        public static ISmsNotification FromDataTransferObject(smsnotification smsNotificationDto)
        {
            if (smsNotificationDto == null)
            {
                return(null);
            }

            var smsNotification = new SmsNotification
            {
                NotifyAfterHours = smsNotificationDto.afterhours?.ToList() ?? new List <int>(),
                NotifyAtTimes    = smsNotificationDto.at?.Select(listedTime => listedTime.time).ToList() ?? new List <DateTime>()
            };

            return(smsNotification);
        }
        public static smsnotification ToDataTransferObject(ISmsNotification smsNotification)
        {
            if (smsNotification == null)
            {
                return(null);
            }

            var smsNotificationDto = new smsnotification();

            if (smsNotification.NotifyAtTimes.Count > 0)
            {
                var timesAsListedTimes = smsNotification.NotifyAtTimes.Select(dateTime => new listedtime {
                    time = dateTime, timeSpecified = true
                });
                smsNotificationDto.at = timesAsListedTimes.ToArray();
            }

            if (smsNotification.NotifyAfterHours.Count > 0)
            {
                smsNotificationDto.afterhours = smsNotification.NotifyAfterHours.ToArray();
            }

            return(smsNotificationDto);
        }