<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web.Mvc;
using FluentMVCTesting.Tests.TestControllers;
using NUnit.Framework;

namespace FluentMVCTesting.Tests
{
    [TestFixture]
    class ControllerResultTestShould
    {
        #region Test cases
        #pragma warning disable 169
        // Expected action return types for the different types of assertions
        private static readonly List<Tuple<string, TestAction>> ReturnTypes = new List<Tuple<string, TestAction>>
        {
            ReturnType<EmptyResult>(t => t.ShouldReturnEmptyResult()),
            ReturnType<RedirectResult>(t => t.ShouldRedirectTo("")),
            ReturnType<RedirectToRouteResult>(t => t.ShouldRedirectTo(c => c.EmptyResult)),
            ReturnType<RedirectToRouteResult>(t => t.ShouldRedirectTo<SomeOtherController>(c => c.SomeAction())),
            ReturnType<ViewResult>(t => t.ShouldRenderView("")),
            ReturnType<ViewResult>(t => t.ShouldRenderDefaultView()),
            ReturnType<PartialViewResult>(t => t.ShouldRenderPartialView("")),
            ReturnType<PartialViewResult>(t => t.ShouldRenderDefaultPartialView()),
            ReturnType<FileContentResult>(t => t.ShouldRenderFile()),
            ReturnType<HttpStatusCodeResult>(t => t.ShouldGiveHttpStatus()),
            ReturnType<JsonResult>(t => t.ShouldReturnJson()),
        };
        // Different ways that action redirects can be asserted along with the expected method name and the correct controller action call for that assertion
        private static readonly List<RedirectToActionTestMetadata> ActionRedirects = new List<RedirectToActionTestMetadata>
        {
            ActionRedirect("ActionWithNoParameters",
                t => t.ShouldRedirectTo(c => c.ActionWithNoParameters),
                c => c.RedirectToActionWithNoParameters()
            ),
            ActionRedirect("ActionWithOneParameter",
                t => t.ShouldRedirectTo(c => c.ActionWithOneParameter),
                c => c.RedirectToActionWithOneParameter()
            ),
            ActionRedirect("ActionWithOneParameter",
                t => t.ShouldRedirectTo<int>(c => c.ActionWithOneParameter),
                c => c.RedirectToActionWithOneParameter()
            ),
            ActionRedirect("ActionWithTwoParameters",
                t => t.ShouldRedirectTo<int, int>(c => c.ActionWithTwoParameters),
                c => c.RedirectToActionWithTwoParameters()
            ),
            ActionRedirect("ActionWithThreeParameters",
                t => t.ShouldRedirectTo<int, int, int>(c => c.ActionWithThreeParameters),
                c => c.RedirectToActionWithThreeParameters()
            ),
            ActionRedirect("ActionWithNoParameters",
                t => t.ShouldRedirectTo(c => c.ActionWithNoParameters()),
                c => c.RedirectToActionWithNoParameters()
            ),
            ActionRedirect("ActionWithOneParameter",
                t => t.ShouldRedirectTo(c => c.ActionWithOneParameter(0)),
                c => c.RedirectToActionWithOneParameter()
            ),
            ActionRedirect("ActionWithTwoParameters",
                t => t.ShouldRedirectTo(c => c.ActionWithTwoParameters(0, 0)),
                c => c.RedirectToActionWithTwoParameters()
            ),
            ActionRedirect("ActionWithThreeParameters",
                t => t.ShouldRedirectTo(c => c.ActionWithThreeParameters(0, 0, 0)),
                c => c.RedirectToActionWithThreeParameters()
            ),
            ActionRedirect("ActionWithMoreThanThreeParameters",
                t => t.ShouldRedirectTo(c => c.ActionWithMoreThanThreeParameters(0, 0, 0, 0)),
                c => c.RedirectToActionWithMoreThanThreeParameters()
            ),
        };
        // Different ways that redirects to another controller can be asserted
        private static readonly List<TestAction> OtherControllerRedirects = new List<TestAction>
        {
            c => c.ShouldRedirectTo<SomeOtherController>(typeof(SomeOtherController).GetMethod("SomeAction")),
            c => c.ShouldRedirectTo<SomeOtherController>(c2 => c2.SomeAction()),
        };
        #pragma warning restore 169
        #endregion

        #region Setup
        public class RedirectToActionTestMetadata : Tuple<string, TestAction, Expression<Func<ControllerResultTestController, ActionResult>>>
        {
            public RedirectToActionTestMetadata(string expectedMethodName, TestAction testCall, Expression<Func<ControllerResultTestController, ActionResult>> validControllerActionCall)
                : base(expectedMethodName, testCall, validControllerActionCall) { }
        }
        private ControllerResultTestController _controller;
        public delegate void TestAction(ControllerResultTest<ControllerResultTestController> testClass);
        private static Tuple<string, TestAction> ReturnType<T>(TestAction a)
        {
            return new Tuple<string, TestAction>(typeof(T).Name, a);
        }
        private static RedirectToActionTestMetadata ActionRedirect(string s, TestAction a, Expression<Func<ControllerResultTestController, ActionResult>> c)
        {
            return new RedirectToActionTestMetadata(s, a, c);
        }

