public void PutSessionPeriod_UnauthorizedException_Test() { int expectedSessionId = 5; int duration = 10; DateTime startTime = DateTime.Now; var expectedSession = new Session() { SessionId = expectedSessionId, EventDefinitionId = 1 }; var eventDefinition = new EventDefinition() { OrganizerId = 1 }; IEventDefinitionRepository eventRepository = new StubIEventDefinitionRepository() { GetByIdInt32 = (id) => { Assert.AreEqual(expectedSession.EventDefinitionId, id); return eventDefinition; } }; ISessionRepository sessionRepository = new StubISessionRepository() { GetInt32 = (sessionId) => { Assert.AreEqual(expectedSessionId, sessionId); return expectedSession; } }; using (ShimsContext.Create()) { MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken(); myeventToken.RegisteredUserIdGet = () => { return 1000; }; ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; }; var target = new SessionsController(sessionRepository, eventRepository); target.PutSessionPeriod(expectedSessionId, startTime.ToString(), duration); } }
public void PutSessionPeriod_NotFail_Test() { int expectedSessionId = 5; int duration = 10; DateTime startTime = DateTime.Now; bool getCalled = false; bool updateCalled = false; var expectedSession = new Session() { SessionId = expectedSessionId, EventDefinitionId = 1 }; var eventDefinition = new EventDefinition() { OrganizerId = 1 }; IEventDefinitionRepository eventRepository = new StubIEventDefinitionRepository() { GetByIdInt32 = (id) => { Assert.AreEqual(expectedSession.EventDefinitionId, id); return eventDefinition; } }; ISessionRepository sessionRepository = new StubISessionRepository() { GetInt32 = (sessionId) => { Assert.AreEqual(expectedSessionId, sessionId); getCalled = true; return expectedSession; }, UpdateSession = session => { Assert.AreEqual(expectedSessionId, session.SessionId); Assert.AreEqual(duration, session.Duration); updateCalled = true; } }; using (ShimsContext.Create()) { MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken(); myeventToken.RegisteredUserIdGet = () => { return eventDefinition.OrganizerId; }; ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; }; var target = new SessionsController(sessionRepository, eventRepository); target.PutSessionPeriod(expectedSessionId, startTime.ToString(), duration); Assert.IsTrue(getCalled); Assert.IsTrue(updateCalled); } }
public void PutSessionPeriod_SessionNotFound_NotFail_Test() { int expectedSessionId = 5; int duration = 10; DateTime startTime = DateTime.Now; bool getCalled = false; bool updateCalled = false; var expectedSession = new Session() { SessionId = expectedSessionId }; IEventDefinitionRepository eventRepository = new StubIEventDefinitionRepository(); ISessionRepository sessionRepository = new StubISessionRepository() { GetInt32 = (sessionId) => { Assert.AreEqual(expectedSessionId, sessionId); getCalled = true; return null; }, UpdateSession = session => { Assert.AreEqual(expectedSessionId, session.SessionId); Assert.AreEqual(startTime, session.StartTime); Assert.AreEqual(duration, session.Duration); updateCalled = true; } }; var target = new SessionsController(sessionRepository, eventRepository); target.PutSessionPeriod(expectedSessionId, startTime.ToString(), duration); Assert.IsTrue(getCalled); Assert.IsFalse(updateCalled); }
public void PutSessionPeriod_DurationBadParam_ExceptionExpected_Test() { int sessionId = 0; int duration = 0; DateTime startTime = DateTime.Now; IEventDefinitionRepository eventRepository = new StubIEventDefinitionRepository(); ISessionRepository sessionRepository = new StubISessionRepository(); var target = new SessionsController(sessionRepository, eventRepository); target.PutSessionPeriod(sessionId, startTime.ToString(), duration); }