Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
- name: setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-version: '9.0.x'
- name: setup dotnet ef
run: dotnet tool install --tool-path .\.dotnet-tools dotnet-ef --version 8.0.6
run: dotnet tool install --tool-path .\.dotnet-tools dotnet-ef --version 9.0.11
- name: setup node
uses: actions/setup-node@v4
with:
Expand Down
32 changes: 21 additions & 11 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ jobs:
- name: setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: setup dotnet ef
run: dotnet tool install --tool-path .\.dotnet-tools dotnet-ef --version 8.0.6
dotnet-version: '9.0.x'
- name: setup node
uses: actions/setup-node@v4
with:
Expand All @@ -60,6 +58,8 @@ jobs:
uses: potatoqualitee/[email protected]
with:
install: localdb
- name: setup dotnet ef
run: dotnet tool install --tool-path .\.dotnet-tools dotnet-ef --version 9.0.11
- name: migrate
run: .\.dotnet-tools\dotnet-ef database update --project web/web.csproj

Expand All @@ -76,7 +76,9 @@ jobs:
- name: setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-version: '9.0.x'
- name: setup dotnet ef
run: dotnet tool install --tool-path .\.dotnet-tools dotnet-ef --version 9.0.11
- name: setup node
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -111,9 +113,13 @@ jobs:
if: always()
run: |
# generate a report just to show in the action history
reportgenerator -reports:coverage.cobertura.xml -targetdir:coverage/ -reporttypes:textSummary
# print out the report
cat coverage/Summary.txt
if (Test-Path coverage.cobertura.xml) {
reportgenerator -reports:coverage.cobertura.xml -targetdir:coverage/ -reporttypes:textSummary
# print out the report
cat coverage/Summary.txt
} else {
Write-Host "Coverage file not found, skipping report generation"
}

- name: upload cov
if: always()
Expand Down Expand Up @@ -194,7 +200,7 @@ jobs:
- name: setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-version: '9.0.x'
- name: setup node
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -229,9 +235,13 @@ jobs:
if: always()
run: |
# generate a report just to show in the action history
reportgenerator -reports:coverage.cobertura.xml -targetdir:coverage/ -reporttypes:textSummary
# print out the report
cat coverage/Summary.txt
if (Test-Path coverage.cobertura.xml) {
reportgenerator -reports:coverage.cobertura.xml -targetdir:coverage/ -reporttypes:textSummary
# print out the report
cat coverage/Summary.txt
} else {
Write-Host "Coverage file not found, skipping report generation"
}

- name: upload cov
if: always()
Expand Down
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ stages:
- publish

precommit:
image: mcr.microsoft.com/dotnet/sdk:8.0-alpine
image: mcr.microsoft.com/dotnet/sdk:9.0-alpine
stage: test
except:
- public
Expand All @@ -40,7 +40,7 @@ precommit:
- pre-commit run stylelint --all-files

build_web:
image: mcr.microsoft.com/dotnet/sdk:8.0-alpine
image: mcr.microsoft.com/dotnet/sdk:9.0-alpine
stage: build
except:
- public
Expand Down
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# to access webapp
# http://localhost:1234

FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1

WORKDIR /app
Expand All @@ -36,9 +36,13 @@ RUN echo "{\"Demo\": true, \"solr\": {\"atlas_address\": \"$SOLR/solr/atlas\", \

RUN dotnet publish -c Release -o out web.csproj

FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
WORKDIR /app
COPY --from=build ["/app/web/out", "./"]

RUN addgroup -S app && adduser -S -G app app && chown -R app:app /app

USER app

