public void SetUp() { Cursus csharp = new Cursus(); AbstractPerson student1 = PersonFactory.Create("Tom", null, null, csharp); AbstractPerson student2 = PersonFactory.Create("Lys", null, null, csharp); AbstractPerson student3 = PersonFactory.Create("Nathaniel", null, null, csharp); List <AbstractPerson> _students = new List <AbstractPerson>(); _students.Add(student1); _students.Add(student2); _students.Add(student3); //List<AbstractPerson> _instructors = new List<AbstractPerson>(); AbstractPerson _instructor = PersonFactory.Create("Instructor1", _students); /*Cursus csharp = new Cursus(); * _students = new List<AbstractPerson> * { * new Students("Tom",csharp), * new Students("Lys", csharp), * new Students("Nathaniel",csharp) * }; * * _instructors = new List<AbstractPerson> * { * new Instructor("Instructor", _students) * }; * * _lead = new LeadInstructor("Chef", _instructors);*/ }
public static void Main(string[] args) { if (args.Length > 1) { Person person = PersonFactory.Create(args[0], args[1]); Console.WriteLine($"{person.CreatedBy} created Person with name {person.Name} at {person.CreatedDate}"); } }
public void BaseClassMethodReturnsBaseType() { var factory = new PersonFactory(); var person = factory.Create("Damir", "Arh"); Assert.That(person.GetType(), Is.EqualTo(typeof(PersonRecordImmutable))); }
public void TestCreateStudents() { Cursus csharp = new Cursus(); AbstractPerson student = PersonFactory.Create("Dan"); string typeName = typeof(Students).ToString(); Assert.AreEqual(typeName, student.GetType().ToString()); }
public void TestLeadingTrainerCreation() { List <AbstractPerson> people = new List <AbstractPerson> { new Trainer() }; AbstractPerson person = PersonFactory.Create(people); Assert.IsTrue(person.IsLead); }
public void TestTrainerCreation() { List <AbstractPerson> people = new List <AbstractPerson> { new Student() }; AbstractPerson person = PersonFactory.Create(people); Assert.AreEqual(person.GetType(), typeof(Trainer)); }
public void Execute_Should_ApplyAction(string firstName, string setInitials, string expectedInitials) { var handler = new ActionHandler <PersonStub>(x => x.Initials = x.FirstName.Substring(0, 1)); var person = PersonFactory.Create(firstName, setInitials); person.Initials.Should().Be(setInitials); handler.Execute(person); person.Initials.Should().Be(expectedInitials); }
public void ShortOrLongPasswordsFail(string name, string password) { try { Person person = PersonFactory.Create(name, password); } catch (ArgumentException e) { Assert.NotNull(e); } }
public void Run() { try { string[] peopleInput = Console.ReadLine() .Split(";") .ToArray(); List <Person> people = new List <Person>(); PersonFactory.Create(peopleInput, people); string[] productsInput = Console.ReadLine() .Split(";", StringSplitOptions.RemoveEmptyEntries) .ToArray(); List <Product> products = new List <Product>(); ProductFactory.Create(productsInput, products); string input = string.Empty; while ((input = Console.ReadLine()) != "END") { string[] elements = input .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToArray(); string personName = elements[0]; string productName = elements[1]; int indexPerson = people.FindIndex(x => x.Name == personName); int indexProduct = products.FindIndex(x => x.Name == productName); if (indexPerson == -1 || indexProduct == -1) { continue; } string result = people[indexPerson].BuyProduct(products[indexProduct]); Console.WriteLine(result); } foreach (Person person in people) { Console.WriteLine(person); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void Execute_Should_ApplyAction_With_ConditionFullFilled(string firstName, string setInitials, string expectedInitials) { var handler = new ActionHandler <PersonStub>( x => x.Initials = x.FirstName.Substring(0, 1), x => x.Initials == default && (x.FirstName?.Length ?? 0) > 0); var person = PersonFactory.Create(firstName, setInitials); person.Initials.Should().Be(setInitials); handler.Execute(person); person.Initials.Should().Be(expectedInitials); }
public void TestCreateInstructor() { Cursus csharp = new Cursus(); List <AbstractPerson> students = new List <AbstractPerson> { new Students("Dan", csharp) }; AbstractPerson instructor = PersonFactory.Create("Instructor", students); string typeName = typeof(Instructor).ToString(); Assert.AreEqual(typeName, instructor.GetType().ToString()); }
static void Main(string[] args) { List <Person> personList = new List <Person>(); PersonFactory factory = PersonFactory.Instance; personList.Add(factory.Create(123456789, "Smith", "John", DateTime.Parse("12 / 12 / 1992"))); personList.Add(factory.Create(111223345, "Kwan", "Steve", DateTime.Parse("06 / 08 / 1978"))); personList.Add(factory.Create(074897865, "Huey", "Leslie", DateTime.Parse("05 / 08 / 1984"))); personList.Add(factory.Create(087458741, "Shmitz", "Rob", DateTime.Parse("04 / 01 / 1965"))); personList.Add(factory.Create(123456789, "May", "Theresa", DateTime.Parse("08 / 09 / 1959"))); Person clonedPerson = personList[3].Clone() as Person; try { clonedPerson.FirstName = "Dolly"; clonedPerson.LastName = "The Human"; clonedPerson.DOB = DateTime.Now; } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(ex.Message); } personList.Add(clonedPerson); Console.WriteLine(Person.GetHeader()); foreach (Person p in personList) { Console.WriteLine(p); } Console.ReadLine(); }
public Person GetPersonById(int id) { try { var db = dbClient.GetDatabase(database); var collection = db.GetCollection <BsonDocument>("Person"); var filter = Builders <BsonDocument> .Filter.Eq("PersonId", id); var document = collection.Find(filter).FirstOrDefault(); Person person = PersonFactory.Create(document); return(person); } catch (Exception e) { Console.WriteLine(e.ToString()); return(null); } }
private void EnterPersons() { string input = Console.ReadLine(); while (input != "END") { string[] data = input.Split(); string name = data[0]; int age = int.Parse(data[1]); string town = data[2]; Person newPerson = factory.Create(name, age, town); persons.Add(newPerson); input = Console.ReadLine(); } }
private void EnterPersons() { int count = int.Parse(Console.ReadLine()); while (count > 0) { string input = Console.ReadLine(); string[] data = input.Split(); string name = data[0]; int age = int.Parse(data[1]); Person newPerson = factory.Create(name, age); personsByName.Add(newPerson); personsByAge.Add(newPerson); count--; } }
public Person GetPersonById(int id) { MySqlConnection conn = Connect(); try { conn.Open(); string sql = "SELECT * FROM person WHERE PersonId = " + id; MySqlCommand cmd = new MySqlCommand(sql, conn); MySqlDataReader rdr = cmd.ExecuteReader(); Person person = PersonFactory.Create(rdr); return(person); } catch (Exception e) { Console.WriteLine(e.ToString()); return(null); } finally { conn.Close(); } }
public void CreatePersonWithNameSucceeds(string name, string password) { Person person = PersonFactory.Create(name, password); Assert.Equal("Pratikchhya Shrestha", person.Name); }
public void Execute_Should_ReturnCorrectNumberOfMessages(string firstName, string intitials, int numberOfMessages) { var messages = Execute(PersonFactory.Create(firstName, intitials)); messages.Count.Should().Be(numberOfMessages); }
public void Execute_Should_ReturnMessage(string firstName) { var message = Execute(PersonFactory.Create(firstName)); message.Should().Be($"{nameof(PersonStub.FirstName)} [{firstName}] should not be null or whitespace."); }
public void Execute_Should_NotReturnMessage() { var message = Execute(PersonFactory.Create()); message.Should().Be(string.Empty); }
public void TestStudentCreation() { AbstractPerson person = PersonFactory.Create(); Assert.AreEqual(person.GetType(), typeof(Student)); }
public void Run() { //List<IIdentifiable> identifiables = new List<IIdentifiable>(); //string input = string.Empty; //while ((input = Console.ReadLine()) != "End") //{ // string[] elements = input // .Split(" ", StringSplitOptions.RemoveEmptyEntries) // .ToArray(); // IIdentifiable identifiable = IdentifiableFactory.Create(elements); // identifiables.Add(identifiable); //} //string targetId = Console.ReadLine(); //identifiables = identifiables // .Where(x => x.Id.EndsWith(targetId)) // .ToList(); //foreach (IIdentifiable identifiable in identifiables) //{ // Console.WriteLine(identifiable.Id); //} //List<IBirthable> birthables = new List<IBirthable>(); //string input = string.Empty; //while ((input = Console.ReadLine()) != "End") //{ // string[] elements = input // .Split(" ", StringSplitOptions.RemoveEmptyEntries) // .ToArray(); // try // { // IBirthable birthable = BirthtableFactory.Create(elements); // birthables.Add(birthable); // } // catch (Exception) // { // } //} //string targetBirthdate = Console.ReadLine(); //birthables = birthables // .Where(x => x.Birthdate.EndsWith(targetBirthdate)) // .ToList(); //foreach (IBirthable birthable in birthables) //{ // Console.WriteLine(birthable.Birthdate); //} List <Person> people = new List <Person>(); int numberOfLines = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfLines; i++) { string[] elements = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToArray(); Person person = PersonFactory.Create(elements); people.Add(person); } string input = string.Empty; while ((input = Console.ReadLine()) != "End") { string targetName = input; Person targetPerson = people .FirstOrDefault(x => x.Name == targetName); bool isValid = targetPerson != null; if (!isValid) { continue; } targetPerson.BuyFood(); } int totalFood = people .Select(x => x.Food) .Sum(); Console.WriteLine(totalFood); }
public static IPerson GetPerson(PersonSpecifications specs) { PersonFactory factory = new PersonFactory(specs); return(factory.Create()); }