-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new extension for cases where a required extension is missing ROB…
…O-4220 (#343) * Add new extension for cases where a required extension is missing ROBO-4220 In case of a missing required extensions we throw a ValidationException. Users might want to handle those cases explicitly and they would need to know the type of the missing extension. To achieve this, we added ExtensionRequiredException which inherits ValidationException and has a single property RequiredExtensionType. * Move custom activity to test class * Add test case for registered extensions * Make RequiredExtensionTypeNotFound an inner exception of ValidationException * Fix implementation of ISerializable * Simplify ISerializable implementation
- Loading branch information
1 parent
1b432f4
commit 1f2f884
Showing
3 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/Test/TestCases.Runtime/MissingRequiredExtensionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// This file is part of Core WF which is licensed under the MIT license. | ||
// See LICENSE file in the project root for full license information. | ||
|
||
using Shouldly; | ||
using System.Activities; | ||
using System.Activities.Statements; | ||
using System.Text; | ||
using Xunit; | ||
|
||
namespace TestCases.Runtime | ||
{ | ||
public class MissingRequiredExtensionTests | ||
{ | ||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void RunActivityWithRequiredExtension(bool registerExtension) | ||
{ | ||
var sequence = new Sequence | ||
{ | ||
Activities = { new ActivityWithRequiredExtension(registerExtension) } | ||
}; | ||
|
||
var exception = Record.Exception(new WorkflowApplication(sequence).Run); | ||
|
||
if (registerExtension) | ||
{ | ||
exception.ShouldBeNull(); | ||
} | ||
else | ||
{ | ||
exception.ShouldBeOfType<ValidationException>(); | ||
exception.InnerException.ShouldBeOfType<ExtensionRequiredException>(); | ||
var expectedName = typeof(StringBuilder).FullName; | ||
((ExtensionRequiredException)exception.InnerException).RequiredExtensionTypeFullName.ShouldBe(expectedName); | ||
} | ||
} | ||
|
||
private class ActivityWithRequiredExtension : NativeActivity | ||
{ | ||
private readonly bool _registerExtension; | ||
|
||
public ActivityWithRequiredExtension(bool registerExtension) | ||
{ | ||
_registerExtension = registerExtension; | ||
} | ||
|
||
protected override void CacheMetadata(NativeActivityMetadata metadata) | ||
{ | ||
metadata.RequireExtension<StringBuilder>(); | ||
if (_registerExtension) | ||
{ | ||
metadata.AddDefaultExtensionProvider(() => new StringBuilder()); | ||
} | ||
} | ||
|
||
protected override void Execute(NativeActivityContext context) | ||
{ | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// This file is part of Core WF which is licensed under the MIT license. | ||
// See LICENSE file in the project root for full license information. | ||
|
||
namespace System.Activities; | ||
|
||
[Serializable] | ||
public class ExtensionRequiredException : Exception | ||
{ | ||
private const string RequiredExtensionTypeName = "requiredExtensionType"; | ||
|
||
public string RequiredExtensionTypeFullName => Data[RequiredExtensionTypeName] as string; | ||
|
||
public ExtensionRequiredException(Type requiredType) | ||
: base() | ||
{ | ||
Data.Add(RequiredExtensionTypeName, requiredType.FullName); | ||
} | ||
|
||
public ExtensionRequiredException(Type requiredType, string message) | ||
: base(message) | ||
{ | ||
Data.Add(RequiredExtensionTypeName, requiredType.FullName); | ||
} | ||
|
||
public ExtensionRequiredException(Type requiredType, string message, Exception innerException) | ||
: base(message, innerException) | ||
{ | ||
Data.Add(RequiredExtensionTypeName, requiredType.FullName); | ||
} | ||
|
||
public ExtensionRequiredException(SerializationInfo info, StreamingContext context) | ||
: base(info, context) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters