fix(codegen): update csharp boilerplate (#6742)

This commit is contained in:
Dmitry Gozman 2021-05-25 10:59:17 -07:00 committed by GitHub
parent 3f43db5cc4
commit 9dd2f83361
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View file

@ -133,13 +133,13 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
generateHeader(options: LanguageGeneratorOptions): string {
const formatter = new CSharpFormatter(0);
formatter.add(`
using Microsoft.Playwright;
using System;
using System.Threading.Tasks;
using Microsoft.Playwright;
class Example
class Program
{
static async Task Main(string[] args)
public static async Task Main()
{
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.${toPascal(options.browserName)}.LaunchAsync(${formatObject(options.launchOptions, ' ', 'BrowserTypeLaunchOptions')});
@ -150,7 +150,7 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
generateFooter(saveStorage: string | undefined): string {
const storageStateLine = saveStorage ? `\n await context.StorageStateAsync(new BrowserContextStorageStateOptions\n {\n Path = ${quote(saveStorage)}\n });\n` : '';
return `${storageStateLine} }
}`;
}\n`;
}
}

View file

@ -29,7 +29,15 @@ function capitalize(browserName: string): string {
test('should print the correct imports and context options', async ({ browserName, channel, runCLI }) => {
const cli = runCLI(['--target=csharp', emptyHTML]);
const expectedResult = ` using var playwright = await Playwright.CreateAsync();
const expectedResult = `using Microsoft.Playwright;
using System;
using System.Threading.Tasks;
class Program
{
public static async Task Main()
{
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.${capitalize(browserName)}.LaunchAsync(new BrowserTypeLaunchOptions
{
${launchOptions(channel)}