コード例 #1
0
        public async Task SetUserSkillsToNull_WhenAppUserIsNotNull_AndAppUserseAssociatedSkillsIsNull_AndEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            var options = this.CreateNewContextOptions();

            const int    eventId = 1;
            const string userId  = "asdfasdf";

            var appUser = new ApplicationUser()
            {
                Id = userId,
                AssociatedSkills = null
            };
            var message = new ShowEventQuery()
            {
                EventId = eventId, User = new ClaimsPrincipal()
            };

            var userManager = CreateUserManagerMock();

            userManager.Setup(x => x.GetUserId(message.User)).Returns(appUser.Id);

            using (var context = new AllReadyContext(options)) {
                context.Users.Add(appUser);
                context.Events.Add(CreateAllReadyEventWithTasks(message.EventId, appUser));
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options)) {
                var sut            = new ShowEventQueryHandler(context, userManager.Object);
                var eventViewModel = sut.Handle(message);

                eventViewModel.UserSkills.ShouldBeEmpty();
            }
        }
コード例 #2
0
        public async Task InvokeGetUserIdWithTheCorrectUser_WhenEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            var options = this.CreateNewContextOptions();

            const int    eventId = 1;
            const string userId  = "1";
            var          message = new ShowEventQuery {
                EventId = eventId, User = new ClaimsPrincipal()
            };

            var userManager = CreateUserManagerMock();

            userManager.Setup(x => x.GetUserId(It.IsAny <ClaimsPrincipal>())).Returns(userId);

            using (var context = new AllReadyContext(options)) {
                context.Events.Add(new Models.Event {
                    Id       = eventId,
                    Campaign = new Campaign {
                        Locked = false
                    }
                });
                context.Users.Add(new ApplicationUser {
                    Id = userId
                });
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options)) {
                var sut = new ShowEventQueryHandler(context, userManager.Object);
                sut.Handle(message);

                userManager.Verify(x => x.GetUserId(message.User), Times.Once);
            }
        }
コード例 #3
0
        public void SetIsUserVolunteerdForEventToTrue_WhenThereAreEventSignupsForTheEventAndTheUser_AndEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            var appUser = new ApplicationUser()
            {
                Id = "asdfasfd"
            };
            var message = new ShowEventQuery()
            {
                EventId = 1, User = new ClaimsPrincipal()
            };
            var dataAccess  = new Mock <IAllReadyDataAccess>();
            var userManager = CreateUserManagerMock();

            userManager.Setup(x => x.GetUserId(message.User)).Returns(appUser.Id);
            dataAccess.Setup(x => x.GetUser(appUser.Id)).Returns(appUser);
            dataAccess.Setup(x => x.GetEvent(message.EventId)).Returns(CreateAllReadyEventWithTasks(message.EventId, appUser));
            dataAccess.Setup(x => x.GetEventSignups(message.EventId, appUser.Id)).Returns(new List <EventSignup>()
            {
                new EventSignup()
            });

            var sut            = new ShowEventQueryHandler(dataAccess.Object, userManager.Object);
            var eventViewModel = sut.Handle(message);

            Assert.True(eventViewModel.IsUserVolunteeredForEvent);
        }
