public async Task ConfigureNotifications_GivenEventNotParticipating_ErrorReturned()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int eventId;
            int johnId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                EntityEntry <User> john = context.Users.Add(ContextUtilities.CreateJohnDoe());
                User  organizer         = ContextUtilities.CreateRichardRoe();
                Event @event            = DummyEvent(organizer);
                context.Events.Add(@event);

                await context.SaveChangesAsync();

                eventId = @event.Id;
                johnId  = john.Entity.Id;
            }

            // Act
            (ParticipateEventController participateEventController, _) = CreateController(getContext, johnId);

            IActionResult response = await participateEventController.ConfigureNotifications(new NotificationConfigurationDto { EventId = eventId, SendReminderEmail = true, SendSummaryEmail = true, SendLastMinuteChangesEmail = true });

            // Assert
            Assert.IsType <BadRequestObjectResult>(response);
            var objectResult = (BadRequestObjectResult)response;

            Assert.Equal(RequestStringMessages.UserNotPartOfEvent, objectResult.Value);
        }
        public async Task JoinEvent_GivenPrivateEvent_UserCanNotJoin()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int johnDoeId;
            int eventId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                EntityEntry <User> john = context.Users.Add(ContextUtilities.CreateJohnDoe());

                Event privateEvent = DummyEvent(ContextUtilities.CreateRichardRoe(), true);
                context.Events.Add(privateEvent);

                await context.SaveChangesAsync();

                johnDoeId = john.Entity.Id;
                eventId   = privateEvent.Id;
            }

            // Act
            (ParticipateEventController participateEventController, _) = CreateController(getContext, johnDoeId);

            IActionResult response = await participateEventController.JoinEvent(new JoinEventDto
            {
                EventId = eventId
            });

            // Assert
            Assert.IsType <BadRequestObjectResult>(response);
            var objectResult = (BadRequestObjectResult)response;

            Assert.Equal(RequestStringMessages.InvitationRequired, objectResult.Value);
        }
        private static async Task <Event> CreateTestDataAsync(GetDatabaseContext getContext, DateTime lastReadJohn, DateTime lastReadRichard, Func <User, User, IEnumerable <ChatMessage> > createMessagesFunc)
        {
            using (IDatabaseContext context = getContext())
            {
                User john    = ContextUtilities.CreateJohnDoe();
                User richard = ContextUtilities.CreateRichardRoe();

                var @event = new Event
                {
                    Title        = "Chatty event",
                    Description  = "An event with an active chat",
                    MeetingPlace = "Somewhere",
                    Organizer    = john,
                    ReminderTimeWindowInHours = 42,
                    SummaryTimeWindowInHours  = 24,
                    EventParticipations       = new List <EventParticipation>
                    {
                        new EventParticipation {
                            Participant = john, LastReadMessageSentDate = lastReadJohn
                        },
                        new EventParticipation {
                            Participant = richard, LastReadMessageSentDate = lastReadRichard
                        }
                    },
                    ChatMessages = createMessagesFunc(john, richard).ToList()
                };

                context.Events.Add(@event);

                await context.SaveChangesAsync();

                return(@event);
            }
        }
        public async Task DeleteEvent_GivenNonExistingEvent_ErrorReturned()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int johnDoeId;
            int eventId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                User john    = ContextUtilities.CreateJohnDoe();
                User richard = ContextUtilities.CreateRichardRoe();

                Event @event = DummyEvent(richard, true);

                await context.SaveChangesAsync();

                johnDoeId = john.Id;
                eventId   = @event.Id;
            }

            // Act
            (OrganizeEventController controller, _) = CreateController(getContext, johnDoeId);

            IActionResult response = await controller.DeleteEvent(eventId);

            // Assert
            Assert.IsType <BadRequestObjectResult>(response);
            var objectResult = (BadRequestObjectResult)response;

            Assert.Equal(RequestStringMessages.EventNotFound, objectResult.Value);
        }
        public async Task GetDetails_GivenPublicEvent_DetailsReturned()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int publicEventId;
            int johnId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                EntityEntry <User> john = context.Users.Add(ContextUtilities.CreateJohnDoe());
                User  richard           = ContextUtilities.CreateRichardRoe();
                Event publicEvent       = DummyEvent(richard);
                context.Events.Add(publicEvent);

                await context.SaveChangesAsync();

                publicEventId = publicEvent.Id;
                johnId        = john.Entity.Id;
            }

            // Act
            (ParticipateEventController participateEventController, _) = CreateController(getContext, johnId);

            IActionResult response = await participateEventController.GetDetails(publicEventId);

            // Assert
            Assert.IsType <OkObjectResult>(response);
        }
