/// <summary> /// Sorts the names in the given file /// outputs sorted names into a file named "sorted-names-list.txt". /// </summary> /// <param name="inputFilename">The file to sort.</param> private static void SortNames(string inputFilename) { try { var delimiter = " "; var outputFilename = "sorted-names-list.txt"; var reader = new PersonFileReader(inputFilename); var parser = new PersonFileParser(delimiter); var writer = new PersonFileWriter(outputFilename); var sorter = new PersonSorter(new PersonNameComparer()); var validator = new PersonValidator(); var processor = new PersonProcessor(reader, parser, writer, validator, sorter); var sortedList = processor.Process(); foreach (var person in sortedList) { System.Console.WriteLine(person.ToString()); } } catch (Exception ex) { System.Console.WriteLine(ex.Message); } }
public void CreatePerson_Successful( string firstName, string lastName, string heightText, int heightInInches) { PersonProcessor processor = new PersonProcessor(null); PersonModel expected = new PersonModel { FirstName = firstName, LastName = lastName, HeightText = heightText, HeightInInches = heightInInches, Id = 0 }; var actual = processor.CreatePerson(firstName, lastName, heightText); Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.FirstName, actual.FirstName); Assert.Equal(expected.LastName, actual.LastName); Assert.Equal(expected.HeightText, actual.HeightText); Assert.Equal(expected.HeightInInches, actual.HeightInInches); }
private void button1_Click(object sender, EventArgs e) { string email = tbEmail.Text; int id = int.Parse(tbID.Text); string fname = tbFN.Text; string lname = tbLN.Text; string phone = tbPhoneNumber.Text; PersonProcessor.CreatePerson(id, fname, lname, email, phone); resetForm(); }
public void WritetoFile_FirstAndLastName_Ordered_ShouldSucceed() { var directoryInfo = Directory.GetParent(Directory.GetCurrentDirectory()).Parent; if (directoryInfo == null) { return; } if (directoryInfo.Parent == null) { return; } // read the csv data file string filename = Path.Combine(directoryInfo.Parent.FullName, "Data\\data.csv"); List <Row> rows = FileProcessor.ReadFile(filename); List <Person> person = PersonProcessor.GetPersonList(rows); Dictionary <string, int> orderFirstname = PersonProcessor.PersonsFirstNameFrequency(person); Dictionary <string, int> orderLastName = PersonProcessor.PersonsLastNameFrequency(person); //Process the data before writing it to a text file List <Row> rowList = new List <Row>(); rowList.Add(new Row() { LineText = "Ordered FirstName" }); rowList.AddRange(orderFirstname.Select(first => new Row() { LineText = first.Key + ", " + first.Value })); rowList.Add(new Row() { LineText = "Ordered LastName" }); rowList.AddRange(orderLastName.Select(last => new Row() { LineText = last.Key + ", " + last.Value })); string writeFileName = Path.Combine(directoryInfo.Parent.FullName, "Data\\Names.txt"); // check and delete file first before creating a new file if (File.Exists(writeFileName)) { File.Delete(writeFileName); } FileProcessor.WriteFile(writeFileName, rowList); bool fileExist = File.Exists(writeFileName); Assert.IsTrue(fileExist); }
public void CanSendMessages() { var processor = new PersonProcessor(consumer.Object, publisher.Object); var elvis = new PersonMessage { Id = Guid.NewGuid(), Name = "Elvis" }; publisher.Setup(x => x.SendMessagesAsync(new[] { elvis })) .ReturnsAsync(true); processor.SendMessagesAsync(new[] { elvis }); }
public void ConvertHeightTextToInches_VariousOptions( string heightText, bool expectedIsValid, double expectedHeightInInches) { PersonProcessor processor = new PersonProcessor(null); var actual = processor.ConvertHeightTextToInches(heightText); Assert.Equal(expectedIsValid, actual.isValid); Assert.Equal(expectedHeightInInches, actual.heightInInches); }
public void ConvertHeightTextToInches_VariousOptions( string heightText, bool expectedIsValid, double expectedHeightInInches) { // We passes 'null' to the constructor because we do not use '_database' variable. PersonProcessor processor = new PersonProcessor(null); var actual = processor.ConvertHeightTextToInches(heightText); Assert.Equal(expectedIsValid, actual.isValid); Assert.Equal(expectedHeightInInches, actual.heightInInches); }
public void CreatePerson_ThrowsException(string firstName, string lastName, string heightText, string expectedInvalidParameter) { PersonProcessor processor = new PersonProcessor(null); var ex = Record.Exception(() => processor.CreatePerson(firstName, lastName, heightText)); Assert.NotNull(ex); Assert.IsType <ArgumentException>(ex); if (ex is ArgumentException argEx) { Assert.Equal(expectedInvalidParameter, argEx.ParamName); } }
public void GetPersonNameFrequency_OrderbyName_ShouldSucceed() { var personList = new List <Person> { new Person() { FirstName = "Matt", LastName = "Brown" }, new Person() { FirstName = "Heinrich", LastName = "Jones" }, new Person() { FirstName = "Johnson", LastName = "Smith" }, new Person() { FirstName = "Tim", LastName = "Johnson" }, }; var orderDictionary = PersonProcessor.PersonNameFrequency(personList); var topNameReturned = orderDictionary.FirstOrDefault(); var lastNameReturned = orderDictionary.LastOrDefault(); var johnsonFrequencyReturned = orderDictionary["Johnson"]; var brownFrequencyReturned = orderDictionary["Brown"]; var heinrichFrequencyReturned = orderDictionary["Heinrich"]; var johnsonFrequencyExpected = 2; var brownFrequencyExpected = 1; var heinrichFrequencyExpected = 1; var topNameCountExpected = 2; var topNameExpected = "Johnson"; var lastNameCountExpected = 1; var lastNameExpected = "Tim"; Assert.IsNotNull(topNameReturned); Assert.AreEqual(topNameCountExpected, topNameReturned.Value); Assert.AreEqual(topNameExpected, topNameReturned.Key); Assert.IsNotNull(lastNameReturned); Assert.AreEqual(lastNameCountExpected, lastNameReturned.Value); Assert.AreEqual(lastNameExpected, lastNameReturned.Key); Assert.AreEqual(johnsonFrequencyExpected, johnsonFrequencyReturned); Assert.AreEqual(brownFrequencyExpected, brownFrequencyReturned); Assert.AreEqual(heinrichFrequencyExpected, heinrichFrequencyReturned); }
public void ConvertHeightTextToInches_VariousOptions( string heightText, bool expectedIsValid, double expectedHeightInInches) { //He passes null because ConvertHeightTextToInches() and CreatePerson_Successful() methods do not access //the database isqlight even though it is a requirement for PersonProcessor PersonProcessor processor = new PersonProcessor(null); var actual = processor.ConvertHeightTextToInches(heightText); Assert.Equal(expectedIsValid, actual.isValid); Assert.Equal(expectedHeightInInches, actual.heightInInches); }
public PersonProcessorTests() { _conversionSvcMock = new Mock <INumberConversionService>(); _humanizerSvcMock = new Mock <IHumanizerService>(); _sut = new PersonProcessor(_conversionSvcMock.Object, _humanizerSvcMock.Object); _conversionSvcMock .Setup(s => s.SplitStringNumberIntoIntegralAndFractionParts(It.IsAny <string>(), out _iPart, out _fPart)) .Verifiable(); _humanizerSvcMock .Setup(s => s.NumbersToMoneyWords(It.IsAny <int>(), It.IsAny <int>())) .Verifiable(); }
public static void StartConsumer(BlockingCollection <Person> bCollection) { Console.WriteLine("Consumer started"); while (!bCollection.IsCompleted) { Person person = bCollection.Take(); AbstractProcessor <Person> processor = new PersonProcessor(); var persons = processor.Run(person); foreach (var p in persons) { Console.WriteLine("{0} - {1} - {2}", p.Id, p.Name, p.Lastname); } //Console.WriteLine(item); } }
public void CanProcessMessage() { var processor = new PersonProcessor(consumer.Object, publisher.Object); var elvis = new PersonMessage { Id = Guid.NewGuid(), Name = "Elvis" }; var message = new SQSEvent.SQSMessage { Body = elvis.ToJson() }; consumer.Setup(x => x.Process(new[] { message })) .Returns(Task.CompletedTask); processor.Process(new[] { message }); }
public void Is_File_Processed_Successfully() { // Arrange var inputFilename = "./unsorted-names-list.txt"; var outputFilename = "sorted-names-list.txt"; var delimiter = ""; var reader = new PersonFileReader(inputFilename); var parser = new PersonFileParser(delimiter); var writer = new PersonFileWriter(outputFilename); var sorter = new PersonSorter(new PersonNameComparer()); var validator = new PersonValidator(); var processor = new PersonProcessor(reader, parser, writer, validator, sorter); // Act var sortedList = processor.Process(); // Assert Assert.IsTrue(true); }
private void button2_Click(object sender, EventArgs e) { listBox1.Items.Clear(); var personId = textBox1.Text; var personData = PersonProcessor.LoadPerson(int.Parse(personId)); foreach (var row in personData) { listBox1.Items.Add( row.FirstName); listBox1.Items.Add( row.LastName); listBox1.Items.Add( row.Id); listBox1.Items.Add( row.PhoneNumber); listBox1.Items.Add( row.EmailAddress); } }
public void ProcessPersonFromFile_ShouldSucceed() { var directoryInfo = Directory.GetParent(Directory.GetCurrentDirectory()).Parent; if (directoryInfo == null) { return; } if (directoryInfo.Parent == null) { return; } // read the csv data file string filename = Path.Combine(directoryInfo.Parent.FullName, "Data\\data.csv"); List <Row> rows = FileProcessor.ReadFile(filename); //Process the data List <Person> person = PersonProcessor.GetPersonList(rows); Assert.AreEqual(8, person.Count); }
public void WritetoFile_PersonAddresses_ShouldSucceed() { var directoryInfo = Directory.GetParent(Directory.GetCurrentDirectory()).Parent; if (directoryInfo == null) { return; } if (directoryInfo.Parent == null) { return; } // read the csv file string filename = Path.Combine(directoryInfo.Parent.FullName, "Data\\data.csv"); List <Row> rows = FileProcessor.ReadFile(filename); List <Person> person = PersonProcessor.GetPersonList(rows); //Process the data before writing it to a text file List <string> orderDictionary = PersonProcessor.PersonsAddresses(person); List <Row> rowList = orderDictionary.Select(address => new Row() { LineText = address }).ToList(); string writeFileName = Path.Combine(directoryInfo.Parent.FullName, "Data\\Address.txt"); // check and delete file first before creating a new file if (File.Exists(writeFileName)) { File.Delete(writeFileName); } FileProcessor.WriteFile(writeFileName, rowList); bool fileExist = File.Exists(writeFileName); Assert.IsTrue(fileExist); }
public void GetPersonLastNameFrequency_ShouldSucceed() { var directoryInfo = Directory.GetParent(Directory.GetCurrentDirectory()).Parent; if (directoryInfo == null) { return; } if (directoryInfo.Parent == null) { return; } // read the csv data file string filename = Path.Combine(directoryInfo.Parent.FullName, "Data\\data.csv"); List <Row> rows = FileProcessor.ReadFile(filename); //Process the data List <Person> person = PersonProcessor.GetPersonList(rows); Dictionary <string, int> orderDictionary = PersonProcessor.PersonsLastNameFrequency(person); Assert.AreEqual(4, orderDictionary.Count); }
public void GetPersonAddresses_OrderbyStreetName_ShouldSucceed() { //Process the data var personList = new List <Person> { new Person() { FirstName = "Steven", LastName = "Jones", Address = new Address() { StreetName = "Alice Lane", StreetNumber = 15 } }, new Person() { FirstName = "Steven", LastName = "Brown", Address = new Address() { StreetName = "Sunset Ave", StreetNumber = 30 } }, new Person() { FirstName = "Jane", LastName = "Brown", Address = new Address() { StreetName = "Rockery Road", StreetNumber = 1 } }, new Person() { FirstName = "Maria", LastName = "Josephs", Address = new Address() { StreetName = "Church Str", StreetNumber = 350 } }, new Person() { FirstName = "Steven", LastName = "Daniels", Address = new Address() { StreetName = "Hamilton", StreetNumber = 5 } }, }; List <string> orderDictionary = PersonProcessor.PersonsAddresses_OrderbyStreetName(personList); var expectedAddress = new Address() { StreetName = "Alice Lane", StreetNumber = 15 }; var result = orderDictionary[0]; Assert.IsNotNull(expectedAddress); Assert.AreEqual(expectedAddress.ToString(), result); }