CMD ASPNETCORE_URLS=http://*:$PORT dotnet "Atlas_Web.dll"
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@
"db:update": "dotnet ef database update --project web/web.csproj -v",
"dotnet:publish": "npm run build && dotnet publish web/web.csproj -r win-x86 --self-contained false -c Release -o out",
"test:report_html": "reportgenerator -reports:coverage.cobertura.xml -targetdir:coverage/ -reporttypes:html",
"test:integrationTests": "coverlet web.Tests/bin/Debug/net8.0/web.Tests.dll --target \"dotnet\" --targetargs \"test --filter IntegrationTests --no-build -e Demo=True\" --format cobertura --exclude-by-file \"**/Migrations/*\"",
"test:browserTests": "coverlet web.Tests/bin/Debug/net8.0/web.Tests.dll --target \"dotnet\" --targetargs \"test --filter=BrowserTests --no-build -e Demo=True\" --format cobertura --exclude-by-file \"**/Migrations/*\"",
"test:functionTests": "coverlet web.Tests/bin/Debug/net8.0/web.Tests.dll --target \"dotnet\" --targetargs \"test --filter=FunctionTests --no-build -e Demo=True\" --format cobertura --exclude-by-file \"**/Migrations/*\"",
"test:integrationTests": "coverlet web.Tests/bin/Debug/net9.0/web.Tests.dll --target \"dotnet\" --targetargs \"test --filter IntegrationTests --no-build -e Demo=True\" --format cobertura --exclude-by-file \"**/Migrations/*\"",
"test:browserTests": "coverlet web.Tests/bin/Debug/net9.0/web.Tests.dll --target \"dotnet\" --targetargs \"test --filter=BrowserTests --no-build -e Demo=True\" --format cobertura --exclude-by-file \"**/Migrations/*\"",
"test:functionTests": "coverlet web.Tests/bin/Debug/net9.0/web.Tests.dll --target \"dotnet\" --targetargs \"test --filter=FunctionTests --no-build -e Demo=True\" --format cobertura --exclude-by-file \"**/Migrations/*\"",
"lint:js": "xo web/wwwroot/js",
"lint:scss": "stylelint \"web/wwwroot/css/**/*.scss\"",
"lint": "npm run lint:js & npm run lint:scss",
Expand Down
6 changes: 5 additions & 1 deletion web.Tests/IntegrationTests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ public async Task Get_EndpointsReturnSuccessAndCorrectContentType(string url)

// Act
var response = await client.GetAsync(url);
var body = await response.Content.ReadAsStringAsync();

// Assert
response.EnsureSuccessStatusCode(); // Status Code 200-299
if (!response.IsSuccessStatusCode)
{
throw new System.Exception($"Request to '{url}' failed with {(int)response.StatusCode} ({response.StatusCode}). Body:\n{body}");
}
// Assert.Equal(
// "text/html; charset=utf-8",
// response.Content.Headers.ContentType.ToString()
Expand Down
63 changes: 31 additions & 32 deletions web.Tests/IntegrationTests/Utilities/WebFactory.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.Linq;
using Atlas_Web.Models;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace web.Tests.IntegrationTests
Expand All @@ -14,46 +15,44 @@ public class WebFactory<TStartup> : WebApplicationFactory<TStartup>
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureServices(services =>
{
var descriptor = services.SingleOrDefault(d =>
d.ServiceType == typeof(DbContextOptions<Atlas_WebContext>)
);

if (descriptor != null)
services.Remove(descriptor);
builder.UseEnvironment("Test");

builder.ConfigureTestServices(services =>
{
// Add InMemory database for testing
// Program.cs won't register SQL Server in Test environment, so no conflict
services.AddDbContext<Atlas_WebContext>(options =>
{
options.UseInMemoryDatabase("AtlasIntegrationDb");
options.UseInMemoryDatabase("AtlasIntegrationTestDb");
});
});
}

var sp = services.BuildServiceProvider();
protected override IHost CreateHost(IHostBuilder builder)
{
var host = base.CreateHost(builder);

using (var scope = sp.CreateScope())
{
var scopedServices = scope.ServiceProvider;
var db = scopedServices.GetRequiredService<Atlas_WebContext>();
var logger = scopedServices.GetRequiredService<ILogger<WebFactory<TStartup>>>();
// Seed the database after host is created
using (var scope = host.Services.CreateScope())
{
var services = scope.ServiceProvider;
var db = services.GetRequiredService<Atlas_WebContext>();
var logger = services.GetRequiredService<ILogger<WebFactory<TStartup>>>();

try
{
db.Database.EnsureCreated();

try
{
web.Tests.FunctionTests.Utilities.InitializeDbForTests(db);
logger.LogWarning("Test database initialized");
}
catch (Exception ex)
{
logger.LogError(
ex,
"An error occurred seeding the "
+ "database with test messages. Error: {Message}",
ex.Message
);
}
web.Tests.FunctionTests.Utilities.InitializeDbForTests(db);
logger.LogInformation("Test database initialized and seeded");
}
});
catch (Exception ex)
{
logger.LogError(ex, "An error occurred seeding the test database.");
throw;
}
}

return host;
}
}
}
12 changes: 6 additions & 6 deletions web.Tests/web.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>disable</Nullable>