Exemple #6
0
        public async Task SetNewUserData_GivenAlreadyUsedEmail_ErrorReturned()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int          johnId;
            const string NewName = "New Fancy Name";
            string       usedEmail;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                User john = context.Users.Add(ContextUtilities.CreateJohnDoe()).Entity;

                User richard = context.Users.Add(ContextUtilities.CreateRichardRoe()).Entity;
                usedEmail = richard.Email;

                await context.SaveChangesAsync();

                johnId = john.Id;
            }

            // Act
            (UserController controller, _, _, _) = CreateController(getContext, johnId);

            IActionResult response = await controller.SetNewUserData(new SetUserDataDto { NewEmail = usedEmail, NewFullName = NewName });

            // Assert
            Assert.IsType <BadRequestObjectResult>(response);
            var objectResult = (BadRequestObjectResult)response;

            Assert.Equal(RequestStringMessages.EmailAlreadyInUse, objectResult.Value);
        }
        public async Task RemoveFromEvent_GivenParticipatingUser_UserLeavesEventAndAppointments()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int johnDoeId;
            int eventId;
            int appointmentId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                EntityEntry <User> john = context.Users.Add(ContextUtilities.CreateJohnDoe());

                Event @event = DummyEvent(ContextUtilities.CreateRichardRoe());

                context.EventParticipations.Add(new EventParticipation {
                    Participant = john.Entity, Event = @event
                });

                var appointment = new Appointment
                {
                    Event     = @event,
                    StartTime = DateTime.UtcNow + TimeSpan.FromDays(1)
                };

                context.AppointmentParticipations.Add(new AppointmentParticipation {
                    Appointment = appointment, Participant = john.Entity, AppointmentParticipationAnswer = AppointmentParticipationAnswer.Accepted
                });

                await context.SaveChangesAsync();

                johnDoeId     = john.Entity.Id;
                eventId       = @event.Id;
                appointmentId = appointment.Id;
            }

            // Act
            (ParticipateEventController participateEventController, Mock <AssertingNotificationService> notificationServiceMock) = CreateController(getContext, johnDoeId);
            Expression <Func <AssertingNotificationService, Task> > sendLastMinuteChangeExpression = n => n.SendLastMinuteChangeIfRequiredAsync(It.Is <Appointment>(a => a.Id == appointmentId));

            notificationServiceMock.Setup(sendLastMinuteChangeExpression).CallBase();

            IActionResult response = await participateEventController.RemoveFromEvent(new RemoveFromEventDto
            {
                EventId = eventId,
                UserId  = johnDoeId
            });

            // Assert
            Assert.IsType <OkResult>(response);
            notificationServiceMock.Verify(sendLastMinuteChangeExpression, Times.Once);
            using (IDatabaseContext context = getContext())
            {
                Assert.Single(context.Events);
                Assert.Empty(context.EventParticipations);
                Assert.Single(context.Appointments);
                Assert.Empty(context.AppointmentParticipations);
            }
        }
        public async Task RemoveFromEvent_GivenDeclinedUser_NoUpdateSent()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int johnDoeId;
            int eventId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                EntityEntry <User> john = context.Users.Add(ContextUtilities.CreateJohnDoe());

                Event @event = DummyEvent(ContextUtilities.CreateRichardRoe());

                context.EventParticipations.Add(new EventParticipation {
                    Participant = john.Entity, Event = @event
                });

                var appointment = new Appointment
                {
                    Event     = @event,
                    StartTime = DateTime.UtcNow + TimeSpan.FromDays(1)
                };

                context.AppointmentParticipations.Add(new AppointmentParticipation {
                    Appointment = appointment, Participant = john.Entity, AppointmentParticipationAnswer = AppointmentParticipationAnswer.Declined
                });
                context.AppointmentParticipations.Add(new AppointmentParticipation {
                    Appointment = appointment, Participant = john.Entity, AppointmentParticipationAnswer = null
                });

                await context.SaveChangesAsync();

                johnDoeId = john.Entity.Id;
                eventId   = @event.Id;
            }

            // Act
            (ParticipateEventController participateEventController, Mock <AssertingNotificationService> _) = CreateController(getContext, johnDoeId);

            IActionResult response = await participateEventController.RemoveFromEvent(new RemoveFromEventDto
            {
                EventId = eventId,
                UserId  = johnDoeId
            });

            // Assert
            Assert.IsType <OkResult>(response);
            using (IDatabaseContext context = getContext())
            {
                Assert.Single(context.Events);
                Assert.Empty(context.EventParticipations);
                Assert.Single(context.Appointments);
                Assert.Empty(context.AppointmentParticipations);
            }
        }
        private static async Task <Appointment> CreateTestDataAsync(GetDatabaseContext getContext, DateTime startTime)
        {
            using (IDatabaseContext context = getContext())
            {
                User john    = ContextUtilities.CreateJohnDoe();
                User richard = ContextUtilities.CreateRichardRoe();

                var @event = new Event
                {
                    Title        = "Upcoming event",
                    Description  = "An event with upcoming appointments",
                    MeetingPlace = "Somewhere",
                    Organizer    = john,
                    ReminderTimeWindowInHours = ReminderTimeWindowInHours,
                    SummaryTimeWindowInHours  = SummaryTimeWindowInHours,
                    EventParticipations       = new List <EventParticipation>
                    {
                        new EventParticipation {
                            Participant = john
                        },
                        new EventParticipation {
                            Participant = richard
                        }
                    }
                };

                var appointment = new Appointment
                {
                    Event = @event,
                    AppointmentParticipations = new List <AppointmentParticipation>
                    {
                        new AppointmentParticipation {
                            Participant = john
                        },
                        new AppointmentParticipation {
                            Participant = richard
                        }
                    },
                    StartTime = startTime
                };

                context.Appointments.Add(appointment);

                await context.SaveChangesAsync();

                return(appointment);
            }
        }
