<commit_before>﻿using Promact.Trappist.DomainModel.DbContext;
using Promact.Trappist.Repository.TestSettings;
using Microsoft.Extensions.DependencyInjection;
using System.Linq;
using Promact.Trappist.Repository.Tests;
using Xunit;

namespace Promact.Trappist.Test.Tests
{
    [Collection("Register Dependency")]
    public class TestSettingsRepositoryTest
    {
        private readonly Bootstrap _bootstrap;
        private readonly TrappistDbContext _trappistDbContext;
        private readonly ITestSettingsRepository _settingsRepository;
        private readonly ITestsRepository _testRepository;

        public TestSettingsRepositoryTest(Bootstrap bootstrap)
        {
            _bootstrap = bootstrap;
            //resolve dependencies to be used in tests
            _trappistDbContext = _bootstrap.ServiceProvider.GetService<TrappistDbContext>();
            _settingsRepository = _bootstrap.ServiceProvider.GetService<ITestSettingsRepository>();
            _testRepository = _bootstrap.ServiceProvider.GetService<ITestsRepository>();
            ClearDatabase.ClearDatabaseAndSeed(_trappistDbContext);
        }

        /// <summary>
        /// Gets Settings of Test selected by Id
        /// </summary>
        [Fact]
        public void GetSettingsById()
        {
            var test = AddNewTest();
            _testRepository.CreateTest(test);
            Assert.NotNull(test);
            var testSettings = _settingsRepository.GetTestSettings(test.Id);
            var testName = testSettings.TestName;
            Assert.Equal(testName, "AOT 669");
        }

        /// <summary>
        /// Updates settings of a particular test with the help of Id
        /// </summary>
        [Fact]
        public void UpdateTestSettingsById()
        {
            var test = AddNewTest();
            _testRepository.CreateTest(test);
            var settingsToUpdate = _settingsRepository.GetTestSettings(test.Id);<commit_msg>Added async and await functionality.<commit_after>﻿using Promact.Trappist.DomainModel.DbContext;
using Promact.Trappist.Repository.TestSettings;
using Microsoft.Extensions.DependencyInjection;
using System.Linq;
using Promact.Trappist.Repository.Tests;
using Xunit;
using System.Threading.Tasks;

namespace Promact.Trappist.Test.Tests
{
    [Collection("Register Dependency")]
    public class TestSettingsRepositoryTest
    {
        private readonly Bootstrap _bootstrap;
        private readonly TrappistDbContext _trappistDbContext;
        private readonly ITestSettingsRepository _settingsRepository;
        private readonly ITestsRepository _testRepository;

        public TestSettingsRepositoryTest(Bootstrap bootstrap)
        {
            _bootstrap = bootstrap;
            //resolve dependencies to be used in tests
            _trappistDbContext = _bootstrap.ServiceProvider.GetService<TrappistDbContext>();
            _settingsRepository = _bootstrap.ServiceProvider.GetService<ITestSettingsRepository>();
            _testRepository = _bootstrap.ServiceProvider.GetService<ITestsRepository>();
            ClearDatabase.ClearDatabaseAndSeed(_trappistDbContext);
        }

        /// <summary>
        /// Gets Settings of Test selected by Id
        /// </summary>
        [Fact]
        public async Task GetSettingsById()
        {
            var test = AddNewTest();
            _testRepository.CreateTest(test);
            Assert.NotNull(test);
            var testSettings = await _settingsRepository.GetTestSettingsAsync(test.Id);
            var testName = testSettings.TestName;
            Assert.Equal(testName, "AOT 669");
        }

        /// <summary>
        /// Updates settings of a particular test with the help of Id
        /// </summary>
        [Fact]
        public async Task UpdateTestSettingsById()
        {
            var test = AddNewTest();
            _testRepository.CreateTest(test);
            var settingsToUpdate = await _settingsRepository.GetTestSettingsAsync(test.Id);
{'fraction_non_alphanumeric': 0.07841166122141241, 'fraction_numerical': 0.0015079165619502387, 'mean_word_length': 2.6715867158671585, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '6962043', 'n_tokens_mistral': 967, 'n_tokens_neox': 951, 'n_words': 219}