<commit_before>﻿using System;
using Core.DomainServices;
using Infrastructure.DataAccess;

namespace Tests.Integration.Presentation.Web.Tools
{
    /// <summary>
    /// NOTE: Keep use of this to a minimum. Prefer changing KITOS data through the KITOS API
    /// </summary>
    public static class DatabaseAccess
    {
        /// <summary>
        /// Helper method to perform queries on entities in a repository.
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <typeparam name="TOutput"></typeparam>
        /// <param name="map"></param>
        /// <returns></returns>
        public static TOutput MapFromEntitySet<TModel, TOutput>(Func<IGenericRepository<TModel>, TOutput> map) where TModel : class
        {
            using var repository = new GenericRepository<TModel>(TestEnvironment.GetDatabase());
            
            return map(repository);
        }

        /// <summary>
        /// Helper method to perform changes to entities in a repository.
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="mutate"></param>
        public static void MutateEntitySet<TModel>(Action<IGenericRepository<TModel>> mutate) where TModel : class
        {
            using var kitosContext = TestEnvironment.GetDatabase();
            using var repository = new GenericRepository<TModel>(kitosContext);

            mutate(repository);

            repository.Save();
        }

        /// <summary>
        /// Helper method to perform changes to entities in a repository.
        /// </summary>
        /// <param name="mutate"></param>
        public static void MutateDatabase(Action<KitosContext> mutate)
        {
            using var db = TestEnvironment.GetDatabase();

            mutate(db);

            db.SaveChanges();
        }
    }<commit_msg>fixed call to save which was invalid<commit_after>﻿using System;
using Core.DomainServices;
using Infrastructure.DataAccess;

namespace Tests.Integration.Presentation.Web.Tools
{
    /// <summary>
    /// NOTE: Keep use of this to a minimum. Prefer changing KITOS data through the KITOS API
    /// </summary>
    public static class DatabaseAccess
    {
        /// <summary>
        /// Helper method to perform queries on entities in a repository.
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <typeparam name="TOutput"></typeparam>
        /// <param name="map"></param>
        /// <returns></returns>
        public static TOutput MapFromEntitySet<TModel, TOutput>(Func<IGenericRepository<TModel>, TOutput> map) where TModel : class
        {
            using var repository = new GenericRepository<TModel>(TestEnvironment.GetDatabase());
            
            return map(repository);
        }

        /// <summary>
        /// Helper method to perform changes to entities in a repository.
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="mutate"></param>
        public static void MutateEntitySet<TModel>(Action<IGenericRepository<TModel>> mutate) where TModel : class
        {
            using var kitosContext = TestEnvironment.GetDatabase();
            using var repository = new GenericRepository<TModel>(kitosContext);

            mutate(repository);

            repository.Save();
        }

        /// <summary>
        /// Helper method to perform changes to entities in a repository.
        /// </summary>
        /// <param name="mutate"></param>
        public static void MutateDatabase(Action<KitosContext> mutate)
        {
            using var db = TestEnvironment.GetDatabase();

            mutate(db);
        }
    }
{'fraction_non_alphanumeric': 0.11952406706327745, 'fraction_numerical': 0.0, 'mean_word_length': 2.1347457627118644, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6538350', 'n_tokens_mistral': 935, 'n_tokens_neox': 920, 'n_words': 257}