public async Task AddMachine() { var rep = CreateMock <IMachineRepository>(); var ctrl = new MachineController(); var machineEntity1 = new CNCLib.Logic.Contracts.DTO.Machine { MachineID = 1, Name = "Maxi", MachineCommands = new CNCLib.Logic.Contracts.DTO.MachineCommand[] { new CNCLib.Logic.Contracts.DTO.MachineCommand { MachineID = 1, MachineCommandID = 1, CommandName = @"1", CommandString = @"1", PosX = 0, PosY = 1 } }, MachineInitCommands = new CNCLib.Logic.Contracts.DTO.MachineInitCommand[] { new CNCLib.Logic.Contracts.DTO.MachineInitCommand { MachineID = 1, MachineInitCommandID = 1, CommandString = "2", SeqNo = 1 } } }; var machineID = await ctrl.Add(machineEntity1); await rep.ReceivedWithAnyArgs().Store(new Machine()); Assert.AreEqual(machineID, 0); }
private void btnAddMachine_Click(object sender, EventArgs e) { bool noWriteMachineInfo = false; List <StateClass> shaftClasses = new List <StateClass>(); List <StateClass> bearingClasses = new List <StateClass>(); string marking = ""; string id = ""; float power = 0; float speed = 0; int countpair = 0; try { marking = tbMarking.Text; id = tbID.Text; power = float.Parse(tbPower.Text); speed = float.Parse(tbSpeed.Text); countpair = Int32.Parse(tbCountPair.Text); } catch (Exception ex) { MessageBox.Show("Данные введены некорректно!"); } finally { if (marking == "" | id == "" | power == 0 | speed == 0 | countpair == 0) { noWriteMachineInfo = true; } } bool noWriteStateClassesShaft = false; bool noWriteStateClassesBearing = false; for (int i = 0; i < dgvStateClassesBearing.RowCount - 1; i++) { for (int j = 0; j < 4; j++) { if (dgvStateClassesBearing[j, i].Value == null) { noWriteStateClassesBearing = true; } } if (!noWriteStateClassesBearing) { float head = float.Parse(dgvStateClassesBearing[0, i].Value.ToString()); // напор float nicely = float.Parse(dgvStateClassesBearing[1, i].Value.ToString()); //Хорошо float acceptably = float.Parse(dgvStateClassesBearing[2, i].Value.ToString()); float limited = float.Parse(dgvStateClassesBearing[3, i].Value.ToString()); StateClass stateClass = new StateClass { PumpHead = head, nicely = nicely, acceptably = acceptably, limited = limited, }; bearingClasses.Add(stateClass); } else if (noWriteStateClassesBearing && ((dgvStateClassesBearing[0, i].Value != null) || (dgvStateClassesBearing[1, i].Value != null) || (dgvStateClassesBearing[2, i].Value != null) || (dgvStateClassesBearing[3, i].Value != null))) { MessageBox.Show("Данные по классам состояния подшипника заполнены не корректно!"); } } for (int i = 0; i < dgvStateClassesShaft.RowCount - 1; i++) { for (int j = 0; j < 4; j++) { if (dgvStateClassesShaft[j, i].Value == null) { noWriteStateClassesShaft = true; } } if (!noWriteStateClassesShaft) { float head = float.Parse(dgvStateClassesShaft[0, i].Value.ToString()); // напор float nicely = float.Parse(dgvStateClassesShaft[1, i].Value.ToString()); //Хорошо float acceptably = float.Parse(dgvStateClassesShaft[2, i].Value.ToString()); float limited = float.Parse(dgvStateClassesShaft[3, i].Value.ToString()); StateClass stateClass = new StateClass { PumpHead = head, nicely = nicely, acceptably = acceptably, limited = limited, }; shaftClasses.Add(stateClass); } else if (noWriteStateClassesShaft && ((dgvStateClassesShaft[0, i].Value != null) || (dgvStateClassesShaft[1, i].Value != null) || (dgvStateClassesShaft[2, i].Value != null) || (dgvStateClassesShaft[3, i].Value != null))) { MessageBox.Show("Данные по классам состояния сопряжения валов заполнены не корректно!"); } } if (!noWriteStateClassesShaft & !noWriteStateClassesBearing & !noWriteMachineInfo) { if (MachineController.Add(marking, id, power, speed, countpair, shaftClasses, bearingClasses)) { MessageBox.Show("Машина добавлена успешно!"); this.Close(); } } else { MessageBox.Show("Данные введены некорректно!"); } }