public void GetAuthorizedEdOrgs_Should_ReturnUserSessionEdOrgs() { var authorizedEdOrgs = new List <EdOrg> { new EdOrg { Id = 12345 }, new EdOrg { Id = 23456 } }; foreach (var edorg in authorizedEdOrgs) { DefaultTestAppUserSession.UserIdentity.AuthorizedEdOrgs.Add(edorg); } AppUserServiceMock.Setup(x => x.GetSession()).Returns(DefaultTestAppUserSession); var edOrgService = new EdOrgService( DbContextFactoryMock.Object, AppUserServiceMock.Object, SchoolYearServiceMock.Object, SchoolYearDbContextFactoryMock.Object, LoggingServiceMock.Object); var result = edOrgService.GetAuthorizedEdOrgs(); result.ShouldHaveSameItems(authorizedEdOrgs); }
public void GetAnnouncements_Should_LogCaughtException() { AppUserServiceMock.Setup(x => x.GetSession()).Throws <InvalidOperationException>(); LoggingServiceMock.Setup(x => x.LogErrorMessage(It.IsAny <string>())); var announcementService = new AnnouncementService(DbContextFactoryMock.Object, AppUserServiceMock.Object, LoggingServiceMock.Object); announcementService.GetAnnouncements(); LoggingServiceMock.Verify(x => x.LogErrorMessage(It.IsAny <string>()), Times.Once); }
public void GetAnnouncements_Should_ReturnAll() { AppUserServiceMock.Setup(x => x.GetSession()).Returns(DefaultTestAppUserSession); // authorized ed orgs should match limited-to ed orgs var authorizedEdOrgId = 12345; DefaultTestAppUserSession.UserIdentity.AuthorizedEdOrgs.Add(new EdOrg { Id = authorizedEdOrgId }); var announcementIdToDismiss = 2345; var announcementIdToKeep = 3456; var announcements = new List <Announcement>( new[] { new Announcement { Id = announcementIdToKeep, Message = "test contact info" }, new Announcement { Id = announcementIdToDismiss, Message = "dismiss me" } }); EntityFrameworkMocks.SetupMockDbSet <ValidationPortalDbContext, Announcement>( EntityFrameworkMocks.GetQueryableMockDbSet(announcements), ValidationPortalDbContextMock, x => x.Announcements, x => x.Announcements = It.IsAny <DbSet <Announcement> >(), announcements); DbContextFactoryMock.Setup(x => x.Create()).Returns(ValidationPortalDbContextMock.Object); var announcementService = new AnnouncementService(DbContextFactoryMock.Object, AppUserServiceMock.Object, LoggingServiceMock.Object); var result = announcementService.GetAnnouncements(); result.ShouldNotBeNull(); result.ShouldNotBeEmpty(); result.ShouldContain(announcements.First(x => x.Id == announcementIdToKeep)); result.ShouldContain(announcements.First(x => x.Id == announcementIdToDismiss)); }
public void GetAnnouncement_Should_LogAndThrowOnNonexistentId() { AppUserServiceMock.Setup(x => x.GetSession()).Returns(DefaultTestAppUserSession); LoggingServiceMock.Setup(x => x.LogErrorMessage(It.IsAny <string>())); // authorized ed orgs should match limited-to ed orgs var authorizedEdOrgId = 12345; DefaultTestAppUserSession.UserIdentity.AuthorizedEdOrgs.Add(new EdOrg { Id = authorizedEdOrgId }); var announcementIdToReturn = 2345; var announcementIdToNotReturn = 3456; var announcementIdThatsBogus = 4567; var announcements = new List <Announcement>( new[] { new Announcement { Id = announcementIdToReturn, Message = "return me" }, new Announcement { Id = announcementIdToNotReturn, Message = "leave me out" } }); EntityFrameworkMocks.SetupMockDbSet( EntityFrameworkMocks.GetQueryableMockDbSet(announcements), ValidationPortalDbContextMock, x => x.Announcements, x => x.Announcements = It.IsAny <DbSet <Announcement> >(), announcements); DbContextFactoryMock.Setup(x => x.Create()).Returns(ValidationPortalDbContextMock.Object); var announcementService = new AnnouncementService(DbContextFactoryMock.Object, AppUserServiceMock.Object, LoggingServiceMock.Object); Assert.Throws <Exception>(() => announcementService.GetAnnouncement(announcementIdThatsBogus)); LoggingServiceMock.Verify(x => x.LogErrorMessage(It.IsAny <string>())); }
public void GetAnnouncement_Should_ReturnOneAnnouncement() { AppUserServiceMock.Setup(x => x.GetSession()).Returns(DefaultTestAppUserSession); // authorized ed orgs should match limited-to ed orgs var authorizedEdOrgId = 12345; DefaultTestAppUserSession.UserIdentity.AuthorizedEdOrgs.Add(new EdOrg { Id = authorizedEdOrgId }); var announcementIdToReturn = 2345; var announcementIdToNotReturn = 3456; var announcements = new List <Announcement>( new[] { new Announcement { Id = announcementIdToReturn, Message = "return me", }, new Announcement { Id = announcementIdToNotReturn, Message = "leave me out", } }); EntityFrameworkMocks.SetupMockDbSet( EntityFrameworkMocks.GetQueryableMockDbSet(announcements), ValidationPortalDbContextMock, x => x.Announcements, x => x.Announcements = It.IsAny <DbSet <Announcement> >(), announcements); DbContextFactoryMock.Setup(x => x.Create()).Returns(ValidationPortalDbContextMock.Object); var announcementService = new AnnouncementService(DbContextFactoryMock.Object, AppUserServiceMock.Object, LoggingServiceMock.Object); var result = announcementService.GetAnnouncement(announcementIdToReturn); result.ShouldNotBeNull(); result.Id.ShouldEqual(announcementIdToReturn); }
public void SetupValidationRun_Should_ReturnValidationReportSummary() { var rulesEngineService = new RulesEngineService( AppUserServiceMock.Object, EdOrgServiceMock.Object, SchoolYearServiceMock.Object, EngineConfigMock.Object, LoggingServiceMock.Object, DbContextFactoryMock.Object, SchoolYearDbContextFactoryMock.Object, EngineObjectModel, null); var schoolYear = new SchoolYear { Id = 1, Enabled = true, ErrorThreshold = null, StartYear = "2019", EndYear = "2020" }; var submissionCycle = new SubmissionCycle { SchoolYearId = schoolYear.Id, CollectionId = "collection" }; SchoolYearServiceMock.Setup(x => x.GetSchoolYearById(schoolYear.Id)).Returns(schoolYear); AppUserServiceMock.Setup(x => x.GetSession()).Returns(DefaultTestAppUserSession); AppUserServiceMock.Setup(x => x.GetUser()).Returns(DefaultTestAppUserSession.UserIdentity); var result = rulesEngineService.SetupValidationRun(submissionCycle, submissionCycle.CollectionId); result.ShouldNotBeNull(); result.SchoolYearId.ShouldEqual(schoolYear.Id); result.Collection.ShouldEqual(submissionCycle.CollectionId); SchoolYearDbContextMock.Verify( x => x.RuleValidations.Add( It.Is <RuleValidation>(y => y.CollectionId == submissionCycle.CollectionId))); }