public void ShouldAddPerson()
        {
            // Arrange
            var employee1        = Testdata.Employees.CreateEmployee1();
            var personRepository = new InMemoryPersonRepository();

            // Act
            personRepository.Add(employee1);

            // Assert
            var allPersons = personRepository.GetAll();

            allPersons.Should().HaveCount(1);
        }
        public async Task ShouldAddPerson_Parallel()
        {
            // Arrange
            var personRepository = new InMemoryPersonRepository();

            // Act
            var tasks = Enumerable.Range(1, 100).Select(i => Task.Factory.StartNew(() =>
            {
                var employee = Testdata.Employees.CreateEmployee1();
                personRepository.Add(employee);
                this.testOutputHelper.WriteLine($"personRepository.Add(Id={employee.Id})");
            }));

            await Task.WhenAll(tasks);

            // Assert
            var allPersons = personRepository.GetAll();

            allPersons.Should().HaveCount(100);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            ICityRepository   cityRepo         = new InMemoryCityRepository();
            IPersonRepository personRepository = new InMemoryPersonRepository(cityRepo);

            // Toutes les villes
            Console.WriteLine("Toutes les villes");
            foreach (var c in cityRepo.GetAll())
            {
                Console.WriteLine(c);
            }
            Console.WriteLine("--------------------------");
            // Toutes les personnes
            Console.WriteLine("Toutes les personnes");
            foreach (var p in personRepository.GetAll())
            {
                Console.WriteLine(p);
            }
            Console.WriteLine("--------------------------");
            // Toutes les personnes nées apres 1970
            Console.WriteLine("Toutes les personnes nées apres 1970");
            var personBornAfter = personRepository.Find(p =>
                                                        p.BirthDate.HasValue &&
                                                        p.BirthDate.Value.Year >= 1970);

            foreach (var p in personBornAfter)
            {
                Console.WriteLine(p);
            }
            Console.WriteLine("--------------------------");

            //Toutes les personne de plus de 40 ans
            Console.WriteLine("Personne ayant plus de 40 ans");
            var personOlderThan = personRepository
                                  .Find(p =>
                                        p.Age.HasValue &&
                                        p.Age.Value >= 40);

            foreach (var p in personOlderThan)
            {
                Console.WriteLine(p);
            }
            Console.WriteLine("--------------------------");

            // Toutes les villes qui contiennent un "e"
            Console.WriteLine("Toute les villes qui contiennent un \"e\"");
            var citiesWithE = cityRepo
                              .Find(c =>
                                    c.Name.IndexOf("e",
                                                   StringComparison.CurrentCultureIgnoreCase) >= 0);

            Console.WriteLine("--------------------------");
            foreach (var c in citiesWithE)
            {
                Console.WriteLine(c);
            }
            Console.WriteLine("--------------------------");

            //Effacer une ville
            var epinal = cityRepo.Single("Epinal");

            cityRepo.Delete(epinal);
            foreach (var c in cityRepo.GetAll())
            {
                Console.WriteLine(c);
            }
            Console.WriteLine("--------------------------");
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            ICityRepository cityRepository =
                new InMemoryCityRepository();
            IPersonRepository personRepository =
                new InMemoryPersonRepository(cityRepository);

            // Etat initial des villes
            foreach (var c in cityRepository.GetAll())
            {
                Console.WriteLine(c);
            }
            Console.WriteLine("- - - - - - - -");
            // Ajouter une ville
            var cannes = new City {
                Name = "Cannes"
            };

            cityRepository.Update(cannes);
            foreach (var c in cityRepository.GetAll())
            {
                Console.WriteLine(c);
            }
            Console.WriteLine("- - - - - - - -");
            // Mettre à jour une ville
            var epinal = cityRepository.Single("Epinal");

            if (epinal != null)
            {
                epinal.Name += " sur mer";
                cityRepository.Update(epinal);
                foreach (var c in cityRepository.GetAll())
                {
                    Console.WriteLine(c);
                }
                Console.WriteLine("- - - - - - - -");
            }
            // ajout et mise à jour dans une même update
            var lyon = new City {
                Name = "Lyon"
            };

            if (epinal != null)
            {
                epinal.Name = "Epinal";
            }
            cityRepository.UpdateRange(lyon, epinal);
            foreach (var c in cityRepository.GetAll())
            {
                Console.WriteLine(c);
            }
            Console.WriteLine("- - - - - - - -");

            // Ajout et mise à jour d'une personne
            var jonDoe = new Person
            {
                FirstName = "Jon",
                LastName  = "DOE",
                BirthDate = new DateTime(1975, 8, 11),
                City      = cityRepository.Single("Lyon")
            };
            var person2 = personRepository.Single(2);

            person2.BirthDate =
                person2.BirthDate.Value.AddYears(-100);
            personRepository.UpdateRange(jonDoe, person2);
            foreach (var p in personRepository.GetAll())
            {
                Console.WriteLine(p);
            }
            Console.WriteLine("- - - - - - - -");
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            /*string result =  Hello.GreetUpper("Kail");
             * Console.WriteLine(result);
             * var me = new Person
             * {
             *  FirstName = "KASSAMBA",
             *  LastName = "Hussein Diaby",
             *  BirthDate = new DateTime(2000,6,6),
             *  city = new City{Name="Toulon"}
             * };
             * Console.WriteLine(me);
             * var cityRepo = new InMemoryCityRepository();
             * Console.WriteLine(cityRepo.Single(3));
             * Console.WriteLine(cityRepo.Single("Toulon"));
             * var allCities = cityRepo.GetAll();
             * foreach(var c  in allCities) {Console.WriteLine(c);}*/

            ICityRepository   cityRepository   = new InMemoryCityRepository();
            IPersonRepository personRepository = new InMemoryPersonRepository(cityRepository);

            //Etat initial
            foreach (var c in cityRepository.GetAll())
            {
                Console.WriteLine(c);
            }
            Console.WriteLine("-------------------");
            //Ajouter une ville
            var cannes = new City {
                Name = "Cannes"
            };

            cityRepository.Update(cannes);
            foreach (var c in cityRepository.GetAll())
            {
                Console.WriteLine(c);
            }
            Console.WriteLine("-----------------");
            //Mettre a jour une ville
            var aubagne = cityRepository.Single("Aubagne");

            if (aubagne != null)
            {
                aubagne.Name += " sur-mer";
                cityRepository.Update(aubagne);
                foreach (var c in cityRepository.GetAll())
                {
                    Console.WriteLine(c);
                }
                Console.WriteLine("----------------");
            }

            //Ajout et mise a jour dans une meme update
            var lyon = new City {
                Name = "Lyon"
            };

            if (aubagne != null)
            {
                aubagne.Name = "Aubagne";
            }
            cityRepository.UpdateRange(lyon, aubagne);
            foreach (var c in  cityRepository.GetAll())
            {
                Console.WriteLine(c);
            }
            Console.WriteLine("--------------------------");

            //ajout et mis a jour d'une personne
            var jonDoe = new Person {
                FirstName = "Jon",
                LastName  = "DOE",
                BirthDate = new DateTime(1975, 8, 1),
                city      = cityRepository.Single("Lyon")
            };

            var person2 = personRepository.Single(2);

            person2.BirthDate = person2.BirthDate.Value.AddYears(-100);
            personRepository.UpdateRange(jonDoe, person2);
            foreach (var p in personRepository.GetAll())
            {
                Console.WriteLine(p);
            }
            Console.WriteLine("-----------------------");
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            /* string world = Hello.Greet("Kall");
             * Console.WriteLine(world);
             *
             * string greet = Hello.World;
             * Console.WriteLine(greet);
             *
             * var greetUpper = Hello.GreetUpper("Kall");
             * Console.WriteLine(greetUpper); */

            /* var me = new Person
             * {
             *  FirstName = "Florian",
             *  LastName = "Munini",
             *  City = new City { Name = "Toulon" },
             *  BirthDate = new DateTime(1996,9,16)
             * };
             *
             * Console.WriteLine(me); */

            ICityRepository   cityRepository   = new InMemoryCityRepository();
            IPersonRepository personRepository = new InMemoryPersonRepository(cityRepository);

            /*  // Toutes les villes
             * foreach (var c in cityRepository.GetAll()) Console.WriteLine(c);
             * Console.WriteLine("----------------------");
             * // Toutes les Person
             * foreach (var p in personRepository.GetAll()) Console.WriteLine(p);
             * Console.WriteLine("----------------------");
             * // Person nés après 1995
             * var personBornAfter =
             *   personRepository.Find(p =>
             *   p.BirthDate.HasValue &&
             *   p.BirthDate.Value.Year >= 1996);
             * foreach (var p in personBornAfter) Console.WriteLine(p);
             * Console.WriteLine("----------------------");
             *
             * // Person ayant plus de 21 ans
             * var personOlderThan = personRepository.Find (p =>
             *   p.Age.HasValue &&
             *   p.Age.Value>=22);
             * foreach (var p in personOlderThan) Console.WriteLine(p);
             * Console.WriteLine("----------------------");
             *
             * // City ayant un e
             * var citiesWithE =
             *   cityRepository.Find (c=>
             *       c.Name.IndexOf("e",StringComparison.CurrentCultureIgnoreCase)>=0);
             * foreach (var p in citiesWithE) Console.WriteLine(p);
             * Console.WriteLine("----------------------");
             *
             * // Delete de Epinal
             * var epinal = cityRepository.Single("Epinal");
             * cityRepository.Delete(epinal);
             * foreach (var c in cityRepository.GetAll()) Console.WriteLine(c);
             * Console.WriteLine("----------------------");
             *
             * // Delete une personne
             * personRepository.Delete (1);
             * foreach  (var p in personRepository.GetAll()) Console.WriteLine(p);
             * Console.WriteLine("----------------------"); */

            // Ajouter une ville
            foreach (var c in cityRepository.GetAll())
            {
                Console.WriteLine(c);
            }
            Console.WriteLine("----------------------");
            var cannes = new City {
                Name = "Cannes"
            };

            cityRepository.Update(cannes);
            foreach (var c in cityRepository.GetAll())
            {
                Console.WriteLine(c);
            }
            Console.WriteLine("----------------------");
            var epinal = cityRepository.Single("Epinal");

            if (epinal != null)
            {
                epinal.Name += " sur mer";
                cityRepository.Update(epinal);
                foreach (var c in cityRepository.GetAll())
                {
                    Console.WriteLine(c);
                }
                Console.WriteLine("----------------------");
            }

            // Ajout et mise a jour dans les updates
            var lyon = new City {
                Name = "Lyon"
            };

            if (epinal != null)
            {
                epinal.Name = "Epinal";
                cityRepository.UpdateRange(lyon, epinal);
                foreach (var c in cityRepository.GetAll())
                {
                    Console.WriteLine(c);
                }
                Console.WriteLine("----------------------");
            }

            var jonDoe = new Person {
                FirstName = "Jon",
                LastName  = "Doe",
                BirthDate = new DateTime(1975, 8, 11),
                City      = cityRepository.Single("Lyon")
            };
            var person2 = personRepository.Single(4);

            person2.BirthDate = person2.BirthDate.Value.AddYears(-100);
            personRepository.UpdateRange(jonDoe, person2);
            foreach (var p in personRepository.GetAll())
            {
                Console.WriteLine(p);
            }
            Console.WriteLine("----------------------");
        }