public void UpdateImageUrlByCallId_AnyCallId_True() { // Setup dependence var settingMock = new Mock<ISettings>(); var componentMock = new Mock<IComponents>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(r => r.GetInstance<IRepository>()) .Returns(repositoryMock.Object); serviceLocatorMock.Setup(r => r.GetInstance<IUnitOfWork>()) .Returns(uowMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); repositoryMock.Setup(r => r.CreateUnitOfWork()).Returns(uowMock.Object); // Arrange data Guid id = Guid.NewGuid(); Call call = new Call { Id = id }; string url = "url"; repositoryMock.Setup(r => r.FindById<Call>(id)).Returns(call); bool expectedResult = true; // Act CallService callService = new CallService(uowMock.Object, repositoryMock.Object, settingMock.Object, componentMock.Object); var currentResult = callService.UpdateImageUrlByCallId(id, url); // Assert repositoryMock.Verify(r => r.FindById<Call>(id)); repositoryMock.Verify(r => r.Update<Call>( It.Is<Call>(b => b.Id == id))); uowMock.Verify(u => u.Save()); Assert.AreEqual(expectedResult, currentResult); }
public void UpdateImageUrlByCallId_AnyCallId_False() { // Setup dependence var settingMock = new Mock<ISettings>(); var componentMock = new Mock<IComponents>(); var uowMock = new Mock<IUnitOfWork>(); var repositoryMock = new Mock<IRepository>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(r => r.GetInstance<IRepository>()) .Returns(repositoryMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); // Arrange data Guid id = Guid.NewGuid(); string url = "url"; bool expectedResult = false; // Act CallService callService = new CallService(uowMock.Object, repositoryMock.Object, settingMock.Object, componentMock.Object); var currentResult = callService.UpdateImageUrlByCallId(id, url); // Assert Assert.AreEqual(expectedResult, currentResult); }