public void CallDataBarsRepository_GetByIdMethod_WithCorrectParameter() { //Arrange var barsRepoMock = new Mock <IEntityFrameworkRepository <ShishaBar> >(); barsRepoMock.Setup(x => x.GetById(It.IsAny <int>())).Verifiable(); var dataMock = new Mock <IShishaTimeData>(); dataMock.Setup(x => x.Bars).Verifiable(); dataMock.Setup(x => x.Bars).Returns(barsRepoMock.Object); var barsService = new BarsService(dataMock.Object); //Act barsService.GetBarById(1); //Assert barsRepoMock.Verify(x => x.GetById(1), Times.Once()); }
public void ReturnCorrectResult() { //Arrange var mockedBar = new Mock <ShishaBar>(); var barsRepoMock = new Mock <IEntityFrameworkRepository <ShishaBar> >(); barsRepoMock.Setup(x => x.GetById(It.IsAny <int>())).Verifiable(); barsRepoMock.Setup(x => x.GetById(It.IsAny <int>())).Returns(mockedBar.Object); var dataMock = new Mock <IShishaTimeData>(); dataMock.Setup(x => x.Bars).Verifiable(); dataMock.Setup(x => x.Bars).Returns(barsRepoMock.Object); var barsService = new BarsService(dataMock.Object); //Act var result = barsService.GetBarById(1); //Assert Assert.AreEqual(mockedBar.Object, result); }