コード例 #1
0
        public async Task BeginSession_QueryReturnsNewSessionOnly_ReturnsNewSessionAndNull()
        {
            // Arrange
            var    cxn          = new SqlConnectionWrapperMock();
            var    repository   = new SqlSessionsRepository(cxn.Object);
            int    userId       = 123;
            string userName     = "******";
            int    licenseLevel = 3;
            Guid   newSessionId = new Guid("12345678901234567890123456789012");

            Session[] result = { new Session {
                                     SessionId = newSessionId
                                 } };
            cxn.SetupQueryAsync(
                "[AdminStore].BeginSession",
                new Dictionary <string, object> {
                { "UserId", userId }, { "UserName", userName }, { "LicenseLevel", licenseLevel }, { "IsSso", true }, { "LicenseLockTimeMinutes", WebApiConfig.LicenseHoldTime }, { "OldSessionId", null }
            },
                result,
                new Dictionary <string, object> {
                { "OldSessionId", null }
            });

            // Act
            Guid?   resultId = null;
            Session session  = await repository.BeginSession(userId, userName, licenseLevel, true, id => resultId = id);

            // Assert
            cxn.Verify();
            Assert.AreEqual(result[0], session);
            Assert.IsNull(resultId);
        }
コード例 #2
0
        public async Task SelectSessions_SessionExistss_ReturnsAll()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlSessionsRepository(cxn.Object);
            int ps         = 100;
            int pn         = 1;

            Session[] result =
            {
                new Session {
                    SessionId = new Guid("12345678901234567890123456789012")
                },
                new Session {
                    SessionId = new Guid("11111111111111111111111111111111")
                }
            };
            cxn.SetupQueryAsync("[AdminStore].SelectSessions", new Dictionary <string, object> {
                { "ps", ps }, { "pn", pn }
            }, result);

            // Act
            IEnumerable <Session> sessions = await repository.SelectSessions(ps, pn);

            // Assert
            cxn.Verify();
            CollectionAssert.AreEquivalent(result, sessions.ToList());
        }
コード例 #3
0
        public async Task GetUserSession_SessionDoesNotExist_ReturnsNull()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlSessionsRepository(cxn.Object);
            int uid        = 5;

            Session[] result = { };
            cxn.SetupQueryAsync("[AdminStore].GetUserSession", new Dictionary <string, object> {
                { "UserId", uid }
            }, result);

            // Act
            Session session = await repository.GetUserSession(uid);

            // Assert
            cxn.Verify();
            Assert.IsNull(session);
        }
コード例 #4
0
        public async Task ExtendSession_SessionDoesNotExist_ReturnsNull()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlSessionsRepository(cxn.Object);
            var guid       = new Guid("12345678901234567890123456789012");

            Session[] result = { };
            cxn.SetupQueryAsync("[AdminStore].ExtendSession", new Dictionary <string, object> {
                { "SessionId", guid }
            }, result);

            // Act
            Session session = await repository.ExtendSession(guid);

            // Assert
            cxn.Verify();
            Assert.IsNull(session);
        }
コード例 #5
0
        public async Task EndSession_TimeoutSessionDoesNotExist_ReturnsNull()
        {
            // Arrange
            var      cxn         = new SqlConnectionWrapperMock();
            var      repository  = new SqlSessionsRepository(cxn.Object);
            var      guid        = new Guid("00000000000000000000000000000000");
            DateTime?timeoutTime = DateTime.UtcNow;
            var      sessions    = new Session[] { };

            cxn.SetupQueryAsync("[AdminStore].EndSession", new Dictionary <string, object> {
                { "SessionId", guid }, { "TimeoutTime", timeoutTime }
            }, sessions);

            // Act
            Session result = await repository.EndSession(guid, timeoutTime);

            // Assert
            cxn.Verify();
            Assert.IsNull(result);
        }
コード例 #6
0
        public async Task SelectSessions_SessionDoesNotExist_ReturnsEmpty()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlSessionsRepository(cxn.Object);
            int ps         = 100;
            int pn         = 1;

            Session[] result = { };
            cxn.SetupQueryAsync("[AdminStore].SelectSessions", new Dictionary <string, object> {
                { "ps", ps }, { "pn", pn }
            }, result);

            // Act
            IEnumerable <Session> sessions = await repository.SelectSessions(ps, pn);

            // Assert
            cxn.Verify();
            Assert.IsFalse(sessions.Any());
        }
コード例 #7
0
        public async Task GetUserSession_SessionExists_ReturnsFirst()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlSessionsRepository(cxn.Object);
            int uid        = 1;

            Session[] result = { new Session {
                                     UserId = uid
                                 } };
            cxn.SetupQueryAsync("[AdminStore].GetUserSession", new Dictionary <string, object> {
                { "UserId", uid }
            }, result);

            // Act
            Session session = await repository.GetUserSession(uid);

            // Assert
            cxn.Verify();
            Assert.AreEqual(result.First(), session);
        }
コード例 #8
0
        public async Task EndSession_LogoutSessionExists_ReturnsFirst()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlSessionsRepository(cxn.Object);
            var guid       = new Guid("12345678901234567890123456789012");
            var sessions   = new[] { new Session {
                                         SessionId = guid
                                     } };

            cxn.SetupQueryAsync("[AdminStore].EndSession", new Dictionary <string, object> {
                { "SessionId", guid }, { "TimeoutTime", null }
            }, sessions);

            // Act
            Session result = await repository.EndSession(guid);

            // Assert
            cxn.Verify();
            Assert.AreEqual(sessions[0], result);
        }