public async void Delete_Errors() { MachineControllerMockFacade mock = new MachineControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object)); MachineController controller = new MachineController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Delete(default(string)); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Delete(It.IsAny <string>())); }
private void BwDo_DoWork(object sender, DoWorkEventArgs e) { try { var model = e.Argument as MachineModel; if (excuteMode == EExcute.Delete) { MachineController.Delete(model.MachineID); } else { MachineController.Insert(model); } machineUpdated = model; } catch (Exception ex) { Dispatcher.Invoke(new Action(() => { MessageBox.Show(ex.Message); })); } }
public async Task DeleteMachine() { var rep = CreateMock <IMachineRepository>(); var ctrl = new MachineController(); var machineEntity1 = new Machine { MachineID = 11, Name = "Maxi", MachineCommands = new MachineCommand[0], MachineInitCommands = new MachineInitCommand[0] }; rep.GetMachine(1).Returns(machineEntity1); var machine = await ctrl.Get(1); machine.Name = "SuperMaxi"; await ctrl.Delete(machine); await rep.Received().Delete(Arg.Is <Machine>(x => x.Name == "SuperMaxi")); await rep.Received().Delete(Arg.Is <Machine>(x => x.MachineID == 11)); }