Exemple #1
0
        public async Task Given_existing_id_When_Read_it_returns_superhero()
        {
            var superhero = await _repository.Read(2);

            Assert.Equal("Bruce Wayne", superhero.Name);
            Assert.Equal("Batman", superhero.AlterEgo);
            Assert.Equal("CEO of Wayne Enterprises", superhero.Occupation);
            Assert.Equal(Male, superhero.Gender);
            Assert.Equal(1939, superhero.FirstAppearance);
            Assert.Equal(2, superhero.CityId);
            Assert.Equal("Gotham City", superhero.CityName);
            Assert.Equal(new[]
            {
                "exceptional martial artist",
                "combat strategy",
                "inexhaustible wealth",
                "brilliant deductive skills",
                "advanced technology"
            },
                         superhero.Powers
                         );
        }
Exemple #2
0
        static void Main(string[] args)
        {
            using var context = new SuperheroContext();
            var repository = new SuperheroRepository(context);

            foreach (var hero in repository.Read())
            {
                Console.WriteLine($"{hero.Id}: {hero.Name} aka {hero.AlterEgo}");
            }

            Console.Write("Enter superhero id: ");
            var id = int.Parse(Console.ReadLine());

            var superhero = repository.Read(id);

            Console.WriteLine($"Name: {superhero.Name}");
            Console.WriteLine($"Alter Ego: {superhero.AlterEgo}");
            Console.WriteLine($"Occupation: {superhero.Occupation}");
            Console.WriteLine($"City: {superhero.CityName}");
            Console.WriteLine($"Gender: {superhero.Gender}");
            Console.WriteLine($"First Appearance: {superhero.FirstAppearance}");
            Console.WriteLine($"Powers: {string.Join(", ", superhero.Powers)}");
        }
        public void Read_returns_all_heroes_sorted_by_AlterEgo()
        {
            var heroes = _repository.Read();

            Assert.Equal(new[] { "Batman", "Catwoman", "Superman" }, heroes.Select(s => s.AlterEgo));
        }