Exemplo n.º 1
0
        public async Task Given_superhero_with_existing_city_When_Create_it_Creates_superhero_and_returns_id()
        {
            var superhero = new SuperheroCreateDTO
            {
                Name            = "Selina Kyle",
                AlterEgo        = "Catwoman",
                CityName        = "Gotham City",
                Occupation      = "Thief",
                Gender          = Gender.Female,
                FirstAppearance = 1940,
                Powers          = new HashSet <string>
                {
                    "exceptional martial artist",
                    "gymnastic ability",
                    "combat skill"
                }
            };

            var id = await _repository.Create(superhero);

            Assert.Equal(3, id);

            var entity = _context.Superheroes
                         .Include(h => h.City)
                         .Include(h => h.Powers)
                         .ThenInclude(h => h.Power)
                         .FirstOrDefault(h => h.Id == id);

            Assert.Equal("Selina Kyle", entity.Name);
            Assert.Equal("Catwoman", entity.AlterEgo);
            Assert.Equal("Thief", entity.Occupation);
            Assert.Equal(Female, entity.Gender);
            Assert.Equal(1940, entity.FirstAppearance);
            Assert.Equal(2, entity.CityId);
            Assert.Equal("Gotham City", entity.City.Name);
            Assert.Equal(new[]
            {
                "exceptional martial artist",
                "gymnastic ability",
                "combat skill"
            },
                         entity.Powers.Select(p => p.Power.Name).ToHashSet()
                         );
        }
Exemplo n.º 2
0
        public void Given_hero_create_creates()
        {
            var hero = new SuperheroCreateDTO
            {
                Name     = "Selina Kyle",
                AlterEgo = "Catwoman",
                CityName = "Gotham City",
                Gender   = Gender.Female
            };

            var id = _repository.Create(hero);

            Assert.Equal(3, id);

            var entity = _context.Superheroes.Include(c => c.City).FirstOrDefault(c => c.Id == id);

            Assert.Equal("Selina Kyle", entity.Name);
            Assert.Equal("Gotham City", entity.City.Name);
        }
Exemplo n.º 3
0
        public void Create_creates_a_hero()
        {
            var hero = new SuperheroCreateDTO
            {
                Name            = "Kara Zor-El",
                AlterEgo        = "Supergirl",
                Occupation      = "Actress",
                Gender          = Female,
                FirstAppearance = 1959,
                CityName        = "New York City"
            };

            var(_, id) = _repository.Create(hero);

            var created = _context.Superheroes.Find(id);

            Assert.Equal(9, created.Id);
            Assert.Equal("Kara Zor-El", created.Name);
            Assert.Equal("Supergirl", created.AlterEgo);
            Assert.Equal("Actress", created.Occupation);
            Assert.Equal(Female, created.Gender);
            Assert.Equal(1959, created.FirstAppearance);
            Assert.Equal(5, created.CityId);
        }