コード例 #4
0
        public void SetTasksToListOfTaskViewModelForAnyTasksWhereTheUserHasNotVolunteeredInAscendingOrderByTaskStartDateTime_WhenThereAreNoEventSignupsForTheEventAndTheUser_AndEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            var appUser = new ApplicationUser()
            {
                Id = "asdfasfd"
            };
            var message = new ShowEventQuery()
            {
                EventId = 1, User = new ClaimsPrincipal()
            };
            var dataAccess  = new Mock <IAllReadyDataAccess>();
            var userManager = CreateUserManagerMock();

            userManager.Setup(x => x.GetUserId(message.User)).Returns(appUser.Id);
            dataAccess.Setup(x => x.GetUser(appUser.Id)).Returns(appUser);
            var allReadyEvent = CreateAllReadyEventWithTasks(message.EventId, appUser);

            dataAccess.Setup(x => x.GetEvent(message.EventId)).Returns(allReadyEvent);
            dataAccess.Setup(x => x.GetEventSignups(message.EventId, appUser.Id)).Returns(new List <EventSignup>());

            var sut            = new ShowEventQueryHandler(dataAccess.Object, userManager.Object);
            var eventViewModel = sut.Handle(message);

            Assert.Equal(allReadyEvent.Tasks.Where(x => !x.AssignedVolunteers.Any(v => v.User.Id.Equals(appUser.Id))).Count(),
                         eventViewModel.Tasks.Count);
            var previousDateTime = DateTimeOffset.MinValue;

            foreach (var userTask in eventViewModel.Tasks)
            {
                Assert.True(userTask.StartDateTime > previousDateTime);
                previousDateTime = userTask.StartDateTime;
            }
        }
コード例 #5
0
        public void SetsEventSignupViewModel_WithTheCorrectData()
        {
            var appUser = new ApplicationUser()
            {
                Id          = "asdfasasdfaf",
                Email       = "*****@*****.**",
                FirstName   = "Foo",
                LastName    = "Bar",
                PhoneNumber = "555-555-5555",
            };
            var message = new ShowEventQuery()
            {
                EventId = 1, User = new ClaimsPrincipal()
            };
            var dataAccess  = new Mock <IAllReadyDataAccess>();
            var userManager = CreateUserManagerMock();

            userManager.Setup(x => x.GetUserId(message.User)).Returns(appUser.Id);
            dataAccess.Setup(x => x.GetUser(appUser.Id)).Returns(appUser);
            dataAccess.Setup(x => x.GetEvent(message.EventId)).Returns(CreateAllReadyEventWithTasks(message.EventId, appUser));

            var sut            = new ShowEventQueryHandler(dataAccess.Object, userManager.Object);
            var eventViewModel = sut.Handle(message);

            Assert.Equal(message.EventId, eventViewModel.SignupModel.EventId);
            Assert.Equal(appUser.Id, eventViewModel.SignupModel.UserId);
            Assert.Equal($"{appUser.FirstName} {appUser.LastName}", eventViewModel.SignupModel.Name);
            Assert.Equal(appUser.Email, eventViewModel.SignupModel.PreferredEmail);
            Assert.Equal(appUser.PhoneNumber, eventViewModel.SignupModel.PreferredPhoneNumber);
        }
コード例 #6
0
        public void InvokeGetEventSignupsWithCorrectParameters_WhenEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            const string userId  = "1";
            var          message = new ShowEventQuery {
                User = new ClaimsPrincipal()
            };
            var @event = new Models.Event {
                Campaign = new Campaign {
                    Locked = false
                }
            };

            var dataAccess = new Mock <IAllReadyDataAccess>();

            dataAccess.Setup(x => x.GetEvent(It.IsAny <int>())).Returns(@event);
            dataAccess.Setup(x => x.GetUser(It.IsAny <string>())).Returns(new ApplicationUser());

            var userManager = CreateUserManagerMock();

            userManager.Setup(x => x.GetUserId(It.IsAny <ClaimsPrincipal>())).Returns(userId);

            var sut = new ShowEventQueryHandler(dataAccess.Object, userManager.Object);

            sut.Handle(message);

            dataAccess.Verify(x => x.GetEventSignups(@event.Id, userId), Times.Once);
        }
