public void UserAgentTest2() { VirtualManager virtualManager = new VirtualManager(); FieldInfo fi = virtualManager.GetType().GetField("VIRTUAL_DTO", BindingFlags.NonPublic | BindingFlags.Static); Mock <VirtualDto> dto = new Mock <VirtualDto>(); dto.Setup(m => m.VirtualName()).Returns("virtualName"); fi.SetValue(null, dto.Object); _homeController = new HomeController(_mockHttpContextBase.Object, _mockAboutManager.Object, _mockContactManager.Object, virtualManager); string userAgent = "Chrome"; _mockHttpContextBase.Setup(m => m.Request.UserAgent).Returns(userAgent).Verifiable(); ViewResult result = (ViewResult)_homeController.UserAgent(); _mockHttpContextBase.Verify(m => m.Request.UserAgent, Times.Once); HomeViewModel resultmodel = (HomeViewModel)result.Model; Assert.AreEqual(userAgent, resultmodel.Browser); Assert.AreEqual("virtualName", resultmodel.Virtual.VirtualName()); }
public void ReadTest() { VirtualManager virtualManager = new VirtualManager(); VirtualDto result = virtualManager.Read(); Assert.AreEqual("This is the original hard coded name", result.HardCodedName()); Assert.AreEqual(new VirtualDto().HardCodedName(), result.HardCodedName()); // }
public HomeController(HttpContextBase httpContextBase, IAboutManager aboutManager, IContactManager contactManager, VirtualManager virtualManager) : base(httpContextBase) { if (null == aboutManager) { throw new ArgumentNullException(nameof(aboutManager)); } if (null == contactManager) { throw new ArgumentNullException(nameof(contactManager)); } if (null == virtualManager) { throw new ArgumentNullException(nameof(virtualManager)); } _aboutManager = aboutManager; _contactManager = contactManager; _virtualManager = virtualManager; }
public HomeController() { _aboutManager = new AboutManager(new DatabaseManager()); _contactManager = new ContactManager(new DatabaseManager()); _virtualManager = new VirtualManager(); }