public void DeleteSession_NotFail_Test() { bool called = false; var expectedSession = new Session() { SessionId = 1, 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() { DeleteInt32 = sessionId => { Assert.AreEqual(expectedSession.SessionId, sessionId); called = true; }, GetInt32 = (sessionId) => { Assert.AreEqual(expectedSession.SessionId, sessionId); return expectedSession; } }; 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.Delete(expectedSession.SessionId); Assert.IsTrue(called); } }
public void DeleteSession_UnauthorizedException_Test() { var expectedSession = new Session() { SessionId = 1, 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(expectedSession.SessionId, sessionId); return expectedSession; } }; using (ShimsContext.Create()) { MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken(); myeventToken.RegisteredUserIdGet = () => { return 10000; }; ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; }; var target = new SessionsController(sessionRepository, eventRepository); target.Delete(expectedSession.SessionId); } }
public void SessionsController_Contructor_NotFail_Test() { ISessionRepository sessionRepository = new StubISessionRepository(); IEventDefinitionRepository eventRepository = new StubIEventDefinitionRepository(); var target = new SessionsController(sessionRepository, eventRepository); }
public void SessionsController_ContructorSessionWithNullDependency_Fail_Test() { ISessionRepository sessionRepository = new StubISessionRepository(); IEventDefinitionRepository eventRepository = new StubIEventDefinitionRepository(); var target = new SessionsController(null , eventRepository); }
public void PutSession_ArgumentNullException_Test() { ISessionRepository sessionRepository = new StubISessionRepository(); IEventDefinitionRepository eventRepository = new StubIEventDefinitionRepository(); var target = new SessionsController(sessionRepository, eventRepository); target.Put(null); }
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_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_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_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); }
public void GetSession_GetResult_NotFail_Test() { int expectedSessionId = 10; bool called = false; var expected = new Session() { SessionId = expectedSessionId }; IEventDefinitionRepository eventRepository = new StubIEventDefinitionRepository(); ISessionRepository sessionRepository = new StubISessionRepository() { GetWithUserInfoInt32Int32 = (userId, eventId) => { Assert.AreEqual(expectedSessionId, eventId); called = true; return expected; } }; using (ShimsContext.Create()) { MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken(); myeventToken.RegisteredUserIdGet = () => { return 0; }; ShimMyEventsToken.GetTokenFromHeader = () => { return myeventToken; }; var target = new SessionsController(sessionRepository, eventRepository); Session actual = target.Get(expectedSessionId); Assert.IsTrue(called); Assert.AreEqual(expectedSessionId, actual.SessionId); } }