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_Update()
        {
            //ARRANGE
            var repoMock = new Mock <IRepository <ResistanceBand> >(MockBehavior.Strict);

            repoMock
            .Setup(mock => mock.Update(It.IsAny <ResistanceBand>(), true))
            .Returns((ResistanceBand resistanceBand, bool save) => resistanceBand);

            var sut            = new ResistanceBandService(repoMock.Object);
            var resistanceBand = new ResistanceBand();

            //ACT
            var result = sut.Update(resistanceBand);

            //ASSERT
            repoMock.Verify(mock => mock.Update(resistanceBand, true), Times.Once);
            result.ShouldBeSameAs(resistanceBand);
        }
        public void Should_Get_By_ID()
        {
            //ARRANGE
            var resistanceBand = new ResistanceBand {
                Color = "Blue", MaxResistanceAmount = 13
            };
            var repoMock = new Mock <IRepository <ResistanceBand> >(MockBehavior.Strict);

            repoMock.Setup(mock => mock.Get(It.IsAny <int>())).Returns(resistanceBand);

            var sut = new ResistanceBandService(repoMock.Object);

            //ACT
            var result = sut.GetById(1);

            //ASSERT
            result.ShouldBe(resistanceBand);
            repoMock.Verify(mock => mock.Get(It.IsAny <int>()), Times.Once);
        }
        public void Should_Update()
        {
            //ARRANGE
            var resistanceBand = new ResistanceBand();
            var service        = new Mock <IResistanceBandService>(MockBehavior.Strict);

            service.Setup(mock => mock.Update(resistanceBand)).Returns(resistanceBand);
            var sut = new ResistanceBandsController(service.Object);

            SetupUser(sut);

            //ACT
            var result = sut.Put(5, resistanceBand);

            //ASSERT
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Result, typeof(OkObjectResult));
            Assert.AreEqual(resistanceBand, (result.Result as OkObjectResult).Value);
            service.Verify(mock => mock.Update(resistanceBand), Times.Once);
        }