コード例 #7
0
        public async Task SetTasksToListOfTaskViewModelForAnyTasksWhereTheUserHasNotVolunteeredInAscendingOrderByTaskStartDateTime_AndEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            var options = CreateNewContextOptions();

            const int eventId = 1;
            const string userId = "asdfasdf";

            var appUser = new ApplicationUser { Id = userId };
            var message = new ShowEventQuery { EventId = eventId, UserId = userId };
            var allReadyEvent = CreateAllReadyEventWithTasks(message.EventId, appUser);

            using (var context = new AllReadyContext(options))
            {
                context.Users.Add(appUser);
                context.Events.Add(allReadyEvent);
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options))
            {
                var sut = new ShowEventQueryHandler(context);
                var eventViewModel = await sut.Handle(message);

                Assert.Equal(allReadyEvent.Tasks.Where(x => !x.AssignedVolunteers.Any(v => v.User.Id.Equals(appUser.Id))).Count(),
                    eventViewModel.Tasks.Count);
                var previousDateTime = DateTimeOffset.MinValue;
                foreach (var userTask in eventViewModel.Tasks)
                {
                    Assert.True(userTask.StartDateTime > previousDateTime);
                    previousDateTime = userTask.StartDateTime;
                }
            }
        }
コード例 #8
0
        public async Task SetsTaskSignupViewModel_WithTheCorrectData()
        {
            var options = CreateNewContextOptions();

            var appUser = new ApplicationUser
            {
                Id = "asdfasasdfaf",
                Email = "*****@*****.**",
                FirstName = "Foo",
                LastName = "Bar",
                PhoneNumber = "555-555-5555",
            };

            var message = new ShowEventQuery { EventId = 1, UserId = appUser.Id };

            using (var context = new AllReadyContext(options))
            {
                context.Users.Add(appUser);
                context.Events.Add(CreateAllReadyEventWithTasks(message.EventId, appUser));
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options))
            {
                var sut = new ShowEventQueryHandler(context);
                var eventViewModel = await sut.Handle(message);

                Assert.Equal(message.EventId, eventViewModel.SignupModel.EventId);
                Assert.Equal(appUser.Id, eventViewModel.SignupModel.UserId);
                Assert.Equal($"{appUser.FirstName} {appUser.LastName}", eventViewModel.SignupModel.Name);
            }
        }
コード例 #9
0
        public async Task ReturnNullWhenEventsCampaignIsLocked()
        {
            var options = CreateNewContextOptions();

            const int eventId = 1;
            var message = new ShowEventQuery { EventId = eventId };

            using (var context = new AllReadyContext(options))
            {
                context.Events.Add(new Models.Event
                {
                    Id = eventId,
                    Campaign = new Campaign { Locked = true }
                });
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options))
            {
                var sut = new ShowEventQueryHandler(context);
                var result = await sut.Handle(message);

                result.ShouldBeNull();
            }
        }
コード例 #10
0
        public void SetsEventSignupViewModel_WithTheCorrectData()
        {
            var appUser = new ApplicationUser()
            {
                Id = "asdfasasdfaf",
                Email = "*****@*****.**",
                FirstName = "Foo",
                LastName = "Bar",
                PhoneNumber = "555-555-5555",
            };
            var message = new ShowEventQuery() { EventId = 1, User = new ClaimsPrincipal() };
            var dataAccess = new Mock<IAllReadyDataAccess>();
            var userManager = CreateUserManagerMock();
            userManager.Setup(x => x.GetUserId(message.User)).Returns(appUser.Id);
            dataAccess.Setup(x => x.GetUser(appUser.Id)).Returns(appUser);
            dataAccess.Setup(x => x.GetEvent(message.EventId)).Returns(CreateAllReadyEventWithTasks(message.EventId, appUser));

            var sut = new ShowEventQueryHandler(dataAccess.Object, userManager.Object);
            var eventViewModel = sut.Handle(message);

            Assert.Equal(message.EventId, eventViewModel.SignupModel.EventId);
            Assert.Equal(appUser.Id, eventViewModel.SignupModel.UserId);
            Assert.Equal($"{appUser.FirstName} {appUser.LastName}", eventViewModel.SignupModel.Name);
            Assert.Equal(appUser.Email, eventViewModel.SignupModel.PreferredEmail);
            Assert.Equal(appUser.PhoneNumber, eventViewModel.SignupModel.PreferredPhoneNumber);
        }
