Skip to content

Commit

Permalink
Merge branch 'CommunityToolkit:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ne0rrmatrix authored Sep 18, 2024
2 parents 1de2010 + cf6360d commit d2b055a
Show file tree
Hide file tree
Showing 40 changed files with 776 additions and 332 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ csharp_style_conditional_delegate_call = true:suggestion

# Collection Expressions
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
dotnet_diagnostic.IDE0303.severity = suggestion

# Naming rules

Expand Down
17 changes: 8 additions & 9 deletions samples/CommunityToolkit.Maui.Sample/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@
using Microsoft.Extensions.Http.Resilience;
using Microsoft.Extensions.Logging;
using Microsoft.Maui.LifecycleEvents;
using Microsoft.Maui.Platform;
using Polly;


#if WINDOWS10_0_17763_0_OR_GREATER
using Microsoft.UI;
using Microsoft.UI.Composition.SystemBackdrops;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml.Media;
using Microsoft.Maui.Platform;
#endif

[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
Expand All @@ -52,12 +51,12 @@ public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder()
#if DEBUG
.UseMauiCommunityToolkit(options =>
.UseMauiCommunityToolkit(static options =>
{
options.SetShouldEnableSnackbarOnWindows(true);
})
#else
.UseMauiCommunityToolkit(options =>
.UseMauiCommunityToolkit(static options =>
{
options.SetShouldEnableSnackbarOnWindows(true);
options.SetShouldSuppressExceptionsInConverters(true);
Expand All @@ -70,7 +69,7 @@ public static MauiApp CreateMauiApp()
.UseMauiCommunityToolkitMediaElement()
.UseMauiCommunityToolkitMaps("KEY") // You should add your own key here from bingmapsportal.com
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
.ConfigureFonts(static fonts =>
{
fonts.AddFont("Font Awesome 6 Brands-Regular-400.otf", FontFamilies.FontAwesomeBrands);
});
Expand All @@ -79,13 +78,13 @@ public static MauiApp CreateMauiApp()
builder.ConfigureLifecycleEvents(events =>
{
#if WINDOWS10_0_17763_0_OR_GREATER
events.AddWindows(wndLifeCycleBuilder =>
events.AddWindows(static windowLifeCycleBuilder =>
{
wndLifeCycleBuilder.OnWindowCreated(window =>
windowLifeCycleBuilder.OnWindowCreated(window =>
{
window.SystemBackdrop = new MicaBackdrop { Kind = MicaKind.Base };
var titleBar = window.GetAppWindow()!.TitleBar;
var titleBar = window.GetAppWindow()?.TitleBar ?? throw new InvalidOperationException("App Window Cannot be Null");
titleBar.PreferredHeightOption = TitleBarHeightOption.Tall;
Expand All @@ -105,7 +104,7 @@ public static MauiApp CreateMauiApp()
});

builder.Services.AddHttpClient<ByteArrayToImageSourceConverterViewModel>()
.AddStandardResilienceHandler(options => options.Retry = new MobileHttpRetryStrategyOptions());
.AddStandardResilienceHandler(static options => options.Retry = new MobileHttpRetryStrategyOptions());

builder.Services.AddSingleton<PopupSizeConstants>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(NetVersion)</TargetFramework>
Expand All @@ -18,7 +18,7 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="All" />
<PackageReference Include="coverlet.collector" Version="6.0.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.10.0" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)" />
</ItemGroup>

<ItemGroup>
Expand All @@ -30,7 +30,11 @@

<ItemGroup>
<ProjectReference Include="..\CommunityToolkit.Maui.Analyzers.CodeFixes\CommunityToolkit.Maui.Analyzers.CodeFixes.csproj" />
<ProjectReference Include="..\CommunityToolkit.Maui.Camera.Analyzers.CodeFixes\CommunityToolkit.Maui.Camera.Analyzers.CodeFixes.csproj" />
<ProjectReference Include="..\CommunityToolkit.Maui.Camera\CommunityToolkit.Maui.Camera.csproj" />
<ProjectReference Include="..\CommunityToolkit.Maui.MediaElement.Analyzers.CodeFixes\CommunityToolkit.Maui.MediaElement.Analyzers.CodeFixes.csproj" />
<ProjectReference Include="..\CommunityToolkit.Maui.MediaElement\CommunityToolkit.Maui.MediaElement.csproj" />
<ProjectReference Include="..\CommunityToolkit.Maui\CommunityToolkit.Maui.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using CommunityToolkit.Maui.Camera.Analyzers;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Testing;
using Xunit;
using static CommunityToolkit.Maui.Analyzers.UnitTests.CSharpCodeFixVerifier<CommunityToolkit.Maui.Camera.Analyzers.UseCommunityToolkitCameraInitializationAnalyzer, CommunityToolkit.Maui.Camera.Analyzers.UseCommunityToolkitCameraInitializationAnalyzerCodeFixProvider>;

namespace CommunityToolkit.Maui.Analyzers.UnitTests;
public class UseCommunityToolkitCameraInitializationAnalyzerTests
{
[Fact]
public void UseCommunityToolkitMediaElementInitializationAnalyzerId()
{
Assert.Equal("MCTC001", UseCommunityToolkitCameraInitializationAnalyzer.DiagnosticId);
}

[Fact]
public async Task VerifyNoErrorsWhenUseMauiCommunityToolkitCamera()
{
const string source = @"
namespace CommunityToolkit.Maui.Analyzers.UnitTests
{
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Maui.Hosting;
using CommunityToolkit.Maui;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder.UseMauiApp<Microsoft.Maui.Controls.Application>()
.UseMauiCommunityToolkitCamera()
.ConfigureFonts(fonts =>
{
fonts.AddFont(""OpenSans-Regular.ttf"", ""OpenSansRegular"");
fonts.AddFont(""OpenSans-Semibold.ttf"", ""OpenSansSemibold"");
});
return builder.Build();
}
}
}";

await VerifyCameraToolkitAnalyzer(source);
}

[Fact]
public async Task VerifyNoErrorsWhenUseMauiCommunityToolkitCameraHasAdditonalWhitespace()
{
const string source = @"
namespace CommunityToolkit.Maui.Analyzers.UnitTests
{
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Maui.Hosting;
using CommunityToolkit.Maui;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder ();
builder.UseMauiApp<Microsoft.Maui.Controls.Application> ()
.UseMauiCommunityToolkitCamera ()
.ConfigureFonts(fonts =>
{
fonts.AddFont(""OpenSans-Regular.ttf"", ""OpenSansRegular"");
fonts.AddFont(""OpenSans-Semibold.ttf"", ""OpenSansSemibold"");
});
return builder.Build ();
}
}
}";

await VerifyCameraToolkitAnalyzer(source);
}

[Fact]
public async Task VerifyErrorsWhenMissingUseMauiCommunityToolkitCamera()
{
const string source = @"
namespace CommunityToolkit.Maui.Analyzers.UnitTests
{
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Maui.Hosting;
using CommunityToolkit.Maui;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder.UseMauiApp<Microsoft.Maui.Controls.Application>()
.ConfigureFonts(fonts =>
{
fonts.AddFont(""OpenSans-Regular.ttf"", ""OpenSansRegular"");
fonts.AddFont(""OpenSans-Semibold.ttf"", ""OpenSansSemibold"");
});
return builder.Build();
}
}
}";

await VerifyCameraToolkitAnalyzer(source, Diagnostic().WithSpan(13, 4, 13, 61).WithSeverity(DiagnosticSeverity.Error));
}

static Task VerifyCameraToolkitAnalyzer(string source, params DiagnosticResult[] diagnosticResults)
{
return VerifyAnalyzerAsync(
source,
[
typeof(Views.CameraView) // CommunityToolkit.Maui.Camera
],
diagnosticResults);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Xunit;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Testing;
using Xunit;
using static CommunityToolkit.Maui.Analyzers.UnitTests.CSharpAnalyzerVerifier<CommunityToolkit.Maui.Analyzers.UseCommunityToolkitInitializationAnalyzer>;

namespace CommunityToolkit.Maui.Analyzers.UnitTests;

Expand All @@ -9,4 +12,107 @@ public void UseCommunityToolkitInitializationAnalyzerId()
{
Assert.Equal("MCT001", UseCommunityToolkitInitializationAnalyzer.DiagnosticId);
}

[Fact]
public async Task VerifyNoErrorsWhenUseMauiCommunityToolkit()
{
const string source = @"
namespace CommunityToolkit.Maui.Analyzers.UnitTests
{
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Maui.Hosting;
using CommunityToolkit.Maui;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder.UseMauiApp<Microsoft.Maui.Controls.Application>()
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
fonts.AddFont(""OpenSans-Regular.ttf"", ""OpenSansRegular"");
fonts.AddFont(""OpenSans-Semibold.ttf"", ""OpenSansSemibold"");
});
return builder.Build();
}
}
}";

await VerifyMauiToolkitAnalyzer(source);
}

[Fact]
public async Task VerifyNoErrorsWhenUseMauiCommunityToolkitHasAdditonalWhitespace()
{
const string source = @"
namespace CommunityToolkit.Maui.Analyzers.UnitTests
{
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Maui.Hosting;
using CommunityToolkit.Maui;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder ();
builder.UseMauiApp<Microsoft.Maui.Controls.Application> ()
.UseMauiCommunityToolkit ()
.ConfigureFonts (fonts =>
{
fonts.AddFont(""OpenSans-Regular.ttf"", ""OpenSansRegular"");
fonts.AddFont(""OpenSans-Semibold.ttf"", ""OpenSansSemibold"");
});
return builder.Build ();
}
}
}";

await VerifyMauiToolkitAnalyzer(source);
}

[Fact]
public async Task VerifyErrorsWhenMissingUseMauiCommunityToolkit()
{
const string source = @"
namespace CommunityToolkit.Maui.Analyzers.UnitTests
{
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Maui.Hosting;
using CommunityToolkit.Maui;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder.UseMauiApp<Microsoft.Maui.Controls.Application>()
.ConfigureFonts(fonts =>
{
fonts.AddFont(""OpenSans-Regular.ttf"", ""OpenSansRegular"");
fonts.AddFont(""OpenSans-Semibold.ttf"", ""OpenSansSemibold"");
});
return builder.Build();
}
}
}";

await VerifyMauiToolkitAnalyzer(source, Diagnostic().WithSpan(13, 4, 13, 61).WithSeverity(DiagnosticSeverity.Error));
}

static Task VerifyMauiToolkitAnalyzer(string source, params DiagnosticResult[] expected)
{
return VerifyAnalyzerAsync(
source,
[
typeof(Options), // CommunityToolkit.Maui
typeof(Core.Options), // CommunityToolkit.Maui.Core;
],
expected);
}
}
Loading

0 comments on commit d2b055a

Please sign in to comment.