Skip to content

Commit

Permalink
formated whole code base
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Motycka committed Sep 19, 2021
1 parent 4be884b commit 49c83eb
Show file tree
Hide file tree
Showing 87 changed files with 895 additions and 699 deletions.
6 changes: 3 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ indent_size = 4
tab_width = 4

[*.cs]
dotnet_naming_rule.private_members_with_underscore.symbols = private_fields
dotnet_naming_rule.private_members_with_underscore.style = prefix_underscore
dotnet_naming_rule.private_members_with_underscore.symbols = private_fields
dotnet_naming_rule.private_members_with_underscore.style = prefix_underscore
dotnet_naming_rule.private_members_with_underscore.severity = suggestion

dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private

dotnet_naming_style.prefix_underscore.capitalization = camel_case
Expand Down
14 changes: 7 additions & 7 deletions Tests/Application2Tests/Application2Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.9" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="FluentAssertions" Version="5.10.3"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.9"/>
<PackageReference Include="NUnit" Version="3.12.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Ridge\Ridge.csproj" />
<ProjectReference Include="..\TestWebAplication2\TestWebAplication2.csproj" />
<ProjectReference Include="..\..\src\Ridge\Ridge.csproj"/>
<ProjectReference Include="..\TestWebAplication2\TestWebAplication2.csproj"/>
</ItemGroup>

