public async void FunctionShouldCallWatchServiceOnce() { //Given var submodel = new SubscribeToMachineModel() { MachineId = "1", WatchId = "1" }; var req = new HttpRequestBuilder().Body(submodel).Build(); var watchService = new Mock <IWatchService>(); var machineService = new Mock <IMachineService>(); MachineWatch mw = new MachineWatch { Machine = new Core.Entity.DB.Machine { MachineId = "1" }, WatchId = "1" }; //When watchService.Setup(ms => ms.SubscribeToMachine(mw)); var res = await new SubscribeToMachine(watchService.Object, machineService.Object).Run(req, logger); //Then watchService.Verify(ms => ms.SubscribeToMachine(It.IsAny <MachineWatch>()), Times.Once()); }
public MachineWatch ReadMachineSubscriptionOfMachineByWatch(string machineId, string watchdId) { MachineWatch mw = _ctx.MachineWatch .Include(mw => mw.Machine) .Where(mw => mw.Machine.MachineId == machineId && mw.WatchId == watchdId) .FirstOrDefault(); return(mw); }
private MachineWatch ParseFunctionModelToDtoModel(SubscribeToMachineModel stmm) { AlarmSystem.Core.Entity.DB.Machine machine = _machineService.GetMachineById(stmm.MachineId); MachineWatch mw = new MachineWatch() { Machine = machine, WatchId = stmm.WatchId }; return(mw); }
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 async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "subscribeToMachine")] HttpRequest req, ILogger log) { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); SubscribeToMachineModel stmm = JsonConvert.DeserializeObject <SubscribeToMachineModel>(requestBody); try { MachineWatch mw = ParseFunctionModelToDtoModel(stmm); _watchservice.SubscribeToMachine(mw); return(new OkResult()); } catch (EntityNotFoundException e) { return(new BadRequestObjectResult(e.Message)); } }
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); }
public void TestRepoShouldBeCalledOnceIfMachineWatchIsNotEmptyOrNull() { //Given var mockRepo = new Mock <IWatchRepository>(); var service = new WatchService(mockRepo.Object); MachineWatch mw = new MachineWatch { Machine = new Core.Entity.DB.Machine { MachineId = "1" }, WatchId = "1" }; //When mockRepo.Setup(mr => mr.SubscribeToMachine(It.IsAny <MachineWatch>())); service.SubscribeToMachine(mw); //Then mockRepo.Verify(mr => mr.SubscribeToMachine(It.IsAny <MachineWatch>()), Times.Once); }
public void SubscribeToMachine(MachineWatch mw) { _ctx.MachineWatch.Add(mw); _ctx.SaveChanges(); }
public void SubscribeToMachine(MachineWatch mw) { _watchRepo.SubscribeToMachine(mw); }
public void DeleteMachineSubscriptionFromWatch(MachineWatch mw) { _watchRepo.RemoveMachineSubscriptionFromWatch(mw); }
public void RemoveMachineSubscriptionFromWatch(MachineWatch mw) { _ctx.MachineWatch.Remove(mw); _ctx.SaveChanges(); }