コード例 #11
0
        public async Task SetUserSkillsToNull_WhenAppUserIsNull_AndEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            var options = CreateNewContextOptions();

            const int eventId = 1;
            const string userId = "asdfasdf";

            var appUser = new ApplicationUser { Id = userId };
            var message = new ShowEventQuery { EventId = eventId, UserId = userId };

            using (var context = new AllReadyContext(options))
            {
                context.Users.Add(appUser);
                context.Events.Add(CreateAllReadyEventWithTasks(message.EventId, appUser));
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options))
            {
                var sut = new ShowEventQueryHandler(context);
                var eventViewModel = await sut.Handle(message);

                eventViewModel.UserSkills.ShouldBeEmpty();
            }
        }
コード例 #12
0
        public void ReturnNullWhenEventsCampaignIslocked()
        {
            var dataAccess = new Mock<IAllReadyDataAccess>();
            dataAccess.Setup(x => x.GetEvent(It.IsAny<int>())).Returns(new Models.Event { Campaign = new Campaign { Locked = true }});

            var sut = new ShowEventQueryHandler(dataAccess.Object, null);
            var result = sut.Handle(new ShowEventQuery());

            result.ShouldBeNull();
        }
コード例 #13
0
        public void ReturnNullWhenEventIsNotFound()
        {
            var dataAccess = new Mock<IAllReadyDataAccess>();
            dataAccess.Setup(x => x.GetEvent(It.IsAny<int>())).Returns<Models.Event>(null);

            var sut = new ShowEventQueryHandler(dataAccess.Object, null);
            var result = sut.Handle(new ShowEventQuery());

            result.ShouldBeNull();
        }
コード例 #14
0
        public void InvokeGetEventWithTheCorrectEventId()
        {
            var message = new ShowEventQuery { EventId = 1 };
            var dataAccess = new Mock<IAllReadyDataAccess>();

            var sut = new ShowEventQueryHandler(dataAccess.Object, null);
            sut.Handle(message);

            dataAccess.Verify(x => x.GetEvent(message.EventId), Times.Once);
        }
コード例 #15
0
 public void WhenEventNotFoundReturnsNull()
 {
     var showEventCommand = new ShowEventQuery { EventId = 1 };
     var dataAccess = new Mock<IAllReadyDataAccess>();
     dataAccess.Setup(x => x.GetEvent(showEventCommand.EventId))
               .Returns<Models.Event>(null);
     var sut = new ShowEventQueryHandler(dataAccess.Object, null, null);
     var viewModel = sut.Handle(showEventCommand);
     viewModel.ShouldBeNull();
 }
コード例 #16
0
        public void ReturnNullWhenEventIsNotFound()
        {
            var dataAccess = new Mock <IAllReadyDataAccess>();

            dataAccess.Setup(x => x.GetEvent(It.IsAny <int>())).Returns <Models.Event>(null);

            var sut    = new ShowEventQueryHandler(dataAccess.Object, null);
            var result = sut.Handle(new ShowEventQuery());

            result.ShouldBeNull();
        }
コード例 #17
0
 public void WhenEventCampaignIsLockedReturnsNull()
 {
     var showEventCommand = new ShowEventQuery { EventId = 1 };
     var mockDbAccess = new Mock<IAllReadyDataAccess>();
     var expectedEvent = new Models.Event { Campaign = new Campaign { Locked = true } };
     mockDbAccess.Setup(x => x.GetEvent(showEventCommand.EventId))
                 .Returns(expectedEvent);
     var sut = new ShowEventQueryHandler(mockDbAccess.Object, null, null);
     var viewModel = sut.Handle(showEventCommand);
     viewModel.ShouldBeNull();
 }
コード例 #18
0
 public void HappyPath()
 {
     var showEventCommand = new ShowEventQuery { EventId = 1, User = ClaimsPrincipal.Current };
     var mockDbAccess = new Mock<IAllReadyDataAccess>();
     var expectedEvent = new Models.Event { Campaign = new Campaign { Locked = false } };
     mockDbAccess.Setup(x => x.GetEvent(showEventCommand.EventId))
                 .Returns(expectedEvent);
     var sut = new ShowEventQueryHandler(mockDbAccess.Object, null, null);
     var viewModel = sut.Handle(showEventCommand);
     viewModel.ShouldNotBeNull();
 }
