Skip to content

Creating additional unit tests - #729

Merged
poppastring merged 13 commits into
mainfrom
more-unit-tests
Sep 7, 2025
Merged

poppastring merged 13 commits into
mainfrom
more-unit-tests

Conversation

@poppastring

Copy link
Copy Markdown
Owner

PR Classification

Code cleanup and test suite enhancement.

PR Summary

This pull request refactors the test suite for the DasBlog project to improve maintainability, consistency, and test coverage. It introduces a reusable mock utility and consolidates redundant tests.

  • Refactored DasBlogSettingTest to DasBlogSettingsMock for modular and reusable test setup.
  • Added new unit tests for managers (ActivityPubManagerTest, ArchiveManagerTest, etc.) to validate core functionality.
  • Consolidated tag helper tests into TagHelperTest and added cases for PostToFacebookTagHelper, SitePageControlTagHelper, and others.
  • Updated DasBlogSettingsTests to use DasBlogSettingsMock and improved test coverage for methods like GetBaseUrl and CompressTitle.
  • Removed redundant test classes (CommentContentTagHelperTest, PostToFacebookTagHelperTest) and unused code.

- Removed `DasBlogSettingTest` class from `DasBlogSettingTest.cs`.
- Added `DasBlogSettingsMock` as a mock implementation of `IDasBlogSettings`.
- Updated unit tests to use `DasBlogSettingsMock` instead of `DasBlogSettingTest`.
- Refactored test data in `TagHelperTest.cs` to use `DasBlogSettingsMock`.
* Centralized mock setup logic in `DasBlogSettingsMock` to reduce duplication.
* Updated all test methods to use `DasBlogSettingsMock.CreateSettings()`.
* Simplified `DasBlogSettingsTests` constructor by replacing individual mock setups.
* Added a static `DasBlogSettings` instance in `TagHelperTest` for reuse.
* Updated `DasBlogPostLinkTagHelperData` to use centralized settings.
* Removed unused methods and properties from `DasBlogSettingsMock`.
* Improved test readability, maintainability, and consistency across the suite.
* Fixed minor test assertion issues to align with updated mock configurations.
* Removed `CommentContentTagHelperTest.cs`, `PostToFacebookTagHelperTest.cs`, and `PostToLinkedInTagHelperTest.cs`.
* Moved all test cases from the removed files into `TagHelperTest.cs`.
- Added tests for `SitePageControlTagHelper` to verify pagination rendering.
- Added tests for `PostCategoriesListTagHelper` to validate category rendering.
- Added tests for `SiteDescriptionTagHelper` to ensure description rendering.
- Added tests for `SiteRootTagHelper` to verify root URL rendering.
- Added tests for `SiteTitleTagHelper` to validate title rendering.
- Used mocked `DasBlogSettings` to simulate configuration settings.
- Improved test coverage to reduce regression risks.
- Expanded `XmlRpcManagerTest` with comprehensive test coverage.
- Added mock setups for `IDasBlogSettings`, `ISiteSecurityManager`, etc.
- Implemented helper method to create `XmlRpcManager` instances.
- Added tests for methods like `mt_publishPost`, `mt_getCategoryList`.
- Verified behavior for Blogger API enable/disable scenarios.
- Configured mocks to simulate dependencies and test edge cases.
- Ensured robust assertions for method outputs and exceptions.
- Introduced `SubscriptionManagerTest` to test `SubscriptionManager`.
- Mocked dependencies: `IDasBlogSettings`, `ISiteConfig`, `IMetaTags`, `IBlogDataService`.
- Configured mocks to simulate `SubscriptionManager` behavior.
- Added helper method `CreateManager` for test setup.
- Implemented xUnit tests for `GetRss`, `GetRssCategory`, `GetRsd`.
- Verified `GetAtom` and `GetAtomCategory` throw `NotImplementedException`.
- Added necessary `using` directives for required namespaces.
- Removed unused `Mock<IBlogDataService>` from `SubscriptionManagerTest`.
- Replaced `Assert.Equal` with `Assert.Single` in `GetRssCategory_ReturnsRssRoot`.
- Added `SiteSecurityManagerTest` with unit tests for password hashing, MD5 validation, user retrieval, and password verification.
- Added `SiteManagerTest` class to test `SiteManager` behavior.
- Introduced mocks for `IDasBlogSettings` and `ISiteConfig`.
- Implemented tests for constructor and `GetGoogleSiteMap`.
- Verified `GetGoogleSiteMap` returns valid URL set with expected properties.
- Added `CategoryManagerTest` class to test `CategoryManager`.
- Introduced mocks for `IDasBlogSettings` and `ISiteConfig`.
- Implemented tests for `GetEntries` and `GetCategoryTitle`.
- Verified `CategoryManager` instantiation with valid dependencies.
- Ensured tests validate entry retrieval and category title logic.
- Added `using` directives for required namespaces to support testing.
- Introduced `BlogManagerTest` class for unit testing `BlogManager`.
- Mocked `IDasBlogSettings`, `ISiteConfig`, and `ILogger<BlogManager>`.
- Implemented constructor to configure mock dependencies.
- Added `CreateManager` helper method to instantiate `BlogManager`.
- Added unit tests:
  - `Constructor_WithValidDependencies_ConstructsInstance`.
  - `GetBlogPost_ByTitle_ReturnsEntry`.
  - `GetEntryForEdit_ReturnsEntry`.
  - `GetFrontPagePosts_ReturnsEntries`.
  - `GetAllEntries_ReturnsEntries`.
* Updated `Constructor_WithValidDependencies_ConstructsInstance` in `CategoryManagerTest.cs` to use `Assert.True(result.Count > 22)`.
* Removed `Assert.NotEmpty` and specific title check from `CategoryManagerTest.cs`.
* Added `ArchiveManagerTest` class in `ArchiveManagerTest.cs` with mock setups for `IDasBlogSettings`, `ISiteConfig`, and `IBlogDataService`.
* Added `CreateManager` helper method to instantiate `ArchiveManager` with mocked dependencies.
* Added tests in `ArchiveManagerTest`:
  - `Constructor_WithValidDependencies_ConstructsInstance`: Verifies instance creation.
  - `GetEntriesForMonth_ReturnsEntries`: Validates 6 entries and title.
  - `GetEntriesForYear_ReturnsEntries`: Validates >9 entries and title.
  - `GetDaysWithEntries_ReturnsDates`: Validates 10 dates and specific date inclusion.
  - `GetEntriesForDay_ReturnsEntries`: Validates 5 entries and title.
* Updated `GetEntriesForYear_ReturnsEntries` to use `Assert.Equal(10, result.Count)` for stricter validation of entry count.
* Removed `Assert.Equal(10, result.Count)` from `GetDaysWithEntries_ReturnsDates` to focus on verifying the presence of a specific date in the result.
- Removed `Mock<IBlogDataService>` from `ArchiveManagerTest`.
- Added `using System.Linq;` to `XmlRpcManagerTest`.
- Refactored `mt_getRecentPostTitles_ReturnsRecentPosts` test.
- Added `ActivityPubManagerTest` with mocked dependencies.
- Implemented unit tests for `ActivityPubManager` methods.
@poppastring
poppastring merged commit 87ddbf4 into main Sep 7, 2025
@poppastring
poppastring deleted the more-unit-tests branch September 7, 2025 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant