Exemple #1
0
        public void WhenDeletingTheMessage_HandlesInvalidId()
        {
            #region Data

            AppMessage actual1 = new AppMessage
            {
                Id          = "1",
                Title       = "1",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Test quote",
                Author      = "Test author",
                Show        = true,
                Source      = "From somewhere"
            };

            AppMessage actual2 = new AppMessage
            {
                Id          = "2",
                Title       = "2",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Quote test",
                Author      = "Author test",
                Show        = false,
                Source      = "Somewhere from"
            };

            #endregion Data

            bool testAdd    = repository.AddMessage(actual1);
            bool testDelete = repository.DeleteMessage(actual2.Id);

            Assert.IsTrue(testAdd);
            Assert.IsFalse(testDelete);
        }
Exemple #2
0
        public void WhenGettingTheMessage_ReturnsValidMessage()
        {
            #region Data

            AppMessage actual = new AppMessage
            {
                Id          = "1",
                Title       = "1",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Test quote",
                Author      = "Test author",
                Show        = true,
                Source      = "From somewhere"
            };

            #endregion Data

            bool       testAdd = repository.AddMessage(actual);
            AppMessage result  = repository.GetMessage(actual.Id);

            Assert.IsTrue(testAdd);
            Assert.AreEqual(actual.Id, result.Id);
            Assert.AreEqual(actual.Title, result.Title);
            Assert.AreEqual(
                actual.CreatedDate.Date,
                result.CreatedDate.Date
                );
            Assert.AreEqual(
                actual.CreatedDate.Time,
                result.CreatedDate.Time
                );
            Assert.AreEqual(actual.Quote, result.Quote);
            Assert.AreEqual(actual.Author, result.Author);
            Assert.AreEqual(actual.Source, result.Source);
        }
Exemple #3
0
        public void WhenGettingTheMessages_HandlesInvalidSearchParam()
        {
            #region Data

            AppMessage actual1 = new AppMessage
            {
                Id          = "1",
                Title       = "1",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Test quote",
                Author      = "Test author",
                Show        = true,
                Source      = "From somewhere"
            };

            AppMessage actual2 = new AppMessage
            {
                Id          = "2",
                Title       = "2",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Test quote",
                Author      = "Test author",
                Show        = false,
                Source      = "From somewhere"
            };

            #endregion Data

            bool testAdd             = repository.AddMessage(actual1) && repository.AddMessage(actual2);
            List <AppMessage> result = repository.GetMessages(null).ToList();

            Assert.IsTrue(testAdd);
            Assert.AreEqual(0, result.Count());
        }
Exemple #4
0
        private void UpdateTodaysEvents(DateTime selectedDate)
        {
            DateAndTime date = TimeAndDateUtility.ConvertDateTime_DateAndTime(selectedDate);

            object[] eventList = _events.GetAll(date);

            Todays_Events.Update(eventList);
        }
Exemple #5
0
        /// <summary>
        /// Updates the views
        /// </summary>
        /// <param name="start">The start date</param>
        /// <param name="end">The end date</param>
        /// <param name="searchTerm">The search term</param>
        public void UpdateEvents(DateTime start, DateTime end, string searchTerm = null)
        {
            DateAndTime startDate = start == DateTime.MaxValue ? null : TimeAndDateUtility.ConvertDateTime_DateAndTime(start);
            DateAndTime endDate   = end == DateTime.MinValue ? null : TimeAndDateUtility.ConvertDateTime_DateAndTime(end);

            ClearEventDetails();
            UpdateTodaysEvents(startDate, endDate, searchTerm);
        }
Exemple #6
0
        /// <summary>
        /// Set the delay and date to start the delay
        /// </summary>
        /// <param name="delay">The amount of seconds to delay</param>
        /// <param name="date">The date to start the delay</param>
        public void SetDelay(int delay, DateAndTime date)
        {
            int delayTime = delay > 0 ? delay : 30;

            DateDelayed = date;
            DateTime continued = TimeAndDateUtility.ConvertDateAndTime_DateTime(date).AddSeconds(delayTime);

            DateContinued = TimeAndDateUtility.ConvertDateTime_DateAndTime(continued);
            Lock          = true;
        }
