Skip to content

Commit

Permalink
Filemanager not working fixed (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
petervandenhout authored Nov 28, 2019
1 parent d48a3ad commit 667ca3c
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 15 deletions.
7 changes: 7 additions & 0 deletions PineBlog.sln
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "01 Docs", "01 Docs", "{5D82
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Opw.PineBlog.EntityFrameworkCore.Tests", "tests\Opw.PineBlog.EntityFrameworkCore.Tests\Opw.PineBlog.EntityFrameworkCore.Tests.csproj", "{09215473-245F-4484-B61C-7FBFC70E8C18}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Opw.PineBlog.Sample.Tests", "tests\Opw.PineBlog.Sample.Tests\Opw.PineBlog.Sample.Tests.csproj", "{FD61CF8C-B52E-4692-9B93-8D48255FD3D1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -104,6 +106,10 @@ Global
{09215473-245F-4484-B61C-7FBFC70E8C18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09215473-245F-4484-B61C-7FBFC70E8C18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09215473-245F-4484-B61C-7FBFC70E8C18}.Release|Any CPU.Build.0 = Release|Any CPU
{FD61CF8C-B52E-4692-9B93-8D48255FD3D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD61CF8C-B52E-4692-9B93-8D48255FD3D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD61CF8C-B52E-4692-9B93-8D48255FD3D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD61CF8C-B52E-4692-9B93-8D48255FD3D1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -119,6 +125,7 @@ Global
{49EA4528-BA74-4FE9-862D-BC1448D50EF8} = {FCEC3C6B-0FC0-42CC-AEE8-EBBC570A67A0}
{122A1302-2B62-485F-B80F-3E9210B0616F} = {64F9A954-9830-45BA-B47F-D3589072E347}
{09215473-245F-4484-B61C-7FBFC70E8C18} = {F800AFAF-471F-41F4-8F17-0C4FAEC41F6A}
{FD61CF8C-B52E-4692-9B93-8D48255FD3D1} = {5FEBABA0-73A1-464A-8715-19F76F742B22}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DF018025-4A97-49F8-888F-C70856C1862A}
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,21 @@ public void ConfigureServices(IServiceCollection services)
...
services.AddPineBlog(Configuration);

services.AddMvc().AddPineBlogRazorPages();
services.AddRazorPages().AddPineBlogRazorPages();
// or services.AddMvcCore().AddPineBlogRazorPages();
// or services.AddMvc().AddPineBlogRazorPages();
...
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
app.UseEndpoints(endpoints =>
{
// make sure to add the endpoint mapping for both RazorPages and Controllers
endpoints.MapRazorPages();
endpoints.MapControllers();
});
...
}
```
Expand Down
15 changes: 14 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@ public void ConfigureServices(IServiceCollection services)
...
services.AddPineBlog(Configuration);

services.AddMvc().AddPineBlogRazorPages();
services.AddRazorPages().AddPineBlogRazorPages();
// or services.AddMvcCore().AddPineBlogRazorPages();
// or services.AddMvc().AddPineBlogRazorPages();
...
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
app.UseEndpoints(endpoints =>
{
// make sure to add the endpoint mapping for both RazorPages and Controllers
endpoints.MapRazorPages();
endpoints.MapControllers();
});
...
}
```
Expand Down
1 change: 0 additions & 1 deletion samples/Opw.PineBlog.Sample/Opw.PineBlog.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.8.2" />
<!--<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />-->
<PackageReference Include="WaffleGenerator" Version="4.0.2" />
</ItemGroup>

Expand Down
4 changes: 1 addition & 3 deletions samples/Opw.PineBlog.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public static void Main(string[] args)
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureAppConfiguration((hostingContext, config) => {
config.AddPineBlogConfiguration(reloadOnChange: true);
})
.ConfigureAppConfiguration((_, config) => config.AddPineBlogConfiguration(reloadOnChange: true))
.ConfigureLogging((hostingContext, builder) =>
{
builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
Expand Down
10 changes: 7 additions & 3 deletions samples/Opw.PineBlog.Sample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void ConfigureServices(IServiceCollection services)
// TODO: combine with AddPineBlogRazorPages?
services.AddPineBlog(Configuration);

services.AddRazorPages()
services
.AddRazorPages()
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddPineBlogRazorPages();
}
Expand All @@ -52,7 +53,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
//TODO: app.UseDatabaseErrorPage();
}
else
{
Expand All @@ -68,7 +68,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints => endpoints.MapRazorPages());
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
});
}
}
}
8 changes: 8 additions & 0 deletions tests/Opw.PineBlog.Core.Tests/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

