public void TestServiceShouldThrowExceptionIfWatchIdIsNullOrEmpty(string watchId) { //Given var mockRepo = new Mock <IWatchRepository>(); var service = new WatchService(mockRepo.Object); int alarmId = 1; //When mockRepo.Setup(mr => mr.ReadSubscriptionOfAlarmFromWatch(It.IsAny <int>(), It.IsAny <string>())).Returns(new AlarmWatch()); //Then Assert.Throws <InvalidDataException>(() => service.GetSubscriptionOfAlarmFromWatch(alarmId, watchId)); mockRepo.Verify(mr => mr.ReadSubscriptionOfAlarmFromWatch(It.IsAny <int>(), It.IsAny <string>()), Times.Never); }
public void TestServiceShouldThrowEntityNotFoundExceptionIfAlarmWatchIsNull() { //Given var mockRepo = new Mock <IWatchRepository>(); var service = new WatchService(mockRepo.Object); int alarmId = 1; string watchId = "watch-id-1"; //When mockRepo.Setup(mr => mr.ReadSubscriptionOfAlarmFromWatch(It.IsAny <int>(), It.IsAny <string>())).Returns(It.IsAny <AlarmWatch>()); //Then Assert.Throws <EntityNotFoundException>(() => service.GetSubscriptionOfAlarmFromWatch(alarmId, watchId)); }
public void TestServiceShouldCallRepoMethodOnce() { //Given var mockRepo = new Mock <IWatchRepository>(); var service = new WatchService(mockRepo.Object); int alarmId = 1; string watchId = "watch-id-1"; //When mockRepo.Setup(mr => mr.ReadSubscriptionOfAlarmFromWatch(It.IsAny <int>(), It.IsAny <string>())).Returns(new AlarmWatch()); service.GetSubscriptionOfAlarmFromWatch(alarmId, watchId); //Then mockRepo.Verify(mr => mr.ReadSubscriptionOfAlarmFromWatch(It.IsAny <int>(), It.IsAny <string>()), Times.Once); }