Exemple #7
0
        public void WhenUpdatingTheMessage_UpdatesSuccessful()
        {
            #region Data

            AppMessage actual = new AppMessage
            {
                Id          = "1",
                Title       = "1",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Test quote",
                Author      = "Test author",
                Show        = true,
                Source      = "From somewhere"
            };

            AppMessage actual2 = new AppMessage
            {
                Id          = "1",
                Title       = "2",
                CreatedDate = actual.CreatedDate,
                Quote       = "Quote test",
                Author      = "Author test",
                Show        = false,
                Source      = "Somewhere from"
            };

            #endregion Data

            bool testAdd = repository.AddMessage(actual);

            Assert.IsTrue(testAdd);

            bool testUpdate = repository.UpdateMessage(actual2);

            Assert.IsTrue(testUpdate);

            AppMessage result = repository.GetMessage(actual2.Id);

            Assert.AreEqual(actual2.Id, result.Id);
            Assert.AreEqual(actual2.Title, result.Title);
            Assert.AreEqual(
                actual2.CreatedDate.Date,
                result.CreatedDate.Date
                );
            Assert.AreEqual(
                actual2.CreatedDate.Time,
                result.CreatedDate.Time
                );
            Assert.AreEqual(actual2.Quote, result.Quote);
            Assert.AreEqual(actual2.Author, result.Author);
            Assert.AreEqual(actual2.Source, result.Source);
        }
        /// <summary>
        /// Gets all the items for the mothly glance list view
        /// </summary>
        /// <param name="groups">The groups to categorize events</param>
        /// <returns>The list of ListViewItem to display</returns>
        public ListViewItem[] GetAll(ListViewGroupCollection groups)
        {
            DateTime today     = DateTime.Now;
            int      maxDay    = DateTime.DaysInMonth(today.Year, today.Month);
            DateTime startDate = today.AddDays(-(today.Day - 1));
            DateTime endDate   = today.AddDays(maxDay - today.Day).AddHours(23 - today.Hour).AddMinutes(59 - today.Minute).AddSeconds(59 - today.Second);

            DateAndTime todaysDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(today);
            DateAndTime start      = TimeAndDateUtility.ConvertDateTime_DateAndTime(startDate);
            DateAndTime end        = TimeAndDateUtility.ConvertDateTime_DateAndTime(endDate);

            List <SavedEvent>   events = _eventController.GetEvents(start, end).ToList();
            List <ListViewItem> items  = new List <ListViewItem>();

            events.ForEach(x =>
            {
                string[] details = CalculateStatus(todaysDate, x, end);
                string date      = details[1];

                ListViewItem item = new ListViewItem(details)
                {
                    Group =
                        date.Contains(COMPLETED) ? groups["Complete"]
                                : (date.Contains(STARTS_IN) ? groups["Upcoming"]
                                    : (date.Contains(ENDS_IN) ? groups["HappeningNow"]
                                        : (date.Contains(OVERDUE_FROM) ? groups["Overdue"] : null)))
                };

                item.Tag        = x.Id;
                bool groupIsSet = item.Group != null && !string.IsNullOrEmpty(item.Group.Name);
                if (groupIsSet)
                {
                    string groupName = item.Group.Name;

                    int groupIndex =
                        groupName == "Complete" ? 1
                                : groupName == "Upcoming" ? 2
                                    : groupName == "HappeningNow" ? 3
                                        : groupName == "Overdue" ? 4 : -1;

                    SetVisualDetails(groupIndex, item);
                    item.Tag = x.Id;
                }

                items.Add(item);
            }
                           );

            return(items.ToArray());
        }
Exemple #9
0
        private IEnumerable <SavedEvent> GetDateRestrictedResults(DateAndTime start, DateAndTime end)
        {
            bool nullStart = start == null;
            bool nullEnd   = end == null;

            new List <SavedEvent>();
            DateAndTime min = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.MinValue);

            IEnumerable <SavedEvent> events = !nullEnd && !nullStart?
                                              _eventRepo.GetEvents(start, end).ToList() : (nullEnd && !nullStart ?
                                                                                           _eventRepo.GetEvents(start).ToList() : (nullStart && !nullEnd ?
                                                                                                                                   _eventRepo.GetEvents(min, end).ToList() : new List <SavedEvent>()));

            return(events);
        }
Exemple #10
0
        public void WhenAddingTheMessage_AddsSuccessful()
        {
            #region Data

            AppMessage actual = new AppMessage
            {
                Id          = "1",
                Title       = "1",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Test quote",
                Author      = "Test author",
                Show        = true,
                Source      = "From somewhere"
            };

            #endregion Data

            bool testAdd = repository.AddMessage(actual);

            Assert.IsTrue(testAdd);
        }
Exemple #11
0
        private IEnumerable <SavedEvent> GetSearchResults(DateAndTime start, DateAndTime end, string searchTerm)
        {
            bool nullStart  = start == null;
            bool nullEnd    = end == null;
            bool nullSearch = string.IsNullOrEmpty(searchTerm);

            IEnumerable <SavedEvent> events = new List <SavedEvent>();
            DateAndTime min = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.MinValue);

            List <SavedEvent> searchEvents = _eventRepo.GetEvents(searchTerm).ToList();

            List <SavedEvent> dateEvents;

            if (!nullStart && !nullEnd)
            {
                dateEvents = _eventRepo.GetEvents(start, end).ToList();
            }
            else
            {
                dateEvents = nullEnd && !nullStart?
                             _eventRepo.GetEvents(start).ToList() : (nullStart && !nullEnd ?
                                                                     _eventRepo.GetEvents(min, end).ToList() : new List <SavedEvent>());
            }

            bool searchHasResults = searchEvents.Any();
            bool dateHasResults   = dateEvents.Any();

            if (searchHasResults && dateHasResults)
            {
                events = searchEvents.Concat(dateEvents).GroupBy(x => x.Id).Select(x => x.First());
            }
            else
            {
                events = searchHasResults ?
                         searchEvents : (dateHasResults ?
                                         dateEvents : new List <SavedEvent>());
            }

            return(events);
        }
Exemple #12
0
        /// <summary>
        /// Toggles the complete status on an event
        /// </summary>
        /// <param name="id">The id of the event to toggle</param>
        /// <returns>Whether the event was updated</returns>
        public bool ToggleStatus(string id)
        {
            SavedEvent @event = GetEvent(id);

            if (@event == null)
            {
                return(false);
            }

            if (@event.Completed)
            {
                @event.Completed     = false;
                @event.CompletedDate = null;
            }
            else
            {
                DateTime date = DateTime.Now;
                @event.Completed     = true;
                @event.CompletedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(date);
            }

            return(_eventRepo.UpdateEvent(@event));
        }
Exemple #13
0
        public void WhenGettingTheMessage_HandlesNullParam()
        {
            #region Data

            AppMessage actual = new AppMessage
            {
                Id          = "1",
                Title       = "1",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Test quote",
                Author      = "Test author",
                Show        = true,
                Source      = "From somewhere"
            };

            #endregion Data

            bool       testAdd = repository.AddMessage(actual);
            AppMessage result  = repository.GetMessage(null);

            Assert.IsTrue(testAdd);
            Assert.IsNull(result);
        }