Exemple #10
0
        public async Task GetOverview_GivenSomeEvents_OnlyShowsPublicEvents()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int publicEventId1;
            int publicEventId2;
            int privateEventId;
            int johnId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                EntityEntry <User> john = context.Users.Add(ContextUtilities.CreateJohnDoe());
                User  organizer         = ContextUtilities.CreateRichardRoe();
                Event publicEvent1      = DummyEvent(organizer);
                Event publicEvent2      = DummyEvent(organizer);
                Event privateEvent      = DummyEvent(organizer, true);
                context.Events.Add(publicEvent1);
                context.Events.Add(publicEvent2);
                context.Events.Add(privateEvent);

                await context.SaveChangesAsync();

                publicEventId1 = publicEvent1.Id;
                publicEventId2 = publicEvent2.Id;
                privateEventId = privateEvent.Id;
                johnId         = john.Entity.Id;
            }

            // Act
            (ParticipateEventController participateEventController, _) = CreateController(getContext, johnId);

            IActionResult response = await participateEventController.GetOverview();

            // Assert
            Assert.IsType <OkObjectResult>(response);
            var okObjectResult = (OkObjectResult)response;
            var eventOverview  = okObjectResult.Value as EventOverview;

            Assert.NotNull(eventOverview);
            Assert.Empty(eventOverview.YourEvents);
            Assert.Equal(2, eventOverview.PublicEvents.Count);
            Assert.Contains(publicEventId1, eventOverview.PublicEvents.Select(e => e.EventId));
            Assert.Contains(publicEventId2, eventOverview.PublicEvents.Select(e => e.EventId));
            Assert.DoesNotContain(privateEventId, eventOverview.PublicEvents.Select(e => e.EventId));
        }
        public async Task DeleteEvent_GivenEventUserOnlyParticipates_EventNotDeleted(bool isPrivate)
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int johnDoeId;
            int eventId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                User john    = ContextUtilities.CreateJohnDoe();
                User richard = ContextUtilities.CreateRichardRoe();

                Event @event = DummyEvent(richard, isPrivate);

                context.EventParticipations.Add(new EventParticipation {
                    Event = @event, Participant = john
                });
                context.EventParticipations.Add(new EventParticipation {
                    Event = @event, Participant = richard
                });

                await context.SaveChangesAsync();

                johnDoeId = john.Id;
                eventId   = @event.Id;
            }

            // Act
            (OrganizeEventController controller, _) = CreateController(getContext, johnDoeId);

            IActionResult response = await controller.DeleteEvent(eventId);

            // Assert
            Assert.IsType <BadRequestObjectResult>(response);
            var objectResult = (BadRequestObjectResult)response;

            Assert.Equal(RequestStringMessages.OrganizerRequired, objectResult.Value);
            using (IDatabaseContext context = getContext())
            {
                Assert.Single(context.Events);
            }
        }
        public async Task ConfigureNotifications_GivenParticipatingEvent_NotificationsConfigured()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int eventId;
            int johnId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                EntityEntry <User> john = context.Users.Add(ContextUtilities.CreateJohnDoe());
                User  organizer         = ContextUtilities.CreateRichardRoe();
                Event @event            = DummyEvent(organizer);
                context.Events.Add(@event);
                context.EventParticipations.Add(new EventParticipation {
                    Event = @event, Participant = john.Entity, SendLastMinuteChangesEmail = false, SendReminderEmail = false, SendSummaryEmail = false
                });

                await context.SaveChangesAsync();

                eventId = @event.Id;
                johnId  = john.Entity.Id;
            }

            // Act
            (ParticipateEventController participateEventController, _) = CreateController(getContext, johnId);

            IActionResult response = await participateEventController.ConfigureNotifications(new NotificationConfigurationDto { EventId = eventId, SendReminderEmail = true, SendSummaryEmail = true, SendLastMinuteChangesEmail = true });

            // Assert
            Assert.IsType <OkResult>(response);
            using (IDatabaseContext context = getContext())
            {
                EventParticipation eventParticipation = context.EventParticipations.Single();
                Assert.True(eventParticipation.SendSummaryEmail);
                Assert.True(eventParticipation.SendLastMinuteChangesEmail);
                Assert.True(eventParticipation.SendReminderEmail);
            }
        }
        public async Task JoinEvent_GivenNotParticipatingUser_UserCanJoin()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int johnDoeId;
            int eventId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                EntityEntry <User> john = context.Users.Add(ContextUtilities.CreateJohnDoe());

                Event @event = DummyEvent(ContextUtilities.CreateRichardRoe());
                context.Events.Add(@event);

                await context.SaveChangesAsync();

                johnDoeId = john.Entity.Id;
                eventId   = @event.Id;
            }

            // Act
            (ParticipateEventController participateEventController, _) = CreateController(getContext, johnDoeId);

            IActionResult response = await participateEventController.JoinEvent(new JoinEventDto
            {
                EventId = eventId
            });

            // Assert
            Assert.IsType <OkResult>(response);
            using (IDatabaseContext context = getContext())
            {
                Event loadedEvent = await context.Events.Include(e => e.EventParticipations).FirstOrDefaultAsync(e => e.Id == eventId);

                Assert.NotNull(loadedEvent);
                Assert.Contains(johnDoeId, loadedEvent.EventParticipations.Select(e => e.ParticipantId));
            }
        }
        public async Task DeleteEvent_GivenEventWithRelations_EventDeleted(bool isPrivate)
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int johnDoeId;
            int eventId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                User john    = ContextUtilities.CreateJohnDoe();
                User richard = ContextUtilities.CreateRichardRoe();

                Event @event = DummyEvent(john, isPrivate);

                context.EventParticipations.Add(new EventParticipation {
                    Event = @event, Participant = john
                });
                context.EventParticipations.Add(new EventParticipation {
                    Event = @event, Participant = richard
                });

                context.EventInvitations.Add(new EventInvitation {
                    Event = @event, Requested = DateTime.UtcNow
                });

                context.ChatMessages.Add(new ChatMessage {
                    Event = @event, Author = john, Content = "Hello World.", SentDate = DateTime.UtcNow
                });

                var appointment = new Appointment {
                    Event = @event, StartTime = DateTime.UtcNow
                };

                context.AppointmentParticipations.Add(new AppointmentParticipation {
                    Appointment = appointment, Participant = john
                });
                context.AppointmentParticipations.Add(new AppointmentParticipation {
                    Appointment = appointment, Participant = richard
                });

                await context.SaveChangesAsync();

                johnDoeId = john.Id;
                eventId   = @event.Id;
            }

            // Act
            (OrganizeEventController controller, Mock <AssertingNotificationService> notificationMock) = CreateController(getContext, johnDoeId);

            notificationMock.Setup(n => n.NotifyEventDeletedAsync(It.Is <EventNotificationInformation>(e => e.Id == eventId))).CallBase();

            IActionResult response = await controller.DeleteEvent(eventId);

            // Assert
            notificationMock.Verify(n => n.NotifyEventDeletedAsync(It.Is <EventNotificationInformation>(e => e.Id == eventId)), Times.Once);

            Assert.IsType <OkResult>(response);
            using (IDatabaseContext context = getContext())
            {
                Assert.Empty(context.Events);
                Assert.Empty(context.EventParticipations);
                Assert.Empty(context.EventInvitations);
                Assert.Empty(context.ChatMessages);
                Assert.Empty(context.Appointments);
                Assert.Empty(context.AppointmentParticipations);
            }
        }
