public void GenerateUpdateAsync() { // Arrange var objUser = new User(); IList <PropertyInfo> props = new List <PropertyInfo>(objUser.GetType().GetProperties()); var content = DapperGenerator.Update("User", props, false, false, false, true); // Act var ret = MethodGenerator.GenerateUpdate(content, model, false, true); // Assert Assert.Contains("public async Task UpdateUser(User user)", ret); Assert.Contains(content, ret); }
private void GenerateCrud() { try { Logger.Log("Initializing generation process..."); SetLoading(true); txtOutput.Text = string.Empty; foreach (var item in lstFiles.CheckedItems) { var model = item.ToString(); IList <PropertyInfo> properties = GetPropertyInfos(model); IList <PropertyInfo> propertiesUpdate = GetPropertyInfos(model); IList <PropertyInfo> propertiesDelete = GetPropertyInfos(model); string output = string.Empty; if (chkClass.Checked) { output += ClassGenerator.GenerateClassBody(model, chkInterface.Checked); if (chkSelect.Checked) { output += MethodGenerator.GenerateSelect( DapperGenerator.Select(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked), model, chkClass.Checked, chkAsync.Checked); } if (chkInsert.Checked) { output += MethodGenerator.GenerateInsert( DapperGenerator.Insert(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked, chkReturnIdentity.Checked), model, chkClass.Checked, chkAsync.Checked, chkReturnIdentity.Checked); } if (chkUpdate.Checked) { output += MethodGenerator.GenerateUpdate( DapperGenerator.Update(model, propertiesUpdate, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked), model, chkClass.Checked, chkAsync.Checked); } if (chkDelete.Checked) { output += MethodGenerator.GenerateDelete( DapperGenerator.Delete(model, propertiesDelete, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked), model, chkClass.Checked, chkAsync.Checked); } output += "}"; txtOutput.Text += output; if (chkGenerateFiles.Checked) { FileHelper.GenerateClass(output, model, Projectpath); } } else { if (chkGenerateMethod.Checked) { if (chkSelect.Checked) { txtOutput.Text += MethodGenerator.GenerateSelect(DapperGenerator.Select(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked), model, chkClass.Checked, chkAsync.Checked); } if (chkInsert.Checked) { txtOutput.Text += MethodGenerator.GenerateInsert(DapperGenerator.Insert(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked, chkReturnIdentity.Checked), model, chkClass.Checked, chkAsync.Checked, chkReturnIdentity.Checked); } if (chkUpdate.Checked) { txtOutput.Text += MethodGenerator.GenerateUpdate(DapperGenerator.Update(model, propertiesUpdate, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked), model, chkClass.Checked, chkAsync.Checked); } if (chkDelete.Checked) { txtOutput.Text += MethodGenerator.GenerateDelete(DapperGenerator.Delete(model, propertiesDelete, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked), model, chkClass.Checked, chkAsync.Checked); } } else { if (chkSelect.Checked) { txtOutput.Text += DapperGenerator.Select(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked); } if (chkInsert.Checked) { txtOutput.Text += DapperGenerator.Insert(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked, chkReturnIdentity.Checked); } if (chkUpdate.Checked) { txtOutput.Text += DapperGenerator.Update(model, propertiesUpdate, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked); } if (chkDelete.Checked) { txtOutput.Text += DapperGenerator.Delete(model, propertiesDelete, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked); } } } if (chkInterface.Checked) { output = InterfaceGenerator.GenerateInterfaceBody(model); if (chkSelect.Checked) { output += InterfaceGenerator.GenerateSelect(model, chkAsync.Checked); } if (chkInsert.Checked) { output += InterfaceGenerator.GenerateInsert(model, chkAsync.Checked, chkReturnIdentity.Checked); } if (chkUpdate.Checked) { output += InterfaceGenerator.GenerateUpdate(model, chkAsync.Checked); } if (chkDelete.Checked) { output += InterfaceGenerator.GenerateDelete(model, chkAsync.Checked); } output += "}"; txtOutput.Text += output; if (chkGenerateFiles.Checked) { FileHelper.GenerateInterface(output, model, Projectpath); } } } SetLoading(false); Logger.Log($"Process Completed Successfully!"); } catch (Exception ex) { SetLoading(false); Logger.Log($"Error during the operation: {ex.Message} InnerException {ex.InnerException} StackTrace {ex.StackTrace} Code {AssemblyHelper.codeGlobal}"); txtOutputLog.ForeColor = Color.Red; txtOutputLog.Text = $"Error during the operation: {ex.Message} InnerException {ex.InnerException} StackTrace {ex.StackTrace} Code {AssemblyHelper.codeGlobal}"; } }