Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(unit-tests): increase code coverage #252

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

dmitrii-kiselev
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows Conventional Commits
  • Tests for the changes have been added (for bug fixes/features)
  • Docs have been added/updated (for bug fixes/features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no API changes)
  • Other... Please describe:

What is the current behavior?

  • Useless warnings in unit test classes
  • Naming mistakes in unit test classes
  • No unit tests for EFCacheKeyPrefixProvider class
  • No unit tests for EFCacheKeyProvider class
  • No unit tests for EFCacheKey class
  • No unit tests for EFCacheServiceCheck class
  • No unit tests for EFDataReaderLoader class
  • No unit tests for EFDebugLogger class
  • No unit tests for EFServiceCollectionExtensions class
  • No unit tests for LockProvider class
  • No unit tests for StringExtensions class
  • No unit tests for TableEntityInfo class
  • No unit tests for XxHash64Unsafe class

What is the new behavior?

  • No useless warnings in unit test classes
  • No naming mistakes in unit test classes
  • The EFCacheKeyPrefixProvider class is covered by 100%
  • The EFCacheKeyProvider class is covered by 96%
  • The EFCacheKey class is covered by 100%
  • The EFCacheServiceCheck class is covered by 97%
  • The EFDataReaderLoader class is covered by 93%
  • The EFDebugLogger class is covered by 100%
  • The EFServiceCollectionExtensions class is covered by 100%
  • The LockProvider class is covered by 100%
  • The StringExtensions class is covered by 100%
  • The TableEntityInfo class is covered by 100%
  • The XxHash64Unsafe class is covered by 100%

Overall code coverage increased from 35% to 53%:

image

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This work improves the overall quality of the project.

Best Regards,
Dmitrii Kiselev

This commit adds:
- Improvements to existing unit test code
- Improvements to existing unit test naming
- Unit tests for `EFCacheKeyPrefixProvider` class
- Unit tests for `EFCacheKeyProvider` class
- Unit tests for `EFCacheKey` class
- Unit tests for `EFCacheServiceCheck` class
- Unit tests for `EFDataReaderLoader` class
- Unit tests for `EFDebugLogger` class
- Unit tests for `EFServiceCollectionExtensions` class
- Unit tests for `LockProvider` class
- Unit tests for `StringExtensions` class
- Unit tests for `TableEntityInfo` class
- Unit tests for `XxHash64Unsafe` class
@VahidN VahidN merged commit 982ec51 into VahidN:master Oct 1, 2024
2 checks passed
{
// Arrange
var dbReaderMock = new Mock<DbDataReader>();
var schemaTable = new DataTable();

Check warning

Code scanning / CodeQL

Missing Dispose call on local IDisposable Warning

Disposable 'DataTable' is created but not disposed.
// Arrange
var dbReaderMock = new Mock<DbDataReader>();

dbReaderMock.Setup(r => r.GetSchemaTable()).Returns((DataTable?)null);

Check warning

Code scanning / CodeQL

Useless upcast Warning

There is no need to upcast from
null
to
DataTable
- the conversion can be done implicitly.
dbReaderMock.Setup(r => r.FieldCount).Returns(1);
dbReaderMock.Setup(r => r.GetValue(0)).Returns("value");
dbReaderMock.Setup(r => r.Read()).Returns(true);
dbReaderMock.Setup(r => r.GetStream(0)).Returns(new MemoryStream(expected));

Check warning

Code scanning / CodeQL

Missing Dispose call on local IDisposable Warning

Disposable 'MemoryStream' is created but not disposed.
x.EventId == CacheableLogEventId.CachingSystemStarted
&& x.Message == "TestMessage"
&& x.CommandText == "TestCommand"
&& x.ServiceProvider == _serviceProviderMock.Object)),

Check warning

Code scanning / CodeQL

Reference equality test on System.Object Warning

Reference equality for System.Object comparisons (
this
argument has type IServiceProvider).
// Assert
_cacheInvalidationEventMock.Verify(e => e.Invoke(It.Is<EFCacheInvalidationInfo>(
x =>
x.CacheDependencies == cacheDependencies

Check warning

Code scanning / CodeQL

Reference equality test on System.Object Warning

Reference equality for System.Object comparisons (
this
argument has type ISet).
_cacheInvalidationEventMock.Verify(e => e.Invoke(It.Is<EFCacheInvalidationInfo>(
x =>
x.CacheDependencies == cacheDependencies
&& x.ClearAllCachedEntries == true

Check notice

Code scanning / CodeQL

Unnecessarily complex Boolean expression Note

The expression 'A == true' can be simplified to 'A'.
x =>
x.CacheDependencies == cacheDependencies
&& x.ClearAllCachedEntries == true
&& x.ServiceProvider == _serviceProviderMock.Object)),

Check warning

Code scanning / CodeQL

Reference equality test on System.Object Warning

Reference equality for System.Object comparisons (
this
argument has type IServiceProvider).
@@ -8,10 +8,10 @@
public void IsNull_ShouldReturnTrue_WhenValueIsNull()
{
// Arrange && Act
var result = ((object)null).IsNull();
var actual = ((object)null).IsNull();

Check warning

Code scanning / CodeQL

Useless upcast Warning

There is no need to upcast from
null
to
Object
- the conversion can be done implicitly.
var hashProvider = new XxHash64Unsafe();

// Act && Assert
Assert.Throws<ArgumentNullException>(() => hashProvider.ComputeHash(((string)null)!));

Check warning

Code scanning / CodeQL

Useless upcast Warning

There is no need to upcast from
null
to
String
- the conversion can be done implicitly.
var hashProvider = new XxHash64Unsafe();

// Act && Assert
Assert.Throws<ArgumentNullException>(() => hashProvider.ComputeHash(((byte[])null)!));

Check warning

Code scanning / CodeQL

Useless upcast Warning

There is no need to upcast from
null
to
Byte[]
- the conversion can be done implicitly.
@dmitrii-kiselev dmitrii-kiselev deleted the feature/unit-tests branch October 2, 2024 16:24
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.

2 participants