Write NUnit tests using FakeItEasy and Shouldly with Arrange-Act-Assert pattern for QNAP backup decryption tool
Instructions for writing unit tests for the QNAP Backup Decryptor project using NUnit, FakeItEasy, and Shouldly.
You must use the following testing tools:
All unit tests must follow the Arrange-Act-Assert (AAA) pattern:
1. **Arrange** - Set up test data, mocks, and dependencies
2. **Act** - Execute the method or functionality being tested
3. **Assert** - Verify the expected outcome using Shouldly assertions
Example:
```
MainProject: QnapBackupDecryptor
Test Project: QnapBackupDecryptor.Tests
Test Class: BackupDecryptorTests
Test Method: Decrypt_WhenFileIsEncrypted_ReturnsDecryptedContent
```
The test project must:
1. Reference the main project
2. Include these NuGet packages:
- NUnit
- NUnit3TestAdapter (for test runner integration)
- FakeItEasy
- Shouldly
```csharp
using NUnit.Framework;
using FakeItEasy;
using Shouldly;
namespace QnapBackupDecryptor.Tests
{
[TestFixture]
public class BackupDecryptorTests
{
[Test]
public void Decrypt_WhenFileIsEncrypted_ReturnsDecryptedContent()
{
// Arrange
var mockFileReader = A.Fake<IFileReader>();
var encryptedData = new byte[] { 0x01, 0x02, 0x03 };
A.CallTo(() => mockFileReader.ReadFile(A<string>._))
.Returns(encryptedData);
var decryptor = new BackupDecryptor(mockFileReader);
// Act
var result = decryptor.Decrypt("test.enc");
// Assert
result.ShouldNotBeNull();
result.Length.ShouldBeGreaterThan(0);
}
[Test]
public void Decrypt_WhenFileNotFound_ThrowsFileNotFoundException()
{
// Arrange
var mockFileReader = A.Fake<IFileReader>();
A.CallTo(() => mockFileReader.ReadFile(A<string>._))
.Throws<FileNotFoundException>();
var decryptor = new BackupDecryptor(mockFileReader);
// Act & Assert
Should.Throw<FileNotFoundException>(() => decryptor.Decrypt("missing.enc"));
}
}
}
```
1. **Separation of Concerns**: Keep test code separate from production code
2. **Descriptive Names**: Test method names should clearly describe what is being tested and the expected outcome
3. **Mocking**: Use FakeItEasy to create test doubles for dependencies
4. **Readable Assertions**: Use Shouldly for expressive, human-readable assertions
5. **AAA Pattern**: Always structure tests with clear Arrange, Act, and Assert sections (comments optional but recommended for clarity)
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/qnap-backup-decryptor-testing-standards/raw