コード例 #19
0
        public void InvokeGetEventWithTheCorrectEventId()
        {
            var message = new ShowEventQuery {
                EventId = 1
            };
            var dataAccess = new Mock <IAllReadyDataAccess>();

            var sut = new ShowEventQueryHandler(dataAccess.Object, null);

            sut.Handle(message);

            dataAccess.Verify(x => x.GetEvent(message.EventId), Times.Once);
        }
コード例 #20
0
        public void WhenEventNotFoundReturnsNull()
        {
            var showEventCommand = new ShowEventQuery {
                EventId = 1
            };
            var dataAccess = new Mock <IAllReadyDataAccess>();

            dataAccess.Setup(x => x.GetEvent(showEventCommand.EventId))
            .Returns <Models.Event>(null);
            var sut       = new ShowEventQueryHandler(dataAccess.Object);
            var viewModel = sut.Handle(showEventCommand);

            viewModel.ShouldBeNull();
        }
コード例 #21
0
        public void InvokeGetUserIdWithTheCorrectUser_WhenEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            var message = new ShowEventQuery { User = new ClaimsPrincipal() };

            var dataAccess = new Mock<IAllReadyDataAccess>();
            dataAccess.Setup(x => x.GetEvent(It.IsAny<int>())).Returns(new Models.Event { Campaign = new Campaign { Locked = false }});
            dataAccess.Setup(x => x.GetUser(It.IsAny<string>())).Returns(new ApplicationUser());

            var userManager = CreateUserManagerMock();

            var sut = new ShowEventQueryHandler(dataAccess.Object, userManager.Object);
            sut.Handle(message);

            userManager.Verify(x => x.GetUserId(message.User), Times.Once);
        }
コード例 #22
0
        public void ReturnNullWhenEventsCampaignIslocked()
        {
            var dataAccess = new Mock <IAllReadyDataAccess>();

            dataAccess.Setup(x => x.GetEvent(It.IsAny <int>())).Returns(new Models.Event {
                Campaign = new Campaign {
                    Locked = true
                }
            });

            var sut    = new ShowEventQueryHandler(dataAccess.Object, null);
            var result = sut.Handle(new ShowEventQuery());

            result.ShouldBeNull();
        }
コード例 #23
0
        public void InvokeGetEventSignupsWithCorrectParameters_WhenEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            const string userId = "1";
            var message = new ShowEventQuery { User = new ClaimsPrincipal() };
            var @event = new Models.Event { Campaign = new Campaign { Locked = false }};

            var dataAccess = new Mock<IAllReadyDataAccess>();
            dataAccess.Setup(x => x.GetEvent(It.IsAny<int>())).Returns(@event);
            dataAccess.Setup(x => x.GetUser(It.IsAny<string>())).Returns(new ApplicationUser());

            var userManager = CreateUserManagerMock();
            userManager.Setup(x => x.GetUserId(It.IsAny<ClaimsPrincipal>())).Returns(userId);

            var sut = new ShowEventQueryHandler(dataAccess.Object, userManager.Object);
            sut.Handle(message);

            dataAccess.Verify(x => x.GetEventSignups(@event.Id, userId), Times.Once);
        }
コード例 #24
0
        public void HappyPath()
        {
            var showEventCommand = new ShowEventQuery {
                EventId = 1, User = ClaimsPrincipal.Current
            };
            var mockDbAccess  = new Mock <IAllReadyDataAccess>();
            var expectedEvent = new Models.Event {
                Campaign = new Campaign {
                    Locked = false
                }
            };

            mockDbAccess.Setup(x => x.GetEvent(showEventCommand.EventId))
            .Returns(expectedEvent);
            var sut       = new ShowEventQueryHandler(mockDbAccess.Object);
            var viewModel = sut.Handle(showEventCommand);

            viewModel.ShouldNotBeNull();
        }
