public void PostSession_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() { AddSession = session => { Assert.AreEqual(expectedSession.SessionId, session.SessionId); called = true; return session.SessionId; } }; 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); int actual = target.Post(expectedSession); Assert.IsTrue(called); Assert.AreEqual(expectedSession.SessionId, actual); } }
public void PostSession_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(); 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); int actual = target.Post(expectedSession); } }
public void PostSession_ArgumentNullException_Test() { ISessionRepository sessionRepository = new StubISessionRepository(); IEventDefinitionRepository eventRepository = new StubIEventDefinitionRepository(); var target = new SessionsController(sessionRepository, eventRepository); target.Post(null); }