using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Linq; using System.Reflection; using System.Web.Mvc; using Controller = Admin.Controllers.PaymentController; namespace Admin.UnitTests.Controllers.Payment.Cancel { [TestClass] public class Get : TestBase { public Get() { SetupController(); } private MethodInfo GetMethod() { return GetMethod(typeof(HttpGetAttribute), nameof(Controller.Cancel)); } private ActionResult GetResult() { return Controller.Cancel(); } [TestMethod] public void HasCorrectNumberOfCustomAttributes() { Assert.AreEqual(1, GetMethod().CustomAttributes.Count()); } [TestMethod] public void HasASingleHttpGetAttribute() { Assert.AreEqual(1, GetMethod().CustomAttributes.Where(ca => ca.AttributeType == typeof(HttpGetAttribute)).Count()); } [TestMethod] public void ReturnsARedirect() { var result = GetResult(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); } [TestMethod] public void ReturnsRedirectToAddress() { var result = GetResult() as RedirectToRouteResult; Assert.IsNotNull(result); var s = result.RouteValues.Values.First(); Assert.IsTrue(s.ToString() == nameof(Controller.Create)); } } }