public IViewComponentResult Invoke() { // first check if it is the current users birthday and if so use the birthday splash screen // because birthdays take priority IViewComponentResult BirthdayView = GetBirthdayView(); if (BirthdayView != null) { return(BirthdayView); } // check if it is a holiday and if so use the holiday splash screen IViewComponentResult HolidayView = GetHolidayView(); if (HolidayView != null) { return(HolidayView); } // or just show the regular splash screen bool showSplashScreen = HttpContext.Request.Cookies["HideSplashScreen"] == null; SplashScreenModel splashScreenLoader = new SplashScreenModel(showSplashScreen); return(View("Default", splashScreenLoader)); //return View(splashScreenLoader); }
/// <summary> /// Initializes a new instance of <see cref="AfterViewComponentEventData"/>. /// </summary> /// <param name="actionDescriptor">The <see cref="ActionDescriptor"/>.</param> /// <param name="viewComponentContext">The <see cref="ViewComponentContext"/>.</param> /// <param name="viewComponentResult">The <see cref="ViewComponentResult"/>.</param> /// <param name="viewComponent">The <see cref="ViewComponent"/>.</param> public AfterViewComponentEventData(ActionDescriptor actionDescriptor, ViewComponentContext viewComponentContext, IViewComponentResult viewComponentResult, object viewComponent) { ActionDescriptor = actionDescriptor; ViewComponentContext = viewComponentContext; ViewComponentResult = viewComponentResult; ViewComponent = viewComponent; }
private IViewComponentResult GetHolidayView() { IViewComponentResult HoldiayView = null; // check if it is a holiday and if so use the holiday splash screen if (HttpContext.Request.Cookies["ItsAHoliday"] == "true") { // check cookies since it is less expensive then running the holiday service var todaysHoliday = HttpContext.Request.Cookies["TodaysHoliday"]; // TODO - J - create all the holiday splash screen models and functionality SplashScreenModel holidaySplashScreen = new SplashScreenModel(true); return(View("BirthdaySplashScreen", holidaySplashScreen)); } else { // check for holidays IEnumerable <Holiday> holidays; //DateTime dayToCheck = DateTime.Parse("12/12/2020"); // TODO - J - remove once testing is done //holidays = _holidayService.GetHolidays(dayToCheck); // TODO - J - remove once testing is done holidays = _holidayService.GetHolidays(); if (holidays.Count() > 0) { // TODO - J - create all the holiday splash screen model(s) and functionality SplashScreenModel holidaySplashScreen = new SplashScreenModel(true); HoldiayView = View("HolidaySplashScreen", holidaySplashScreen); } } return(HoldiayView); }
public async Task <IViewComponentResult> InvokeAsync(DomainReference domainReference, ContentReference contentReference = null) { IViewComponentResult result = View("Default", domainReference); if (domainReference != null) { switch (domainReference.Type) { case DomainType.Subverse: Subverse subverse = null; if (!String.IsNullOrEmpty(domainReference.Name)) { var q = new QuerySubverse(domainReference.Name); subverse = await q.ExecuteAsync(); } if (subverse != null) { var qa = new QueryActiveSessionCount(domainReference); ViewBag.OnlineUsers = await qa.ExecuteAsync(); var view = "Subverse"; // contentReference != null && contentReference.Type == ContentType.Submission ? "Submission" : "Subverse"; if (contentReference != null) { switch (contentReference.Type) { case ContentType.Vote: view = "VoteSubmission"; break; } } result = View(view, subverse); } else { result = View("Default"); } break; case DomainType.User: result = View("User", domainReference); break; case DomainType.Set: var qSet = new QuerySet(domainReference.Name, domainReference.OwnerName); var set = await qSet.ExecuteAsync(); result = View("Set", set); break; } } return(result); return(View("Chat", domainReference)); }
public static T ViewDataModelAs <T>(this IViewComponentResult viewComponentResult) { var componentResult = viewComponentResult as ViewViewComponentResult; var viewComponentModel = (T)componentResult?.ViewData.Model; return(viewComponentModel); }
public void WhenInvokeIsCalledThenUseDefaultView() { IViewComponentResult result = this.viewComponent.Invoke(); Assume.That(result, Is.TypeOf(typeof(ViewViewComponentResult))); Assert.That(((ViewViewComponentResult)result).ViewName, Is.Null); }
public async Task <IViewComponentResult> InvokeAsync(Core.Main.DataObjects.PTMagicData.MarketPairSummary mps) { IViewComponentResult result = null; await Task.Run(() => { result = View(mps); }); return(result); }
public When_Back_Component_Is_Loaded_With_Saved_Opportunities() { _opportunityService = Substitute.For <IOpportunityService>(); _opportunityService.GetSavedOpportunityItemCountAsync(1).Returns(2); var viewComponent = new BackViewComponent(_opportunityService); _result = viewComponent.InvokeAsync(1, 2).GetAwaiter().GetResult(); }
public static void AfterViewComponent( this DiagnosticListener diagnosticListener, ViewComponentContext context, IViewComponentResult result, object viewComponent) { // Inlinable fast-path check if Diagnositcs is enabled if (diagnosticListener.IsEnabled()) { AfterViewComponentImpl(diagnosticListener, context, result, viewComponent); } }
private TResultType AssertViewComponentResultType <TResultType>(IViewComponentResult viewComponentResult) where TResultType : IViewComponentResult { Type expectedType = typeof(TResultType); if (viewComponentResult == null || !TypeTester.IsOfType(viewComponentResult, expectedType)) { string actualTypeName = (viewComponentResult == null) ? "null" : viewComponentResult.GetType().FullName; throw new ActionTestException( $"Expected IViewComponentResult type {expectedType.FullName}. Actual: {actualTypeName}."); } return((TResultType)viewComponentResult); }
public Task <IViewComponentResult> InvokeAsync() { string name = null; var identity = HttpContextAccessor.HttpContext.User.Identity; if (identity.IsAuthenticated) { name = identity.Name; } IViewComponentResult result = View(new ProfileViewModel { Name = name }); return(Task.FromResult(result)); }
public void Invoke_ContentViewComponentResult() { // Arrange int notificationsCount = 5, userId = 1; Mock <GenericRepository <Notification> > mockNotificationRepository = new Mock <GenericRepository <Notification> >(); mockNotificationRepository .Setup(nr => nr.Count(It.IsAny <Expression <Func <Notification, bool> > >())) .Returns(notificationsCount); Mock <IUnitOfWork> mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork .Setup(u => u.GetRepository <Notification, GenericRepository <Notification> >()) .Returns(mockNotificationRepository.Object); NotificationsCountViewComponent viewComponent = new NotificationsCountViewComponent(mockUnitOfWork.Object); Mock <ClaimsPrincipal> userMock = new Mock <ClaimsPrincipal>(); userMock .Setup(p => p.FindFirst(It.IsAny <string>())) .Returns(new Claim(nameof(User.Id), userId.ToString())); viewComponent.ViewComponentContext = new ViewComponentContext { ViewContext = new Microsoft.AspNetCore.Mvc.Rendering.ViewContext { HttpContext = new DefaultHttpContext { User = userMock.Object } } }; // Act IViewComponentResult result = viewComponent.Invoke(); // Assert Assert.NotNull(result); ContentViewComponentResult contentViewComponentResult = Assert.IsType <ContentViewComponentResult>(result); Assert.NotNull(contentViewComponentResult.Content); Assert.Equal(notificationsCount.ToString(), contentViewComponentResult.Content); }
public static void AfterViewComponent( this DiagnosticSource diagnosticSource, ViewComponentContext context, IViewComponentResult result, object viewComponent) { if (diagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.AfterViewComponent")) { diagnosticSource.Write( "Microsoft.AspNet.Mvc.AfterViewComponent", new { actionDescriptor = context.ViewContext.ActionDescriptor, viewComponentContext = context, viewComponentResult = result, viewComponent = viewComponent }); } }
public static void AfterViewComponent( this DiagnosticSource diagnosticSource, ViewComponentContext context, IViewComponentResult result, object viewComponent) { if (diagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.AfterViewComponent")) { diagnosticSource.Write( "Microsoft.AspNet.Mvc.AfterViewComponent", new { actionDescriptor = context.ViewContext.ActionDescriptor, viewComponentContext = context, viewComponentResult = result, viewComponent = viewComponent }); } }
private IViewComponentResult GetBirthdayView() { IViewComponentResult BirthdayView = null; if (User.Identity.IsAuthenticated && false && // TODO - J - Check for users birthday is today HttpContext.Request.Cookies["HideBirthdaySplashScreen"] == null && HttpContext.Request.Cookies["HideBirthdaySplashScreenForSession"] != "true") { var identity = (ClaimsIdentity)User.Identity; IEnumerable <Claim> claims = identity.Claims; string name = claims.Where(x => x.Type == "ContactName").FirstOrDefault().Value; BirthdaySplashScreenModel birthdaySplashScreen = new BirthdaySplashScreenModel(true, name); BirthdayView = View("BirthdaySplashScreen", birthdaySplashScreen); } return(BirthdayView); }
public IViewComponentResult EditLearnerFeature(ExercisePurposeViewModel viewModel) { IViewComponentResult result = PrepareLearner(viewModel, out UserProfile item); if (result != null) { return(result); } var purpose = item.PersonalExercisePurpose; if (purpose != null) { viewModel.Purpose = purpose.Purpose.GetEfficientString(); viewModel.Ability = purpose.PowerAbility; viewModel.Cardiopulmonary = purpose.Cardiopulmonary; viewModel.Flexibility = purpose.Flexibility; viewModel.MuscleStrength = purpose.MuscleStrength; viewModel.AbilityStyle = purpose.AbilityStyle; viewModel.AbilityLevel = (Naming.PowerAbilityLevel?)purpose.AbilityLevel; } return(View("~/Views/LearnerProfile/Module/EditLearnerFeature.cshtml", item)); }
public void WhenInvokeIsCalledThenViewComponentResultIsReturned() { IViewComponentResult result = this.viewComponent.Invoke(); Assert.That(result, Is.TypeOf(typeof(ViewViewComponentResult))); }
private static void AfterViewComponentImpl(DiagnosticListener diagnosticListener, ViewComponentContext context, IViewComponentResult result, object viewComponent) { if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterViewComponent")) { diagnosticListener.Write( "Microsoft.AspNetCore.Mvc.AfterViewComponent", new { actionDescriptor = context.ViewContext.ActionDescriptor, viewComponentContext = context, viewComponentResult = result, viewComponent = viewComponent }); } }
internal T GetComponentViewModel <T>(IViewComponentResult result) where T : class { return((result as ViewViewComponentResult)?.ViewData.Model as T); }
private IEnumerable <_LatestArticlesViewComponent.RssItem> GetResultModel(IViewComponentResult result) { return((result as ViewViewComponentResult).ViewData.Model as IEnumerable <_LatestArticlesViewComponent.RssItem>); }
private static void AfterViewComponentImpl(DiagnosticListener diagnosticListener, ViewComponentContext context, IViewComponentResult result, object viewComponent) { if (diagnosticListener.IsEnabled(Diagnostics.AfterViewComponentEventData.EventName)) { diagnosticListener.Write( Diagnostics.AfterViewComponentEventData.EventName, new AfterViewComponentEventData( context.ViewContext.ActionDescriptor, context, result, viewComponent )); } }
public void Test_Perché_Luca_Se_L_è_Ricordato() { //var options = new DbContextOptionsBuilder<TRDBContext>().UseInMemoryDatabase(databaseName: "database_super_cazzuto").Options; //using (var context = new TRDBContext(options)) //{ // context.TCourts.Add(new Court() { Name = "Nicolettodromo", Type = "Grass" }); // context.TCourts.Add(new Court() { Name = "Valeriorama", Type = "Grass" }); // context.TCourts.Add(new Court() { Name = "FrasabbiField", Type = "RedGround" }); // context.TCourts.Add(new Court() { Name = "Campetto di Gianluca", Type = "RedGround" }); // context.TCourts.Add(new Court() { Name = "Andredrome", Type = "Concrete" }); // context.SaveChanges(); //} //using (var context = new TRDBContext(options)) //{ // var navigationMenu = new NavigationMenuViewComponent(new Repository(context)) ; // var viewComponentResult = navigationMenu.Invoke() as ViewComponentResult; // IEnumerable<String> model = viewComponentResult.ViewData.Model as IEnumerable<String>; // Assert.Equal("Grass", model.First()); //} Mock <ITSRepository> mock = new Mock <ITSRepository>(); mock.Setup(mockObject => mockObject.Courts).Returns((new Court[] { new Court() { Name = "Nicolettodromo", Type = "Grass" }, new Court() { Name = "Valeriorama", Type = "Grass" }, new Court() { Name = "FrasabbiField", Type = "RedGround" }, new Court() { Name = "Campetto di Gianluca", Type = "RedGround" }, new Court() { Name = "Andredrome", Type = "Concrete" } }).AsQueryable <Court>()); NavigationMenuViewComponent target = new NavigationMenuViewComponent(mock.Object); IViewComponentResult viewComponentResult = target.Invoke(); ViewViewComponentResult viewResultOfMyViewComponent = viewComponentResult as ViewViewComponentResult; // Act = get the set of categories IQueryable <string> resultsQuery = viewResultOfMyViewComponent.ViewData.Model as IQueryable <string>; string[] results = resultsQuery.ToArray(); // Assert Assert.True(Enumerable.SequenceEqual(new string[] { "Concrete", "Grass", "RedGround" }, results)); }
public async Task <IViewComponentResult> InvokeAsync() { IViewComponentResult result = await Task.FromResult((IViewComponentResult)View("_LogixFooter", LogixHealth.EnterpriseLibrary.Extensions.HeadersAndFooters.LogixFooter.ConnectFooter)); return(result); }
public static T ExtractViewModel <T>(this IViewComponentResult r) where T : class { return((r as ViewViewComponentResult)?.ViewData.Model as T); }