CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
ApplicationContextTests.cs
Go to the documentation of this file.
1using Microsoft.VisualStudio.TestTools.UnitTesting;
3using System;
5using Csla.Core;
6using Microsoft.AspNetCore.Components.Authorization;
7using System.Threading.Tasks;
8using System.Collections.Generic;
9using System.Linq;
10
12{
13 [TestClass]
15 {
16#if NET6_0_OR_GREATER
17 [TestMethod]
18 public void CorrectManagerChosen()
19 {
20 IServiceCollection services = new ServiceCollection();
21 services.AddHttpContextAccessor();
22 services.AddScoped<Csla.AspNetCore.Blazor.ActiveCircuitState>();
23 services.AddScoped(typeof(AuthenticationStateProvider), typeof(TestAuthenticationStateProvider));
24 services.AddCsla(c => c
25 .AddAspNetCore()
26 .AddServerSideBlazor()
27 );
28 IServiceProvider provider = services.BuildServiceProvider();
29 var managers = provider.GetRequiredService<IEnumerable<IContextManager>>();
30 Assert.IsTrue(managers.Count() == 2);
31 var blazorMgr = (Csla.AspNetCore.Blazor.ApplicationContextManagerBlazor)managers.FirstOrDefault(mgr => mgr is Csla.AspNetCore.Blazor.ApplicationContextManagerBlazor);
33 Assert.IsNotNull(blazorMgr);
34 Assert.IsTrue(blazorMgr.IsStatefulContext);
35 Assert.IsFalse(blazorMgr.IsValid); //because no circuit exists
36
37
38 Assert.IsNotNull(httpMgr);
39 Assert.IsFalse(httpMgr.IsStatefulContext);
40 Assert.IsFalse(httpMgr.IsValid); //because no httpcontext exists
41
42 //in this scenario the appliclication context should choose the asynclocal as the
43 var appContext = provider.GetRequiredService<ApplicationContext>();
44 Assert.IsNotNull(appContext);
45 Assert.IsTrue(appContext.ContextManager is Csla.Core.ApplicationContextManagerAsyncLocal);
46
47 }
48#endif
49 }
50
51 public class TestAuthenticationStateProvider : AuthenticationStateProvider
52 {
53 public override Task<AuthenticationState> GetAuthenticationStateAsync()
54 => Task.FromResult<AuthenticationState>(null);
55 }
56}
Provides consistent context information between the client and server DataPortal objects.
Application context manager that uses HttpContextAccessor when resolving HttpContext to store context...
override Task< AuthenticationState > GetAuthenticationStateAsync()
Application context manager using AsyncLocal for user and context dictionaries.