public void Post_ThrowsExceptionIfHobbitAlreadyExists() { long testId; Hobbit testHobbit = HobbitHelper.CreateHobbit(FIRST_HOBBIT_NAME); Mock <IDataManager <Hobbit> > mockDataManager = new Mock <IDataManager <Hobbit> >(MockBehavior.Loose); mockDataManager.Setup(dm => dm.TryGet(testHobbit, out testId)).Returns(true); mockDataManager.Setup(dm => dm.Insert(testHobbit)).Returns(testHobbit); HobbitController controller = new HobbitController(mockDataManager.Object); Assert.Throws <HttpResponseException>(() => controller.Post(testHobbit)); }
public void Post_PassesHobbitToDataManager() { long testId; Hobbit testHobbit = HobbitHelper.CreateHobbit(FIRST_HOBBIT_NAME); Mock <IDataManager <Hobbit> > mockDataManager = new Mock <IDataManager <Hobbit> >(MockBehavior.Loose); mockDataManager.Setup(dm => dm.TryGet(testHobbit, out testId)).Returns(false); mockDataManager.Setup(dm => dm.Insert(testHobbit)).Returns(testHobbit); HobbitController controller = new HobbitController(mockDataManager.Object); Hobbit hobbit = controller.Post(testHobbit); mockDataManager.Verify(dm => dm.Insert(testHobbit)); }