Browse Source

fix #666, enable dotnet watch to refresh on razer file changes (#831)

* fix #666, enable dotnet watch to refresh on razer file changes

* Fix code format
pull/833/head
Hossam Barakat 6 years ago
committed by GitHub
parent
commit
af84b2d3e8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/Microsoft.Tye.Hosting/Watch/assets/DotNetWatch.targets
  2. 48
      test/E2ETest/TyeRunTests.cs
  3. 26
      test/E2ETest/testassets/projects/web-app/Pages/Error.cshtml
  4. 27
      test/E2ETest/testassets/projects/web-app/Pages/Error.cshtml.cs
  5. 10
      test/E2ETest/testassets/projects/web-app/Pages/Index.cshtml
  6. 25
      test/E2ETest/testassets/projects/web-app/Pages/Index.cshtml.cs
  7. 25
      test/E2ETest/testassets/projects/web-app/Pages/Shared/_Layout.cshtml
  8. 3
      test/E2ETest/testassets/projects/web-app/Pages/_ViewImports.cshtml
  9. 3
      test/E2ETest/testassets/projects/web-app/Pages/_ViewStart.cshtml
  10. 20
      test/E2ETest/testassets/projects/web-app/Program.cs
  11. 27
      test/E2ETest/testassets/projects/web-app/Properties/launchSettings.json
  12. 50
      test/E2ETest/testassets/projects/web-app/Startup.cs
  13. 9
      test/E2ETest/testassets/projects/web-app/appsettings.Development.json
  14. 10
      test/E2ETest/testassets/projects/web-app/appsettings.json
  15. 10
      test/E2ETest/testassets/projects/web-app/tye.yaml
  16. 8
      test/E2ETest/testassets/projects/web-app/web-app.csproj
  17. 71
      test/E2ETest/testassets/projects/web-app/wwwroot/css/site.css
  18. BIN
      test/E2ETest/testassets/projects/web-app/wwwroot/favicon.ico

1
src/Microsoft.Tye.Hosting/Watch/assets/DotNetWatch.targets

@ -26,6 +26,7 @@ Returns: @(Watch)
</_CollectWatchItemsDependsOn>
<_CollectWatchItemsDependsOn Condition=" '$(TargetFramework)' != '' ">
_CoreCollectWatchItems;
$(CustomCollectWatchItems);
</_CollectWatchItemsDependsOn>
</PropertyGroup>

48
test/E2ETest/TyeRunTests.cs

@ -381,6 +381,54 @@ services:
});
}
[Fact]
public async Task WebAppWatchRunTest()
{
using var projectDirectory = CopyTestProjectDirectory("web-app");
var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye.yaml"));
var outputContext = new OutputContext(_sink, Verbosity.Debug);
var application = await ApplicationFactory.CreateAsync(outputContext, projectFile);
var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (a, b, c, d) => true,
AllowAutoRedirect = false
};
var client = new HttpClient(new RetryHandler(handler));
await RunHostingApplication(application, new HostOptions() { Watch = true }, async (app, uri) =>
{
// make sure app is running
var appUri = await GetServiceUrl(client, uri, "web-app");
var response = await client.GetAsync(appUri);
Assert.True(response.IsSuccessStatusCode);
var startupPath = Path.Combine(projectDirectory.DirectoryPath, "Pages", "index.cshtml");
File.AppendAllText(startupPath, "\n");
const int retries = 10;
for (var i = 0; i < retries; i++)
{
var logs = await client.GetStringAsync(new Uri(uri, $"/api/v1/logs/web-app"));
// "Application Started" should be logged twice due to the file change
if (logs.IndexOf("Application started") != logs.LastIndexOf("Application started"))
{
return;
}
await Task.Delay(5000);
}
throw new Exception("Failed to relaunch project with dotnet watch");
});
}
[Fact]
public async Task DockerBaseImageAndTagTest()
{

26
test/E2ETest/testassets/projects/web-app/Pages/Error.cshtml

@ -0,0 +1,26 @@
@page
@model ErrorModel
@{
ViewData["Title"] = "Error";
}
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>

27
test/E2ETest/testassets/projects/web-app/Pages/Error.cshtml.cs

@ -0,0 +1,27 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
namespace web_app.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public class ErrorModel : PageModel
{
public string RequestId { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
private readonly ILogger<ErrorModel> _logger;
public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}

10
test/E2ETest/testassets/projects/web-app/Pages/Index.cshtml

@ -0,0 +1,10 @@
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>

25
test/E2ETest/testassets/projects/web-app/Pages/Index.cshtml.cs

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
namespace web_app.Pages
{
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
public void OnGet()
{
}
}
}

25
test/E2ETest/testassets/projects/web-app/Pages/Shared/_Layout.cshtml

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - web_app</title>
<link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
<div>
<main role="main">
@RenderBody()
</main>
</div>
<footer class="border-top footer text-muted">
<div>
&copy; 2020 - web_app
</div>
</footer>
@RenderSection("Scripts", required: false)
</body>
</html>

3
test/E2ETest/testassets/projects/web-app/Pages/_ViewImports.cshtml

@ -0,0 +1,3 @@
@using web_app
@namespace web_app.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

3
test/E2ETest/testassets/projects/web-app/Pages/_ViewStart.cshtml

@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}

20
test/E2ETest/testassets/projects/web-app/Program.cs

@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
namespace web_app
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}

27
test/E2ETest/testassets/projects/web-app/Properties/launchSettings.json

@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:19132",
"sslPort": 44328
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"web_app": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

50
test/E2ETest/testassets/projects/web-app/Startup.cs

@ -0,0 +1,50 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace web_app
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
}
}
}

9
test/E2ETest/testassets/projects/web-app/appsettings.Development.json

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

10
test/E2ETest/testassets/projects/web-app/appsettings.json

@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}

10
test/E2ETest/testassets/projects/web-app/tye.yaml

@ -0,0 +1,10 @@
# tye application configuration file
# read all about it at https://github.com/dotnet/tye
#
# when you've given us a try, we'd love to know what you think:
# https://aka.ms/AA7q20u
#
name: web-app
services:
- name: web-app
project: web-app.csproj

8
test/E2ETest/testassets/projects/web-app/web-app.csproj

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>web_app</RootNamespace>
</PropertyGroup>
</Project>

71
test/E2ETest/testassets/projects/web-app/wwwroot/css/site.css

@ -0,0 +1,71 @@
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
for details on configuring this project to bundle and minify static web assets. */
a.navbar-brand {
white-space: normal;
text-align: center;
word-break: break-all;
}
/* Provide sufficient contrast against white background */
a {
color: #0366d6;
}
.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
/* Sticky footer styles
-------------------------------------------------- */
html {
font-size: 14px;
}
@media (min-width: 768px) {
html {
font-size: 16px;
}
}
.border-top {
border-top: 1px solid #e5e5e5;
}
.border-bottom {
border-bottom: 1px solid #e5e5e5;
}
.box-shadow {
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
}
button.accept-policy {
font-size: 1rem;
line-height: inherit;
}
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
white-space: nowrap;
line-height: 60px; /* Vertically center the text there */
}

BIN
test/E2ETest/testassets/projects/web-app/wwwroot/favicon.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Loading…
Cancel
Save