public void TestDeleteMeasurement_RepositoryReturnsNull_ShouldNotCallRepositoryDelete(int id, string userId) { // Arrange var mockedMeasurementRepository = new Mock <IRepository <Measurement> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedFactory = new Mock <IMeasurementFactory>(); var service = new MeasurementService(mockedMeasurementRepository.Object, mockedUnitOfWork.Object, mockedFactory.Object); // Act service.DeleteMeasurement(id, userId); // Assert mockedMeasurementRepository.Verify(r => r.Delete(It.IsAny <Measurement>()), Times.Never); }
public void TestDeleteMeasurement_RepositoryReturnsNull_ShouldReturnFalse(int id, string userId) { // Arrange var mockedMeasurementRepository = new Mock <IRepository <Measurement> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedFactory = new Mock <IMeasurementFactory>(); var service = new MeasurementService(mockedMeasurementRepository.Object, mockedUnitOfWork.Object, mockedFactory.Object); // Act var result = service.DeleteMeasurement(id, userId); // Assert Assert.IsFalse(result); }
public void TestDeleteMeasurement_ShouldCallRepositoryGetById(int id, string userId) { // Arrange var mockedMeasurementRepository = new Mock <IRepository <Measurement> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedFactory = new Mock <IMeasurementFactory>(); var service = new MeasurementService(mockedMeasurementRepository.Object, mockedUnitOfWork.Object, mockedFactory.Object); // Act service.DeleteMeasurement(id, userId); // Assert mockedMeasurementRepository.Verify(r => r.GetById(id), Times.Once); }
public void TestDeleteMeasurement_RepositoryReturnsMeasurementWithDifferentUserId_ShouldReturnFalse(int id, string userId) { // Arrange var mockedMeasurementRepository = new Mock <IRepository <Measurement> >(); mockedMeasurementRepository.Setup(r => r.GetById(It.IsAny <object>())).Returns(new Measurement()); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedFactory = new Mock <IMeasurementFactory>(); var service = new MeasurementService(mockedMeasurementRepository.Object, mockedUnitOfWork.Object, mockedFactory.Object); // Act var result = service.DeleteMeasurement(id, userId); // Assert Assert.IsFalse(result); }
public void TestDeleteMeasurement_RepositoryReturnsMeasurementWithCorrectUserId_ShouldCallUnitOfWorkCommit(int id, string userId) { // Arrange var measurement = new Measurement { UserId = userId }; var mockedMeasurementRepository = new Mock <IRepository <Measurement> >(); mockedMeasurementRepository.Setup(r => r.GetById(It.IsAny <object>())).Returns(measurement); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedFactory = new Mock <IMeasurementFactory>(); var service = new MeasurementService(mockedMeasurementRepository.Object, mockedUnitOfWork.Object, mockedFactory.Object); // Act service.DeleteMeasurement(id, userId); // Assert mockedUnitOfWork.Verify(u => u.Commit(), Times.Once); }