Skip to content

Commit

Permalink
#4089 Add unit tests for Blazor context manager configuration (#4113)
Browse files Browse the repository at this point in the history
  • Loading branch information
rockfordlhotka authored Jul 22, 2024
1 parent 1418457 commit 1ff5352
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions Source/Csla.Blazor.Test/AppContext/ContextManagerTests.cs
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();
}
}

0 comments on commit 1ff5352

Please sign in to comment.