Skip to content

Commit

Permalink
Merge pull request #1779 from qdraw/feature/202410_architecturetest
Browse files Browse the repository at this point in the history
Add architecture test
  • Loading branch information
qdraw authored Oct 18, 2024
2 parents 33ff263 + 1c7f640 commit 28bc3b5
Show file tree
Hide file tree
Showing 6 changed files with 479 additions and 102 deletions.
6 changes: 3 additions & 3 deletions documentation/docs/developer-guide/api/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This document is auto generated

| Path | Type | Description |
|---------------------------------------------------|-------|---------------------------------------------------------------------------------|
| __/api/account/status__ | GET | Check the account status of the current logged in user |
| __/api/account/status__ | GET | Check the account status of the current logged-in user |
| __/account/login__ | GET | Login form page (HTML) |
| __/api/account/login__ | POST | Login the current HttpContext in |
| __/api/account/logout__ | POST | Logout the current HttpContext out |
Expand All @@ -28,7 +28,7 @@ This document is auto generated
| __/api/cache/list__ | GET | Get Database Cache (only the cache) |
| __/api/remove-cache__ | GET | Delete Database Cache (only the cache) |
| __/api/remove-cache__ | POST | Delete Database Cache (only the cache) |
| __/api/delete__ | DELETE| Remove files from the disk, but the file must contain the !delete! (TrashKeyw...|
| __/api/delete__ | DELETE| Remove files from the disk, but the file must contain the !delete!(TrashKeywo...|
| _Parameters: f (subPaths, separated by dot comma), collections (true is to update files with the same name before _ |
| _ the extenstion) _ |
| __/api/desktop-editor/open__ | POST | Open a file in the default editor or a specific editor on the desktop |
Expand Down Expand Up @@ -101,7 +101,7 @@ This document is auto generated
| __/api/suggest/inflate__ | GET | To fill the cache with the data (only if cache is not already filled) |
| __/api/synchronize__ | POST | Faster API to Check if directory is changed (not recursive) |
| __/api/synchronize__ | GET | Faster API to Check if directory is changed (not recursive) |
| __/api/thumbnail/small/\{f\}__ | GET | Get thumbnail for index pages (300 px or 150px or 1000px (based on whats there))|
| __/api/thumbnail/small/\{f\}__ | GET | Get thumbnail for index pages (300 px or 150px or 1000px (based on what's the...|
| __/api/thumbnail/list-sizes/\{f\}__ | GET | Get overview of what exists by name |
| __/api/thumbnail/\{f\}__ | GET | Get thumbnail with fallback to original source image.Return source image when...|
| _Parameters: f (one single fileHash (NOT path)), filePath (fallback FilePath), isSingleItem (true = load original), _ |
Expand Down
8 changes: 8 additions & 0 deletions documentation/docs/developer-guide/testing/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Testing",
"position": 12,
"link": {
"type": "generated-index",
"description": "Overview of Testing in the Platform"
}
}
82 changes: 82 additions & 0 deletions documentation/docs/developer-guide/testing/architecture-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Architecture Test Documentation

## Overview

The `ArchitectureTest.cs` file contains automated tests to ensure that the project's architecture
adheres to specific guidelines. These guidelines are based on the Sitecore Helix principles, which
help maintain a clean and scalable architecture over time.

## Key Concepts

### Fitness Functions

Fitness functions are tests that confirm whether a particular characteristic of the solution's
architecture is maintained over time. These tests help ensure that the architecture remains
consistent and adheres to predefined rules.

### Helix Principles

The Helix principles define a set of guidelines for structuring projects within a solution. The key
rules enforced by these tests are:

- **Foundation projects** should only reference other Foundation projects.
- **Feature projects** should only reference Foundation projects.
- **Project projects** should only reference Foundation or Feature projects.

## Test Class: `TheSolutionShould`

### Purpose

The `TheSolutionShould` class contains tests that validate the project reference structure within
the solution. It ensures that the inter-project references comply with the Helix principles.

### Key Methods

#### `ContainNoHelixInvalidProjectReferences`

This test method verifies that there are no invalid project references within the solution. It
performs the following steps:

1. **Arrange**: Retrieves a list of projects and their references.
2. **Act**: Reviews the project list for invalid references.
3. **Assert**: Checks if any invalid references are found and asserts that there should be none.

#### `GetProjectsWithReferences`

This method retrieves a dictionary of projects and their references from the solution file.

#### `GetSolutionFilePath`

This method locates the solution file path based on the base directory.

#### `GetProjectsFromSolutionFileContents`

This method extracts project references from the solution file contents using a regular expression.

#### `GetReferencedProjects`

This method retrieves the referenced projects from a given project file.

#### `GetInvalidReferences`

This method identifies invalid references for a given project based on the specified invalid layers.

#### `AssertLayerReferences`

This method asserts that there are no invalid references for a given layer.

## Known Issues

- The `starsky.feature.trash` project references the `starsky.feature.metaupdate` project, which is
a known issue and should be refactored in the future.

## References

- [Microservices and Evolutionary Architecture](https://www.thoughtworks.com/insights/blog/microservices-evolutionary-architecture)
- [Building Evolutionary Architectures](http://shop.oreilly.com/product/0636920080237.do)
- [Sitecore Helix Documentation](http://helix.sitecore.net/introduction/index.html)

---

This documentation provides an overview of the purpose and functionality of the
`ArchitectureTest.cs` file, along with explanations of key concepts and methods.
38 changes: 38 additions & 0 deletions documentation/docs/developer-guide/testing/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Unit tests

In this project, we use unit tests to verify the correctness of individual components
in.

- Language: The unit tests are written in C#.
- Framework: The tests use a testing framework such as MSTest.
- Structure: The tests are organized to cover various layers and components of the application,
ensuring comprehensive coverage.
- Test Cases: Each test case is designed to validate specific functionality, edge cases, and error
conditions.
- Automation: The tests can be run automatically as part of a continuous integration (CI) pipeline to
ensure that new changes do not introduce regressions.

## Here are some best practices for writing unit tests:

1. **Write Independent Tests**: Each test should be independent and not rely on the outcome of other
tests.
2. **Use Descriptive Names**: Test method names should clearly describe what is being tested and the
expected outcome.
3. **Follow the AAA Pattern**: Arrange, Act, Assert. First, set up the test data and environment (
Arrange), then execute the code being tested (Act), and finally verify the result (Assert).
4. **Test One Thing at a Time**: Each test should focus on a single piece of functionality or
behavior.
5. **Keep Tests Small and Focused**: Small, focused tests are easier to understand, maintain, and
debug.
6. **Use Mocks and Stubs**: We manually mock services, at the moment we don't use a library for this.
7. **Ensure Tests are Repeatable**: Tests should produce the same results every time they are run,
regardless of the environment or order of execution.
8. **Run Tests Frequently**: Integrate tests into the development process and run them frequently to
catch issues early.
9. **Test Edge Cases and Error Conditions**: Ensure that tests cover edge cases and potential error
conditions.
10. **Maintain Test Code Quality**: Apply the same standards to test code as you do to production
code, including readability, maintainability, and adherence to coding standards.

By following these best practices, you can create effective and reliable unit tests that help
maintain the quality of your codebase.
Loading

0 comments on commit 28bc3b5

Please sign in to comment.