Exemple #15
0
        public async Task DeleteAccount_GivenUserWithEvents_UserAndEventsDeleted()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int johnDoeId;
            int eventId1;
            int eventId2;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                User john    = ContextUtilities.CreateJohnDoe();
                User richard = ContextUtilities.CreateRichardRoe();

                Event event1 = DummyEvent(john);
                Event event2 = DummyEvent(john, true);
                context.EventParticipations.Add(new EventParticipation {
                    Event = event1, Participant = john
                });
                context.EventParticipations.Add(new EventParticipation {
                    Event = event1, Participant = richard
                });
                context.EventParticipations.Add(new EventParticipation {
                    Event = event2, Participant = john
                });
                context.EventParticipations.Add(new EventParticipation {
                    Event = event2, Participant = richard
                });

                context.EventInvitations.Add(new EventInvitation {
                    Event = event1, Requested = DateTime.UtcNow
                });
                context.EventInvitations.Add(new EventInvitation {
                    Event = event2, Requested = DateTime.UtcNow
                });

                context.ChatMessages.Add(new ChatMessage {
                    Event = event1, Author = john, Content = "Hello World.", SentDate = DateTime.UtcNow
                });
                context.ChatMessages.Add(new ChatMessage {
                    Event = event2, Author = john, Content = "Hello World.", SentDate = DateTime.UtcNow
                });

                await context.SaveChangesAsync();

                johnDoeId = john.Id;
                eventId1  = event1.Id;
                eventId2  = event2.Id;
            }

            // Act
            (UserController controller, _, _, Mock <AssertingNotificationService> notificationMock) = CreateController(getContext, johnDoeId);

            notificationMock.Setup(n => n.NotifyEventDeletedAsync(It.Is <EventNotificationInformation>(e => e.Id == eventId1))).CallBase();
            notificationMock.Setup(n => n.NotifyEventDeletedAsync(It.Is <EventNotificationInformation>(e => e.Id == eventId2))).CallBase();

            IActionResult response = await controller.DeleteAccount();

            // Assert
            notificationMock.Verify(n => n.NotifyEventDeletedAsync(It.Is <EventNotificationInformation>(e => e.Id == eventId1)), Times.Once);
            notificationMock.Verify(n => n.NotifyEventDeletedAsync(It.Is <EventNotificationInformation>(e => e.Id == eventId2)), Times.Once);

            Assert.IsType <OkResult>(response);
            using (IDatabaseContext context = getContext())
            {
                Assert.Single(context.Users);
                Assert.Empty(context.Events);
                Assert.Empty(context.EventParticipations);
                Assert.Empty(context.ChatMessages);
            }
        }
