using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using System.Web.Mvc; namespace Admin.UnitTests.Controllers.AccountHolder.List { [TestClass] [ExcludeFromCodeCoverage] public class Get : TestBase { public Get() { SetupController(); } private MethodInfo GetMethod() { return GetMethod(typeof(HttpGetAttribute), nameof(Controller.List)); } private ActionResult GetResult() { return Controller.List(); } [TestMethod] public void HasCorrectNumberOfCustomAttributes() { Assert.AreEqual(3, GetMethod().CustomAttributes.Count()); } [TestMethod] public void HasASingleHttpGetAttribute() { Assert.AreEqual(1, GetMethod().CustomAttributes.Where(ca => ca.AttributeType == typeof(HttpGetAttribute)).Count()); } [TestMethod] public void ReturnsRedirectResult() { var result = GetResult(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); } [TestMethod] public void RedirectsToSearch() { var result = GetResult(); Assert.IsNotNull(result); Assert.AreEqual("Search", ((RedirectToRouteResult)result).RouteValues["action"]); } } }