<commit_before>﻿using System;
using Retry;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data.SqlClient;

namespace TryRetryTest
{
    [TestClass]
    public class Test
    {
        public TestContext TestContext { get; set; }

        /// <summary>
        /// Loop to test. Throws <see cref="IndexOutOfRangeException"/> on fail.
        /// </summary>
        /// <param name="fail">Whether the loop should throw <see cref="IndexOutOfRangeException"/> or not.</param>
        /// <returns>Returns 0 on pass.</returns>
        private int Thrower(bool fail = true)
        {
            TestContext.WriteLine("Thrower");
            if (fail) {
                SqlConnection conn = new SqlConnection(@"Connection Timeout=1");
                conn.Open();
            }
            return 1;
        }

        /// <summary>
        /// Method for catching exceptions.
        /// </summary>
        /// <returns>Returns 1 on catch.</returns>
        private int Catcher(Exception e)
        {
            TestContext.WriteLine("Catcher");
            SqlException sEx = e as SqlException;
            return -1;
        }

        /// <summary>
        /// Test for the wrong exception.
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(SqlException))]
        public void WrongException()
        {
            Retry<int> retry = new Retry<int>();
            retry.Run<NullReferenceException>(
                () => Thrower(),
                Catcher);
        }

        /// <summary>
        /// Test for a failed attempt despite retrying.
        /// </summary>
        [TestMethod]
        public void Failed()
        {
            Retry<int> retry = new Retry<int>();
            int result = retry.Run<SqlException>(
                () => Thrower(),
                Catcher);
            Assert.AreEqual<int>(-1, result);
        }

        /// <summary>
        /// Test for a passed attempt without retrying.
        /// </summary>
        [TestMethod]
        public void Passed()
        {
            Retry<int> retry = new Retry<int>();
            int result = retry.Run<SqlException>(
                () => Thrower(false),
                Catcher);
            Assert.AreEqual<int>(1, result);
        }

        /// <summary>
        /// Test tryonce case with id
        /// </summary>
        [TestMethod]
        public void RunOnce()
        {
            Retry<int> retry = new Retry<int>();
            int result = retry.Run<IndexOutOfRangeException>(
                () => {
                    TestContext.WriteLine("Outer Thrower");
                    retry.Run<SqlException>(
                        () => Thrower(),
                        Catcher, 1, 0, "Test2");
                    throw new IndexOutOfRangeException();
                },
                Catcher, 5, 0, "Test");
            Assert.AreEqual<int>(-1, result);
        }
<commit_msg>Fix, test<commit_after>﻿using System;
using Retry;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data.SqlClient;

namespace TryRetryTest
{
    [TestClass]
    public class Test
    {
        public TestContext TestContext { get; set; }

        /// <summary>
        /// Loop to test. Throws <see cref="IndexOutOfRangeException"/> on fail.
        /// </summary>
        /// <param name="fail">Whether the loop should throw <see cref="IndexOutOfRangeException"/> or not.</param>
        /// <returns>Returns 0 on pass.</returns>
        private int Thrower(bool fail = true)
        {
            TestContext.WriteLine("Thrower");
            if (fail) {
                SqlConnection conn = new SqlConnection(@"Connection Timeout=1");
                conn.Open();
            }
            return 1;
        }

        /// <summary>
        /// Method for catching exceptions.
        /// </summary>
        /// <returns>Returns 1 on catch.</returns>
        private int Catcher(Exception e)
        {
            TestContext.WriteLine("Catcher");
            SqlException sEx = e as SqlException;
            return -1;
        }

        /// <summary>
        /// Test for the wrong exception.
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(SqlException))]
        public void WrongException()
        {
            Retry<int> retry = new Retry<int>();
            retry.Run<NullReferenceException>(
                () => Thrower(),
                Catcher);
        }

        /// <summary>
        /// Test for a failed attempt despite retrying.
        /// </summary>
        [TestMethod]
        public void Failed()
        {
            Retry<int> retry = new Retry<int>();
            int result = retry.Run<SqlException>(
                () => Thrower(),
                Catcher);
            Assert.AreEqual<int>(-1, result);
        }

        /// <summary>
        /// Test for a passed attempt without retrying.
        /// </summary>
        [TestMethod]
        public void Passed()
        {
            Retry<int> retry = new Retry<int>();
            int result = retry.Run<SqlException>(
                () => Thrower(false),
                Catcher);
            Assert.AreEqual<int>(1, result);
        }

        /// <summary>
        /// Test tryonce case with id
        /// </summary>
        [TestMethod]
        public void RunOnce()
        {
            Retry<int> retry = new Retry<int>();
            Retry<int> retry2 = new Retry<int>();
            int result = retry.Run<IndexOutOfRangeException>(
                () => {
                    TestContext.WriteLine("Outer Thrower");
                    retry2.Run<SqlException>(
                        () => Thrower(),
                        Catcher, 1, 0, "Test2");
                    throw new IndexOutOfRangeException();
                },
                Catcher, 5, 0, "Test");
            Assert.AreEqual<int>(-1, result);
        }

{'fraction_non_alphanumeric': 0.12578296935838834, 'fraction_numerical': 0.004740138818351109, 'mean_word_length': 1.3909348441926346, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 87, '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': '6048612', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1483, 'n_words': 371}