Exemplo n.º 1
0
        public void TestGetCurrentMandantIfThereIsNoSelectedInSession()
        {
            var testSessionService = new TestSessionService();
            var testCookieService  = new TestCookieService();

            testSessionService.SelectedMandantId = null;
            testCookieService.SelectedMandantId  = null;

            var securityService = GetSecurityService(testSessionService, testCookieService);

            var currentMandant = securityService.GetCurrentMandant();

            Assert.AreEqual(TestMandatorNameOne, currentMandant.MandantName);
            Assert.AreEqual(testMandantOneId, currentMandant.Id);
        }
Exemplo n.º 2
0
        private ISecurityService GetSecurityService(TestSessionService testSessionService, TestCookieService testCookieService)
        {
            Mock <IIdentityService> ldapWebServiceMock = new Mock <IIdentityService>();

            ldapWebServiceMock.Setup(
                m => m.GetMandatorShort(StubUserIdentityProvider.TestUsername, IdentityCacheService.ApplicationName))
            .Returns(new List <IdentityMandatorShort>
            {
                new IdentityMandatorShort
                {
                    Applicationname = IdentityCacheService.ApplicationName,
                    Mandatorname    = TestMandatorNameTwo
                },
                new IdentityMandatorShort
                {
                    Applicationname = IdentityCacheService.ApplicationName,
                    Mandatorname    = TestMandatorNameOne
                }
            });
            ldapWebServiceMock.Setup(
                m => m.GetRole(StubUserIdentityProvider.TestUsername, IdentityCacheService.ApplicationName))
            .Returns(new List <UserRole>
            {
                new UserRole {
                    MandatorName = TestMandatorNameTwo, Rolle = Rolle.DataManager
                },
                new UserRole {
                    MandatorName = TestMandatorNameOne, Rolle = Rolle.DataManager
                },
            });
            ldapWebServiceMock.Setup(
                m =>
                m.GetRoleMandator(It.IsAny <string>(), StubUserIdentityProvider.TestUsername, IdentityCacheService.ApplicationName))
            .Returns <string, string, string>((m, u, a) => new List <UserRole>()
            {
                new UserRole()
                {
                    MandatorName = m, Rolle = Rolle.DataManager
                }
            });

            Mock <IMandantenService> mandantRepositoryMock = new Mock <IMandantenService>();

            mandantRepositoryMock.Setup(m => m.GetCurrentMandanten())
            .Returns(new List <Mandant>
            {
                new Mandant()
                {
                    Id = testMandantTwoId, MandantName = TestMandatorNameTwo
                },
                new Mandant()
                {
                    Id = testMandantOneId, MandantName = TestMandatorNameOne
                },
            });
            mandantRepositoryMock.Setup(m => m.GetMandantById(testMandantOneId))
            .Returns(new Mandant
            {
                Id          = testMandantOneId,
                MandantName = TestMandatorNameOne
            });

            Mock <IServerConfigurationProvider> serverConfigurationProviderMock = new Mock <IServerConfigurationProvider>();

            return(new SecurityService(new StubUserIdentityProvider(), testSessionService, mandantRepositoryMock.Object, testCookieService, new IdentityCacheService(new SessionCacheService(testSessionService), serverConfigurationProviderMock.Object, ldapWebServiceMock.Object)));
        }