Skip to content

Commit bbe9b1f

Browse files
authored
Merge pull request #36 from Atypical-Consulting/vfsexception
Refactor VFSException and add unit tests
2 parents d94714c + 361067c commit bbe9b1f

File tree

7 files changed

+123
-1
lines changed

7 files changed

+123
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#### [Atypical.VirtualFileSystem.Core](VirtualFileSystem.md 'VirtualFileSystem')
2+
### [Atypical.VirtualFileSystem.Core.Exceptions](VirtualFileSystem.md#Atypical.VirtualFileSystem.Core.Exceptions 'Atypical.VirtualFileSystem.Core.Exceptions').[VFSException](VFSException.md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException')
3+
4+
## VFSException() Constructor
5+
6+
Initializes a new instance of the [VFSException](VFSException.md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException') class.
7+
8+
```csharp
9+
public VFSException();
10+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#### [Atypical.VirtualFileSystem.Core](VirtualFileSystem.md 'VirtualFileSystem')
2+
### [Atypical.VirtualFileSystem.Core.Exceptions](VirtualFileSystem.md#Atypical.VirtualFileSystem.Core.Exceptions 'Atypical.VirtualFileSystem.Core.Exceptions').[VFSException](VFSException.md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException')
3+
4+
## VFSException(SerializationInfo, StreamingContext) Constructor
5+
6+
Initializes a new instance of the [VFSException](VFSException.md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException') class with a specified error message and a reference to the
7+
inner exception that is the cause of this exception.
8+
9+
```csharp
10+
protected VFSException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
11+
```
12+
#### Parameters
13+
14+
<a name='Atypical.VirtualFileSystem.Core.Exceptions.VFSException.VFSException(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization.StreamingContext).info'></a>
15+
16+
`info` [System.Runtime.Serialization.SerializationInfo](https://docs.microsoft.com/en-us/dotnet/api/System.Runtime.Serialization.SerializationInfo 'System.Runtime.Serialization.SerializationInfo')
17+
18+
The [System.Runtime.Serialization.SerializationInfo](https://docs.microsoft.com/en-us/dotnet/api/System.Runtime.Serialization.SerializationInfo 'System.Runtime.Serialization.SerializationInfo') that holds the serialized object data about the exception being thrown.
19+
20+
<a name='Atypical.VirtualFileSystem.Core.Exceptions.VFSException.VFSException(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization.StreamingContext).context'></a>
21+
22+
`context` [System.Runtime.Serialization.StreamingContext](https://docs.microsoft.com/en-us/dotnet/api/System.Runtime.Serialization.StreamingContext 'System.Runtime.Serialization.StreamingContext')
23+
24+
The [System.Runtime.Serialization.StreamingContext](https://docs.microsoft.com/en-us/dotnet/api/System.Runtime.Serialization.StreamingContext 'System.Runtime.Serialization.StreamingContext') that contains contextual information about the source or destination.

docs/api/VFSException.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ Inheritance [System.Object](https://docs.microsoft.com/en-us/dotnet/api/System.O
1313
1414
| Constructors | |
1515
| :--- | :--- |
16+
| [VFSException()](VFSException.VFSException().md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException.VFSException()') | Initializes a new instance of the [VFSException](VFSException.md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException') class. |
1617
| [VFSException(string, Exception)](VFSException.VFSException(string,Exception).md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException.VFSException(string, System.Exception)') | Initializes a new instance of the [VFSException](VFSException.md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException') class with a message and an inner exception that is the cause<br/>of this exception. |
1718
| [VFSException(string)](VFSException.VFSException(string).md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException.VFSException(string)') | Initializes a new instance of the [VFSException](VFSException.md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException') class with a message that describes the error. |
19+
| [VFSException(SerializationInfo, StreamingContext)](VFSException.VFSException(SerializationInfo,StreamingContext).md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException.VFSException(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)') | Initializes a new instance of the [VFSException](VFSException.md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException') class with a specified error message and a reference to the<br/>inner exception that is the cause of this exception. |

docs/api/VirtualFileSystem.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,12 @@
214214

215215
## Atypical.VirtualFileSystem.Core.Exceptions Namespace
216216
- **[VFSException](VFSException.md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException')** `Class` Exception thrown by the VFS.
217+
- **[VFSException()](VFSException.VFSException().md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException.VFSException()')** `Constructor` Initializes a new instance of the [VFSException](VFSException.md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException') class.
217218
- **[VFSException(string, Exception)](VFSException.VFSException(string,Exception).md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException.VFSException(string, System.Exception)')** `Constructor` Initializes a new instance of the [VFSException](VFSException.md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException') class with a message and an inner exception that is the cause
218219
of this exception.
219220
- **[VFSException(string)](VFSException.VFSException(string).md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException.VFSException(string)')** `Constructor` Initializes a new instance of the [VFSException](VFSException.md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException') class with a message that describes the error.
221+
- **[VFSException(SerializationInfo, StreamingContext)](VFSException.VFSException(SerializationInfo,StreamingContext).md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException.VFSException(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)')** `Constructor` Initializes a new instance of the [VFSException](VFSException.md 'Atypical.VirtualFileSystem.Core.Exceptions.VFSException') class with a specified error message and a reference to the
222+
inner exception that is the cause of this exception.
220223

221224
<a name='Atypical.VirtualFileSystem.Core.Models'></a>
222225

docs/links

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ T:Atypical.VirtualFileSystem.Core.Models.FileNode|FileNode.md|FileNode
7878
M:Atypical.VirtualFileSystem.Core.Models.RootNode.#ctor|RootNode.RootNode().md|RootNode()
7979
M:Atypical.VirtualFileSystem.Core.Models.RootNode.ToString|RootNode.ToString().md|ToString()
8080
T:Atypical.VirtualFileSystem.Core.Models.RootNode|RootNode.md|RootNode
81+
M:Atypical.VirtualFileSystem.Core.Exceptions.VFSException.#ctor|VFSException.VFSException().md|VFSException()
8182
M:Atypical.VirtualFileSystem.Core.Exceptions.VFSException.#ctor(System.String)|VFSException.VFSException(string).md|VFSException(string)
8283
M:Atypical.VirtualFileSystem.Core.Exceptions.VFSException.#ctor(System.String,System.Exception)|VFSException.VFSException(string,Exception).md|VFSException(string, Exception)
84+
M:Atypical.VirtualFileSystem.Core.Exceptions.VFSException.#ctor(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization.StreamingContext)|VFSException.VFSException(SerializationInfo,StreamingContext).md|VFSException(SerializationInfo, StreamingContext)
8385
N:Atypical.VirtualFileSystem.Core.Exceptions|VirtualFileSystem.md#Atypical.VirtualFileSystem.Core.Exceptions|Atypical.VirtualFileSystem.Core.Exceptions
8486
T:Atypical.VirtualFileSystem.Core.Exceptions.VFSException|VFSException.md|VFSException
8587
P:Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode.Directories|IDirectoryNode.Directories.md|Directories

src/Atypical.VirtualFileSystem.Core/Exceptions/VFSException.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@
44
// This source code is licensed under the BSD-style license found in the
55
// LICENSE file in the root directory of this source tree.
66

7+
using System.Runtime.Serialization;
8+
79
namespace Atypical.VirtualFileSystem.Core.Exceptions;
810

911
/// <summary>
1012
/// Exception thrown by the VFS.
1113
/// </summary>
14+
[Serializable]
1215
public class VFSException : Exception
1316
{
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="VFSException"/> class.
19+
/// </summary>
20+
public VFSException()
21+
{
22+
}
23+
1424
/// <summary>
1525
/// Initializes a new instance of the <see cref="VFSException"/> class with a message that describes the error.
1626
/// </summary>
@@ -33,4 +43,16 @@ public VFSException(string message, Exception innerException)
3343
: base(message, innerException)
3444
{
3545
}
36-
}
46+
47+
/// <summary>
48+
/// Initializes a new instance of the <see cref="VFSException"/> class with a specified error message and a reference to the
49+
/// inner exception that is the cause of this exception.
50+
/// </summary>
51+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
52+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
53+
protected VFSException(SerializationInfo info, StreamingContext context)
54+
: base(info, context)
55+
{
56+
}
57+
}
58+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
namespace VirtualFileSystem.UnitTests.Exceptions;
2+
3+
public class VFSExceptionTests
4+
{
5+
public class Constructor
6+
{
7+
[Fact]
8+
public void Constructor_Creates_VFSException_With_Message()
9+
{
10+
// Arrange
11+
const string message = "Test message.";
12+
13+
// Act
14+
var exception = new VFSException(message);
15+
16+
// Assert
17+
exception.Message.Should().Be(message);
18+
}
19+
20+
[Fact]
21+
public void Constructor_Creates_VFSException_With_Message_And_InnerException()
22+
{
23+
// Arrange
24+
const string message = "Test message.";
25+
var innerException = new InvalidOperationException("Inner exception message.");
26+
27+
// Act
28+
var exception = new VFSException(message, innerException);
29+
30+
// Assert
31+
exception.Message.Should().Be(message);
32+
exception.InnerException.Should().Be(innerException);
33+
}
34+
35+
[Fact]
36+
public void Constructor_Creates_VFSException_With_InnerException()
37+
{
38+
// Arrange
39+
var innerException = new InvalidOperationException("Inner exception message.");
40+
41+
// Act
42+
var exception = new VFSException(null!, innerException);
43+
44+
// Assert
45+
exception.InnerException.Should().Be(innerException);
46+
}
47+
48+
[Fact]
49+
public void Constructor_Creates_VFSException_Without_Arguments()
50+
{
51+
// Act
52+
var exception = new VFSException();
53+
54+
// Assert
55+
exception.Message.Should().NotBeNull();
56+
exception.InnerException.Should().BeNull();
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)