public void TestConstructor_ShouldSetDateCreatedCorrectly(string name, int logId, string username, string lastActivityUser) { // Arrange var log = new TrainingLog { Name = name, LogId = logId, Owner = username, LastActivityUser = lastActivityUser, DateCreated = new DateTime(), LogEntries = new List <LogEntry>(), LastEntryDate = new DateTime(), Votes = new List <Vote>() }; // Act var model = new ShortLogViewModel(log); // Assert Assert.AreEqual(log.DateCreated, model.DateCreated); }
public void TestSearch_ShouldReturnCorrectPartialViewWithModel(string searchTerm) { // Arrange var logs = new List <TrainingLog> { new TrainingLog(), new TrainingLog() }; var mockedLogService = new Mock <ILogService>(); mockedLogService.Setup(s => s.Search(It.IsAny <string>())).Returns(logs); var viewModel = new ShortLogViewModel(); var mockedViewModelFactory = new Mock <IViewModelFactory>(); mockedViewModelFactory.Setup(f => f.CreateShortLogViewModel(It.IsAny <TrainingLog>())).Returns(viewModel); var controller = new SearchController(mockedLogService.Object, mockedViewModelFactory.Object); var model = new SearchViewModel { SearchTerm = searchTerm }; var expectedModelList = new List <ShortLogViewModel> { viewModel, viewModel }; // Act, Assert controller .WithCallTo(c => c.Search(model)) .ShouldRenderPartialView("_LogListPartial") .WithModel <IEnumerable <ShortLogViewModel> >(m => { CollectionAssert.AreEqual(expectedModelList, m); }); }