public void SearchByName_CatsAddressProperly()
        {
            // Arrange
            var mockPersonRepository = new Mock <IPersonRepository>();
            var persons = new List <Person>();
            var person1 = new Person
            {
                AddressLine1 = "AL1",
                AddressLine2 = "AL2",
                City         = "City",
                State        = "TX",
                Zip          = "12345"
            };

            persons.Add(person1);

            mockPersonRepository.Setup(foo => foo.SearchByName(It.IsAny <string>()))
            .Returns(Task.FromResult(persons));

            var sut = new PersonSearchService(mockPersonRepository.Object);

            // Act
            var ret = sut.SearchByName("anySearchString");

            // Assert
            Assert.Equal(ret.Result[0].Address, "AL1 AL2 City, TX 12345");
        }
        public void SearchByName_ConvertsDOBToAge()
        {
            // Arrange
            var mockPersonRepository = new Mock <IPersonRepository>();
            var persons = new List <Person>();

            persons.Add(new Person {
                FirstName = "test 1", DateOfBirth = DateTime.Now.AddYears(-10)
            });

            mockPersonRepository.Setup(foo => foo.SearchByName(It.IsAny <string>()))
            .Returns(Task.FromResult(persons));

            var sut = new PersonSearchService(mockPersonRepository.Object);

            // Act
            var ret = sut.SearchByName("anySearchString");

            // Assert
            Assert.Equal(ret.Result[0].Age, 10);
        }
Example #3
0
        public void WhenSearchingPeople(string name, Gender?gender, int pageNum, int pageSize, int resultCount)
        {
            // Arrange
            Mock <IDataStore <Data> > dataStore = new Mock <IDataStore <Data> >();

            dataStore.Setup(ds => ds.Get())
            .Returns(new Data
            {
                places = TestPlaces.GetPlaces(),
                people = TestPeople.GetPeople()
            });
            PersonSearchService classUnderTest = new PersonSearchService(dataStore.Object);

            PersonView[] result = null;

            // Act
            result = classUnderTest.Search(name, gender.HasValue ? gender.Value : Gender.Male | Gender.Female, pageNum, pageSize);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(resultCount, result.Length);
        }
        public void SearchByName_CatsNameProperly()
        {
            // Arrange
            var mockPersonRepository = new Mock <IPersonRepository>();
            var persons = new List <Person>();
            var person1 = new Person
            {
                FirstName = "FN1",
                LastName  = "LN1",
            };

            persons.Add(person1);

            mockPersonRepository.Setup(foo => foo.SearchByName(It.IsAny <string>()))
            .Returns(Task.FromResult(persons));

            var sut = new PersonSearchService(mockPersonRepository.Object);

            // Act
            var ret = sut.SearchByName("anySearchString");

            // Assert
            Assert.Equal(ret.Result[0].Name, "FN1 LN1");
        }
Example #5
0
        public void WhenSearchingAncestry(string name, Gender?gender, Ancestry ancestry, int resultCount,
                                          int[] expectedIds)
        {
            // Arrange
            Mock <IDataStore <Data> > dataStore = new Mock <IDataStore <Data> >();

            dataStore.Setup(ds => ds.Get())
            .Returns(new Data
            {
                places = TestPlaces.GetPlaces(),
                people = TestPeople.GetPeople()
            });
            PersonSearchService classUnderTest = new PersonSearchService(dataStore.Object);

            PersonView[] result = null;

            // Act
            result = classUnderTest.AncestrySearch(name, gender.HasValue ? gender.Value : Gender.Male | Gender.Female,
                                                   ancestry);
            Assert.IsNotNull(result);
            Assert.AreEqual(resultCount, result.Length);
            Assert.IsTrue(Enumerable.SequenceEqual(expectedIds, result.Select(p => p.Id)));
            // Assert
        }
        static void Main(string[] args)
        {
            var service       = new PersonService(new TextFileRepository());
            var searchservice = new PersonSearchService(new TextFileRepository());
            var bdayService   = new BirthdayMathService(new TextFileRepository());
            int option        = 0;

            do
            {
                Console.WriteLine("Who's having their birthday today:\n");

                bdayService.BirthdayPeople();

                Console.WriteLine("");

                Console.WriteLine("1 - Register a New Friend");
                Console.WriteLine("2 - Edit Friend");
                Console.WriteLine("3 - See Full List of Birthdays");
                Console.WriteLine("4 - Delete Friend");
                Console.WriteLine("5 - Search Friend");
                Console.WriteLine("6 - Exit");
                option = int.Parse(Console.ReadLine());
                Console.Clear();
                Person person;

                switch (option)
                {
                case 1:
                    person = new Person();

                    Console.WriteLine("Enter the friend's first name:");
                    person.FirstName = Console.ReadLine();

                    Console.WriteLine("Enter the friend's last name:");
                    person.LastName = Console.ReadLine();

                    Console.Write("Enter the day of the friend's birthday: ");
                    person.Day = int.Parse(Console.ReadLine());

                    Console.Write("Enter the month of the friend's birthday: ");
                    person.Month = int.Parse(Console.ReadLine());

                    Console.Write("Enter the year of the friend's birthday: ");
                    person.Year = int.Parse(Console.ReadLine());

                    service.RegisterPerson(person);
                    break;

                case 2:
                    person = new Person();
                    Console.WriteLine("Digite o Id do contato que deseja editar");
                    person.Id = Guid.Parse(Console.ReadLine());

                    Console.WriteLine("Enter the new first name");
                    person.FirstName = Console.ReadLine();

                    Console.WriteLine("Enter the new last name");
                    person.LastName = Console.ReadLine();

                    Console.Write("Enter the day of the friend's birthday: ");
                    person.Day = int.Parse(Console.ReadLine());

                    Console.Write("Enter the month of the friend's birthday: ");
                    person.Month = int.Parse(Console.ReadLine());

                    Console.Write("Enter the year of the friend's birthday: ");
                    person.Year = int.Parse(Console.ReadLine());

                    service.EditPerson(person);
                    break;

                case 3:
                    var people = service.GetAllBirthdays();
                    foreach (var listedperson in people)
                    {
                        Console.WriteLine("Id: " + listedperson.Id);
                        Console.WriteLine("Name: " + listedperson.FirstName + " " + listedperson.LastName);
                        Console.WriteLine("Birthday: " + listedperson.Birthday);
                        bdayService.RemainingDays(listedperson);
                        Console.WriteLine();
                    }
                    break;

                case 4:
                    Console.WriteLine("Digite o Id do contato que deseja remover:");
                    var id = Guid.Parse(Console.ReadLine());
                    service.DeletePerson(id);
                    break;

                case 5:
                    Console.WriteLine("Digite o nome do contato que está procurando:");
                    var name         = Console.ReadLine();
                    var searchResult = searchservice.SearchByName(name);
                    foreach (var curContact in searchResult)
                    {
                        Console.WriteLine("Id: " + curContact.Id);
                        Console.WriteLine("Name: " + curContact.FirstName + " " + curContact.LastName);
                        Console.WriteLine("Birthday: " + curContact.Birthday);
                        Console.WriteLine();
                    }
                    break;
                }

                Console.WriteLine();
                Console.WriteLine("Press ENTER to continue...");
                Console.ReadKey();
                Console.Clear();
            } while (option != 6);
        }