public async Task CustomerDomainServiceTests_ImportCustomer_Success() { _ = await RunWithTelemetryAsync( totalOfExecutions : 1, runInParallel : false, handler : async execution => { #region Arrange var result = false; var customer = new CustomerTest(null).CreateDefaultImportCustomer(); var customerDomainService = ServiceProvider.GetService <ICustomerDomainService>(); #endregion #region Act result = await customerDomainService.ImportCustomerAsync(customer) != null; #endregion #region Assert return(result); #endregion } ).ConfigureAwait(false); }
/// <summary> /// Update customer test by id /// </summary> /// <param name="id"></param> /// <param name="ct"></param> /// <returns></returns> public static CustomerRepsonse UpdateCustomerById(int id, CustomerTest ct) { CustomerRepsonse response = new CustomerRepsonse(); try { var cust = db.CustomerTests.Where(x => x.ID == id).FirstOrDefault(); if (cust != null) { db.CustomerTests.Remove(cust); //validate id int maxId = db.CustomerTests.Where(x => x.ID != cust.ID).Max(x => x.ID); if (maxId == ct.ID) { response.message = String.Format("There is already a customer with id {0}", id); return(response); } db.CustomerTests.Add(ct); } else { response.message = "No customer found"; return(response); } db.SaveChanges(); response.message = "Customer Updated successfully"; } catch (Exception ex) { response.message = String.Format("Unable to add cutomer test. Inner Exception {0}", ex.InnerException); } return(response); }
public async Task <ActionResult> Put(string id, [FromBody] CustomerTest value) { try { //kiểm tra giống ID hay không if (id.Equals(value.Id, StringComparison.OrdinalIgnoreCase)) { value.Code = value.Code.ToLower().Trim(); //cập nhật UpdatedOn value.UpdatedOn = DateTime.Now; //không cho chỉnh người tạo và IsActive- đề phòng hack /*value.CreatedBy = null; * value.IsActive = true;*/ //cập nhật UpdatedOn value.UpdatedOn = DateTime.Now; value.UpdatedBy = UserClaim.UserId; //gọi hàm update var result = await _serviceCustomerTest.UpdateAsync(id, value); return(Ok(result)); } return(BadRequest(StaticVar.MessageNotFound)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <ActionResult <CustomerTest> > Post([FromBody] CustomerTest data) { try { data.Code = data.Code.ToLower().Trim(); data.CreatedOn = DateTime.Now; data.CreatedBy = UserClaim.UserId; return(await _serviceCustomerTest.InsertAsync(data)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void Compose_Functions_ShouldResultFailureOutcome() { // Act PossibleBe <CustomerTest> possibleBeCustomer = new CustomerTest(); Outcome <CustomerTest> outcomeCustomer = possibleBeCustomer.TranslateToOutcome("error"); var outcomeResult = outcomeCustomer .Bind(outcome => Test(outcome)) .Bind(outcome2 => Test3(outcome2)) .WhenFailDo(outcome => Log(outcome.ErrorMessages.First())) .Return(x => x.Success ? 1 : -1); outcomeResult .Should() .Be(-1); }
public void TranslatePossibleBe_NullType_ToOutcome_T_ShouldBeSuccessfully() { PossibleBe <CustomerTest> possibleBeCustomer = new CustomerTest(); Outcome <CustomerTest> outcomeCustomer = possibleBeCustomer.TranslateToOutcome("error"); outcomeCustomer.Success .Should() .BeTrue(); outcomeCustomer.Value .Should() .NotBeNull(); outcomeCustomer.ErrorMessages .Should() .HaveCount(0); }
/// <summary> /// Insert customer test /// </summary> /// <param name="ct"></param> /// <returns></returns> public static CustomerRepsonse InsertCustomerTest(CustomerTest ct) { CustomerRepsonse response = new CustomerRepsonse(); try { //validate id int id = db.CustomerTests.Max(x => x.ID); if (id == ct.ID) { response.message = String.Format("There is already a customer with id {0}", id); return(response); } db.CustomerTests.Add(ct); db.SaveChanges(); response.message = "Customer added successfully"; } catch (Exception ex) { response.message = String.Format("Unable to add cutomer test. Inner Exception {0}", ex.InnerException); } return(response); }
public static IMaestroTester GetTester(string transaction) { IMaestroTester result = null; switch(transaction) { case "ORDER": result = new OrderTest(); break; case "CUSTOMER": result = new CustomerTest(); break; case "PRODUCT": result = new ProductTest(); break; case "UNIT": result = new UnitTest(); break; case "UNIT_TYPE": result = new UnitTypeTest(); break; case "TRAN_DEFINITION": result = new TranDefTest(); break; case "REGION": result = new RegionTest(); break; case "CUSTOMER_PRODUCT_UNIT": result = new CustomerProductUnitTest(); break; case "QUICKBOOKS_INVOICE": result = new QbInvoiceTest(); break; } return result; }
public void Compose_Functions_ShouldResultSuccessullyOutcome() { // Act PossibleBe <CustomerTest> possibleBeCustomer = new CustomerTest(); Outcome <CustomerTest> outcomeCustomer = possibleBeCustomer.TranslateToOutcome("error"); var outcomeResult = outcomeCustomer .Bind(firstParameter => Test(firstParameter)) .Bind(parameterFromPreviousExecution => Test2(parameterFromPreviousExecution)); outcomeResult.Failure .Should() .BeFalse(); outcomeResult.ErrorMessages .Should() .NotBeNull() .And .HaveCount(0); outcomeResult.Success .Should() .BeTrue(); }
public async Task <IActionResult> AddOrEdit(string id, CustomerTest data) { if (ModelState.IsValid) { //Insert if (String.IsNullOrEmpty(id)) { try { // Check isset code ? if (await ApiHelper <bool> .CheckIssetCode($"{StaticVar.ApiUrlCustomers}/ExistsCode/{data.Code}")) { ModelState.AddModelError("", StaticVar.MessageCodeDuplicated); return(Json(new { isValid = false, html = MyViewHelper.RenderRazorViewToString(this, "AddOrEdit", data) })); } else { try { CustomerTest result = await ApiHelper <CustomerTest> .RunPostAsync(StaticVar.ApiUrlCustomers, data); } catch (Exception ex) { return(Json(new { isValid = false, html = MyViewHelper.RenderRazorViewToString(this, "Error", new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, Message = ex.Message }) })); } } } catch (Exception ex) { return(Json(new { isValid = false, mes = ex.Message })); } } //Update else { // Check isset code , but allow itself !! CustomerTest _object = await ApiHelper <CustomerTest> .RunGetAsync($"{StaticVar.ApiUrlCustomers}/GetDetails/{data.Code}"); if (_object == null || _object.Id.Equals(data.Id)) { try { await ApiHelper <CustomerTest> .RunPutAsync($"{StaticVar.ApiUrlCustomers}/{id}", data); } catch (Exception ex) { return(Json(new { isValid = false, html = MyViewHelper.RenderRazorViewToString(this, "Error", new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, Message = ex.Message }) })); } } else { ModelState.AddModelError("", StaticVar.MessageCodeDuplicated); return(Json(new { isValid = false, html = MyViewHelper.RenderRazorViewToString(this, "AddOrEdit", data) })); } } return(Json(new { isValid = true, html = MyViewHelper.RenderRazorViewToString(this, "_ViewAll") })); } return(Json(new { isValid = false, html = MyViewHelper.RenderRazorViewToString(this, "AddOrEdit", data) })); }
private void Btn_Click(object sender, EventArgs e) { try { switch (((SimpleButton)sender).Name) { case "btnBrowse": LF_ImageFile(); break; case "btnNew": panelMain.Enabled = true; txtCustomerID.Focus(); _customer = new CustomerTest(); _test.CustomerTest.Add(_customer); customerTestBindingSource.Add(_customer); customerTestBindingSource.MoveLast(); break; case "btnEdit": panelMain.Enabled = true; txtCustomerID.Focus(); break; case "btnCancel": panelMain.Enabled = false; txtCustomerID.Focus(); foreach (DbEntityEntry entry in _test.ChangeTracker.Entries()) { switch (entry.State) { case EntityState.Added: entry.State = EntityState.Detached; break; case EntityState.Modified: entry.State = EntityState.Unchanged; break; case EntityState.Deleted: entry.Reload(); break; default: break; } } break; case "btnSave": customerTestBindingSource.EndEdit(); _test.SaveChangesAsync(); panelMain.Enabled = false; break; default: break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public CustomerRepsonse UpdateCutomer(int id, CustomerTest ct) { return(CustomerCRUD.UpdateCustomerById(id, ct)); }
public CustomerRepsonse PostCustomer(CustomerTest ct) { return(CustomerCRUD.InsertCustomerTest(ct)); }
public async Task <CustomerTest> GetDetails(string id) { CustomerTest _data = await _serviceCustomerTest.GetByIDAsync(id); return(_data); }