Beispiel #1
0
        public void UpdateFocusedSchoolYear_Should_FailSilentlyBecauseItJustDoes()
        {
            var announcements = new List <Announcement>();

            EntityFrameworkMocks.SetupMockDbSet(
                EntityFrameworkMocks.GetQueryableMockDbSet(announcements),
                ValidationPortalDbContextMock,
                x => x.Announcements,
                x => x.Announcements = It.IsAny <DbSet <Announcement> >(),
                announcements);

            var oldFocusedSchoolYear = 12345;
            var newFocusedSchoolYear = 23456;
            var appUserSessionId     = 123;

            var schoolYears = new List <SchoolYear>(new[]
            {
                new SchoolYear
                {
                    Id      = newFocusedSchoolYear,
                    Enabled = true
                }
            });

            EntityFrameworkMocks.SetupMockDbSet(
                EntityFrameworkMocks.GetQueryableMockDbSet(schoolYears),
                ValidationPortalDbContextMock,
                x => x.SchoolYears,
                x => x.SchoolYears = It.IsAny <DbSet <SchoolYear> >(),
                schoolYears);

            var userIdentity = new ValidationPortalIdentity();

            var appUserSession = new AppUserSession
            {
                Id = appUserSessionId.ToString(),
                FocusedSchoolYearId = oldFocusedSchoolYear,
                UserIdentity        = userIdentity
            };

            DbContextFactoryMock.Setup(x => x.Create()).Returns(ValidationPortalDbContextMock.Object);

            var httpContext = new HttpContext(
                new HttpRequest(string.Empty, "http://wearedoubleline.com", string.Empty),
                new HttpResponse(new StringWriter()));

            httpContext.Items[AppUserService.SessionItemName] = null;
            HttpContextProviderMock.SetupGet(x => x.CurrentHttpContext).Returns(httpContext);

            LoggingServiceMock.Setup(x => x.LogDebugMessage(It.IsAny <string>()));

            var appUserService = new AppUserService(
                DbContextFactoryMock.Object,
                HttpContextProviderMock.Object,
                LoggingServiceMock.Object);

            appUserService.UpdateFocusedSchoolYear(newFocusedSchoolYear);

            ValidationPortalDbContextMock.Verify(x => x.SaveChanges(), Times.Never);
        }
        public void UpdateFocusedSchoolYear_WithInvalidYear_Should_LogError()
        {
            var newFocusedSchoolYear = 23456;
            var appUserSessionId     = 123;

            var appUserSession = new AppUserSession
            {
                Id           = appUserSessionId.ToString(),
                UserIdentity = null
            };

            DbContextFactoryMock.Setup(x => x.Create()).Returns(ValidationPortalDbContextMock.Object);

            var httpContext = new HttpContext(
                new HttpRequest(string.Empty, "http://wearedoubleline.com", string.Empty),
                new HttpResponse(new StringWriter()));

            httpContext.Items[AppUserService.SessionItemName] = appUserSession;
            HttpContextProviderMock.SetupGet(x => x.CurrentHttpContext).Returns(httpContext);

            LoggingServiceMock.Setup(x => x.LogDebugMessage(It.IsAny <string>()));
            LoggingServiceMock.Setup(x => x.LogErrorMessage(It.IsAny <string>()));

            var appUserService = new AppUserService(
                DbContextFactoryMock.Object,
                HttpContextProviderMock.Object,
                LoggingServiceMock.Object);

            appUserService.UpdateFocusedSchoolYear(newFocusedSchoolYear);

            ValidationPortalDbContextMock.Verify(x => x.SaveChanges(), Times.Never);
            LoggingServiceMock.Verify(x => x.LogErrorMessage(It.IsAny <string>()), Times.Once());
        }
