private void ShouldReturnSuccessForInsert() { var operationSecceded = false; var dataAccessJsonStr = string.Empty; var formattedJsonStr = string.Empty; try { for (int i = 1; i <= 10; i++) { var model = new BarangModel { tipe_id = (uint)(i % 2 == 0 ? 2 : 1), sub_tipe_id = (uint)(i % 2 == 0 ? 2 : 1), supplier_id = (uint)(i % 2 == 0 ? 2 : 1), satuan_id = (uint)(i % 2 == 0 ? 2 : 1), kode = $"0000{i}", nama = $"Nama Barang #{i}", stok = 0, hpp = 1000, harga_jual = 2000, minimal_stok = 0, }; _services.Insert(model); } operationSecceded = true; } catch (DataAccessException ex) { operationSecceded = ex.DataAccessStatusInfo.OperationSucceeded; dataAccessJsonStr = JsonConvert.SerializeObject(ex.DataAccessStatusInfo); formattedJsonStr = JToken.Parse(dataAccessJsonStr).ToString(); } try { Assert.True(operationSecceded); _testOutputHelper.WriteLine("Data berhasil ditambahkan."); } finally { _testOutputHelper.WriteLine(formattedJsonStr); } }
private void BarangEntryView_OnSaveData(object sender, EventArgs e) { using (new WaitCursorHandler()) { try { var listDataGrid = _view.ListDataGrid; var newModel = ((ModelEventArgs <BarangModel>)e).Value; var barangEntryView = ((BarangEntryView)sender); if (newModel.id == default(uint)) { _barangServices.Insert(newModel); barangEntryView.Controls.ClearControls(); Messages.InfoSave(_typeName); _listObjs.Add(newModel); _bindingView.DataSource = _listObjs; if (listDataGrid.SelectedItem != null) { listDataGrid.SelectedItem = null; } listDataGrid.SelectedItem = newModel; } else { _barangServices.Update(newModel); Messages.InfoUpdate(_typeName); barangEntryView.Close(); var model = _bindingView.Where(b => b.id == newModel.id).FirstOrDefault(); if (model != null) { model.nama = newModel.nama; model.tipe_id = newModel.tipe_id; model.stok_akhir = newModel.stok_akhir; model.keterangan = newModel.keterangan; _bindingView.Refresh(); } } } catch (ArgumentException ex) { Messages.Error(ex); } catch (DataAccessException ex) { Messages.Error(ex); } } }
private void ShouldReturnSuccessForInsert() { var operationSucceeded = false; var dataAccessJsonStr = string.Empty; var formattedJsonStr = string.Empty; try { for (int i = 1; i <= 10; i++) { var model = new BarangModel { nama = $"Nama Barang #{i}", tipe_id = (int)(i % 2 == 0 ? 2 : 1), stok_akhir = 100, keterangan = "Test" }; _services.Insert(model); } operationSucceeded = true; } catch (DataAccessException ex) { operationSucceeded = ex.DataAccessStatusInfo.OperationSucceeded; dataAccessJsonStr = JsonConvert.SerializeObject(ex.DataAccessStatusInfo); formattedJsonStr = JToken.Parse(dataAccessJsonStr).ToString(); } try { Assert.True(operationSucceeded); _testOutputHelper.WriteLine("Data berhasil ditambahkan."); } finally { _testOutputHelper.WriteLine(formattedJsonStr); } }