Esempio n. 1
0
        public void username_should_be_null()
        {
            using(var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var user = eventUoW.Users.GetUserByUsername("Laurene");

                user.Should().BeNull();

            }
        }
Esempio n. 2
0
        public void should_return_username()
        {
            using( var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var user = eventUoW.Users.GetUserByUsername("Lars");

                user.Should().NotBeNull();
                user.UserName.Should().Be("Lars");
            }
        }
        public void GetInvitedToEventReturnsOnlyPeopleInvitedToAnEvent()
        {
            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");
                var user3 = context.Users.Single(t => t.UserName == "TestUser3");

                Event e1 = new Event();
                e1.Brief = "User 1 Event";
                e1.Visibility = EventVisibility.Private;
                e1.ModificationState = ModificationState.Added;
                e1.AppUser = user1;
                eventUoW.Events.Attach(e1);

                Invite i1 = new Invite();
                i1.AppUser = user2;
                i1.Event = e1;
                i1.ModificationState = ModificationState.Added;
                eventUoW.Invites.Attach(i1);

                Invite i2 = new Invite();
                i2.AppUser = user3;
                i2.Event = e1;
                i2.ModificationState = ModificationState.Added;
                eventUoW.Invites.Attach(i2);

                eventUoW.Save();
            }

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var e1 = context.Events.Single(t => t.Brief == "User 1 Event");
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");
                var user3 = context.Users.Single(t => t.UserName == "TestUser3");

                var invited = eventUoW.Invites.GetInvitedToEvent(e1);
                invited.Should().HaveCount(2);
                invited.Any(t => t.AppUser == null).Should().BeFalse();
                invited.Any(t => t.AppUser == user1).Should().BeFalse();
                invited.Any(t => t.AppUser == user2).Should().BeTrue();
                invited.Any(t => t.AppUser == user3).Should().BeTrue();
            }
        }
        public void CanCreateNewEvents()
        {
            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));

                Event e = new Event();
                e.Brief = "Test";
                e.Detailed = "Test";
                e.ModificationState = ModificationState.Added;
                e.AppUser = context.Users.Single(t => t.UserName == "TestUser");

                eventUoW.Events.Attach(e);
                eventUoW.Save();
            }

            using (var context = new EventContext())
            {
                Event e = context.Events.Single(t => t.Brief == "Test");
                e.Detailed.Should().Be("Test");
            }
        }
        public void TransferInviteOwnershipShouldTransferAllInvites()
        {
            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");
                var user3 = context.Users.Single(t => t.UserName == "TestUser3");

                Event e1 = new Event();
                e1.Brief = "User 1 Event 1";
                e1.Visibility = EventVisibility.Private;
                e1.ModificationState = ModificationState.Added;
                e1.AppUser = user1;
                eventUoW.Events.Attach(e1);

                Event e2 = new Event();
                e2.Brief = "User 1 Event 2";
                e2.Visibility = EventVisibility.Private;
                e2.ModificationState = ModificationState.Added;
                e2.AppUser = user1;
                eventUoW.Events.Attach(e2);

                Invite i1 = new Invite();
                i1.AppUser = user2;
                i1.Event = e1;
                i1.Status = InviteStatus.Pending;
                i1.ModificationState = ModificationState.Added;
                eventUoW.Invites.Attach(i1);

                Invite i2 = new Invite();
                i2.AppUser = user2;
                i2.Event = e2;
                i2.Status = InviteStatus.Pending;
                i2.ModificationState = ModificationState.Added;
                eventUoW.Invites.Attach(i2);

                eventUoW.Save();
            }

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");
                var user3 = context.Users.Single(t => t.UserName == "TestUser3");

                eventUoW.Invites.TransferInviteOwnership(user2, user3);
                eventUoW.Save();
            }

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");
                var user3 = context.Users.Single(t => t.UserName == "TestUser3");

                context.Invites.Where(t => t.AppUserId == user2.Id).ToList().Should().HaveCount(0);
                context.Invites.Where(t => t.AppUserId == user3.Id).ToList().Should().HaveCount(2);
            }
        }
        public void RemoveInvitesByHostRemovesAllInvitesByASpecificHost()
        {
            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");
                var user3 = context.Users.Single(t => t.UserName == "TestUser3");

                Event e1 = new Event();
                e1.Brief = "User 1 Event 1";
                e1.Visibility = EventVisibility.Private;
                e1.ModificationState = ModificationState.Added;
                e1.AppUser = user1;
                eventUoW.Events.Attach(e1);

                Event e2 = new Event();
                e2.Brief = "User 3 Event 1";
                e2.Visibility = EventVisibility.Private;
                e2.ModificationState = ModificationState.Added;
                e2.AppUser = user3;
                eventUoW.Events.Attach(e2);

                Invite i1 = new Invite();
                i1.AppUser = user2;
                i1.Event = e1;
                i1.Status = InviteStatus.Pending;
                i1.ModificationState = ModificationState.Added;
                eventUoW.Invites.Attach(i1);

                Invite i2 = new Invite();
                i2.AppUser = user2;
                i2.Event = e2;
                i2.Status = InviteStatus.Pending;
                i2.ModificationState = ModificationState.Added;
                eventUoW.Invites.Attach(i2);

                eventUoW.Save();
            }

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");
                var user3 = context.Users.Single(t => t.UserName == "TestUser3");

                eventUoW.Invites.RemoveInvitesByHost(user2, user1);
                eventUoW.Save();
            }

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");
                var user3 = context.Users.Single(t => t.UserName == "TestUser3");

                var invites = context.Invites.Include(t => t.Event).Where(t => t.AppUserId == user2.Id).ToList();

                invites.Any(t => t.Event.OwnerId == user1.Id).Should().BeFalse();
            }
        }
        public void MarkAllInvitesAsSeenShouldResetTheUnseenInviteCount()
        {
            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");

                Event e1 = new Event();
                e1.Brief = "User 1 Event 1";
                e1.Visibility = EventVisibility.Private;
                e1.ModificationState = ModificationState.Added;
                e1.AppUser = user1;
                eventUoW.Events.Attach(e1);

                Event e2 = new Event();
                e2.Brief = "User 1 Event 2";
                e2.Visibility = EventVisibility.Private;
                e2.ModificationState = ModificationState.Added;
                e2.AppUser = user1;
                eventUoW.Events.Attach(e2);

                Invite i1 = new Invite();
                i1.AppUser = user2;
                i1.Event = e1;
                i1.Status = InviteStatus.Pending;
                i1.ModificationState = ModificationState.Added;
                eventUoW.Invites.Attach(i1);

                Invite i2 = new Invite();
                i2.AppUser = user2;
                i2.Event = e2;
                i2.Status = InviteStatus.Pending;
                i2.ModificationState = ModificationState.Added;
                eventUoW.Invites.Attach(i2);

                eventUoW.Save();
            }

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");

                var count = eventUoW.Invites.GetUnseenPendingInvitesCount(user2);
                count.Should().Be(2);

                eventUoW.Invites.MarkAllInvitesAsSeen(user2);
                eventUoW.Save();
            }

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");

                var count = eventUoW.Invites.GetUnseenPendingInvitesCount(user2);
                count.Should().Be(0);
            }
        }
        public void IsInvitedIsOnlyTrueWhenTheUserIsInvitedToAnEvent()
        {
            int id = 0;
            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");
                var user3 = context.Users.Single(t => t.UserName == "TestUser3");

                Event e1 = new Event();
                e1.Brief = "User 1 Event";
                e1.Visibility = EventVisibility.Private;
                e1.ModificationState = ModificationState.Added;
                e1.AppUser = user1;
                eventUoW.Events.Attach(e1);

                Invite i1 = new Invite();
                i1.AppUser = user2;
                i1.Event = e1;
                i1.ModificationState = ModificationState.Added;
                eventUoW.Invites.Attach(i1);

                eventUoW.Save();
                id = e1.Id;
            }

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");
                var user3 = context.Users.Single(t => t.UserName == "TestUser3");
                var e = eventUoW.Events.GetEventByID(id);

                eventUoW.Invites.IsInvited(e, user2).Should().BeTrue();
                eventUoW.Invites.IsInvited(e, user3).Should().BeFalse();
            }
        }
        public void GetPendingInvitesWithEventGraphReturnsOnlyEventsTheUserIsInvitedTo()
        {
            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");
                var user3 = context.Users.Single(t => t.UserName == "TestUser3");

                Event e1 = new Event();
                e1.Brief = "User 1 Event 1";
                e1.Visibility = EventVisibility.Private;
                e1.ModificationState = ModificationState.Added;
                e1.AppUser = user1;
                eventUoW.Events.Attach(e1);

                Event e2 = new Event();
                e2.Brief = "User 1 Event 2";
                e2.Visibility = EventVisibility.Private;
                e2.ModificationState = ModificationState.Added;
                e2.AppUser = user1;
                eventUoW.Events.Attach(e2);

                Event e3 = new Event();
                e3.Brief = "User 2 Event";
                e3.Visibility = EventVisibility.Private;
                e3.ModificationState = ModificationState.Added;
                e3.AppUser = user2;
                eventUoW.Events.Attach(e3);

                Invite i1 = new Invite();
                i1.AppUser = user2;
                i1.Event = e1;
                i1.ModificationState = ModificationState.Added;
                eventUoW.Invites.Attach(i1);

                Invite i2 = new Invite();
                i2.AppUser = user3;
                i2.Event = e1;
                i2.ModificationState = ModificationState.Added;
                eventUoW.Invites.Attach(i2);

                Invite i3 = new Invite();
                i3.AppUser = user1;
                i3.Event = e2;
                i3.ModificationState = ModificationState.Added;
                eventUoW.Invites.Attach(i3);

                eventUoW.Save();
            }

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");
                var user3 = context.Users.Single(t => t.UserName == "TestUser3");

                var invites = eventUoW.Invites.GetPendingInvitesWithEventGraph(user2);

                invites.Should().HaveCount(1);
                invites.Single().Event.Brief.Should().Be("User 1 Event 1");
            }
        }
        public void ChangingAnEventDisconnectedDoesNotCreateDuplicates()
        {
            Event e;
            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);

                e = new Event();
                e.Brief = "Test";
                e.Detailed = "Test";
                e.ModificationState = ModificationState.Added;
                e.AppUser = context.Users.Single(t => t.UserName == "TestUser");

                eventUoW.Events.Attach(e);
                eventUoW.Save();
            }

            e.Brief = "MyBrief";
            e.Detailed = "MyDetailed";
            e.ModificationState = ModificationState.Modified;

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                eventUoW.Events.Attach(e);
                eventUoW.Save();
            }

            using (var context = new EventContext())
            {
                context.Invoking(t => t.Events.Single()).ShouldNotThrow();
            }
        }
        public void TransferEventOwnershipTransfersAllEvents()
        {
            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");

                Event e1 = new Event();
                e1.Brief = "User 1 Event";
                e1.ModificationState = ModificationState.Added;
                e1.AppUser = user1;
                eventUoW.Events.Attach(e1);

                Event e2 = new Event();
                e2.Brief = "User 2 Event 1";
                e2.ModificationState = ModificationState.Added;
                e2.AppUser = user2;
                eventUoW.Events.Attach(e2);

                Event e3 = new Event();
                e3.Brief = "User 2 Event 2";
                e3.ModificationState = ModificationState.Added;
                e3.AppUser = user2;
                eventUoW.Events.Attach(e3);

                eventUoW.Save();
            }

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);

                context.Events.ToList();
                context.Invites.ToList();

                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");

                eventUoW.Events.TransferEventOwnership(user2, user1);
                eventUoW.Save();
            }

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");

                eventUoW.Events.GetAllCreatedEvents(user1).Should().HaveCount(3);
                eventUoW.Events.GetAllCreatedEvents(user2).Should().HaveCount(0);
            }
        }
        public void LoadUserGraphMakesTheOwnerNodeAccessible()
        {
            int id = 0;
            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");

                Event e1 = new Event();
                e1.Brief = "User 1 Event";
                e1.Visibility = EventVisibility.Private;
                e1.ModificationState = ModificationState.Added;
                e1.AppUser = user1;

                eventUoW.Events.Attach(e1);
                eventUoW.Save();

                id = e1.Id;
            }

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var e = eventUoW.Events.GetEventByID(id);

                e.AppUser.Should().BeNull();
                eventUoW.Events.LoadUserGraph(e);
                e.AppUser.UserName.Should().Be("TestUser");
            }
        }
        public void GetEventByIdReturnsCorrectEvent()
        {
            int id1 = 0;
            int id2 = 0;
            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");

                Event e1 = new Event();
                e1.Brief = "User 1 Event";
                e1.Visibility = EventVisibility.Private;
                e1.ModificationState = ModificationState.Added;
                e1.AppUser = user1;

                Event e2 = new Event();
                e2.Brief = "User 2 Event";
                e2.Visibility = EventVisibility.Private;
                e2.ModificationState = ModificationState.Added;
                e2.AppUser = user2;

                eventUoW.Events.Attach(e1);
                eventUoW.Events.Attach(e2);
                eventUoW.Save();

                id1 = e1.Id;
                id2 = e2.Id;
            }

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                eventUoW.Events.GetEventByID(id1).Brief.Should().Be("User 1 Event");
                eventUoW.Events.GetEventByID(id2).Brief.Should().Be("User 2 Event");
            }
        }
        public void GetAllPublicEventsOnlyReturnsPublic()
        {
            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user = context.Users.Single(t => t.UserName == "TestUser");

                Event pub = new Event();
                pub.Brief = "Public";
                pub.Visibility = EventVisibility.Public;
                pub.ModificationState = ModificationState.Added;
                pub.AppUser = user;

                Event pri = new Event();
                pri.Brief = "Private";
                pri.Visibility = EventVisibility.Private;
                pri.ModificationState = ModificationState.Added;
                pri.AppUser = user;

                eventUoW.Events.Attach(pub);
                eventUoW.Events.Attach(pri);
                eventUoW.Save();
            }

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);

                List<Event> events = eventUoW.Events.GetAllPublicEvents();

                events.Should().HaveCount(1);
                events[0].Brief.Should().Be("Public");
            }
        }
        public void GetAllPublicEventsOfUserReturnsCorrect()
        {
            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var user = context.Users.SingleOrDefault(t => t.UserName == "TestUser");
                var user2 = context.Users.SingleOrDefault(t => t.UserName == "TestUser2");

                Event e1 = new Event();
                e1.Brief = "User 1 Event";
                e1.Visibility = EventVisibility.Private;
                e1.ModificationState = ModificationState.Added;
                e1.AppUser = user;

                Event e2 = new Event();
                e2.Brief = "User 1 Event";
                e2.Visibility = EventVisibility.Public;
                e2.ModificationState = ModificationState.Added;
                e2.AppUser = user;

                Event e3 = new Event();
                e3.Brief = "User 2 Event";
                e3.Visibility = EventVisibility.Public;
                e3.ModificationState = ModificationState.Added;
                e3.AppUser = user2;

                eventUoW.Events.Attach(e1);
                eventUoW.Events.Attach(e2);
                eventUoW.Events.Attach(e3);
                eventUoW.Save();

            }
            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var user = context.Users.SingleOrDefault(t => t.UserName == "TestUser");
                var e = eventUoW.Events.GetAllPublicEventsOfUser(user);

                e.Should().HaveCount(1);
                e[0].Visibility.Should().Be(EventVisibility.Public);
                e[0].OwnerId.Should().Be(user.Id);
            }
        }
        public void GetAllInvitedEventsOnlyReturnsEventsThisUserIsInvitedTo()
        {
            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user1 = context.Users.Single(t => t.UserName == "TestUser");
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");

                Event e1 = new Event();
                e1.Brief = "User 1 Event";
                e1.Visibility = EventVisibility.Private;
                e1.ModificationState = ModificationState.Added;
                e1.AppUser = user1;
                eventUoW.Events.Attach(e1);

                Event e2 = new Event();
                e2.Brief = "User 2 Event";
                e2.Visibility = EventVisibility.Private;
                e2.ModificationState = ModificationState.Added;
                e2.AppUser = user2;
                eventUoW.Events.Attach(e2);

                Event e3 = new Event();
                e3.Brief = "User 1 Public Event";
                e3.Visibility = EventVisibility.Public;
                e3.ModificationState = ModificationState.Added;
                e3.AppUser = user1;
                eventUoW.Events.Attach(e3);

                Invite i = new Invite();
                i.AppUser = user2;
                i.Event = e1;
                i.ModificationState = ModificationState.Added;
                eventUoW.Invites.Attach(i);

                eventUoW.Save();
            }

            using (var context = new EventContext())
            {
                var eventUoW = new EventUnitOfWork(context);
                var userManager = new UserManager<AppUser>(new UserStore<AppUser>(context));
                var user2 = context.Users.Single(t => t.UserName == "TestUser2");

                List<Event> events = eventUoW.Events.GetAllInvitedEvents(user2);

                events.Should().HaveCount(1);
                events[0].Brief.Should().Be("User 1 Event");
            }
        }