Skip to content

Commit

Permalink
Merge pull request #94 from ChaosEngine/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ChaosEngine authored Jul 29, 2021
2 parents 93e0e7c + a5a85b6 commit 1f9d0fd
Show file tree
Hide file tree
Showing 29 changed files with 4,619 additions and 152 deletions.
12 changes: 6 additions & 6 deletions DotnetPlayground.Tests/DotnetPlayground.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.5">
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
40 changes: 20 additions & 20 deletions DotnetPlayground.Tests/HashesControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ internal static Moq.Mock<IHashesRepository> MockHashesRepository()
(IEnumerable<ThinHashes> Itemz, int Count) orgtuple =
WebControllers.BaseController<ThinHashes>.ItemsToJson(items, sort, order, limit, offset);
(IEnumerable<string[]> Itemz, int Count) tuple =
(orgtuple.Itemz.Select(tab => new string[] { tab.Key, tab.HashMD5, tab.HashSHA256 }), orgtuple.Count);
(IEnumerable<ThinHashes> Itemz, int Count) tuple =
(orgtuple.Itemz, orgtuple.Count);
return Task.FromResult(tuple);
});
Expand Down Expand Up @@ -653,9 +653,9 @@ await repository.AddRangeAsync(new[]
//fetching anonymous object from JsonResult is weird; use reflection
Assert.IsType<int>(((JsonResult)result).Value.GetType().GetProperty("total").GetValue(((JsonResult)result).Value));
Assert.Equal(1, (int)((JsonResult)result).Value.GetType().GetProperty("total").GetValue(((JsonResult)result).Value));
Assert.IsAssignableFrom<IEnumerable<string[]>>(((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Single((IEnumerable<string[]>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Equal("ilfad", ((IEnumerable<string[]>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value)).ElementAt(0)[0]);
Assert.IsAssignableFrom<IEnumerable<ThinHashes>>(((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Single((IEnumerable<ThinHashes>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Equal("ilfad", ((IEnumerable<ThinHashes>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value)).ElementAt(0).Key);

// Act - search by Hash256 dont mind ordering
result = await controller.Load(new HashesDataTableLoadInput(null, null, "b3a7dc", 0, 0, "blah"));
Expand All @@ -664,9 +664,9 @@ await repository.AddRangeAsync(new[]
Assert.IsType<JsonResult>(result);
Assert.IsType<int>(((JsonResult)result).Value.GetType().GetProperty("total").GetValue(((JsonResult)result).Value));
Assert.Equal(1, (int)((JsonResult)result).Value.GetType().GetProperty("total").GetValue(((JsonResult)result).Value));
Assert.IsAssignableFrom<IEnumerable<string[]>>(((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Single((IEnumerable<string[]>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Equal("aaaac", ((IEnumerable<string[]>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value)).ElementAt(0)[0]);
Assert.IsAssignableFrom<IEnumerable<ThinHashes>>(((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Single((IEnumerable<ThinHashes>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Equal("aaaac", ((IEnumerable<ThinHashes>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value)).ElementAt(0).Key);

// Act - search by Hash256 but not from start - should not find anything
result = await controller.Load(new HashesDataTableLoadInput(null, null, "e7fc0c5", 0, 0, "blah"));
Expand All @@ -675,37 +675,37 @@ await repository.AddRangeAsync(new[]
Assert.IsType<JsonResult>(result);
Assert.IsType<int>(((JsonResult)result).Value.GetType().GetProperty("total").GetValue(((JsonResult)result).Value));
Assert.Equal(0, (int)((JsonResult)result).Value.GetType().GetProperty("total").GetValue(((JsonResult)result).Value));
Assert.IsAssignableFrom<IEnumerable<string[]>>(((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Empty((IEnumerable<string[]>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.IsAssignableFrom<IEnumerable<ThinHashes>>(((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Empty((IEnumerable<ThinHashes>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));


// Act - ensure order by Key desc
result = await controller.Load(new HashesDataTableLoadInput(nameof(ThinHashes.Key), "DESC", "", 0, 0, "blah"));

Assert.IsType<int>(((JsonResult)result).Value.GetType().GetProperty("total").GetValue(((JsonResult)result).Value));
Assert.True((int)((JsonResult)result).Value.GetType().GetProperty("total").GetValue(((JsonResult)result).Value) > 0);
Assert.IsAssignableFrom<IEnumerable<string[]>>(((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.NotEmpty((IEnumerable<string[]>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Equal("aaaaa", ((IEnumerable<string[]>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value)).Last()[0]);
Assert.IsAssignableFrom<IEnumerable<ThinHashes>>(((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.NotEmpty((IEnumerable<ThinHashes>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Equal("aaaaa", ((IEnumerable<ThinHashes>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value)).Last().Key);


// Act - ensure order by HashSHA256 asc
result = await controller.Load(new HashesDataTableLoadInput(nameof(ThinHashes.HashSHA256), "ASC", "", 3, 3, "blah"));

Assert.IsType<int>(((JsonResult)result).Value.GetType().GetProperty("total").GetValue(((JsonResult)result).Value));
Assert.True((int)((JsonResult)result).Value.GetType().GetProperty("total").GetValue(((JsonResult)result).Value) > 0);
Assert.IsAssignableFrom<IEnumerable<string[]>>(((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Equal(3, ((IEnumerable<string[]>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value)).Count());
Assert.Equal("aaaab", ((IEnumerable<string[]>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value)).First()[0]);
Assert.IsAssignableFrom<IEnumerable<ThinHashes>>(((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Equal(3, ((IEnumerable<ThinHashes>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value)).Count());
Assert.Equal("aaaab", ((IEnumerable<ThinHashes>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value)).First().Key);


// Act - search unexisting, empty result
result = await controller.Load(new HashesDataTableLoadInput(nameof(ThinHashes.HashMD5), "ASC", "dummy", 3, 3, "blah"));

Assert.IsType<int>(((JsonResult)result).Value.GetType().GetProperty("total").GetValue(((JsonResult)result).Value));
Assert.Equal(0, (int)((JsonResult)result).Value.GetType().GetProperty("total").GetValue(((JsonResult)result).Value));
Assert.IsAssignableFrom<IEnumerable<string[]>>(((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Empty(((IEnumerable<string[]>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value)));
Assert.IsAssignableFrom<IEnumerable<ThinHashes>>(((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.Empty(((IEnumerable<ThinHashes>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value)));

// Act - order by bad column - should raise an exception
var exception = Assert.ThrowsAnyAsync<Exception>(async () =>
Expand All @@ -721,8 +721,8 @@ await repository.AddRangeAsync(new[]
Assert.IsType<JsonResult>(result);
Assert.IsType<int>(((JsonResult)result).Value.GetType().GetProperty("total").GetValue(((JsonResult)result).Value));
Assert.Equal(12, (int)((JsonResult)result).Value.GetType().GetProperty("total").GetValue(((JsonResult)result).Value));
Assert.IsAssignableFrom<IEnumerable<string[]>>(((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.True(12 == ((IEnumerable<string[]>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value)).Count());
Assert.IsAssignableFrom<IEnumerable<ThinHashes>>(((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value));
Assert.True(12 == ((IEnumerable<ThinHashes>)((JsonResult)result).Value.GetType().GetProperty("rows").GetValue(((JsonResult)result).Value)).Count());
}
}

Expand Down
10 changes: 5 additions & 5 deletions DotnetPlayground.Tests/HashesRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ await repository.AddRangeAsync(new[]{
Assert.True(found.Count > 0);
Assert.NotEmpty(found.Itemz);
Assert.True(1 == found.Itemz.Count());
Assert.Equal("fakefakef", found.Itemz.First()[0]);
Assert.Equal("fakefakef", found.Itemz.First().Key);
}
}
catch (Exception)
Expand Down Expand Up @@ -253,8 +253,8 @@ public async Task Paging_lots_of_elements(int itemsCount)
Assert.NotEmpty(found.Itemz);
Assert.Equal(found.Count, itemsCount);
Assert.Equal(10, found.Itemz.Count());
Assert.Equal("fakefakef_10", found.Itemz.First()[0]);
Assert.Equal("fakefakefakefakefakefakefakefakefakefakefakefakefakefakefakefake_10", found.Itemz.First()[2]);
Assert.Equal("fakefakef_10", found.Itemz.First().Key);
Assert.Equal("fakefakefakefakefakefakefakefakefakefakefakefakefakefakefakefake_10", found.Itemz.First().HashSHA256);
}
}
catch (Exception)
Expand Down Expand Up @@ -306,8 +306,8 @@ public async Task Paging_lots_of_elements(int itemsCount)
Assert.NotEmpty(found.Itemz);
Assert.Equal(found.Count, itemsCount);
Assert.Equal(10, found.Itemz.Count());
Assert.Equal("alamakota_10", found.Itemz.First()[0]);
Assert.Equal("63b347973bb99fed9277b33cb4646b205e9a31331acfa574add3d2351f445e43_10", found.Itemz.First()[2]);
Assert.Equal("alamakota_10", found.Itemz.First().Key);
Assert.Equal("63b347973bb99fed9277b33cb4646b205e9a31331acfa574add3d2351f445e43_10", found.Itemz.First().HashSHA256);
}
}
catch (Exception)
Expand Down
10 changes: 5 additions & 5 deletions DotnetPlayground.Tests/IntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public class HashesDataTablePage
class TypedResult
{
public int total { get; set; }
public string[][] rows { get; set; }
public ThinHashes[] rows { get; set; }
};

private readonly TestServerFixture<Startup> _fixture;
Expand Down Expand Up @@ -393,20 +393,20 @@ public async Task<int> Load_Valid(string sort, string order, string search, int
var typed_result = new TypedResult
{
total = 1,
rows = new string[][] { }
rows = new ThinHashes[] { }
};

// Deserialize JSON String into concrete class
var data = JsonSerializer.Deserialize<TypedResult>(jsonString);
var data = JsonSerializer.Deserialize<TypedResult>(jsonString, new JsonSerializerOptions{ PropertyNameCaseInsensitive = true });
Assert.IsType(typed_result.GetType(), data);
Assert.IsAssignableFrom<IEnumerable<string[]>>(data.rows);
Assert.IsAssignableFrom<IEnumerable<ThinHashes>>(data.rows);

Assert.True(data.rows.Length == 5 || data.rows.Length == 0);
Assert.True(data.total >= 0);

if (data.rows.Length > 0)
{
Assert.StartsWith(search, data.rows[0][0]);
Assert.StartsWith(search, data.rows[0].Key);

if (query_input.TryGetValue("ExtraParam", out string value) && value == "cached")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public async Task<IActionResult> Stream(HashesDataTableLoadInput input)
//string separator = string.Empty;
foreach (var item in found.Itemz)
{
sb.AppendFormat("{{ \"arr\": [\"{0}\",\"{1}\",\"{2}\"] }}", item[0], item[1], item[2]/*, separator*/);
sb.AppendFormat("{{ \"arr\": [Key:\"{0}\",HashMD5:\"{1}\",HashSHA256:\"{2}\"] }}", item.Key, item.HashMD5, item.HashSHA256/*, separator*/);
//separator = ";";
}
string result = sb.ToString();
Expand Down
34 changes: 17 additions & 17 deletions DotnetPlayground.Web/DotnetPlayground.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.5" Condition="$(DefineConstants.Contains('INCLUDE_SQLSERVER'))" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.8" Condition="$(DefineConstants.Contains('INCLUDE_SQLSERVER'))" />
<PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="5.0.1" Condition="$(DefineConstants.Contains('INCLUDE_SQLSERVER'))" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" Condition="$(DefineConstants.Contains('INCLUDE_POSTGRES'))" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.0-alpha.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.8" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.7" Condition="$(DefineConstants.Contains('INCLUDE_POSTGRES'))" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.1" />
<PackageReference Include="Oracle.EntityFrameworkCore" Version="5.21.1" Condition="$(DefineConstants.Contains('INCLUDE_ORACLE'))" />
<PackageReference Include="IdentityManager2.AspNetIdentity" Version="1.0.0" />
<PackageReference Include="Lib.AspNetCore.ServerTiming" Version="4.0.0" />
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.13.1" Condition="$(DefineConstants.Contains('INCLUDE_COSMOSDB'))" />
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.51.0.2238" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="5.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="5.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="5.0.5" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="5.0.5" />
<PackageReference Include="MessagePack" Version="2.2.85" />
<PackageReference Include="Lib.AspNetCore.ServerTiming" Version="4.1.0" />
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.15.0" Condition="$(DefineConstants.Contains('INCLUDE_COSMOSDB'))" />
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.53.0.2378" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="5.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="5.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="5.0.8" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="5.0.8" />
<PackageReference Include="MessagePack" Version="2.3.75" />
<!--<PackageReference Include="RedHat.AspNetCore.Server.Kestrel.Transport.Linux" Version="3.0.0-*" />-->
</ItemGroup>

Expand All @@ -75,9 +75,9 @@
</ItemGroup>

<ItemGroup Condition="'$(Configuration)'=='Debug'">
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.5">
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="5.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit 1f9d0fd

Please sign in to comment.