-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ODS-5070 - Handle TargetInvocationException so correct validation res…
…ults gets returned from api (#394)
- Loading branch information
1 parent
763cdaa
commit 97e438b
Showing
2 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
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
49 changes: 49 additions & 0 deletions
49
Application/EdFi.Ods.Tests/EdFi.Ods.Common/Extensions/ValidationExtensionsTests.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,49 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
using System; | ||
using System.Linq; | ||
using EdFi.Ods.Api.Validation; | ||
using EdFi.Ods.Common; | ||
using EdFi.Ods.Common.Attributes; | ||
using EdFi.Ods.Common.Extensions; | ||
using EdFi.Ods.Common.Validation; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
|
||
namespace EdFi.Ods.Tests.EdFi.Ods.Common.Extensions | ||
{ | ||
public class ValidationExtensionsTests | ||
{ | ||
[TestFixture] | ||
public class When_class_with_required_non_default_throws_exception_during_validation | ||
{ | ||
[Test] | ||
public void Should_still_capture_validation_message() | ||
{ | ||
var testClass = new ClassThatWillThrowValidationException { Value = "NewValueHere" }; | ||
|
||
var validators = new IEntityValidator[] { new DataAnnotationsEntityValidator() }; | ||
var results = validators.ValidateObject(testClass); | ||
|
||
results.IsValid().ShouldBe(false); | ||
results.Count.ShouldBe(1); | ||
results.First().ErrorMessage.ShouldBe("Test validation failure message."); | ||
} | ||
} | ||
} | ||
|
||
class ClassThatWillThrowValidationException | ||
{ | ||
private string _value; | ||
|
||
[RequiredWithNonDefault] | ||
public string Value | ||
{ | ||
get => throw new Exception("Test validation failure message."); | ||
set => _value = value; | ||
} | ||
} | ||
} |