Example #1
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();
            }
        }
Example #2
0
        public void AddNullCharStatsThrowsNullException()
        {
            // 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 <Exception>(() => charRepo.AddCharStats(null));
                }
            }
            finally
            {
                connection.Close();
            }
        }