Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
EdCharbeneau committed May 24, 2021
2 parents 691806f + 9cab86f commit b0b9dfb
Show file tree
Hide file tree
Showing 42 changed files with 371 additions and 1,606 deletions.
15 changes: 15 additions & 0 deletions BlazorPro.BlazorSize.Bunit/BlazorPro.BlazorSize.Bunit.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="bunit.web" Version="1.1.5" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BlazorSize\BlazorPro.BlazorSize.csproj" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions BlazorPro.BlazorSize.Bunit/BunitExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using BlazorPro.BlazorSize;
using Microsoft.Extensions.DependencyInjection;

namespace Bunit
{
public static class BunitExtensions
{
public static FakeMediaQueryService AddBlazorSize(this TestContextBase testContext)
{
testContext.RenderTree.Add<MediaQueryList>();
var mediaQueryServices = new FakeMediaQueryService(testContext);
testContext.Services.AddSingleton<IMediaQueryService>(mediaQueryServices);
return mediaQueryServices;
}
}
}
92 changes: 92 additions & 0 deletions BlazorPro.BlazorSize.Bunit/FakeMediaQueryService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using BlazorPro.BlazorSize;
using Bunit;
using Microsoft.JSInterop;

namespace Bunit
{
public class FakeMediaQueryService : IMediaQueryService
{
private readonly TestContextBase contextBase;
private MediaQueryArgs? activeMediaQuery = null;

public List<MediaQueryCache> MediaQueries { get; } = new();

public FakeMediaQueryService(TestContextBase contextBase)
{
this.contextBase = contextBase;
}

public void AddQuery(MediaQuery newMediaQuery)
{
var mediaQueryCache = GetMediaQueryFromCache(newMediaQuery.Media);

if (mediaQueryCache is null)
{
mediaQueryCache = new MediaQueryCache()
{
MediaRequested = newMediaQuery.Media
};
MediaQueries.Add(mediaQueryCache);
}

mediaQueryCache.MediaQueries.Add(newMediaQuery);

SetActiveMediaQuery(activeMediaQuery);
}

public Task CreateMediaQueryList(DotNetObjectReference<MediaQueryList> dotNetObjectReference)
=> Task.CompletedTask;

public Task Initialize(MediaQuery mediaQuery)
=> Task.CompletedTask;

public Task RemoveQuery(MediaQuery mediaQuery)
{
var mediaQueryFromCache = GetMediaQueryFromCache(mediaQuery.Media);
if (mediaQueryFromCache is null)
return Task.CompletedTask;

mediaQueryFromCache.MediaQueries.Remove(mediaQuery);

if (mediaQueryFromCache.MediaQueries.Count == 0)
MediaQueries.Remove(mediaQueryFromCache);

return Task.CompletedTask;
}

public void SetActiveBreakPoint(string breakpoint)
=> SetActiveMediaQuery(new MediaQueryArgs
{
Matches = true,
Media = breakpoint
});

public void SetActiveMediaQuery(MediaQueryArgs args)
{
if (args is null)
return;

activeMediaQuery = args;

// cache must be compared by actual value, not RequestedMedia when invoked from JavaScript
// DOM Media value my be different that the initally requested media query value.
var cache = GetMediaQueryFromCache(args.Media);

if (cache is null) return;

// Dispatch events to all subscribers
contextBase.Renderer.Dispatcher.InvokeAsync(() =>
{
foreach (var item in cache.MediaQueries)
{
item.MediaQueryChanged(args);
}
});
}

private MediaQueryCache GetMediaQueryFromCache(string byMedia)
=> MediaQueries?.Find(q => q.MediaRequested == byMedia);
}
}
10 changes: 0 additions & 10 deletions BlazorSize.ExampleNet30/App.razor

This file was deleted.

20 changes: 0 additions & 20 deletions BlazorSize.ExampleNet30/BlazorSize.ExampleNet30.csproj

This file was deleted.

27 changes: 0 additions & 27 deletions BlazorSize.ExampleNet30/Data/WeatherForecastService.cs

This file was deleted.

32 changes: 0 additions & 32 deletions BlazorSize.ExampleNet30/Program.cs

This file was deleted.

29 changes: 0 additions & 29 deletions BlazorSize.ExampleNet30/Properties/launchSettings.json

This file was deleted.

18 changes: 0 additions & 18 deletions BlazorSize.ExampleNet30/Shared/MainLayout.razor

This file was deleted.

52 changes: 0 additions & 52 deletions BlazorSize.ExampleNet30/Shared/NavMenu.razor

This file was deleted.

16 changes: 0 additions & 16 deletions BlazorSize.ExampleNet30/Shared/SurveyPrompt.razor

This file was deleted.

12 changes: 0 additions & 12 deletions BlazorSize.ExampleNet30/_Imports.razor

This file was deleted.

Loading

0 comments on commit b0b9dfb

Please sign in to comment.