public void Execute_Should_ReturnCustomerModel(string value, Delimiter value2) { var cust = DataParser.Execute(value, value2); Assert.Equal(cust.FirstName, FirstName); Assert.Equal(cust.LastName, LastName); Assert.Equal(cust.PropertyType, PropertyType); Assert.Equal(cust.Project, Project); Assert.Equal(cust.StartDate, FormattedDate); Assert.Equal(cust.Phone, Phone); }
public void Execute_Should_ReturnListOfCustomerModels(string[] value, Delimiter value2) { var customers = (DataParser.Execute(value, value2)).ToList(); Assert.Equal(2, customers.Count); foreach (var cust in customers) { Assert.Equal(cust.FirstName, FirstName); Assert.Equal(cust.LastName, LastName); Assert.Equal(cust.PropertyType, PropertyType); Assert.Equal(cust.Project, Project); Assert.Equal(cust.StartDate, FormattedDate); Assert.Equal(cust.Phone, Phone); } }
public ActionResult <CustomerModel> CreateCustomer([FromForm] string data) { try { var badRequestMsg = "The data format is not supported"; CustomerModel customer = null; if (String.IsNullOrEmpty(data)) { return(BadRequest(badRequestMsg)); } if (data.Contains("|")) { customer = DataParser.Execute(data, Delimiter.Pipe); } else if (data.Contains(",")) { customer = DataParser.Execute(data, Delimiter.Comma); } else if (data.Contains(" ")) { customer = DataParser.Execute(data, Delimiter.Space); } if (customer == null) { return(BadRequest(badRequestMsg)); } _collection.Add(customer); return(Created(String.Empty, customer)); } catch (Exception ex) { if (ex is DataParsingException) { return(BadRequest(ex.Message)); } return(StatusCode(500)); } }
public static IEnumerable <CustomerModel> Execute(string[] args) { ConsoleInput input = new ConsoleInput(); ParseFilePath(args[0], ref input); IEnumerable <string> lines = null; if (input.FilePath != null) { lines = File.ReadLines(input.FilePath); ParseDelimiter(args[1], ref input); ParseCommand(args[2], ref input); ParseCommandOption(args[3], ref input); } CustomerCollection collection = new CustomerCollection(); var customers = DataParser.Execute(lines, input.Delimiter); collection.AddRange(customers); return(collection.Sort(input.CommandOption)); }