Skip to content

Commit c5f3340

Browse files
authored
Merge pull request #44 from followynne/feat/base-test-architecture
feat: create tests library structure & projects
2 parents ae2aebd + b7c9e00 commit c5f3340

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+16180
-6675
lines changed

README.md

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ Install-Package Serilog.UI
1515

1616
Then install one of the providers based upon your sink:
1717

18-
| Provider Name | Install | Package |
19-
| ------------------------------ | ------------------------------------------------ | ------------------------------------------------------------------------------ |
20-
| Serilog.UI.MsSqlServerProvider | `Install-Package Serilog.UI.MsSqlServerProvider` | [NuGet package](https://www.nuget.org/packages/Serilog.UI.MsSqlServerProvider) |
21-
| Serilog.UI.MySqlProvider | `Install-Package Serilog.UI.MySqlProvider` | [NuGet package](https://www.nuget.org/packages/Serilog.UI.MySqlProvider) |
22-
| Serilog.UI.PostgreSqlProvider | `Install-Package Serilog.UI.PostgreSqlProvider` | [NuGet package](https://www.nuget.org/packages/Serilog.UI.PostgreSqlProvider) |
23-
| Serilog.UI.MongoDbProviderr | `Install-Package Serilog.UI.MongoDbProvider` | [NuGet package](https://www.nuget.org/packages/Serilog.UI.MongoDbProvider) |
18+
| Provider Name | Install | Package |
19+
| -------------------------------- | ------------------------------------------------- | -------------------------------------------------------------------------------- |
20+
| Serilog.UI.MsSqlServerProvider | `Install-Package Serilog.UI.MsSqlServerProvider` | [NuGet package](https://www.nuget.org/packages/Serilog.UI.MsSqlServerProvider) |
21+
| Serilog.UI.MySqlProvider | `Install-Package Serilog.UI.MySqlProvider` | [NuGet package](https://www.nuget.org/packages/Serilog.UI.MySqlProvider) |
22+
| Serilog.UI.PostgreSqlProvider | `Install-Package Serilog.UI.PostgreSqlProvider` | [NuGet package](https://www.nuget.org/packages/Serilog.UI.PostgreSqlProvider) |
23+
| Serilog.UI.MongoDbProviderr | `Install-Package Serilog.UI.MongoDbProvider` | [NuGet package](https://www.nuget.org/packages/Serilog.UI.MongoDbProvider) |
2424
| Serilog.UI.ElasticSearchProvider | `Install-Package Serilog.UI.ElasticSearcProvider` | [NuGet package](https://www.nuget.org/packages/Serilog.UI.ElasticSearchProvider) |
2525

2626
Then, add `AddSerilogUi()` to `IServiceCollection` in `Startup.ConfigureServices` method:
@@ -58,12 +58,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
5858
}
5959
```
6060

61-
The default url to view the log page is `http://<your-app>/serilog-ui`. If you want to change this url path, just configure the route prefix:
62-
```csharp
63-
app.UseSerilogUi(option => option.RoutePrefix = "logs");
64-
```
65-
66-
**Authorization configuration required**
61+
## Authorization: configuration
6762

6863
By default serilog-ui allows access to the log page only for local requests. In order to give appropriate rights for production use, you need to configure authorization. You can secure the log page by allowing specific users or roles to view logs:
6964

@@ -78,30 +73,39 @@ public void ConfigureServices(IServiceCollection services)
7873
authOptions.Roles = new[] { "AdminRole" };
7974
})
8075
.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), "LogTableName"));
81-
.
82-
.
83-
.
76+
// ...
77+
}
8478
```
85-
Only `User1` and `User2` or users with `AdminRole` role can view logs. If you set `AuthenticationType` to `Jwt`, you can set a jwt token and an `Authorization` header will be added to the request and for `Cookie` just login into you website and no extra step is required.
79+
Only `User1` and `User2` or users with `AdminRole` role can view logs.
80+
81+
If you set `AuthenticationType` to `Jwt`, you can set a jwt token and an `Authorization` header will be added to the request and for `Cookie` just login into you website and no extra step is required.
82+
83+
To disable anonymous access for local requests, (e.g. for testing authentication locally) set `AlwaysAllowLocalRequests` to `false`.
8684

87-
To disable access for local requests, (e.g. for testing authentication locally) set `AlwaysAllowLocalRequests` to `false`.
85+
To disable authorization on production, set `Enabled` to false.
8886

8987
``` csharp
9088
services.AddSerilogUi(options => options
9189
.EnableAuthorization(authOption =>
9290
{
93-
authOption.AlwaysAllowLocalRequests = false;
91+
authOption.AlwaysAllowLocalRequests = false; // disable anonymous access on local
92+
authOption.Enabled = false; // disable authorization access check on production
9493
})
9594
.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), "Logs"));
9695
```
9796

98-
## Limitations
99-
* Additional columns are not supported and only main columns can be retrieved.
100-
10197
## Options
10298
Options can be found in the [UIOptions](src/Serilog.Ui.Web/Extensions/UiOptions.cs) class.
10399
`internal` properties can generally be set via extension methods, see [SerilogUiOptionBuilderExtensions](src/Serilog.Ui.Web/Extensions/SerilogUiOptionBuilderExtensions.cs)
104100

101+
### Log page URL
102+
103+
The default url to view the log page is `http://<your-app>/serilog-ui`. If you want to change this url path, just configure the route prefix:
104+
105+
```csharp
106+
app.UseSerilogUi(option => option.RoutePrefix = "logs");
107+
```
108+
105109
### Home url
106110
![image](https://user-images.githubusercontent.com/8641495/185874822-1d4b6f52-864c-4ffb-9064-6fc5ee9a079c.png)
107111

@@ -114,10 +118,14 @@ app.UseSerilogUi(options =>
114118
});
115119
```
116120

117-
### Custom Javascript and CSS
121+
### Inject custom Javascript and CSS
122+
123+
For customization of the dashboard UI, custom JS and CSS can be injected.
124+
125+
CSS gets injected in the `<head>` element.
126+
127+
JS gets injected at the end of the `<body>` element by default.
118128

119-
For customization of the dashboard UI custom JS and CSS can be injected.
120-
CSS gets injected in the `<head>` element. JS gets injected at the end of the `<body>` element by default.
121129
To inject JS in the `<head>` element set `injectInHead` to `true`.
122130

123131
``` csharp
@@ -138,6 +146,7 @@ app.UseStaticFiles();
138146
```
139147

140148
With the default configuration static files are served under the wwwroot folder, so in the example above the file structure should be:
149+
141150
![image](https://user-images.githubusercontent.com/8641495/185877921-99aaf19a-3e62-4ad9-85c3-47994e7e6ba1.png)
142151

143152
JS code can be ran when loading the file by wrapping the code in a function, and directly running that function like so:
@@ -147,7 +156,7 @@ JS code can be ran when loading the file by wrapping the code in a function, and
147156
})();
148157
```
149158