Exemple #16
0
        public async Task DeleteAccount_GivenEventOrganizedByOtherUser_PossibleLastMinuteChangesSent()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int johnDoeId;
            int acceptedAppointmentId;
            int declinedAppointmentId;
            int noAnswerAppointmentId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                User john = ContextUtilities.CreateJohnDoe();

                Event @event = DummyEvent(ContextUtilities.CreateRichardRoe());
                context.EventParticipations.Add(new EventParticipation {
                    Event = @event, Participant = john
                });
                var acceptedAppointment = new Appointment {
                    Event = @event, StartTime = DateTime.UtcNow
                };
                var declinedAppointment = new Appointment {
                    Event = @event, StartTime = DateTime.UtcNow
                };
                var noAnswerAppointment = new Appointment {
                    Event = @event, StartTime = DateTime.UtcNow
                };
                context.AppointmentParticipations.Add(new AppointmentParticipation {
                    Appointment = acceptedAppointment, Participant = john, AppointmentParticipationAnswer = AppointmentParticipationAnswer.Accepted
                });
                context.AppointmentParticipations.Add(new AppointmentParticipation {
                    Appointment = declinedAppointment, Participant = john, AppointmentParticipationAnswer = AppointmentParticipationAnswer.Declined
                });
                context.AppointmentParticipations.Add(new AppointmentParticipation {
                    Appointment = noAnswerAppointment, Participant = john, AppointmentParticipationAnswer = null
                });

                await context.SaveChangesAsync();

                johnDoeId             = john.Id;
                acceptedAppointmentId = acceptedAppointment.Id;
                declinedAppointmentId = declinedAppointment.Id;
                noAnswerAppointmentId = noAnswerAppointment.Id;
            }

            // Act
            (UserController controller, _, _, Mock <AssertingNotificationService> notificationMock) = CreateController(getContext, johnDoeId);

            notificationMock.Setup(n => n.SendLastMinuteChangeIfRequiredAsync(It.Is <Appointment>(e => e.Id == acceptedAppointmentId))).CallBase();

            IActionResult response = await controller.DeleteAccount();

            // Assert
            notificationMock.Verify(n => n.SendLastMinuteChangeIfRequiredAsync(It.Is <Appointment>(e => e.Id == acceptedAppointmentId)), Times.Once);
            notificationMock.Verify(n => n.SendLastMinuteChangeIfRequiredAsync(It.Is <Appointment>(e => e.Id == declinedAppointmentId)), Times.Never);
            notificationMock.Verify(n => n.SendLastMinuteChangeIfRequiredAsync(It.Is <Appointment>(e => e.Id == noAnswerAppointmentId)), Times.Never);

            Assert.IsType <OkResult>(response);
            using (IDatabaseContext context = getContext())
            {
                Assert.Single(context.Users);
                Assert.Empty(context.EventParticipations);
                Assert.Empty(context.AppointmentParticipations);
            }
        }
