public void Post_EndGameSession_adds_it_to_database() { Mock <DbSet <EndGameSession> > endGameSessionSet = new Mock <DbSet <EndGameSession> >(); Mock <PGDbContext> context = new Mock <PGDbContext>(); context.Setup(m => m.EndGameSessions).Returns(endGameSessionSet.Object); var endGameSessionsController = new EndGameSessionsController(context.Object); endGameSessionsController.PostEndGameSession(GetTestEndGameSession()); endGameSessionSet.Verify(m => m.Add(It.IsAny <EndGameSession>()), Times.Once()); context.Verify(m => m.SaveChanges(), Times.Once()); }
public void Get_EndGameSession_with_id_4_returns_EndGameSession_object_with_id_4() { var data = new List <EndGameSession> { GetTestEndGameSession(), }.AsQueryable(); Mock <PGDbContext> context = GetTestEndGameSessionContext(data); var controller = new EndGameSessionsController(context.Object); IHttpActionResult response = controller.GetEndGameSession(4); Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <EndGameSession>), "GetEndGameSession should return OK with EndGameSession data"); OkNegotiatedContentResult <EndGameSession> responseWithData = (OkNegotiatedContentResult <EndGameSession>)response; Assert.IsNotNull(responseWithData.Content, "EndGameSession data that was fetched with Get should not be null"); Assert.AreEqual(4, responseWithData.Content.EndGameSessionId, "EndGameSession data ID should be 4"); }
public void Get_EndGameSessions_returns_all_in_database() { var data = new List <EndGameSession> { GetTestEndGameSession(), GetTestEndGameSession(), GetTestEndGameSession(), GetTestEndGameSession(), }.AsQueryable(); Mock <PGDbContext> context = GetTestEndGameSessionContext(data); EndGameSessionsController controller = new EndGameSessionsController(context.Object); List <EndGameSession> endGameSessions = controller.GetEndGameSessions(); Assert.AreEqual(4, endGameSessions.Count); foreach (var item in endGameSessions) { Assert.IsNotNull(item, "All EndGameSessions that were fethed by Get shouldnt be null"); } }