Esempio n. 1
0
        public void Test_GenerateCode()
        {
            // Arrange
            _dbObjectName         = "GET_RATE_GROUP_DEF";
            _target.DbDataContext = _dbDataContext;
            _testSqlParameters    = new List <SqlParameter>();
            _dbSysUtilsMock.Setup(d => d.GetTablesFromSP(_connectionString, _dbObjectName)).Returns(_testParameters);
            _dbSysUtilsMock.Setup(d => d.GetParametersFromSP(_connectionString, _dbObjectName)).Returns(_testSqlParameters);

            var testClass = new StringBuilder();

            testClass.AppendLine("public interface IRategroupdefRepo");
            testClass.AppendLine("{");
            testClass.AppendLine("  IEnumerable<TableRategroupdef> GetAll();");
            testClass.AppendLine("  void Save(TableRategroupdef tableRategroupdef);");
            testClass.AppendLine("}");
            testClass.AppendLine();
            testClass.AppendLine("public class RategroupdefRepo : DataAccessBaseRepo, IRategroupdefRepo");
            testClass.AppendLine("{");
            testClass.AppendLine("  public IEnumerable<TableRategroupdef> GetAll()");
            testClass.AppendLine("  {");
            testClass.AppendLine("      var tableRategroupdef = new List<TableRategroupdef>();");
            testClass.AppendLine();
            testClass.AppendLine("      using (var db = new TransitDbDataContext(ConnectionString))");
            testClass.AppendLine("      {");
            testClass.AppendLine("          var dataList = db.GET_RATE_GROUP_DEF().ToList();");
            testClass.AppendLine("          tableRategroupdef.AddRange(dataList.Select(dataRategroupdef => new TableRategroupdef");
            testClass.AppendLine("          {");
            testClass.AppendLine("              Rate_group_code = dataRategroupdef.Rate_group_code,");
            testClass.AppendLine("              Service_level_no = dataRategroupdef.Service_level_no,");
            testClass.AppendLine("              Rate_group_description = dataRategroupdef.Rate_group_description,");
            testClass.AppendLine("              User_id = dataRategroupdef.User_id,");
            testClass.AppendLine("              Record_insert_timestamp = dataRategroupdef.Record_insert_timestamp.UtcDateTime");
            testClass.AppendLine("          }));");
            testClass.AppendLine("      }");
            testClass.AppendLine();
            testClass.AppendLine("      return tableRategroupdef;");
            testClass.AppendLine("  }");
            testClass.AppendLine();
            testClass.AppendLine("  public void Save(TableRategroupdef tableRategroupdef)");
            testClass.AppendLine("  {");
            testClass.AppendLine("      using (var db = new TransitDbDataContext(ConnectionString))");
            testClass.AppendLine("      {");
            testClass.AppendLine("          db.SAVE_RATE_GROUP_DEF(tableRategroupdef.Rate_group_code, tableRategroupdef.Service_level_no, tableRategroupdef.Rate_group_description, tableRategroupdef.User_id, tableRategroupdef.Record_insert_timestamp);");
            testClass.AppendLine("      }");
            testClass.AppendLine("  }");
            testClass.AppendLine("}");

            // Act
            var result = _target.GenerateCode(_testProperties, _connectionString, _dbObjectName);

            // Assert
            Assert.IsTrue(testClass.Equals(result));
        }
Esempio n. 2
0
        public IResult Add(Product product)
        {
            var result = BusinessRules.Run(CheckIfProductNameExists(product.Name));

            if (result != null)
            {
                return(new ErrorResult(result.Message));
            }

            product.Code       = _codeGeneratorService.GenerateCode(product);
            product.CreateDate = DateTime.Now;
            product.Active     = true;
            _productDal.Add(product);
            return(new SuccessResult(BusinessMessages.ProductAdded));
        }
Esempio n. 3
0
        public void GenerateCode_Test()
        {
            // Arrange
            _modelPropertyControllerMock.Setup(m => m.GetNullableMarkIfApplicable(_testModelProperties[0])).Returns("");
            _modelPropertyControllerMock.Setup(m => m.GetNullableMarkIfApplicable(_testModelProperties[1])).Returns("");
            _modelPropertyControllerMock.Setup(m => m.GetNullableMarkIfApplicable(_testModelProperties[2])).Returns("");
            _modelPropertyControllerMock.Setup(m => m.GetNullableMarkIfApplicable(_testModelProperties[3])).Returns("");
            _modelPropertyControllerMock.Setup(m => m.GetNullableMarkIfApplicable(_testModelProperties[4])).Returns("");
            _dbSysUtilsMock.Setup(d => d.GetTablesFromSP(_connectionString, _dbObjectName)).Returns(_testTables);

            var testClass = new StringBuilder();

            testClass.AppendLine("public class TableRate_group_def");
            testClass.AppendLine("{");
            testClass.AppendLine("  public int Rate_group_code { get; set; }");
            testClass.AppendLine("  public int Service_level_no { get; set; }");
            testClass.AppendLine("  public string Rate_group_description { get; set; }");
            testClass.AppendLine("  public string User_id { get; set; }");
            testClass.AppendLine("  public DateTimeOffset Record_insert_timestamp { get; set; }");
            testClass.AppendLine("}");

            // Act
            var result = _target.GenerateCode(_testModelProperties, _connectionString, _dbObjectName);

            // Assert
            Assert.IsTrue(testClass.Equals(result));
        }
Esempio n. 4
0
        public IActionResult GenerateCode([FromBody] CodeGenerateRequest request)
        {
            var response = new OperationResponse <GeneratedCode>();

            try
            {
                response.Data = codeGeneratorService.GenerateCode(request.ProcedureName, request.Parameters);
            }
            catch (Exception exception)
            {
                response.State = ResponseState.Error;
                response.Messages.Add(exception.Message);
                _logger.LogError(exception, "Error Getting Procedure Params");
            }

            return(Json(response));
        }
Esempio n. 5
0
        /// <summary>
        /// handles the flow of user selection for code generator/reader
        /// </summary>
        /// <param name="codeReaderService"></param>
        /// <param name="codeGeneratorService"></param>
        /// <param name="configuration"></param>
        /// <param name="userSelection"></param>

        public static void ProcessUserSelection(ICodeReaderService codeReaderService, ICodeGeneratorService codeGeneratorService,
                                                IConfigurationRoot configuration, ConsoleKeyInfo userSelection, ILogger logger)
        {
            switch (userSelection.KeyChar)
            {
            case '1':
                codeReaderService.ReadCode(configuration, logger);
                break;

            case '2':
                codeGeneratorService.GenerateCode(configuration, logger);
                break;

            default:
                break;
            }
        }