Exemple #17
0
        public async Task GetOverview_GivenParticipatingEvents_ShowsYourAndPublicEvents()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int richardsPublicEventId;
            int richardsPrivateEventId;
            int richardsPublicEventParticipatingId;
            int richardsPrivateEventParticipatingId;
            int johnId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                EntityEntry <User> john = context.Users.Add(ContextUtilities.CreateJohnDoe());
                User richard            = ContextUtilities.CreateRichardRoe();

                Event richardsPublicEvent  = DummyEvent(richard);
                Event richardsPrivateEvent = DummyEvent(richard, true);

                Event richardsPublicEventParticipating  = DummyEvent(richard);
                Event richardsPrivateEventParticipating = DummyEvent(richard, true);

                context.Events.Add(richardsPublicEvent);
                context.Events.Add(richardsPrivateEvent);

                context.Events.Add(richardsPublicEventParticipating);
                context.Events.Add(richardsPrivateEventParticipating);

                context.EventParticipations.Add(new EventParticipation {
                    Participant = john.Entity, Event = richardsPublicEventParticipating
                });
                context.EventParticipations.Add(new EventParticipation {
                    Participant = john.Entity, Event = richardsPrivateEventParticipating
                });

                await context.SaveChangesAsync();

                richardsPublicEventId               = richardsPublicEvent.Id;
                richardsPrivateEventId              = richardsPrivateEvent.Id;
                richardsPublicEventParticipatingId  = richardsPublicEventParticipating.Id;
                richardsPrivateEventParticipatingId = richardsPrivateEventParticipating.Id;
                johnId = john.Entity.Id;
            }

            // Act
            (ParticipateEventController participateEventController, _) = CreateController(getContext, johnId);

            IActionResult response = await participateEventController.GetOverview();

            // Assert
            Assert.IsType <OkObjectResult>(response);
            var okObjectResult = (OkObjectResult)response;
            var eventOverview  = okObjectResult.Value as EventOverview;

            Assert.NotNull(eventOverview);
            Assert.Single(eventOverview.PublicEvents);
            Assert.Equal(2, eventOverview.YourEvents.Count);
            Assert.Contains(richardsPublicEventId, eventOverview.PublicEvents.Select(e => e.EventId));
            Assert.DoesNotContain(richardsPrivateEventId, eventOverview.PublicEvents.Select(e => e.EventId));
            Assert.Contains(richardsPublicEventParticipatingId, eventOverview.YourEvents.Select(e => e.EventId));
            Assert.Contains(richardsPrivateEventParticipatingId, eventOverview.YourEvents.Select(e => e.EventId));
        }