namespace Opw.PineBlog
{
public static class Constants
{
public const string SkipAzureStorageEmulatorTests = "Requires Azure Storage Emulator.";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task Validator_Should_ThrowValidationErrorException()
ex.Errors.Single(e => e.Key.Equals(nameof(DeleteAzureBlobCommand.FileName))).Should().NotBeNull();
}

[Fact(Skip = "Integration Test; requires Azure Storage Emulator.")]
[Fact(Skip = Constants.SkipAzureStorageEmulatorTests)]
public async Task Handler_Should_ReturnTrue()
{
await Mediator.Send(new UploadAzureBlobCommand { File = _formFileMock.Object, TargetPath = "files", AllowedFileType = FileType.All });
Expand All @@ -48,7 +48,7 @@ public async Task Handler_Should_ReturnTrue()
result.IsSuccess.Should().BeTrue();
}

[Fact(Skip = "Integration Test; requires Azure Storage Emulator.")]
[Fact(Skip = Constants.SkipAzureStorageEmulatorTests)]
public async Task Handler_Should_ReturnFalse_WhenFileDoesNotExist()
{
var result = await Mediator.Send(new DeleteAzureBlobCommand { FileName = "invalid-filename.txt", TargetPath = "files" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Opw.PineBlog.Files.Azure
{
public class GetPagedAzureBlobListQueryTest : MediatRTestsBase
{
[Fact(Skip = "Integration Test; requires Azure Storage Emulator.")]
[Fact(Skip = Constants.SkipAzureStorageEmulatorTests)]
public async Task Handler_Should_ReturnFirstPageWith5Files()
{
var directory = $"{DateTime.UtcNow.Ticks}-{Guid.NewGuid()}";
Expand All @@ -28,7 +28,7 @@ public async Task Handler_Should_ReturnFirstPageWith5Files()
result.Value.Pager.Total.Should().Be(9);
}

[Fact(Skip = "Integration Test; requires Azure Storage Emulator.")]
[Fact(Skip = Constants.SkipAzureStorageEmulatorTests)]
public async Task Handler_Should_ReturnSecondPageWith4Files()
{
var directory = $"{DateTime.UtcNow.Ticks}-{Guid.NewGuid()}";
Expand All @@ -46,7 +46,7 @@ public async Task Handler_Should_ReturnSecondPageWith4Files()
result.Value.Pager.Total.Should().Be(9);
}

[Fact(Skip = "Integration Test; requires Azure Storage Emulator.")]
[Fact(Skip = Constants.SkipAzureStorageEmulatorTests)]
public async Task Handler_Should_Return3Files_ForFileTypeImage()
{
var directory = $"{DateTime.UtcNow.Ticks}-{Guid.NewGuid()}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task Validator_Should_ThrowValidationErrorException()
ex.Errors.Single(e => e.Key.Equals(nameof(UploadAzureBlobCommand.AllowedFileType))).Should().NotBeNull();
}

[Fact(Skip = "Integration Test; requires Azure Storage Emulator.")]
[Fact(Skip = Constants.SkipAzureStorageEmulatorTests)]
public async Task Handler_Should_ReturnTrue()
{
var result = await Mediator.Send(new UploadAzureBlobCommand { File = _formFileMock.Object, TargetPath = "files", AllowedFileType = FileType.All });
Expand Down
30 changes: 30 additions & 0 deletions tests/Opw.PineBlog.Sample.Tests/Controllers/FileControllerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Newtonsoft.Json;
using Opw.PineBlog.Models;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Opw.PineBlog.Sample.Controllers
{
public class FileControllerTests : IClassFixture<TestWebApplicationFactory>
{
private readonly TestWebApplicationFactory _factory;
private readonly HttpClient _client;

public FileControllerTests(TestWebApplicationFactory factory)
{
_factory = factory;
_client = _factory.CreateClient();
}

[Fact]
public async Task Get_Should_BeFound()
{
var response = await _client.GetAsync("admin/file");
response.EnsureSuccessStatusCode();
}
}
}
37 changes: 37 additions & 0 deletions tests/Opw.PineBlog.Sample.Tests/Opw.PineBlog.Sample.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
<IsPackable>false</IsPackable>
<RootNamespace>Opw.PineBlog.Sample</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\samples\Opw.PineBlog.Sample\Opw.PineBlog.Sample.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
35 changes: 35 additions & 0 deletions tests/Opw.PineBlog.Sample.Tests/TestWebApplicationFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Net.Http;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;
using Opw.PineBlog.EntityFrameworkCore;

namespace Opw.PineBlog.Sample
{
public class TestWebApplicationFactory : WebApplicationFactory<Startup>
{
public IConfigurationRoot Configuration { get; }

public TestWebApplicationFactory()
{
Configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
}

protected override IWebHostBuilder CreateWebHostBuilder()
{
return new WebHostBuilder()
.UseConfiguration(Configuration)
.UseStartup<Startup>()
.ConfigureAppConfiguration((_, config) => config.AddPineBlogConfiguration(reloadOnChange: true));
}

//public new HttpClient CreateClient()
//{
// var baseAddress = new Uri($"http://localhost/");
// return CreateClient(new WebApplicationFactoryClientOptions { BaseAddress = baseAddress });
//}
}
}
28 changes: 28 additions & 0 deletions tests/Opw.PineBlog.Sample.Tests/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=inMemory; Database=pineblog-db;"
},
"PineBlogOptions": {
"Title": "PineBlog",
"Description": "A blogging engine based on ASP.NET Core MVC Razor Pages and Entity Framework Core",
"CoverUrl": "/images/woods.gif",
"CoverCaption": "Battle background for the Misty Woods in the game Shadows of Adam by Tim Wendorf",
"CoverLink": "http://pixeljoint.com/pixelart/94359.htm",
"ItemsPerPage": 2,
"CreateAndSeedDatabases": true,
"ConnectionStringName": "DefaultConnection",
"AzureStorageConnectionString": "UseDevelopmentStorage=true",
"AzureStorageBlobContainerName": "pineblog",
"FileBaseUrl": "http://127.0.0.1:10000/devstoreaccount1"
},
"Logging": {
"LogLevel": {
"Default": "Information"
}
},
"AllowedHosts": "*",
"StopApplicationPath": "/stop-app",
"ApplicationInsights": {
"InstrumentationKey": null
}
}

0 comments on commit 667ca3c

Please sign in to comment.