Esempio n. 1
0
        public ActionResult <ClimberDto> CreateClimber(ClimberCreationDto climber)
        {
            var entity = _mapper.Map <Climber>(climber);

            _set.Add(entity);
            _context.SaveChanges();
            return(CreatedAtRoute(
                       "GetClimber",
                       new { climberId = entity.ClimberId },
                       _mapper.Map <ClimberDto>(entity)
                       ));
        }
        public void BasicDatabaseTest()
        {
            // Arrange
            var connectionStringBuilder =
                new SqliteConnectionStringBuilder {
                DataSource = ":memory:"
            };

            var connection = new SqliteConnection(connectionStringBuilder.ToString());

            var options = new DbContextOptionsBuilder <ClimbingRoutesContext>()
                          .UseSqlite(connection)
                          .Options;

            using (var context = new ClimbingRoutesContext(options))
            {
                context.Database.OpenConnection();
                context.Database.EnsureCreated();

                context.Users.Add(new Climber()
                {
                    FirstName = "Matthew", LastName = "??", Email = "*****@*****.**"
                });
                context.Users.Add(new Climber()
                {
                    FirstName = "Mark", LastName = "??", Email = "*****@*****.**"
                });
                context.Users.Add(new Climber()
                {
                    FirstName = "Luke", LastName = "??", Email = "*****@*****.**"
                });
                context.Users.Add(new Climber()
                {
                    FirstName = "John", LastName = "??", Email = "*****@*****.**"
                });

                context.SaveChanges();
            }

            int numUser;

            // Three are added in the seed data. For a total of 7...
            int expected = 7;

            using (var context = new ClimbingRoutesContext(options))
            {
                // Act
                numUser = context.Users.ToList().Count;
            }

            // Assert
            Assert.Equal(numUser, expected);
        }