Exemple #18
0
        public async Task GetOverview_GivenSomeEvents_EventsSortedByDateOfUpcomingAppointment()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);

            (Event eventWithoutAppointments, Event eventWithSoonerAppointment, Event eventWithLaterAppointment)yourEvents;
            (Event eventWithoutAppointments, Event eventWithSoonerAppointment, Event eventWithLaterAppointment)publicEvents;

            int johnId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                User john    = ContextUtilities.CreateJohnDoe();
                User richard = ContextUtilities.CreateRichardRoe();

                yourEvents   = CreateEvents(context, john);
                publicEvents = CreateEvents(context, richard);

                await context.SaveChangesAsync();

                johnId = john.Id;
            }

            // Act
            (ParticipateEventController participateEventController, _) = CreateController(getContext, johnId);

            IActionResult response = await participateEventController.GetOverview();

            // Assert
            Assert.IsType <OkObjectResult>(response);
            var okObjectResult = (OkObjectResult)response;
            var eventOverview  = okObjectResult.Value as EventOverview;

            Assert.NotNull(eventOverview);
            AssertEventOrder(eventOverview.YourEvents, yourEvents);
            AssertEventOrder(eventOverview.PublicEvents, publicEvents);

            (Event eventWithoutAppointments, Event eventWithSoonerAppointment, Event eventWithLaterAppointment) CreateEvents(IDatabaseContext context, User organizer)
            {
                Event eventWithoutAppointments   = DummyEvent(organizer);
                Event eventWithSoonerAppointment = DummyEvent(organizer);
                Event eventWithLaterAppointment  = DummyEvent(organizer);

                context.Events.Add(eventWithLaterAppointment);
                context.Events.Add(eventWithSoonerAppointment);
                context.Events.Add(eventWithoutAppointments);

                context.Appointments.Add(new Appointment {
                    Event = eventWithSoonerAppointment, StartTime = DateTime.UtcNow + TimeSpan.FromHours(1)
                });
                context.Appointments.Add(new Appointment {
                    Event = eventWithLaterAppointment, StartTime = DateTime.UtcNow + TimeSpan.FromHours(2)
                });

                return(eventWithoutAppointments, eventWithSoonerAppointment, eventWithLaterAppointment);
            }

            void AssertEventOrder(List <EventOverviewInformation> loadedEvents, (Event eventWithoutAppointments, Event eventWithSoonerAppointment, Event eventWithLaterAppointment) providedEvents)
            {
                Assert.Equal(3, loadedEvents.Count);
                Assert.Equal(providedEvents.eventWithSoonerAppointment.Id, loadedEvents[0].EventId);
                Assert.Equal(providedEvents.eventWithLaterAppointment.Id, loadedEvents[1].EventId);
                Assert.Equal(providedEvents.eventWithoutAppointments.Id, loadedEvents[2].EventId);
            }
        }
        public async Task RemoveFromEvent_GivenParticipatingUser_CanNotRemoveOthersFromEvent()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int johnDoeId;
            int richardId;
            int eventId;
            int appointmentId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                EntityEntry <User> john    = context.Users.Add(ContextUtilities.CreateJohnDoe());
                EntityEntry <User> richard = context.Users.Add(ContextUtilities.CreateRichardRoe());

                Event @event = DummyEvent(richard.Entity);

                context.EventParticipations.Add(new EventParticipation {
                    Participant = richard.Entity, Event = @event
                });

                var appointment = new Appointment
                {
                    Event     = @event,
                    StartTime = DateTime.UtcNow + TimeSpan.FromDays(1)
                };

                context.AppointmentParticipations.Add(new AppointmentParticipation {
                    Appointment = appointment, Participant = richard.Entity
                });

                await context.SaveChangesAsync();

                johnDoeId     = john.Entity.Id;
                richardId     = richard.Entity.Id;
                eventId       = @event.Id;
                appointmentId = appointment.Id;
            }

            // Act
            (ParticipateEventController participateEventController, Mock <AssertingNotificationService> notificationServiceMock) = CreateController(getContext, johnDoeId);

            Expression <Func <AssertingNotificationService, Task> > sendLastMinuteChangeExpression       = n => n.SendLastMinuteChangeIfRequiredAsync(It.Is <Appointment>(a => a.Id == appointmentId));
            Expression <Func <AssertingNotificationService, Task> > notifyOrganizerUpdatedUserExpression = n => n.NotifyOrganizerUpdatedUserInfoAsync(It.Is <Event>(e => e.Id == eventId), It.Is <User>(u => u.Id == richardId), It.IsAny <string>());

            notificationServiceMock.Setup(sendLastMinuteChangeExpression).CallBase();
            notificationServiceMock.Setup(notifyOrganizerUpdatedUserExpression).CallBase();

            IActionResult response = await participateEventController.RemoveFromEvent(new RemoveFromEventDto
            {
                EventId = eventId,
                UserId  = richardId
            });

            // Assert
            Assert.IsType <BadRequestObjectResult>(response);
            var objectResult = (BadRequestObjectResult)response;

            Assert.Equal(RequestStringMessages.OrganizerRequired, objectResult.Value);

            using (IDatabaseContext context = getContext())
            {
                Assert.Single(context.Events);
                Assert.Single(context.EventParticipations);
                Assert.Single(context.Appointments);
                Assert.Single(context.AppointmentParticipations);
            }
        }
        public async Task GetDetails_GivenPublicEvent_OnlyMaxAmountOfAppointmentsReturned()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);
            int      publicEventId;
            int      johnId;
            DateTime earlyStartTime  = DateTime.UtcNow + TimeSpan.FromMinutes(15);
            DateTime middleStartTime = DateTime.UtcNow + TimeSpan.FromMinutes(30);
            DateTime lateStartTime   = DateTime.UtcNow + TimeSpan.FromMinutes(45);

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                EntityEntry <User> john = context.Users.Add(ContextUtilities.CreateJohnDoe());
                User  richard           = ContextUtilities.CreateRichardRoe();
                Event publicEvent       = DummyEvent(richard);
                context.Events.Add(publicEvent);

                // Add an early and late first
                context.Appointments.Add(new Appointment {
                    Event = publicEvent, StartTime = earlyStartTime
                });
                context.Appointments.Add(new Appointment {
                    Event = publicEvent, StartTime = lateStartTime
                });

                // Add some fillers to the middle
                for (var i = 0; i < MaxAmountOfAppointments; i++)
                {
                    context.Appointments.Add(new Appointment {
                        Event = publicEvent, StartTime = middleStartTime
                    });
                }

                // Add an early and late last
                context.Appointments.Add(new Appointment {
                    Event = publicEvent, StartTime = earlyStartTime
                });
                context.Appointments.Add(new Appointment {
                    Event = publicEvent, StartTime = lateStartTime
                });

                await context.SaveChangesAsync();

                publicEventId = publicEvent.Id;
                johnId        = john.Entity.Id;
            }

            // Act
            (ParticipateEventController participateEventController, _) = CreateController(getContext, johnId);

            IActionResult response = await participateEventController.GetDetails(publicEventId);

            // Assert
            Assert.IsType <OkObjectResult>(response);
            var okObjectResult = (OkObjectResult)response;
            var eventDetails   = okObjectResult.Value as EventDetails;

            Assert.NotNull(eventDetails);
            Assert.Equal(MaxAmountOfAppointments, eventDetails.UpcomingAppointments.Count);
            Assert.Equal(2, eventDetails.UpcomingAppointments.Count(a => a.StartTime == earlyStartTime));
            Assert.Equal(MaxAmountOfAppointments - 2, eventDetails.UpcomingAppointments.Count(a => a.StartTime == middleStartTime));
            Assert.Equal(0, eventDetails.UpcomingAppointments.Count(a => a.StartTime == lateStartTime));
        }
