public PartialViewResult Edit(LogDetailsViewModel model) { if (ModelState.IsValid) { this.logService.EditLog(model.LogId, model.Description, model.Name); } return(this.PartialView("_LogDescription", model)); }
public void VerifyThatPropertyAreSet() { var vm = new LogDetailsViewModel(new LogEventInfo(LogLevel.Info, "testlogger", "testMsg")); Assert.AreNotEqual(0, vm.DetailRows.Count); Assert.That(vm.DetailRows.First().Content, Is.Not.Null.Or.Empty); Assert.That(vm.DetailRows.First().Property, Is.Not.Null.Or.Empty); Assert.That(vm.DialogTitle, Is.Not.Null.Or.Empty); }
public void TestConstructor_LogUserIsNull_ShouldSetProfileImageUrlNull() { // Arrange var trainingLog = new TrainingLog(); // Act var model = new LogDetailsViewModel(trainingLog, true, true, true, null); // Assert Assert.IsNull(model.ProfileImageUrl); }
public void TestConstructor_ShouldSetCanVoteCorrectly(bool canVote) { // Arrange var trainingLog = new TrainingLog(); // Act var model = new LogDetailsViewModel(trainingLog, true, false, canVote, null); // Assert Assert.AreEqual(canVote, model.CanVote); }
public void TestConstructor_ShouldSetEntriesCorrectly() { // Arrange var trainingLog = new TrainingLog(); var entries = new List <LogEntryViewModel>().ToPagedList(1, 1); // Act var model = new LogDetailsViewModel(trainingLog, true, true, true, entries); // Assert CollectionAssert.AreEqual(entries, model.Entries); }
public void TestConstructor_ShouldSetIsAuthenticatedCorrectly(bool isAuthenticated) { // Arrange var trainingLog = new TrainingLog(); // Act // Act var model = new LogDetailsViewModel(trainingLog, isAuthenticated, true, false, null); // Assert Assert.AreEqual(isAuthenticated, model.IsAuthenticated); }
public void TestDetails_PageIsNegative_ShouldSetPageToLastPage(int id, string userId, int page) { // Arrange var vote = new Vote { UserId = userId }; var user = new User { Id = userId }; var log = new TrainingLog { User = user }; log.Votes.Add(vote); var mockedLogService = new Mock <ILogService>(); mockedLogService.Setup(s => s.GetTrainingLogById(It.IsAny <int>())).Returns(log); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var model = new LogDetailsViewModel(); var currentPage = page; var mockedFactory = new Mock <IViewModelFactory>(); mockedFactory.Setup(f => f.CreateLogDetailsViewModel(It.IsAny <TrainingLog>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <IPagedList <LogEntryViewModel> >())) .Returns((TrainingLog trainingLog, bool isAuthenticated, bool isOwner, bool canVote, IPagedList <LogEntryViewModel> entries) => { currentPage = entries.PageNumber; return(model); }); var controller = new LogsController(mockedLogService.Object, mockedAuthenticationProvider.Object, mockedFactory.Object); // Act controller.Details(id, page); // Assert Assert.AreNotEqual(page, currentPage); }
public void TestConstructor_ShouldSetLogIdCorrectly(int logId) { // Arrange var trainingLog = new TrainingLog { LogId = logId }; // Act var model = new LogDetailsViewModel(trainingLog, true, true, false, null); // Assert Assert.AreEqual(logId, model.LogId); }
public void TestConstructor_ShouldSetDescriptionCorrectly(string description) { // Arrange var trainingLog = new TrainingLog { Description = description }; // Act var model = new LogDetailsViewModel(trainingLog, true, true, true, null); // Assert Assert.AreEqual(description, model.Description); }
public void TestConstructor_ShouldSetUserCorrectly(string owner) { // Arrange var trainingLog = new TrainingLog { Owner = owner }; // Act var model = new LogDetailsViewModel(trainingLog, true, true, true, null); // Assert Assert.AreEqual(owner, model.User); }
public void TestConstructor_ShouldSetNameCorrectly(string name) { // Arrange var trainingLog = new TrainingLog { Name = name }; // Act var model = new LogDetailsViewModel(trainingLog, true, true, true, null); // Assert Assert.AreEqual(name, model.Name); }
public void TestConstructor_ShouldSetDateCreatedCorrectly() { // Arrange var date = new DateTime(); var trainingLog = new TrainingLog { DateCreated = date }; // Act var model = new LogDetailsViewModel(trainingLog, true, true, true, null); // Assert Assert.AreEqual(date, model.DateCreated); }
public void TestConstructor_LogUserIsNotNull_ShouldSetProfileImageUrlCorrectly(string imageUrl) { // Arrange var user = new User { ProfileImageUrl = imageUrl }; var trainingLog = new TrainingLog { User = user }; // Act var model = new LogDetailsViewModel(trainingLog, true, true, true, null); // Assert Assert.AreEqual(imageUrl, model.ProfileImageUrl); }
public void TestConstructor_ShouldSetVotesCountCorrectly() { // Arrange var votes = new List <Vote> { new Vote(), new Vote() }; var trainingLog = new TrainingLog { Votes = votes }; // Act var model = new LogDetailsViewModel(trainingLog, true, true, false, null); // Assert Assert.AreEqual(votes.Count, model.VotesCount); }
public void TestDetails_LogContainsViewWithCurrentUser_ShouldNotBeAbleToVote(int id, string userId, bool isAuthenticated) { // Arrange var vote = new Vote { UserId = userId }; var user = new User { Id = userId }; var log = new TrainingLog { User = user }; log.Votes.Add(vote); var mockedLogService = new Mock <ILogService>(); mockedLogService.Setup(s => s.GetTrainingLogById(It.IsAny <int>())).Returns(log); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var model = new LogDetailsViewModel(); var mockedFactory = new Mock <IViewModelFactory>(); mockedFactory.Setup(f => f.CreateLogDetailsViewModel(It.IsAny <TrainingLog>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <IPagedList <LogEntryViewModel> >())) .Returns(model); var controller = new LogsController(mockedLogService.Object, mockedAuthenticationProvider.Object, mockedFactory.Object); var expectedIsOwner = log.User.Id.Equals(userId); var expectedCanVote = (log.Votes .FirstOrDefault(v => v.UserId.Equals(userId))) == null && !expectedIsOwner && isAuthenticated; // Act var result = controller.Details(id) as ViewResult; // Assert Assert.AreEqual(expectedCanVote, ((LogDetailsViewModel)result.Model).CanVote); }
public void TestEdit_ModelStateIsNotValid_ShouldNotCallServiceEditLogDescriptionCorrectly() { // Arrange var mockedLogService = new Mock <ILogService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var mockedFactory = new Mock <IViewModelFactory>(); var controller = new LogsController(mockedLogService.Object, mockedAuthenticationProvider.Object, mockedFactory.Object); controller.ModelState.AddModelError("", ""); var model = new LogDetailsViewModel(); // Act controller.Edit(model); // Assert mockedLogService.Verify(s => s.EditLog(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never); }
// GET: Logs/Details/5 public async Task <ActionResult> Details(int id) { //if (id == null) //{ // Alert($"Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); // return View(); //} try { var result = await _logService.FindAllLogById(id); if (result.Success) { var log = result.Data; var logResource = new LogDetailsViewModel { Id = log.Id, Exception = log.Exception, LogEvent = log.LogEvent, Level = log.Level, Message = log.Message, MessageTemplate = log.MessageTemplate, //Properties = log.Properties, TimeStamp = log.TimeStamp }; return(View(logResource)); } else { Alert($"Error! : {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } } catch (Exception ex) { Alert($"An Error Occurred While Fetching The Requested Resource. {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } }
public void TestDetails_ShouldSetViewWithModel(int id, string userId) { // Arrange var user = new User { Id = userId }; var log = new TrainingLog { User = user }; var mockedLogService = new Mock <ILogService>(); mockedLogService.Setup(s => s.GetTrainingLogById(It.IsAny <int>())).Returns(log); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var model = new LogDetailsViewModel(); var mockedFactory = new Mock <IViewModelFactory>(); mockedFactory.Setup(f => f.CreateLogDetailsViewModel(It.IsAny <TrainingLog>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <IPagedList <LogEntryViewModel> >())) .Returns(model); var controller = new LogsController(mockedLogService.Object, mockedAuthenticationProvider.Object, mockedFactory.Object); // Act, Assert controller .WithCallTo(c => c.Details(id, 1, 1)) .ShouldRenderDefaultView() .WithModel <LogDetailsViewModel>(m => { Assert.AreSame(model, m); }); }
public void TestEdit_ShouldSetViewModelCorrectly(int logId, string newDescription, string newName) { // Arrange var mockedLogService = new Mock <ILogService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var mockedFactory = new Mock <IViewModelFactory>(); var controller = new LogsController(mockedLogService.Object, mockedAuthenticationProvider.Object, mockedFactory.Object); var model = new LogDetailsViewModel { LogId = logId, Description = newDescription, Name = newName }; // Act, Assert controller .WithCallTo(c => c.Edit(model)) .ShouldRenderPartialView("_LogDescription") .WithModel <LogDetailsViewModel>(m => Assert.AreEqual(model, m)); }
public void TestEdit_ShouldCallServiceEditLogDescriptionCorrectly(int logId, string newDescription, string newName) { // Arrange var mockedLogService = new Mock <ILogService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var mockedFactory = new Mock <IViewModelFactory>(); var controller = new LogsController(mockedLogService.Object, mockedAuthenticationProvider.Object, mockedFactory.Object); var model = new LogDetailsViewModel { LogId = logId, Description = newDescription, Name = newName }; // Act controller.Edit(model); // Assert mockedLogService.Verify(s => s.EditLog(logId, newDescription, newName), Times.Once); }
/// <summary> /// Executes the Open Log Dialog Command /// </summary> private void ExecuteOpenLogDialog() { var logDetails = new LogDetailsViewModel(this.LogEventInfo); this.dialogNavigationService.NavigateModal(logDetails); }