public async Task BuildAsync_WhenCalledAndRedditLinkToInformationViewModelBuilderThrowsAggregateException_AddsExceptionToSystemViewModelsInDashboardViewModel() { IEnumerable <INews> newsCollection = CreateNewsCollection(0); IEnumerable <ISystemError> systemErrorCollection = CreateSystemErrorCollection(0); IEnumerable <IRedditSubreddit> redditSubredditCollection = CreateRedditSubredditCollection(0); IEnumerable <IRedditLink> redditLinkCollection = CreateRedditLinkCollection(1); IDashboard dashboard = CreateDashboard(newsCollection: newsCollection, systemErrorCollection: systemErrorCollection, redditSubredditCollection: redditSubredditCollection, redditLinkCollection: redditLinkCollection); string aggregateExceptionMessage = Guid.NewGuid().ToString(); IViewModelBuilder <DashboardViewModel, IDashboard> sut = CreateSut(aggregateExceptionMessage: aggregateExceptionMessage); DashboardViewModel result = await sut.BuildAsync(dashboard); Assert.IsNotNull(result); Assert.IsNotNull(result.Informations); Assert.AreEqual(0, result.Informations.Count()); Assert.IsNotNull(result.LatestInformationsWithImage); Assert.AreEqual(0, result.LatestInformationsWithImage.Count()); Assert.IsNotNull(result.SystemErrors); Assert.AreEqual(1, result.SystemErrors.Count()); Assert.IsNull(result.Settings); Assert.IsNull(result.RedditAuthenticatedUser); Assert.IsNotNull(result.RedditSubreddits); Assert.AreEqual(0, result.RedditSubreddits.Count()); SystemErrorViewModel systemErrorViewModel = result.SystemErrors.First(); Assert.IsNotNull(systemErrorViewModel); Assert.IsNotNull(systemErrorViewModel.SystemErrorIdentifier); Assert.IsTrue(systemErrorViewModel.Timestamp >= DateTime.Now.AddSeconds(-3) && systemErrorViewModel.Timestamp <= DateTime.Now); Assert.IsNotNull(systemErrorViewModel.Message); Assert.AreEqual($"HtmlHelper.ConvertNewLines:{aggregateExceptionMessage}", systemErrorViewModel.Message); Assert.IsNotNull(systemErrorViewModel.Details); }
private byte[] BuildDashboardViewModelAsByteArray() { InformationViewModel informationViewModel = new InformationViewModel { InformationIdentifier = Guid.NewGuid().ToString("D"), Timestamp = DateTime.Now, Header = Guid.NewGuid().ToString("D"), Summary = Guid.NewGuid().ToString("D"), Details = Guid.NewGuid().ToString("D"), ImageUrl = Guid.NewGuid().ToString("D"), Provider = Guid.NewGuid().ToString("D"), Author = Guid.NewGuid().ToString("D"), ExternalUrl = Guid.NewGuid().ToString("D") }; ImageViewModel <InformationViewModel> imageViewModel = new ImageViewModel <InformationViewModel>(informationViewModel, Convert.FromBase64String("R0lGODlhDgAOAKIAAAAAAP///wAAgP//AP8AAMDAwICAgP///yH5BAEAAAcALAAAAAAOAA4AAAM+aLq8YCPIOGV5YdV5IRFgCAbdFlFDNygkWRQGiXHZkj5rXKDWHBUu2A3C2jFkMRolMDyReMiXdCoFWK/YbAIAOw==")); SystemErrorViewModel systemErrorViewModel = new SystemErrorViewModel { SystemErrorIdentifier = Guid.NewGuid().ToString("D"), Timestamp = DateTime.Now, Message = Guid.NewGuid().ToString("D"), Details = Guid.NewGuid().ToString("D"), }; ObjectViewModel <IRedditAuthenticatedUser> redditAuthenticatedUserObjectViewModel = new ObjectViewModel <IRedditAuthenticatedUser> { ObjectIdentifier = Guid.NewGuid().ToString("D"), Object = new RedditAuthenticatedUser(), Timestamp = DateTime.Now, Html = Guid.NewGuid().ToString("D") }; ObjectViewModel <IRedditSubreddit> redditSubredditObjectViewModel = new ObjectViewModel <IRedditSubreddit> { ObjectIdentifier = Guid.NewGuid().ToString("D"), Object = new RedditSubreddit(), Timestamp = DateTime.Now, Html = Guid.NewGuid().ToString("D") }; DashboardViewModel dashboardViewModel = new DashboardViewModel { Informations = new List <InformationViewModel> { informationViewModel }, LatestInformationsWithImage = new List <ImageViewModel <InformationViewModel> > { imageViewModel }, SystemErrors = new List <SystemErrorViewModel> { systemErrorViewModel }, Settings = BuildDashboardSettingsViewModel(), RedditAuthenticatedUser = redditAuthenticatedUserObjectViewModel, RedditSubreddits = new List <ObjectViewModel <IRedditSubreddit> > { redditSubredditObjectViewModel } }; return(new Web.Helpers.ContentHelper(_dataProtectionProviderMock.Object, _httpContextAccessorMock.Object, _urlHelperMock.Object).ToByteArray(dashboardViewModel)); }
public IActionResult SystemError(SystemErrorViewModel systemErrorViewModel) { if (systemErrorViewModel == null) { throw new ArgumentNullException(nameof(systemErrorViewModel)); } return(View("SystemError", systemErrorViewModel)); }
public void SystemError_WhenCalled_ReturnsViewWithSystemErrorViewModel() { SystemErrorViewModel systemErrorViewModel = new SystemErrorViewModel(); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(); IActionResult result = sut.SystemError(systemErrorViewModel); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(ViewResult)); ViewResult viewResult = (ViewResult)result; Assert.IsNotNull(viewResult); Assert.IsNotNull(viewResult.ViewName); Assert.AreEqual("SystemError", viewResult.ViewName); Assert.IsNotNull(viewResult.Model); Assert.AreEqual(systemErrorViewModel, viewResult.Model); }
public async Task BuildAsync_WhenCalled_ReturnsInitializedSystemErrorViewModel() { string identifier = Guid.NewGuid().ToString("D"); DateTime timestamp = DateTime.Now.AddTicks(_random.Next(-5000, 5000)); string information = Guid.NewGuid().ToString("D"); string details = Guid.NewGuid().ToString("D"); ISystemError systemErrorMock = CreateSystemError(identifier, timestamp, information, details); IViewModelBuilder <SystemErrorViewModel, ISystemError> sut = CreateSut(); SystemErrorViewModel result = await sut.BuildAsync(systemErrorMock); Assert.IsNotNull(result); Assert.IsNotNull(result.SystemErrorIdentifier); Assert.AreEqual(identifier, result.SystemErrorIdentifier); Assert.AreEqual(timestamp, result.Timestamp); Assert.IsNotNull(result.Message); Assert.AreEqual($"HtmlHelper.ConvertNewLines:{information}", result.Message); Assert.IsNotNull(result.Details); Assert.AreEqual($"HtmlHelper.ConvertNewLines:{details}", result.Details); }
private void HandleException(Exception exception, IList <SystemErrorViewModel> systemErrorViewModelCollection, object syncRoot) { if (exception == null) { throw new ArgumentNullException(nameof(exception)); } if (systemErrorViewModelCollection == null) { throw new ArgumentNullException(nameof(systemErrorViewModelCollection)); } if (syncRoot == null) { throw new ArgumentNullException(nameof(syncRoot)); } AggregateException aggregateException = exception as AggregateException; if (aggregateException != null) { aggregateException.Handle(ex => { HandleException(ex, systemErrorViewModelCollection, syncRoot); return(true); }); return; } SystemErrorViewModel systemErrorViewModel = new SystemErrorViewModel { SystemErrorIdentifier = Guid.NewGuid().ToString(), Timestamp = DateTime.Now, Message = _htmlHelper.ConvertNewLines(exception.Message), Details = _htmlHelper.ConvertNewLines(exception.StackTrace) }; AddViewModelToViewModelCollection(systemErrorViewModel, systemErrorViewModelCollection, syncRoot); }
protected static DashboardViewModel BuildDashboardViewModel(Random random) { if (random == null) { throw new ArgumentNullException(nameof(random)); } InformationViewModel informationViewModel = new InformationViewModel { InformationIdentifier = Guid.NewGuid().ToString("D"), Timestamp = DateTime.Now, Header = Guid.NewGuid().ToString("D"), Summary = Guid.NewGuid().ToString("D"), Details = Guid.NewGuid().ToString("D"), ImageUrl = Guid.NewGuid().ToString("D"), Provider = Guid.NewGuid().ToString("D"), Author = Guid.NewGuid().ToString("D"), ExternalUrl = Guid.NewGuid().ToString("D") }; ImageViewModel <InformationViewModel> imageViewModel = new ImageViewModel <InformationViewModel>(informationViewModel, Convert.FromBase64String("R0lGODlhDgAOAKIAAAAAAP///wAAgP//AP8AAMDAwICAgP///yH5BAEAAAcALAAAAAAOAA4AAAM+aLq8YCPIOGV5YdV5IRFgCAbdFlFDNygkWRQGiXHZkj5rXKDWHBUu2A3C2jFkMRolMDyReMiXdCoFWK/YbAIAOw==")); SystemErrorViewModel systemErrorViewModel = new SystemErrorViewModel { SystemErrorIdentifier = Guid.NewGuid().ToString("D"), Timestamp = DateTime.Now, Message = Guid.NewGuid().ToString("D"), Details = Guid.NewGuid().ToString("D"), }; ObjectViewModel <IRedditAuthenticatedUser> redditAuthenticatedUserObjectViewModel = new ObjectViewModel <IRedditAuthenticatedUser> { ObjectIdentifier = Guid.NewGuid().ToString("D"), Object = new RedditAuthenticatedUser(), Timestamp = DateTime.Now, Html = Guid.NewGuid().ToString("D") }; ObjectViewModel <IRedditSubreddit> redditSubredditObjectViewModel = new ObjectViewModel <IRedditSubreddit> { ObjectIdentifier = Guid.NewGuid().ToString("D"), Object = new RedditSubreddit(), Timestamp = DateTime.Now, Html = Guid.NewGuid().ToString("D") }; return(new DashboardViewModel { Informations = new List <InformationViewModel> { informationViewModel }, LatestInformationsWithImage = new List <ImageViewModel <InformationViewModel> > { imageViewModel }, SystemErrors = new List <SystemErrorViewModel> { systemErrorViewModel }, Settings = BuildDashboardSettingsViewModel(random), RedditAuthenticatedUser = redditAuthenticatedUserObjectViewModel, RedditSubreddits = new List <ObjectViewModel <IRedditSubreddit> > { redditSubredditObjectViewModel } }); }