Exemple #21
0
        public async Task GetOverview_GivenEventWithAppointments_AppointmentDetailsCorrect()
        {
            GetDatabaseContext getContext = ContextUtilities.CreateInMemoryContext(_output);

            DateTime expectedDateTime = DateTime.UtcNow + TimeSpan.FromDays(1);
            Event    yourEvent;
            Event    publicEvent;
            int      johnId;

            // Arrange
            using (IDatabaseContext context = getContext())
            {
                User john    = ContextUtilities.CreateJohnDoe();
                User richard = ContextUtilities.CreateRichardRoe();

                yourEvent   = CreateEventWithAppointments(context, john, expectedDateTime);
                publicEvent = CreateEventWithAppointments(context, richard, expectedDateTime);

                await context.SaveChangesAsync();

                johnId = john.Id;
            }

            // Act
            (ParticipateEventController participateEventController, _) = CreateController(getContext, johnId);

            IActionResult response = await participateEventController.GetOverview();

            // Assert
            Assert.IsType <OkObjectResult>(response);
            var okObjectResult = (OkObjectResult)response;
            var eventOverview  = okObjectResult.Value as EventOverview;

            Assert.NotNull(eventOverview);
            AssertAppointmentSummary(eventOverview.YourEvents, yourEvent);
            AssertAppointmentSummary(eventOverview.PublicEvents, publicEvent);

            Event CreateEventWithAppointments(IDatabaseContext context, User organizer, DateTime dateOfNewestAppointment)
            {
                Event @event = DummyEvent(organizer);

                context.Events.Add(@event);
                context.Appointments.Add(new Appointment {
                    Event = @event, StartTime = dateOfNewestAppointment + TimeSpan.FromSeconds(1)
                });
                context.Appointments.Add(new Appointment {
                    Event = @event, StartTime = dateOfNewestAppointment
                });
                context.Appointments.Add(new Appointment {
                    Event = @event, StartTime = dateOfNewestAppointment + TimeSpan.FromSeconds(2)
                });

                return(@event);
            }

            // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
            void AssertAppointmentSummary(IReadOnlyList <EventOverviewInformation> loadedEvents, Event expectedEvent)
            {
                Assert.Single(loadedEvents);
                EventOverviewInformation loadedYourEvent = loadedEvents[0];

                Assert.Equal(expectedEvent.Id, loadedYourEvent.EventId);
                Assert.Equal(expectedDateTime, loadedYourEvent.LatestAppointmentInformation.StartTime);
            }
        }