コード例 #1
0
 public DataSeeding(ANightsTaleContext db, CharacterRepository repo)
 {
     _db       = db ?? throw new ArgumentNullException(nameof(db));
     _repo     = repo;
     _campRepo = new CampaignRepository(_db);
     _userRepo = new UserRepository(_db);
 }
コード例 #2
0
        public void DeleteCharacterFromDbAlsoDeletesCharStats()
        {
            // arrange
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var rand    = new RngProvider();
                var options = new DbContextOptionsBuilder <ANightsTaleContext>()
                              .UseSqlite(connection)
                              .Options;

                // Create the schema in the database
                using (var context = new ANightsTaleContext(options))
                {
                    context.Database.EnsureCreated();
                }

                // Act

                // Run the test against one instance of the context
                using (var context = new ANightsTaleContext(options))
                {
                    var         charRepo = new CharacterRepository(context);
                    DataSeeding seed     = new DataSeeding(context, charRepo);
                    seed.SeedCharacterSupportClasses();

                    var character = seed.SeedCharacter();

                    charRepo.AddCharacter(character);
                    charRepo.Save();

                    var stats = seed.SeedCharStats(character);
                    charRepo.AddCharStats(stats);
                    charRepo.Save();

                    charRepo.RemoveCharacter(1);
                    charRepo.Save();

                    // Assert
                    Assert.False(context.CharStats.Any());
                }
            }
            finally
            {
                connection.Close();
            }
        }
コード例 #3
0
        public void DeleteUserFromDbIsSuccessful()
        {
            // arrange
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <ANightsTaleContext>()
                              .UseSqlite(connection)
                              .Options;

                // Create the schema in the database
                using (var context = new ANightsTaleContext(options))
                {
                    context.Database.EnsureCreated();
                }

                // Act

                // Run the test against one instance of the context
                using (var context = new ANightsTaleContext(options))
                {
                    var repo = new UserRepository(context);

                    Library.Users user = new Library.Users
                    {
                        Username   = "******",
                        Password   = "******",
                        Permission = 0,
                        Email      = "*****@*****.**"
                    };

                    repo.CreateUser(user);
                    repo.Save();

                    repo.DeleteUser(1);
                    repo.Save();

                    // Assert
                    Assert.Empty(context.Users);
                }
            }
            finally
            {
                connection.Close();
            }
        }
コード例 #4
0
        public void SetAppropriateSavingThrows()
        {
            // arrange
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var rand    = new RngProvider();
                var options = new DbContextOptionsBuilder <ANightsTaleContext>()
                              .UseSqlite(connection)
                              .Options;

                // Create the schema in the database
                using (var context = new ANightsTaleContext(options))
                {
                    context.Database.EnsureCreated();
                }

                // Act

                // Run the test against one instance of the context
                using (var context = new ANightsTaleContext(options))
                {
                    var         charRepo = new CharacterRepository(context);
                    DataSeeding seed     = new DataSeeding(context, charRepo);
                    seed.SeedCharacterSupportClasses();

                    var character = seed.SeedCharacter();
                    var stats     = seed.SeedCharStats(character);

                    charRepo.SetSavingThrows(character, stats);

                    // Assert
                    Assert.Equal(-3, stats.STR_Save);
                    Assert.Equal(-1, stats.DEX_Save);
                    Assert.Equal(3, stats.CON_Save);
                    Assert.Equal(2, stats.INT_Save);
                    Assert.Equal(0, stats.WIS_Save);
                    Assert.Equal(-3, stats.CHA_Save);
                }
            }
            finally
            {
                connection.Close();
            }
        }
コード例 #5
0
        public void AddCharacterToDbIsSuccessful()
        {
            // arrange
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <ANightsTaleContext>()
                              .UseSqlite(connection)
                              .Options;

                // Create the schema in the database
                using (var context = new ANightsTaleContext(options))
                {
                    context.Database.EnsureCreated();
                }

                // Act

                // Run the test against one instance of the context
                using (var context = new ANightsTaleContext(options))
                {
                    var         charRepo = new CharacterRepository(context);
                    DataSeeding seed     = new DataSeeding(context, charRepo);
                    seed.SeedCharacterSupportClasses();

                    var character = seed.SeedCharacter();

                    charRepo.AddCharacter(character);
                    charRepo.Save();

                    // Assert
                    Assert.Equal("Test", context.Character.First().Name);
                }
            }
            finally
            {
                connection.Close();
            }
        }
コード例 #6
0
        public void BarbarianProficiencyCalculatedCorrectly()
        {
            // arrange
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var rand    = new RngProvider();
                var options = new DbContextOptionsBuilder <ANightsTaleContext>()
                              .UseSqlite(connection)
                              .Options;

                // Create the schema in the database
                using (var context = new ANightsTaleContext(options))
                {
                    context.Database.EnsureCreated();
                }

                // Act

                // Run the test against one instance of the context
                using (var context = new ANightsTaleContext(options))
                {
                    var         charRepo = new CharacterRepository(context);
                    DataSeeding seed     = new DataSeeding(context, charRepo);
                    seed.SeedClass(1);

                    var val = charRepo.GetSavingThrowProficiency(1);

                    // Assert
                    Assert.Equal(new List <bool> {
                        true, false, true, false, false, false
                    }, val);
                }
            }
            finally
            {
                connection.Close();
            }
        }
コード例 #7
0
        public void InvalidClassIdThrowsException(int id)
        {
            // arrange
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var rand    = new RngProvider();
                var options = new DbContextOptionsBuilder <ANightsTaleContext>()
                              .UseSqlite(connection)
                              .Options;

                // Create the schema in the database
                using (var context = new ANightsTaleContext(options))
                {
                    context.Database.EnsureCreated();
                }

                // Act

                // Run the test against one instance of the context
                using (var context = new ANightsTaleContext(options))
                {
                    var         charRepo = new CharacterRepository(context);
                    DataSeeding seed     = new DataSeeding(context, charRepo);
                    seed.SeedClass(3);

                    // Assert
                    Assert.ThrowsAny <ArgumentException>(() => charRepo.GetSavingThrowProficiency(id));
                }
            }
            finally
            {
                connection.Close();
            }
        }
コード例 #8
0
        public void AddNullCharacterThrowsNullException()
        {
            // arrange
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var rand    = new RngProvider();
                var options = new DbContextOptionsBuilder <ANightsTaleContext>()
                              .UseSqlite(connection)
                              .Options;

                // Create the schema in the database
                using (var context = new ANightsTaleContext(options))
                {
                    context.Database.EnsureCreated();
                }

                // Act

                // Run the test against one instance of the context
                using (var context = new ANightsTaleContext(options))
                {
                    var charRepo = new CharacterRepository(context);

                    // Assert
                    Assert.ThrowsAny <ArgumentNullException>(() => charRepo.AddCharacter(null));
                }
            }
            finally
            {
                connection.Close();
            }
        }
コード例 #9
0
 public UserRepository(ANightsTaleContext db)
 {
     _db = db ?? throw new ArgumentNullException(nameof(db));
 }