-
-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
1418457
commit 1ff5352
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="ContextManagerTests.cs" company="Marimer LLC"> | ||
// Copyright (c) Marimer LLC. All rights reserved. | ||
// Website: https://cslanet.com | ||
// </copyright> | ||
// <summary>Context Manager configuration tests</summary> | ||
//----------------------------------------------------------------------- | ||
|
||
using Csla.Configuration; | ||
using Microsoft.AspNetCore.Components.Authorization; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Csla.Blazor.Test.AppContext; | ||
|
||
/// <summary> | ||
/// Context Manager configuration tests | ||
/// </summary> | ||
[TestClass] | ||
public class ContextManagerTests | ||
{ | ||
[TestMethod] | ||
public void UseApplicationContextManagerInMemory() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddScoped<AuthenticationStateProvider, AuthenticationStateProviderFake>(); | ||
services.AddHttpContextAccessor(); | ||
services.AddCsla(o => o | ||
.AddAspNetCore() | ||
.AddServerSideBlazor(o => o.UseInMemoryApplicationContextManager = true)); | ||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
var activeState = serviceProvider.GetRequiredService<AspNetCore.Blazor.ActiveCircuitState>(); | ||
activeState.CircuitExists = true; | ||
|
||
var applicationContext = serviceProvider.GetRequiredService<ApplicationContext>(); | ||
Assert.IsInstanceOfType(applicationContext.ContextManager, typeof(Csla.AspNetCore.Blazor.ApplicationContextManagerInMemory)); | ||
} | ||
|
||
[TestMethod] | ||
public void UseApplicationContextManagerBlazor() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddScoped<AuthenticationStateProvider, AuthenticationStateProviderFake>(); | ||
services.AddHttpContextAccessor(); | ||
services.AddCsla(o => o | ||
.AddAspNetCore() | ||
.AddServerSideBlazor(o => o.UseInMemoryApplicationContextManager = false)); | ||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
var activeState = serviceProvider.GetRequiredService<AspNetCore.Blazor.ActiveCircuitState>(); | ||
activeState.CircuitExists = true; | ||
|
||
var applicationContext = serviceProvider.GetRequiredService<ApplicationContext>(); | ||
Assert.IsInstanceOfType(applicationContext.ContextManager, typeof(Csla.AspNetCore.Blazor.ApplicationContextManagerBlazor)); | ||
|
||
} | ||
} | ||
|
||
|
||
public class AuthenticationStateProviderFake : AuthenticationStateProvider | ||
{ | ||
public override Task<AuthenticationState> GetAuthenticationStateAsync() | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} |