public void Should_Return_NotFound_From_GetById_When_Entity_Not_Found() { //ARRANGE ResistanceBand resistanceBand = null; var service = new Mock <IResistanceBandService>(MockBehavior.Strict); service.Setup(mock => mock.GetById(It.IsAny <int>())).Returns(resistanceBand); var sut = new ResistanceBandsController(service.Object); //ACT var result = sut.Get(2); //ASSERT Assert.IsNotNull(result); Assert.IsInstanceOfType(result.Result, typeof(NotFoundResult)); service.Verify(mock => mock.GetById(2), Times.Once); }
public void Should_Get_By_Id() { //ARRANGE var resistanceBand = new ResistanceBand(); var service = new Mock <IResistanceBandService>(MockBehavior.Strict); service.Setup(mock => mock.GetById(It.IsAny <int>())).Returns(resistanceBand); var sut = new ResistanceBandsController(service.Object); //ACT var result = sut.Get(1); //ASSERT Assert.IsNotNull(result); Assert.IsInstanceOfType(result.Result, typeof(OkObjectResult)); Assert.AreEqual(resistanceBand, (result.Result as OkObjectResult).Value); service.Verify(mock => mock.GetById(1), Times.Once); }
public void Should_Get_All() { //ARRANGE var resistanceBands = new List <ResistanceBand>(2) { new ResistanceBand(), new ResistanceBand() }; var service = new Mock <IResistanceBandService>(MockBehavior.Strict); service.Setup(mock => mock.GetAll()).Returns(resistanceBands); var sut = new ResistanceBandsController(service.Object); //ACT var result = sut.Get(); //ASSERT Assert.IsNotNull(result); Assert.IsInstanceOfType(result.Result, typeof(OkObjectResult)); Assert.AreEqual(resistanceBands, (result.Result as OkObjectResult).Value); service.Verify(mock => mock.GetAll(), Times.Once); }