public void People()
        {
            File.WriteAllText(_filePath, "last_name,first_name,date_of_birth,email\r\nDoe,John,1982/10/08,[email protected]\r\nAnn,Mary,1975/09/11,[email protected]\r\n");
            _csvRepository = new CsvPersonRepository(_filePath);

            var expectedPeople = new List <PersonDto>
            {
                new PersonDto
                {
                    FirstName   = "John",
                    LastName    = "Doe",
                    DateOfBirth = "1982/10/08",
                    Email       = "*****@*****.**"
                },
                new PersonDto
                {
                    FirstName   = "Mary",
                    LastName    = "Ann",
                    DateOfBirth = "1975/09/11",
                    Email       = "*****@*****.**"
                }
            };

            expectedPeople.Should().BeEquivalentTo(_csvRepository.People());
        }
        public void TestDeleteRemovesPassedPerson()
        {
            CsvPersonRepository repo  = new CsvPersonRepository();
            IPerson             barry = repo.Get("Barry");
            bool barryExistsPrior     = repo.Get("Barry") != null;

            repo.Delete(repo.Get("Barry"));
            bool barryExistsAfter = repo.Get("Barry") != null;

            repo.Insert(barry);
            Assert.IsTrue(barryExistsPrior && !barryExistsAfter);
        }
        public void TestInsertInsertsPassedPerson()
        {
            CsvPersonRepository repo = new CsvPersonRepository();
            Person newPerson         = new Person()
            {
                Name = "TestMan",
                Age  = 999
            };
            bool personExistsBeforeInsert = repo.Get("TestMan") != null;
            bool personExistsAfterInsert  = repo.Insert(newPerson);
            bool personCanBeRetrieved     = repo.Get("TestMan") != null;

            Assert.IsTrue(!personExistsBeforeInsert && personExistsAfterInsert && personCanBeRetrieved);
        }
        public void TestGetPersonReturnsCorrectPerson()
        {
            CsvPersonRepository repo  = new CsvPersonRepository();
            IPerson             barry = repo.Get("Barry");

            try
            {
                Assert.IsTrue(barry.Name == "Barry");
                Assert.IsTrue(barry.Age == 32);
            }
            catch
            {
                Assert.IsTrue(false);
            }
        }
        public void TestGetAllReturnsExpectedCollection()
        {
            bool testPasses                 = true;
            CsvPersonRepository  repo       = new CsvPersonRepository();
            IQueryable <IPerson> repoPeople = repo.GetAll();

            foreach (IPerson person in GetExpectedCollection())
            {
                if (!repoPeople.Contains(person, new PersonComparator()))
                {
                    testPasses = false;
                }
            }

            Assert.IsTrue(testPasses);
        }
Exemple #6
0
 public void Main()
 {
     File.WriteAllText(_filePath, "last_name,first_name,date_of_birth,email\r\nDoe,John,1982/10/08,[email protected]\r\nAnn,Mary,1975/09/11,[email protected]\r\n");
     _csvRepository = new CsvPersonRepository(_filePath);
 }