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