using Admin.Models.Transaction; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using System.Web.Mvc; using Web.Mvc.Navigation; namespace Admin.UnitTests.Controllers.Transaction.ListForTransactionImport { [TestClass] [ExcludeFromCodeCoverage] public class Get : TestBase { public Get() { SetupController(); } private MethodInfo GetMethod() { return GetMethod(typeof(AcceptVerbsAttribute), nameof(Controller.ListForTransactionImport)); } private ActionResult GetResult(SearchCriteria model) { return Controller.ListForTransactionImport(model); } [TestMethod] public void HasCorrectNumberOfCustomAttributes() { Assert.AreEqual(3, GetMethod().CustomAttributes.Count()); } [TestMethod] public void HasASingleAcceptVerbsAttribute() { Assert.AreEqual(1, GetMethod().CustomAttributes.Where(ca => ca.AttributeType == typeof(AcceptVerbsAttribute)).Count()); } [TestMethod] public void HasASingleNavigatablePageActionFilterAttribute() { Assert.AreEqual(1, GetMethod().CustomAttributes.Where(ca => ca.AttributeType == typeof(NavigatablePageActionFilterAttribute)).Count()); } [TestMethod] public void NavigatablePageActionFilterAttributeHasCorrectDisplayText() { var attribute = GetMethod().CustomAttributes.Single(ca => ca.AttributeType == typeof(NavigatablePageActionFilterAttribute)); var namedArgument = attribute.NamedArguments.Where(x => x.MemberName == "DisplayText").First(); Assert.AreEqual("Transactions", namedArgument.TypedValue.Value); } [TestMethod] public void ReturnsAView() { var result = GetResult(null); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(ViewResult)); } [TestMethod] public void ReturnsCorrectViewName() { var result = GetResult(null) as ViewResult; Assert.IsNotNull(result); Assert.IsTrue(string.IsNullOrEmpty(result.ViewName) || result.ViewName == "~/Views/Transaction/List.cshtml"); } } }