        [SetUp]
        public void Setup()
        {<commit_msg>Added a test for the MethodInfo action redirect test<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web.Mvc;
using FluentMVCTesting.Tests.TestControllers;
using NUnit.Framework;

namespace FluentMVCTesting.Tests
{
    [TestFixture]
    class ControllerResultTestShould
    {
        #region Test cases
        #pragma warning disable 169
        // Expected action return types for the different types of assertions
        private static readonly List<Tuple<string, TestAction>> ReturnTypes = new List<Tuple<string, TestAction>>
        {
            ReturnType<EmptyResult>(t => t.ShouldReturnEmptyResult()),
            ReturnType<RedirectResult>(t => t.ShouldRedirectTo("")),
            ReturnType<RedirectToRouteResult>(t => t.ShouldRedirectTo(c => c.EmptyResult)),
            ReturnType<RedirectToRouteResult>(t => t.ShouldRedirectTo<SomeOtherController>(c => c.SomeAction())),
            ReturnType<ViewResult>(t => t.ShouldRenderView("")),
            ReturnType<ViewResult>(t => t.ShouldRenderDefaultView()),
            ReturnType<PartialViewResult>(t => t.ShouldRenderPartialView("")),
            ReturnType<PartialViewResult>(t => t.ShouldRenderDefaultPartialView()),
            ReturnType<FileContentResult>(t => t.ShouldRenderFile()),
            ReturnType<HttpStatusCodeResult>(t => t.ShouldGiveHttpStatus()),
            ReturnType<JsonResult>(t => t.ShouldReturnJson()),
        };
        // Different ways that action redirects can be asserted along with the expected method name and the correct controller action call for that assertion
        private static readonly List<RedirectToActionTestMetadata> ActionRedirects = new List<RedirectToActionTestMetadata>
        {
            ActionRedirect("ActionWithNoParameters",
                t => t.ShouldRedirectTo(c => c.ActionWithNoParameters),
                c => c.RedirectToActionWithNoParameters()
            ),
            ActionRedirect("ActionWithOneParameter",
                t => t.ShouldRedirectTo(c => c.ActionWithOneParameter),
                c => c.RedirectToActionWithOneParameter()
            ),
            ActionRedirect("ActionWithOneParameter",
                t => t.ShouldRedirectTo<int>(c => c.ActionWithOneParameter),
                c => c.RedirectToActionWithOneParameter()
            ),
            ActionRedirect("ActionWithTwoParameters",
                t => t.ShouldRedirectTo<int, int>(c => c.ActionWithTwoParameters),
                c => c.RedirectToActionWithTwoParameters()
            ),
            ActionRedirect("ActionWithThreeParameters",
                t => t.ShouldRedirectTo<int, int, int>(c => c.ActionWithThreeParameters),
                c => c.RedirectToActionWithThreeParameters()
            ),
            ActionRedirect("ActionWithNoParameters",
                t => t.ShouldRedirectTo(c => c.ActionWithNoParameters()),
                c => c.RedirectToActionWithNoParameters()
            ),
            ActionRedirect("ActionWithOneParameter",
                t => t.ShouldRedirectTo(c => c.ActionWithOneParameter(0)),
                c => c.RedirectToActionWithOneParameter()
            ),
            ActionRedirect("ActionWithTwoParameters",
                t => t.ShouldRedirectTo(c => c.ActionWithTwoParameters(0, 0)),
                c => c.RedirectToActionWithTwoParameters()
            ),
            ActionRedirect("ActionWithThreeParameters",
                t => t.ShouldRedirectTo(c => c.ActionWithThreeParameters(0, 0, 0)),
                c => c.RedirectToActionWithThreeParameters()
            ),
            ActionRedirect("ActionWithMoreThanThreeParameters",
                t => t.ShouldRedirectTo(c => c.ActionWithMoreThanThreeParameters(0, 0, 0, 0)),
                c => c.RedirectToActionWithMoreThanThreeParameters()
            ),
            ActionRedirect("ActionWithMoreThanThreeParameters",
                t => t.ShouldRedirectTo(typeof(ControllerResultTestController).GetMethod("ActionWithMoreThanThreeParameters")),
                c => c.RedirectToActionWithMoreThanThreeParameters()
            ),
        };
        // Different ways that redirects to another controller can be asserted
        private static readonly List<TestAction> OtherControllerRedirects = new List<TestAction>
        {
            c => c.ShouldRedirectTo<SomeOtherController>(typeof(SomeOtherController).GetMethod("SomeAction")),
            c => c.ShouldRedirectTo<SomeOtherController>(c2 => c2.SomeAction()),
        };
        #pragma warning restore 169
        #endregion

        #region Setup
        public class RedirectToActionTestMetadata : Tuple<string, TestAction, Expression<Func<ControllerResultTestController, ActionResult>>>
        {
            public RedirectToActionTestMetadata(string expectedMethodName, TestAction testCall, Expression<Func<ControllerResultTestController, ActionResult>> validControllerActionCall)
                : base(expectedMethodName, testCall, validControllerActionCall) { }
        }
        private ControllerResultTestController _controller;
        public delegate void TestAction(ControllerResultTest<ControllerResultTestController> testClass);
        private static Tuple<string, TestAction> ReturnType<T>(TestAction a)
        {
            return new Tuple<string, TestAction>(typeof(T).Name, a);
        }
        private static RedirectToActionTestMetadata ActionRedirect(string s, TestAction a, Expression<Func<ControllerResultTestController, ActionResult>> c)
        {
            return new RedirectToActionTestMetadata(s, a, c);
        }

        [SetUp]
        public void Setup()
        {
{'fraction_non_alphanumeric': 0.09623241034952337, 'fraction_numerical': 0.003268270540172492, 'mean_word_length': 2.762295081967213, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 169, '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': '6339817', 'n_tokens_mistral': 2674, 'n_tokens_neox': 2593, 'n_words': 515}