public void TestServiceShouldThrowErrorIfParametersAreEmptyOrNull(string machineId, string watchId) { //Given var mockRepo = new Mock <IWatchRepository>(); var service = new WatchService(mockRepo.Object); var mw = new MachineWatch(); //When mockRepo.Setup(mr => mr.ReadMachineSubscriptionOfMachineByWatch(It.IsAny <string>(), It.IsAny <string>())).Returns(mw); //Then Assert.Throws <InvalidDataException>(() => service.GetMachineSubcriptionOfMachineFromWatch(machineId, watchId)); mockRepo.Verify(mr => mr.ReadMachineSubscriptionOfMachineByWatch(It.IsAny <string>(), It.IsAny <string>()), Times.Never); }
public void TestServiceShouldThrowErrorIfMachineWatchIsNotFound() { //Given var mockRepo = new Mock <IWatchRepository>(); var service = new WatchService(mockRepo.Object); var machineId = "machine-id-1"; var watchId = "watch-id-1"; //When mockRepo.Setup(mr => mr.ReadMachineSubscriptionOfMachineByWatch(It.IsAny <string>(), It.IsAny <string>())).Returns(It.IsAny <MachineWatch>); //Then Assert.Throws <EntityNotFoundException>(() => service.GetMachineSubcriptionOfMachineFromWatch(machineId, watchId)); mockRepo.Verify(mr => mr.ReadMachineSubscriptionOfMachineByWatch(It.IsAny <string>(), It.IsAny <string>()), Times.Once); }
public void TestServiceShouldCallRepoOnceIfParametersAreNotEmptyOrNull() { //Given var mockRepo = new Mock <IWatchRepository>(); var service = new WatchService(mockRepo.Object); var machineId = "machine-id-1"; var watchId = "watch-id-1"; var mw = new MachineWatch(); //When mockRepo.Setup(mr => mr.ReadMachineSubscriptionOfMachineByWatch(It.IsAny <string>(), It.IsAny <string>())).Returns(mw); service.GetMachineSubcriptionOfMachineFromWatch(machineId, watchId); //Then mockRepo.Verify(mr => mr.ReadMachineSubscriptionOfMachineByWatch(It.IsAny <string>(), It.IsAny <string>()), Times.Once); }