150-
## serilog-ui UI frontend development
159+
## UI: Frontend development
151160

152161
The serilog-ui frontend is located inside the Serilog.Ui.Web package.
153162

@@ -202,3 +211,37 @@ There are two Grunt tasks you can use to build the frontend project:
202211
- restart Chrome
203212
- you should be able to run the dev environment on both localhost and 127.0.0.1 (to check if it's working fine, open the console: you'll find a red message: **"[MSW] Mocking enabled."**)
204213
</details>
214+
215+
# Known Limitations
216+
* Additional columns are not supported and only main columns can be retrieved.
217+
218+
# Test
219+
220+
## .NET Serilog.UI Projects
221+
222+
The test projects are located inside the */tests* folder.
223+
224+
Each Serilog.Ui project has a separate test project.
225+
Each project is based onto the **xUnit** test framework.
226+
227+
**Serilog.Ui.Common.Tests**: contains anything that can be shared between the tests projects.
228+
229+
To run the tests, use Test Explorer in Visual Studio or run from the root folder:
230+
231+
```
232+
dotnet test
233+
```
234+
235+
## JS UI assets
236+
237+
Tests are located inside src/Serilog.Ui.Web/assets/__tests__
238+
239+
Tests are based onto Jest test framework, with the help of JSDOM and testing-library packages. Any HTTP request is mocked through [msw](https://mswjs.io/).
240+
241+
Jest configuration can be found in src/Serilog.Ui.Web/jest.config.js; any additional setup item is located inside src/Serilog.Ui.Web/assets/__tests__/util (this folder is excluded from test runs).
242+
243+
To run the tests, open a terminal in src/Serilog.Ui.Web/ and launch this command (watch-mode):
244+
245+
```
246+
npm test
247+
```

0 commit comments

Comments
 (0)