コード例 #25
0
        public void WhenEventCampaignIsLockedReturnsNull()
        {
            var showEventCommand = new ShowEventQuery {
                EventId = 1
            };
            var mockDbAccess  = new Mock <IAllReadyDataAccess>();
            var expectedEvent = new Models.Event {
                Campaign = new Campaign {
                    Locked = true
                }
            };

            mockDbAccess.Setup(x => x.GetEvent(showEventCommand.EventId))
            .Returns(expectedEvent);
            var sut       = new ShowEventQueryHandler(mockDbAccess.Object);
            var viewModel = sut.Handle(showEventCommand);

            viewModel.ShouldBeNull();
        }
コード例 #26
0
        public async Task ReturnNullWhenEventIsNotFound()
        {
            var options = CreateNewContextOptions();

            var message = new ShowEventQuery { EventId = 1 };

            using (var context = new AllReadyContext(options))
            {
                // add nothing
                //await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options))
            {
                var sut = new ShowEventQueryHandler(context);
                var result = await sut.Handle(message);

                result.ShouldBeNull();
            }
        }
コード例 #27
0
        public void SetUserSkillsToNull_WhenAppUserIsNull_AndEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            var appUser = new ApplicationUser()
            {
                Id = "asdfasdf"
            };
            var message = new ShowEventQuery()
            {
                EventId = 1, User = new ClaimsPrincipal()
            };
            var dataAccess  = new Mock <IAllReadyDataAccess>();
            var userManager = CreateUserManagerMock();

            userManager.Setup(x => x.GetUserId(message.User)).Returns("adfasdfaf");
            dataAccess.Setup(x => x.GetEvent(message.EventId)).Returns(CreateAllReadyEventWithTasks(message.EventId, appUser));

            var sut            = new ShowEventQueryHandler(dataAccess.Object, userManager.Object);
            var eventViewModel = sut.Handle(message);

            Assert.Null(eventViewModel.UserSkills);
        }
コード例 #28
0
        public void InvokeGetUserIdWithTheCorrectUser_WhenEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            var message = new ShowEventQuery {
                User = new ClaimsPrincipal()
            };

            var dataAccess = new Mock <IAllReadyDataAccess>();

            dataAccess.Setup(x => x.GetEvent(It.IsAny <int>())).Returns(new Models.Event {
                Campaign = new Campaign {
                    Locked = false
                }
            });
            dataAccess.Setup(x => x.GetUser(It.IsAny <string>())).Returns(new ApplicationUser());

            var userManager = CreateUserManagerMock();

            var sut = new ShowEventQueryHandler(dataAccess.Object, userManager.Object);

            sut.Handle(message);

            userManager.Verify(x => x.GetUserId(message.User), Times.Once);
        }
コード例 #29
0
        public async Task SetsTaskSignupViewModel_WithTheCorrectData()
        {
            var options = this.CreateNewContextOptions();

            var appUser = new ApplicationUser()
            {
                Id          = "asdfasasdfaf",
                Email       = "*****@*****.**",
                FirstName   = "Foo",
                LastName    = "Bar",
                PhoneNumber = "555-555-5555",
            };
            var message = new ShowEventQuery()
            {
                EventId = 1, User = new ClaimsPrincipal()
            };
            var userManager = CreateUserManagerMock();

            userManager.Setup(x => x.GetUserId(message.User)).Returns(appUser.Id);

            using (var context = new AllReadyContext(options)) {
                context.Users.Add(appUser);
                context.Events.Add(CreateAllReadyEventWithTasks(message.EventId, appUser));
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options)) {
                var sut            = new ShowEventQueryHandler(context, userManager.Object);
                var eventViewModel = sut.Handle(message);

                Assert.Equal(message.EventId, eventViewModel.SignupModel.EventId);
                Assert.Equal(appUser.Id, eventViewModel.SignupModel.UserId);
                Assert.Equal($"{appUser.FirstName} {appUser.LastName}", eventViewModel.SignupModel.Name);
                Assert.Equal(appUser.Email, eventViewModel.SignupModel.PreferredEmail);
                Assert.Equal(appUser.PhoneNumber, eventViewModel.SignupModel.PreferredPhoneNumber);
            }
        }