</Project>
13 changes: 5 additions & 8 deletions Tests/Application2Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,30 @@ public static Application CreateApplication()
{
var webAppFactory = new WebApplicationFactory<Startup>();
var client = webAppFactory.CreateClient();
return new Application
(
return new Application(
webAppFactory,
new ControllerFactory(client, webAppFactory.Services, new NunitLogWriter())
);
}

public sealed class Application : IDisposable
{
public WebApplicationFactory<Startup> WebApplicationFactory { get; set; }
public ControllerFactory ControllerFactory { get; set; }

public Application(
WebApplicationFactory<TestWebAplication2.Startup> webApplicationFactory,
WebApplicationFactory<Startup> webApplicationFactory,
ControllerFactory controllerFactory)
{
WebApplicationFactory = webApplicationFactory;
ControllerFactory = controllerFactory;
}

public WebApplicationFactory<TestWebAplication2.Startup> WebApplicationFactory { get; set; }
public ControllerFactory ControllerFactory { get; set; }

public void Dispose()
{
WebApplicationFactory?.Dispose();
GC.SuppressFinalize(this);
}
}
}


}
2 changes: 1 addition & 1 deletion Tests/RidgeExamples/ExampleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void ComplexTest()
},
complexObjectsFromBody: new List<ComplexObject>()
{
new ComplexObject()
new()
{
Str = "str",
NestedComplexObject = new NestedComplexObject()
Expand Down
12 changes: 6 additions & 6 deletions Tests/RidgeExamples/RidgeExamples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.3" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.3"/>
<PackageReference Include="NUnit" Version="3.12.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Ridge\Ridge.csproj" />
<ProjectReference Include="..\TestWebApplication\TestWebApplication.csproj" />
<ProjectReference Include="..\..\src\Ridge\Ridge.csproj"/>
<ProjectReference Include="..\TestWebApplication\TestWebApplication.csproj"/>
</ItemGroup>

</Project>
32 changes: 15 additions & 17 deletions Tests/RidgeTests/IsSimpleTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,6 @@ namespace RidgeTests
{
public class IsSimpleTypeTests
{
#pragma warning disable
private struct TestStruct
{
public string Prop1;
public int Prop2;
}

private class TestClass1
{
public string Prop1;
public int Prop2;
}
#pragma warning restore

private enum TestEnum { TheValue }

[Test]
public void IsSimpleType()
{
Expand Down Expand Up @@ -75,6 +59,20 @@ public void IsSimpleType()

Assert.IsFalse(GeneralHelpers.IsSimpleType(typeof(TestStruct?)));
}


private enum TestEnum { TheValue }
#pragma warning disable
private struct TestStruct
{
public string Prop1;
public int Prop2;
}

private class TestClass1
{
public string Prop1;
public int Prop2;
}
#pragma warning restore
}
}
10 changes: 4 additions & 6 deletions Tests/RidgeTests/PagesTests/Infrastructure/PagesApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace RidgeTests.PagesTests.Infrastructure
{
public sealed class PagesApplication : IDisposable
{
public WebApplicationFactory<Startup> WebApplicationFactory { get; }
public RazorPageFactory RazorPageFactory { get; }
public HttpClient HttpClient { get; }

public PagesApplication(
WebApplicationFactory<Startup> webApplicationFactory,
RazorPageFactory razorPageFactory,
Expand All @@ -18,16 +22,10 @@ public PagesApplication(
HttpClient = httpClient;
}

public WebApplicationFactory<Startup> WebApplicationFactory { get; }
public RazorPageFactory RazorPageFactory { get; }
public HttpClient HttpClient { get; }

public void Dispose()
{
WebApplicationFactory?.Dispose();
GC.SuppressFinalize(this);
}
}


}
28 changes: 17 additions & 11 deletions Tests/RidgeTests/PagesTests/PageInterceptorCreationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ public void InterceptorCanBeCreated()
using var application = ApplicationBuilder.CreateApplication();

Action sutCall = () => application.RazorPageFactory.CreateRazorPage<PageWithRouteParameter>();

sutCall.Should().NotThrow<Exception>();
}

[Test]
public void PageWithNonVirtualActionCanNotBeIntercepted()
{
using var application = ApplicationBuilder.CreateApplication();

Action sutCall = () => application.RazorPageFactory.CreateRazorPage<PageWithMultipleNonVirtualMethod>();

sutCall.Should().Throw<InvalidOperationException>()
.And.Message.Should().Contain("virtual")

sutCall.Should()
.Throw<InvalidOperationException>()
.And.Message.Should()
.Contain("virtual")
.And.Contain($"{nameof(PageWithMultipleNonVirtualMethod.OnPostNonVirtual)}")
.And.Contain($"{nameof(PageWithMultipleNonVirtualMethod.OnGetNonVirtual)}")
.And.NotContain($"{nameof(PageWithMultipleNonVirtualMethod.OnGetSomething)}");
Expand All @@ -39,22 +41,26 @@ public void GenericTypeOfCustomActionResultMustMatchPageType()

Action sutCall = () => application.RazorPageFactory.CreateRazorPage<PageWithIncorrectReturnTypeInCustomActionResult>();

sutCall.Should().Throw<InvalidOperationException>()
.And.Message.Should().NotContain("virtual")
sutCall.Should()
.Throw<InvalidOperationException>()
.And.Message.Should()
.NotContain("virtual")
.And.Contain($"{nameof(PageWithIncorrectReturnTypeInCustomActionResult.OnGetGenericTypeOfCustomActionResultIsWrong)}")
.And.Contain($"{nameof(PageWithIncorrectReturnTypeInCustomActionResult.OnGetIncorrectToo)}");
}

[Test]
public void AllActionsMustReturnCustomActionResult()
{
using var application = ApplicationBuilder.CreateApplication();

Action sutCall = () => application.RazorPageFactory.CreateRazorPage<PageWithIncorrectReturnType>();


sutCall.Should().Throw<InvalidOperationException>()
.And.Message.Should().NotContain("virtual")

sutCall.Should()
.Throw<InvalidOperationException>()
.And.Message.Should()
.NotContain("virtual")
.And.Contain($"{nameof(PageWithIncorrectReturnType.OnGetVoid)}")
.And.Contain($"{nameof(PageWithIncorrectReturnType.OnGetInt)}");
}
Expand Down
44 changes: 21 additions & 23 deletions Tests/RidgeTests/PagesTests/RazorPagesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ public async Task GetPageSimpleCase()
var page = application.RazorPageFactory.CreateRazorPage<GeneralPageModel>();

var response = await page.OnGet();

response.Model.Test.ParamFromBody.Should().Be("asd");
response.Response.Should().Contain("body");
}

[Test]
public async Task GetSpecificPageHandler()
{
using var application = ApplicationBuilder.CreateApplication();
var page = application.RazorPageFactory.CreateRazorPage<GeneralPageModel>();

var response = await page.OnGetFooStatic();

response.Model.Test.ParamFromBody.Should().Be("Foo");
response.Response.Should().Contain("body");
}


[Test]
public void ExceptionIsPropagatedToTest()
{
Expand All @@ -47,21 +47,21 @@ public void ExceptionIsPropagatedToTest()

call.Should().Throw<InvalidOperationException>().WithMessage("Error");
}

[Test]
public async Task FromBodyQueryRouteIsSupported()
{
using var application = ApplicationBuilder.CreateApplication();

var page = application.RazorPageFactory.CreateRazorPage<GeneralPageModel>();

var response = await page.OnGetFoo2("returnValue", "testQuery");
response.Model.Test.ParamFromBody.Should().Be("returnValue");
response.Model.Test.ParamFromQuery.Should().Be("testQuery");
response.Response.Should().Contain("body");
}


[Test]
public async Task ResultsWithResponseCode4xxAreSupported()
{
Expand All @@ -73,47 +73,47 @@ public async Task ResultsWithResponseCode4xxAreSupported()
response.StatusCode.Should().Be(StatusCodes.Status400BadRequest);
response.Response.Should().Be("Bad request error");
}


[Test]
public async Task ResponsesWith3xxCodeAreSupported()
{
using var application = ApplicationBuilder.CreateApplication();

var page = application.RazorPageFactory.CreateRazorPage<GeneralPageModel>();

var response = await page.OnGetRedirect();
response.StatusCode.Should().Be(StatusCodes.Status200OK);
response.Response.Should().Be("Redirected!!");
}


[Test]
public async Task RouteParamsAreSupported()
{
using var application = ApplicationBuilder.CreateApplication();

var page = application.RazorPageFactory.CreateRazorPage<PageWithRouteParameter>();

var response = await page.OnGet("test");
response.StatusCode.Should().Be(StatusCodes.Status200OK);
response.Response.Should().Be("test");
}

[Test]
public async Task RequestReturning5xxButNotThrowingIsSupported()
{
using var application = ApplicationBuilder.CreateApplication();

var page = application.RazorPageFactory.CreateRazorPage<GeneralPageModel>();

var response = await page.OnGetReturn500();
response.StatusCode.Should().Be(StatusCodes.Status500InternalServerError);
}

[Test]
[Parallelizable(ParallelScope.None)]
[SuppressMessage("", "CA1508", Justification="False positive")]
[SuppressMessage("", "CA1508", Justification = "False positive")]
public async Task WhenControllerCallerIsTurnedOffEverythingWorksNormally()
{
CallDataDictionary.Clear();
Expand All @@ -125,10 +125,10 @@ public async Task WhenControllerCallerIsTurnedOffEverythingWorksNormally()
content.Should().Contain("body");
CallDataDictionary.IsEmpty().Should().BeTrue();
}

[Test]
[Parallelizable(ParallelScope.None)]
[SuppressMessage("", "CA1508", Justification="False positive")]
[SuppressMessage("", "CA1508", Justification = "False positive")]
public async Task WhenControllerCallerIsTurnedOffMiddlewareIsNotHit()
{
CallDataDictionary.Clear();
Expand All @@ -140,7 +140,5 @@ public async Task WhenControllerCallerIsTurnedOffMiddlewareIsNotHit()
CallDataDictionary.IsEmpty().Should().BeTrue();
}
}

}
}

Loading

0 comments on commit 49c83eb

Please sign in to comment.