<IsPackable>false</IsPackable>
Expand All @@ -13,19 +13,19 @@
<ItemGroup>
<PackageReference Include="BrowserStackLocal" Version="2.3.1" />
<PackageReference Include="MartinCostello.BrowserStack.Automate" Version="4.0.1" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="9.0.11" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />

<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Selenium.WebDriver" Version="4.21.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.11">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.11" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">

<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
40 changes: 32 additions & 8 deletions web/Pages/Analytics/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Atlas_Web.Authorization;
using Atlas_Web.Helpers;
using Atlas_Web.Models;
using System.Globalization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -41,7 +42,7 @@ public ActionResult OnGet()

public async Task<ActionResult> OnGetLiveUsers()
{
var ActiveUserData = await (
var rawActiveUserData = await (
from b in _context.Analytics
join sub in (
from a in _context.Analytics
Expand All @@ -68,22 +69,45 @@ from a in _context.Analytics
time = sub.Time
}
join u in _context.Users on b.UserId equals u.UserId
select new ActiveUserData
select new
{
Fullname = u.FullnameCalc,
UserId = b.UserId,
SessionId = b.SessionId,
SessionTime = TimeSpan.FromMilliseconds(sub.SessionTime).ToString(@"h\:mm\:ss"),
PageTime = TimeSpan.FromMilliseconds(b.PageTime ?? 0).ToString(@"h\:mm\:ss"),
SessionTime = sub.SessionTime,
PageTime = b.PageTime,
Href = b.Href,
AccessDateTime = (b.AccessDateTime ?? DateTime.Now).ToString(
@"M/d/yy h\:mm\:ss tt"
),
UpdateTime = (b.UpdateTime ?? DateTime.Now).ToString(@"M/d/yy h\:mm\:ss tt"),
AccessDateTime = b.AccessDateTime,
UpdateTime = b.UpdateTime,
Pages = sub.Pages
}
).ToListAsync();

var ActiveUserData = rawActiveUserData
.Select(x => new ActiveUserData
{
Fullname = x.Fullname,
UserId = x.UserId,
SessionId = x.SessionId,
SessionTime = TimeSpan
.FromMilliseconds(x.SessionTime)
.ToString(@"h\:mm\:ss", CultureInfo.InvariantCulture),
PageTime = TimeSpan
.FromMilliseconds(x.PageTime ?? 0)
.ToString(@"h\:mm\:ss", CultureInfo.InvariantCulture),
Href = x.Href,
AccessDateTime = (x.AccessDateTime ?? DateTime.Now).ToString(
@"M/d/yy h\:mm\:ss tt",
CultureInfo.InvariantCulture
),
UpdateTime = (x.UpdateTime ?? DateTime.Now).ToString(
@"M/d/yy h\:mm\:ss tt",
CultureInfo.InvariantCulture
),
Pages = x.Pages
})
.ToList();

var ActiveUsers = (
from a in ActiveUserData
group a by new { a.UserId, a.SessionId } into grp
Expand Down
Loading
Loading