コード例 #30
0
        public void SetUserSkillsToNull_WhenAppUserIsNotNull_AndAppUserseAssociatedSkillsIsNull_AndEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            var appUser = new ApplicationUser()
            {
                Id = "asdfasfd",
                AssociatedSkills = null
            };
            var message = new ShowEventQuery() { EventId = 1, User = new ClaimsPrincipal() };
            var dataAccess = new Mock<IAllReadyDataAccess>();
            var userManager = CreateUserManagerMock();
            userManager.Setup(x => x.GetUserId(message.User)).Returns(appUser.Id);
            dataAccess.Setup(x => x.GetUser(appUser.Id)).Returns(appUser);
            dataAccess.Setup(x => x.GetEvent(message.EventId)).Returns(CreateAllReadyEventWithTasks(message.EventId, appUser));

            var sut = new ShowEventQueryHandler(dataAccess.Object, userManager.Object);
            var eventViewModel = sut.Handle(message);

            Assert.Null(eventViewModel.UserSkills);
        }
コード例 #31
0
        public void SetIsUserVolunteerdForEventToFalse_WhenThereAreNoEventSignupsForTheEventAndTheUser_AndEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            var appUser = new ApplicationUser() { Id = "asdfasfd" };
            var message = new ShowEventQuery() { EventId = 1, User = new ClaimsPrincipal() };
            var dataAccess = new Mock<IAllReadyDataAccess>();
            var userManager = CreateUserManagerMock();
            userManager.Setup(x => x.GetUserId(message.User)).Returns(appUser.Id);
            dataAccess.Setup(x => x.GetUser(appUser.Id)).Returns(appUser);
            dataAccess.Setup(x => x.GetEvent(message.EventId)).Returns(CreateAllReadyEventWithTasks(message.EventId, appUser));

            var sut = new ShowEventQueryHandler(dataAccess.Object, userManager.Object);
            var eventViewModel = sut.Handle(message);

            Assert.False(eventViewModel.IsUserVolunteeredForEvent);
        }
コード例 #32
0
        public void SetTasksToListOfTaskViewModelForAnyTasksWhereTheUserHasNotVolunteeredInAscendingOrderByTaskStartDateTime_WhenThereAreNoEventSignupsForTheEventAndTheUser_AndEventIsNotNullAndEventsCampaignIsUnlocked()
        {
            var appUser = new ApplicationUser() { Id = "asdfasfd" };
            var message = new ShowEventQuery() { EventId = 1, User = new ClaimsPrincipal() };
            var dataAccess = new Mock<IAllReadyDataAccess>();
            var userManager = CreateUserManagerMock();
            userManager.Setup(x => x.GetUserId(message.User)).Returns(appUser.Id);
            dataAccess.Setup(x => x.GetUser(appUser.Id)).Returns(appUser);
            var allReadyEvent = CreateAllReadyEventWithTasks(message.EventId, appUser);
            dataAccess.Setup(x => x.GetEvent(message.EventId)).Returns(allReadyEvent);
            dataAccess.Setup(x => x.GetEventSignups(message.EventId, appUser.Id)).Returns(new List<EventSignup>());

            var sut = new ShowEventQueryHandler(dataAccess.Object, userManager.Object);
            var eventViewModel = sut.Handle(message);

            Assert.Equal(allReadyEvent.Tasks.Where(x => !x.AssignedVolunteers.Any(v => v.User.Id.Equals(appUser.Id))).Count(), 
                         eventViewModel.Tasks.Count);
            var previousDateTime = DateTimeOffset.MinValue;
            foreach (var userTask in eventViewModel.Tasks)
            {
                Assert.True(userTask.StartDateTime > previousDateTime);
                previousDateTime = userTask.StartDateTime;
            }
        }