public void Get_ThrowsExceptionForUnknownHobbit() { Hobbit testHobbit = null; Mock <IDataManager <Hobbit> > mockDataManager = new Mock <IDataManager <Hobbit> >(); mockDataManager.Setup(dm => dm.TryGet(ID, out testHobbit)).Returns(false); HobbitController controller = new HobbitController(mockDataManager.Object); Assert.Throws <HttpResponseException>(() => controller.Get(ID)); }
public void Get_ReturnsHobbitsFromDataManager(IEnumerable <Hobbit> hobbitsArray) { Mock <IDataManager <Hobbit> > mockDataManager = new Mock <IDataManager <Hobbit> >(); mockDataManager.Setup(dm => dm.GetAll()).Returns(hobbitsArray); HobbitController controller = new HobbitController(mockDataManager.Object); IEnumerable <Hobbit> hobbits = controller.Get(); Assert.True(hobbitsArray.Equals(hobbits)); }
public void Get_ReturnsSpecifiedHobbitFromDataManager() { Hobbit testHobbit = HobbitHelper.CreateHobbit(FIRST_HOBBIT_NAME, id: ID); Mock <IDataManager <Hobbit> > mockDataManager = new Mock <IDataManager <Hobbit> >(); mockDataManager.Setup(dm => dm.TryGet(ID, out testHobbit)).Returns(true); HobbitController controller = new HobbitController(mockDataManager.Object); Hobbit hobbit = controller.Get(ID); Assert.Same(testHobbit, hobbit); }