Exemple #1
0
        public EventDTO(Event ev)
            : base(ev)
        {
            Activity = new ActivityDTO(ev.Activity);

            //UsersInEvent = new List<EventUserDTO>();
            //GuestsInEvent = new List<EventGuestDTO>();
            //ev.UsersInEvent.ForEach(x => UsersInEvent.Add(new EventUserDTO(x)));
            //ev.GuestsInEvent.ForEach(x => GuestsInEvent.Add(new EventGuestDTO(x)));
        }
        public void DoesEventExistTrueTest()
        {
            var selectedDate = DateTime.Today;

            // Arrange
            var activity = new Activity {
                Name = "Test",
            };

            var activity2 = new Activity {
                Name = "Test2",
            };

            var ev1 = new Event {
                Name = activity.Name,
                Activity = activity,
                DateTime = selectedDate
            };

            var ev2 = new Event {
                Name = activity.Name,
                Activity = activity2,
                DateTime = selectedDate
            };

            IEnumerable<Event> events = new List<Event> {
                ev1, ev2
            };

            _eventRepo.Setup(x => x.GetEventsOn(selectedDate)).Returns(events);

            // Act
            var does = _sut.DoesEventExistForActivityAndDate(activity, selectedDate);

            // Assert
            Assert.IsTrue(does);
        }
        public void DoesEventExistFalseTest()
        {
            var selectedDate = DateTime.Today;

            // Arrange
            var activity = new Activity
            {
                Name = "Test",
                ActivityID = 1
            };

            var activity2 = new Activity
            {
                Name = "Test2",
                ActivityID = 2
            };

            var activity3 = new Activity
            {
                Name = "Test3",
                ActivityID = 3
            };

            var ev1 = new Event
            {
                Activity = activity
            };

            var ev2 = new Event
            {
                Activity = activity2
            };

            IEnumerable<Event> events = new List<Event> {
                ev1, ev2
            };

            _eventRepo.Setup(x => x.GetEventsOn(selectedDate)).Returns(events);

            // Act
            var does = _sut.DoesEventExistForActivityAndDate(activity3, selectedDate);

            // Assert
            Assert.IsFalse(does);
        }
Exemple #4
0
        public void EventDTOTest()
        {
            Location location = new Location()
            {
                Name = "asdf",
                Address = "zxvc",
                LocationID = 1
            };

            Activity activity = new Activity()
            {
                ActivityID = 1,
                Name = "asdf",
                DayOfWeek = "Thursday",
                PreferredTime = new TimeSpan(1),
                Location = location
            };

            User user = new User()
            {
                Name = "kevin"
            };

            Guest guest = new Guest()
            {
                Name = "kevin",
                Host = user
            };

            Event ev = new Event()
            {
                Activity = activity,
                ActivityID = activity.ActivityID,
                UsersInEvent = new List<User>()
                {
                    user
                },
                GuestsInEvent = new List<Guest>()
                {
                    guest
                },
                DateTime = new DateTime(),
                EventID = 1,
                Name = "asdf"
            };

            var dto = new EventDTO(ev);

            AssertEventDTO(ev, dto);

            Assert.AreEqual(1, dto.UsersInEvent.Count());
            Assert.AreEqual(1, dto.GuestsInEvent.Count());
        }
Exemple #5
0
 private void AssertEventDTO(Event ev, EventDTO dto)
 {
     AssertDTO(ev, dto, new[] { "DateTime", "EventID", "Name" });
     AssertActivityDTO(ev.Activity, new ActivityDTO(ev.Activity));
 }
        public List<Event> GenerateEventsForActivitiesAndDateRange(IEnumerable<Activity> activities, DateTime startDate, DateTime endDate)
        {
            var dates = DatesInRange(startDate, endDate);
            var events = new List<Event>();

            Event ev;
            DateTime time;
            foreach (var date in dates)
            {
                foreach (var activity in activities)
                {
                    if (activity.DayOfWeek.Equals(date.DayOfWeek.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        // Check to see if an event already exists for this day
                        if (DoesEventExistForActivityAndDate(activity, date))
                            continue;

                        time = new DateTime(
                            date.Year,
                            date.Month,
                            date.Day,
                            activity.PreferredTime.Hours,
                            activity.PreferredTime.Minutes,
                            activity.PreferredTime.Seconds,
                            activity.PreferredTime.Milliseconds,
                            date.Kind);
                        ev = new Event
                        {
                            Name = activity.Name,
                            ActivityID = activity.ActivityID,
                            DateTime = time
                        };

                        events.Add(ev);
                    }
                }
            }
            return events;
        }