using Admin.Models.Transaction; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using System.Web.Mvc; using Web.Mvc.Navigation; namespace Admin.UnitTests.Controllers.Transaction.Origin { [TestClass] [ExcludeFromCodeCoverage] public class Get : TestBase { public Get() { SetupController(); } private MethodInfo GetMethod() { return GetMethod(typeof(HttpGetAttribute), nameof(Controller.Origin)); } private ActionResult GetResult(bool includeTransaction) { var processedTransactions = new List() { { new BusinessLogic.Entities.ProcessedTransaction() { TransactionReference = "12345", AccountReference = "ABCDE", FundCode = "F1", Amount = 100, MopCode = "90", Mop = new BusinessLogic.Entities.Mop() { MopCode = "90", Metadata = new List() } } } }; var pendingTransactions = new List(); var failedRefunds = new List(); var processedRefunds = new List() { { new BusinessLogic.Entities.ProcessedTransaction() { TransactionReference = "12345", AccountReference = "ABCDE", FundCode = "F1", Amount = 1 } } }; var transfers = new List(); MockDetailsViewModelBuilder.Setup(x => x.Build( It.IsAny())) .Returns(new DetailsViewModel() { Transaction = includeTransaction ? new BusinessLogic.Models.Transaction( processedTransactions, pendingTransactions, failedRefunds, processedRefunds, transfers, string.Empty) : null } ); return Controller.Origin("test"); } [TestMethod] public void HasCorrectNumberOfCustomAttributes() { Assert.AreEqual(3, GetMethod().CustomAttributes.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("Origin Details", namedArgument.TypedValue.Value); } [TestMethod] public void HasASingleHttpGetAttribute() { Assert.AreEqual(1, GetMethod().CustomAttributes.Where(ca => ca.AttributeType == typeof(HttpGetAttribute)).Count()); } [TestMethod] public void ReturnsAView() { var result = GetResult(true); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(ViewResult)); } [TestMethod] public void ReturnsCorrectViewName() { var result = GetResult(true) as ViewResult; Assert.IsNotNull(result); Assert.IsTrue(string.IsNullOrEmpty(result.ViewName) || result.ViewName == nameof(Controller.Details)); } [TestMethod] public void ReturnsAViewModel() { var result = GetResult(true) as ViewResult; Assert.IsNotNull(result); Assert.IsNotNull(result.Model); } [TestMethod] public void ReturnsCorrectViewModelType() { var result = GetResult(true) as ViewResult; Assert.IsNotNull(result); Assert.IsInstanceOfType(result.Model, typeof(DetailsViewModel)); } } }