Beispiel #3
0
        public void UpdateFocusedEdOrg_Should_FailSilentlyBecauseItJustDoes()
        {
            var authorizedEdOrgId = 12345;

            DefaultTestAppUserSession.UserIdentity.AuthorizedEdOrgs.Add(new EdOrg {
                Id = authorizedEdOrgId
            });

            var announcements = new List <Announcement>();

            EntityFrameworkMocks.SetupMockDbSet(
                EntityFrameworkMocks.GetQueryableMockDbSet(announcements),
                ValidationPortalDbContextMock,
                x => x.Announcements,
                x => x.Announcements = It.IsAny <DbSet <Announcement> >(),
                announcements);

            var oldFocusedEdOrg       = 12345;
            var newFocusedEdOrg       = 23456;
            var randomAuthorizedEdOrg = newFocusedEdOrg + 1;
            var appUserSessionId      = 123;

            var userIdentity = new ValidationPortalIdentity
            {
                AuthorizedEdOrgs = new List <EdOrg>(new[] { new EdOrg {
                                                                Id = randomAuthorizedEdOrg
                                                            } })
            };

            var appUserSession = new AppUserSession
            {
                Id             = appUserSessionId.ToString(),
                FocusedEdOrgId = oldFocusedEdOrg,
                UserIdentity   = userIdentity
            };

            DbContextFactoryMock.Setup(x => x.Create()).Returns(ValidationPortalDbContextMock.Object);

            var httpContext = new HttpContext(
                new HttpRequest(string.Empty, "http://wearedoubleline.com", string.Empty),
                new HttpResponse(new StringWriter()));

            httpContext.Items[AppUserService.SessionItemName] = appUserSession;
            HttpContextProviderMock.SetupGet(x => x.CurrentHttpContext).Returns(httpContext);

            LoggingServiceMock.Setup(x => x.LogDebugMessage(It.IsAny <string>()));

            var appUserService = new AppUserService(
                DbContextFactoryMock.Object,
                HttpContextProviderMock.Object,
                LoggingServiceMock.Object);

            appUserService.UpdateFocusedEdOrg(newFocusedEdOrg.ToString());

            ValidationPortalDbContextMock.Verify(x => x.SaveChanges(), Times.Never);
        }
Beispiel #4
0
        public void UpdateFocusedEdOrg_Should_LogException()
        {
            var announcements = new List <Announcement>();

            EntityFrameworkMocks.SetupMockDbSet(
                EntityFrameworkMocks.GetQueryableMockDbSet(announcements),
                ValidationPortalDbContextMock,
                x => x.Announcements,
                x => x.Announcements = It.IsAny <DbSet <Announcement> >(),
                announcements);

            var oldFocusedEdOrg  = 12345;
            var newFocusedEdOrg  = 23456;
            var appUserSessionId = 123;

            var appUserSession = new AppUserSession
            {
                Id             = appUserSessionId.ToString(),
                FocusedEdOrgId = oldFocusedEdOrg,
                UserIdentity   = null
            };

            DbContextFactoryMock.Setup(x => x.Create()).Returns(ValidationPortalDbContextMock.Object);

            var httpContext = new HttpContext(
                new HttpRequest(string.Empty, "http://wearedoubleline.com", string.Empty),
                new HttpResponse(new StringWriter()));

            httpContext.Items[AppUserService.SessionItemName] = appUserSession;
            HttpContextProviderMock.SetupGet(x => x.CurrentHttpContext).Returns(httpContext);

            LoggingServiceMock.Setup(x => x.LogDebugMessage(It.IsAny <string>()));
            LoggingServiceMock.Setup(x => x.LogErrorMessage(It.IsAny <string>()));

            var appUserService = new AppUserService(
                DbContextFactoryMock.Object,
                HttpContextProviderMock.Object,
                LoggingServiceMock.Object);

            appUserService.UpdateFocusedEdOrg(newFocusedEdOrg.ToString());

            ValidationPortalDbContextMock.Verify(x => x.SaveChanges(), Times.Never);
            LoggingServiceMock.Verify(x => x.LogErrorMessage(It.IsAny <string>()), Times.Once());
        }
Beispiel #5
0
        public void GetUser_Should_ReturnUser()
        {
            var httpContext = new HttpContext(
                new HttpRequest(string.Empty, "http://wearedoubleline.com", string.Empty),
                new HttpResponse(new StringWriter()));

            httpContext.Items[AppUserService.SessionItemName] = DefaultTestAppUserSession;

            HttpContextProviderMock.SetupGet(x => x.CurrentHttpContext).Returns(httpContext);

            var appUserService = new AppUserService(
                DbContextFactoryMock.Object,
                HttpContextProviderMock.Object,
                LoggingServiceMock.Object);

            var result = appUserService.GetUser();

            result.ShouldEqual(DefaultTestAppUserSession.UserIdentity);
        }