public void Delete_SessionFound_DeletesUserFromSession(int id) { Session session = _dummyContext.Sessions.First(s => s.SessionId == id); _mockSessionRepository.Setup(s => s.GetById(id)).Returns(session); // user1 is dummyUser uit dummyDBContext en is op einde daar al toegevoegd aan sessie5 (met id 1) _sessionController.Add(id, user1); Assert.Contains(user1, session.GetUsers()); _sessionController.Delete(id, user1); Assert.DoesNotContain(user1, session.GetUsers()); _mockUserRepository.Verify(m => m.SaveChanges(), Times.Exactly(2)); }
public void GivenALoggdInUser_WhenILogout_ThenTheCookieIsExpired() { var cookies = new HttpCookieCollection(); string cookieName = "USER"; cookies.Add(new HttpCookie(cookieName)); MockRequest.Setup(r => r.Cookies).Returns(cookies); _sessionController.Delete(); HttpCookie cookie = FakeResponse.Cookies[GetCookieUserFilterAttribute.UserCookieName]; Assert.That(cookie.Expires, Is.EqualTo(new DateTime(1970, 1, 1))); }
public async Task <HttpResponseMessage> Delete(string sessionId) { SessionController sessionController = new SessionController(); try { Session session = null; try { session = sessionController.GetSessionWithId(new SessionId(sessionId)); } catch (FileNotFoundException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message)); } bool deleted = await sessionController.Delete(session); if (deleted) { return(Request.CreateResponse(HttpStatusCode.OK, "Data successfully deleted")); } else { return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "Cannot delete an Active session. Make sure to cancel the session first.")); } } catch (Exception ex) { Logger.LogSessionErrorEvent($"Failed while deleting the session", ex, sessionId); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, $"Failed with error {ex.Message} while trying to delete data for the Session {sessionId}")); } }
public async Task Delete_HappyPath_ShouldReturnOk() { //Arrange var startDate = DateTime.Now.AddDays(-1); var endDate = DateTime.Now; var mockSessionService = A.Fake <ISessionService>(); A.CallTo(() => mockSessionService.DeleteSession(2)).Returns( new ServiceResponse <List <GetSessionDto> > { Data = new List <GetSessionDto>() { new GetSessionDto { Id = 1, StartDateTime = startDate, EndDateTime = endDate } } }); var controller = new SessionController(mockSessionService); //Act var result = await controller.Delete(2); var okResult = result as OkObjectResult; var actualResult = okResult.Value as ServiceResponse <List <GetSessionDto> >; //Assert Assert.AreEqual(typeof(OkObjectResult), result.GetType()); Assert.AreEqual(1, actualResult.Data[0].Id); Assert.AreEqual(startDate, actualResult.Data[0].StartDateTime); Assert.AreEqual(endDate, actualResult.Data[0].EndDateTime); }
public void TestLogoffWithCorrectParameters() { // Arrange var requestMock = new Mock <HttpRequestMessage>(); requestMock.Object.Method = new HttpMethod("POST"); requestMock.Object.Properties.Add("MS_HttpConfiguration", GetHttpConfiguration()); requestMock.Object.RequestUri = new Uri(UrlConst); SetRequiredUser(); IUserRepository userRepository = GetFakeUserRepository(); IAuthenticationKeeper authenticationKeeper = GetFakeAuthenticationKeeper(); IRoleRepository roleRepository = GetFakeRoleRepository(); var usersController = new SessionController(userRepository, roleRepository, authenticationKeeper) { Request = requestMock.Object }; // Act Task <HttpResponseMessage> response = usersController.Delete(); response.Wait(); // Assert _authenticationKeeperMock.Verify(m => m.Clean(), Times.Once()); Assert.IsFalse(response.IsFaulted); Assert.IsNotNull(response.Result); Assert.IsTrue(response.Result.StatusCode == HttpStatusCode.OK); }
public void Delete_ReturnsA404_WhenTheUserCannotBeFound() { var sessionRepository = Substitute.For <ISessionRepository>(); var voteRepository = Substitute.For <IVoteRepository>(); var controller = new SessionController(sessionRepository, voteRepository); var actionResult = controller.Delete(123); Assert.That(actionResult.GetHttpStatusCode(), Is.EqualTo(HttpStatusCode.NotFound)); }
public void WhenTheSessionIsDestroyed_TheTheCookieShouldBeReset() { const string userName = "******"; const string password = "******"; _userService.Setup(u => u.Logon(userName, password)).Returns(new User()); var controller = new SessionController(_userService.Object, _configurationManager.Object, _logger.Object); SetControllerContext(controller); var view = controller.Delete(); var cookie = FakeResponse.Cookies.Get(0); cookie.Expires.Should().BeBefore(DateTime.Now); }
public void WhenTheSessionIsDestroyed_TheTheUserShouldNotBeAuthenticated() { const string userName = "******"; const string password = "******"; _userService.Setup(u => u.Logon(userName, password)).Returns(new User()); var controller = new SessionController(_userService.Object, _configurationManager.Object, _logger.Object); SetControllerContext(controller); var view = controller.Delete(); var model = (UserViewModel)view.Data; model.IsAuthenticated.Should().BeFalse(); }
private static void CompletedSessionCleanup() { int maxSessionsToKeep = _DaaS.MaxDiagnosticSessionsToKeep; int numberOfDays = _DaaS.MaxNumberOfDaysForSessions; var completedSessions = _DaaS.GetAllInActiveSessions().OrderByDescending(s => s.StartTime).ToList(); MonitoringSessionController controllerMonitoring = new MonitoringSessionController(); var completedMonitoringSessions = controllerMonitoring.GetAllCompletedSessions(); Logger.LogVerboseEvent($"Starting cleanup for Completed Sessions MaxDiagnosticSessionsToKeep = [{maxSessionsToKeep}] MaxNumberOfDaysForSessions= [{numberOfDays}]"); while (true) { List <Session> sessionsToRemove = completedSessions.Skip(maxSessionsToKeep).ToList(); string logMessage = $"[MaxDiagnosticSessionsToKeep] Found {sessionsToRemove.Count()} sessions to remove as we have {completedSessions.Count()} completed sessions"; DeleteSessions(sessionsToRemove, async(session) => { await _DaaS.Delete(session); }, logMessage); completedSessions = _DaaS.GetAllInActiveSessions().OrderByDescending(s => s.StartTime).ToList(); if (CheckIfTimeToCleanupSymbols(completedSessions)) { CleanupSymbolsDirectory(); } List <Session> olderSessions = completedSessions.Where(x => x.StartTime < DateTime.UtcNow.AddDays(-1 * numberOfDays)).ToList(); logMessage = $"[MaxNumberOfDaysForSessions] Found {olderSessions.Count()} older sessions to remove"; DeleteSessions(olderSessions, async(session) => { await _DaaS.Delete(session); }, logMessage); List <MonitoringSession> monitoringSessionsToRemove = completedMonitoringSessions.Skip(maxSessionsToKeep).ToList(); logMessage = $"[MaxDiagnosticSessionsToKeep] Found {monitoringSessionsToRemove.Count()} monitoring sessions to remove as we have {completedMonitoringSessions.Count()} completed sessions"; DeleteSessions(monitoringSessionsToRemove, (session) => { controllerMonitoring.DeleteSession(session.SessionId); }, logMessage); completedMonitoringSessions = controllerMonitoring.GetAllCompletedSessions().OrderByDescending(s => s.StartDate).ToList(); List <MonitoringSession> olderSessionsMonitoring = completedMonitoringSessions.Where(x => x.StartDate < DateTime.UtcNow.AddDays(-1 * numberOfDays)).ToList(); logMessage = $"[MaxNumberOfDaysForSessions] Found {olderSessionsMonitoring.Count()} older monitoring sessions to remove"; DeleteSessions(olderSessionsMonitoring, (session) => { controllerMonitoring.DeleteSession(session.SessionId); }, logMessage); Thread.Sleep(5 * 60 * 1000); } }
public void Delete_GetsTheCorrectUserDetails() { const int sessionId = 123; var sessionRepository = Substitute.For <ISessionRepository>(); sessionRepository.Get(sessionId).Returns(new Session { SessionId = sessionId }); var voteRepository = Substitute.For <IVoteRepository>(); var controller = new SessionController(sessionRepository, voteRepository); var actionResult = controller.Delete(sessionId); var model = actionResult.GetViewModel <Session>(); Assert.That(model.SessionId, Is.EqualTo(sessionId)); }
public async Task Delete_HappyPath_ShouldReturnNotFound() { //Arrange var mockSessionService = A.Fake <ISessionService>(); A.CallTo(() => mockSessionService.DeleteSession(2)).Returns( new ServiceResponse <List <GetSessionDto> > { Data = null }); var controller = new SessionController(mockSessionService); //Act var result = await controller.Delete(2); //Assert Assert.AreEqual(typeof(NotFoundObjectResult), result.GetType()); }
private void button1_Click(object sender, EventArgs e) { sessionController.Delete(DateTime.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString()), FileWorker.pathToSession); initializeCombo(); }
public void TestLogoffWithCorrectParameters() { // Arrange var requestMock = new Mock<HttpRequestMessage>(); requestMock.Object.Method = new HttpMethod("POST"); requestMock.Object.Properties.Add("MS_HttpConfiguration", GetHttpConfiguration()); requestMock.Object.RequestUri = new Uri(UrlConst); SetRequiredUser(); IUserRepository userRepository = GetFakeUserRepository(); IAuthenticationKeeper authenticationKeeper = GetFakeAuthenticationKeeper(); IRoleRepository roleRepository = GetFakeRoleRepository(); var usersController = new SessionController(userRepository, roleRepository, authenticationKeeper) {Request = requestMock.Object}; // Act Task<HttpResponseMessage> response = usersController.Delete(); response.Wait(); // Assert _authenticationKeeperMock.Verify(m => m.Clean(), Times.Once()); Assert.IsFalse(response.IsFaulted); Assert.IsNotNull(response.Result); Assert.IsTrue(response.Result.StatusCode == HttpStatusCode.OK); }