forked from CommunityToolkit/Maui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'CommunityToolkit:main' into main
- Loading branch information
Showing
40 changed files
with
776 additions
and
332 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
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
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
117 changes: 117 additions & 0 deletions
117
...yToolkit.Maui.Analyzers.UnitTests/UseCommunityToolkitCameraInitializationAnalyzerTests.cs
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,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); | ||
} | ||
} |
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
Oops, something went wrong.