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); }
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()); }
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); }
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); }
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); }
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()); }
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); }
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); }