Example #1
0
        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);
        }
Example #2
0
        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));
        }
Example #3
0
        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);
        }