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

Dot net standard #257

Open
wants to merge 194 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 182 commits
Commits
Show all changes
194 commits
Select commit Hold shift + click to select a range
bbfaa83
95878, install Orleans 2.3.3 (latest stable)
chirlin-sap May 16, 2019
fdbf30a
95878, small advance with Legacy abstraction: Core.Legacy, Runtime.Le…
chirlin-sap May 17, 2019
bc45ab9
95878, solving DI issues
chirlin-sap May 17, 2019
daa6ac6
change ServiceLifetime.Scoped to be InTransientScope
May 17, 2019
85c6cee
temp code for binding (IKeyedService<,> to multiple impl…
May 17, 2019
9256e2d
95878, bring it up so far without interceptor
chirlin-sap May 19, 2019
2a5b215
start refactor unwrap legacy to builder
May 19, 2019
308b56e
refactor temp code
May 19, 2019
fa043d5
add Install-Package Microsoft.Orleans.OrleansCodeGenerator.Build to f…
May 19, 2019
272216f
Refactor to add silo initialization in configurable way
May 19, 2019
88217ca
Refactor add logger and start using orleance builder
May 20, 2019
1b564a6
refactor orelance builder
May 20, 2019
64ff56c
new orleans RequestContext
May 20, 2019
a488a57
add Copyright
May 20, 2019
0d6aa8d
95878, CurrentApplicationInfo refactor remove static
chirlin-sap May 20, 2019
81c04f4
Merge branch 'us/95878.infra.orleans.2_20.5' of https://github.com/gi…
chirlin-sap May 20, 2019
547f4e3
start fixing test
May 20, 2019
5f33279
fix test remove app domain
May 20, 2019
387d4f9
95878, fix event related tests and config verification tests
chirlin-sap May 20, 2019
3758381
95878, merge from remote
chirlin-sap May 20, 2019
94ab97e
95878, fix tests code
chirlin-sap May 20, 2019
7f7b6c7
Refactor tests
May 20, 2019
babe76c
fix test
May 21, 2019
da7701c
95878, refactor publishing event, convert to factory
chirlin-sap May 21, 2019
fca752c
fix more test
May 21, 2019
d767829
95878, fix recompilation w/o changes
chirlin-sap May 21, 2019
fb9266a
fix silo stop
May 21, 2019
a237f33
fix tests
May 21, 2019
f877757
95878, fix refs after install
chirlin-sap May 21, 2019
da64e83
remove dead code from silohost and continue fixing the test
May 21, 2019
e968f3d
Merge branch 'us/95878.infra.orleans.2_20.5' of https://github.com/gi…
May 21, 2019
14741d6
95878, revert HostName to be static on CurrentApplicationInfo to redu…
chirlin-sap May 21, 2019
7f49da2
95878, uncomment the row, commented with lack of paket install
chirlin-sap May 21, 2019
6e59096
refactor host test
May 22, 2019
0c9fd62
refactor silo host
May 22, 2019
6ab0687
Service Tester Support allocatin a free port for test
May 22, 2019
9b37658
95878, change binding of OrleansLogAdapter w/o ILog
chirlin-sap May 22, 2019
9c0d729
Fix local silo and Grain client init for testsing
EranOfer May 26, 2019
0ad2262
95878, Support non-typed logger source
chirlin-sap May 26, 2019
01f4b8c
fix drain test
EranOfer May 27, 2019
7f73833
Merge branch 'us/95878.infra.orleans.2_20.5' of https://github.com/gi…
EranOfer May 27, 2019
6d17daf
refactor silo builder to support zookeaper
EranOfer May 27, 2019
521fa92
fix silo ip in zookeaper
EranOfer May 27, 2019
c6a2afb
fix interseptor
EranOfer May 27, 2019
e8776b8
make inteseptor configrable
EranOfer May 27, 2019
d2f897c
consume orleanse metrics via mtrics.net
May 28, 2019
a6c9912
95878, better error handling, bring the silo start exception towards …
chirlin-sap May 29, 2019
938b508
95878, avoid static context in decrypt funcs
chirlin-sap May 30, 2019
1c73e3f
95878, ServiceTest improve error handling, avoid templating of Servic…
chirlin-sap May 30, 2019
9039c7a
95878, Remove non-needed Orleans references from Tests Shared library…
chirlin-sap May 30, 2019
79e86f6
95878, fix initialization of ConfigDecrytor
chirlin-sap May 30, 2019
46cdb84
95878, add parallel running of tests on TestFixture level
chirlin-sap May 30, 2019
4bbf3e0
Revert "95878, add parallel running of tests on TestFixture level"
chirlin-sap May 30, 2019
0d994b0
95878, Improve crash handler own error handling
chirlin-sap Jun 3, 2019
eb67c73
95878, Fix binding to be Bind() call instead of Rebind(), add singlet…
chirlin-sap Jun 3, 2019
45a5d8b
95878, solve an issue of duplicate logs and statistics logged into co…
chirlin-sap Jun 3, 2019
6321791
add alert on duplicate tags
Jun 10, 2019
6632e38
add intrface to interSeptor, fix convension parameter name
Jun 10, 2019
a48126d
CurrentApplicationInfo is now bound into Kernel, to prevent possible …
Jun 10, 2019
1ae063e
Ignore Orleans helper .sql scaffloding
Jun 10, 2019
9fc91ea
Code review, comment, add error handling
Jun 10, 2019
7aabc3a
move appInfo init to the top
Jun 10, 2019
7bdee8a
remvoe current app info from microdotInitalzer
Jun 10, 2019
04d4bd8
add one more constractor to httpServiceRequest
Jun 11, 2019
819ce74
95878, incapsulate internal fields
chirlin-sap Jun 12, 2019
b250a43
change solution Version
Jun 12, 2019
7ac6ae0
Merge branch 'us/95878.infra.orleans.2_20.5' of https://github.com/gi…
Jun 12, 2019
417a127
95878, initialize secondary node, while taking explicitly service arg…
chirlin-sap Jun 12, 2019
05e3df2
Merge branch 'us/95878.infra.orleans.2_20.5' of https://github.com/gi…
chirlin-sap Jun 12, 2019
a28777e
95878, Add Orleans Dashboard
chirlin-sap Jun 12, 2019
515c879
95878, optimize gauge creation on non existing metric
chirlin-sap Jun 12, 2019
047714c
try to simplfy servcie provider
Jun 13, 2019
9aac291
implimant scop from Microsoft.Framework.DependencyInjection.Ninject
Jun 13, 2019
afc78f8
Merge branch 'us/95878.infra.orleans.2_20.5' into us/95878.infra.orle…
Jun 13, 2019
b578e33
make fake to crashHandler
Jun 13, 2019
647b568
use ninject Parallelizable by defualt
Jun 13, 2019
479c721
Enrichment Orleans log by map eventId to name (Heuristic )
Jun 16, 2019
7ec38c2
95878, Reconfigure the dashboard to discover grain types from Current…
chirlin-sap Jun 17, 2019
327b8b3
95878, ServiceHost Name refactor, [BREAKING]
chirlin-sap Jun 17, 2019
1289adb
95878, stabilize metrics tests
chirlin-sap Jun 17, 2019
9a8b10c
fix MetricsStatisticsConsumer
Jun 17, 2019
a244eca
reduce warnup errors
Jun 20, 2019
f28c73c
Move all Environment GetEnvironmentVariable to the EnvironmentVariabl…
Jun 20, 2019
6843352
Refactor delete dead code extra
Jun 20, 2019
365606c
Remove update message on create
Jun 20, 2019
6f7cef3
95878, Refactor tracing context
Jun 24, 2019
f3f586d
95878, Fix tracing context broken tests
chirlin-sap Jun 24, 2019
2dc72db
fix validate on request TracingData and request Overrides
Jun 24, 2019
2da19a5
fix test
Jun 24, 2019
e528d34
service tester use kernel
Jun 24, 2019
decd5bc
create new test for server event
Jun 25, 2019
8317fd8
fix test
Jun 25, 2019
fa62510
95878, close handled issued
chirlin-sap Jun 25, 2019
f559fe7
95878, Remove BeforeOrleansShutdown (as not supported)
chirlin-sap Jun 25, 2019
30be262
95878, add enhanced infra for custom serialization
chirlin-sap Jun 25, 2019
4148006
Merge branch 'us/95878.infra.orleans.2_20.5' of https://github.com/gi…
chirlin-sap Jun 25, 2019
b1f4535
fix log per string
Jun 25, 2019
494141b
fix startup task
Jun 26, 2019
d818152
95878, fix broken initialization of Configuration Verification Mode
chirlin-sap Jul 1, 2019
feef958
95878, De-comment tests related to exception serialization was commen…
chirlin-sap Jul 2, 2019
6ad0ea7
fix small bug
Jul 2, 2019
75009cf
init time is now 180 sec by default (edited)
Jul 3, 2019
0d1899a
95878, handle registration of custom serializer in ServiceTester
chirlin-sap Jul 3, 2019
b28844b
95878, Add Dashboard toggle
chirlin-sap Jul 8, 2019
a1cecb3
95878, Fix Dashboard config initialization
chirlin-sap Jul 9, 2019
611bf86
fix dead lock with ninject and microsoft log abstrction
Jul 9, 2019
8843a85
refactor
Jul 10, 2019
cb44983
Log grainReq events at certain percentage
Jul 14, 2019
a7b75c8
MicrodotIncomingGrainCallFilter is not trying to extarct the grain id…
Jul 15, 2019
ac72a19
Grain call filter is recourd the type of the garin instead of the int…
Jul 15, 2019
51b5051
98981, catch unhandled exception
chirlin-sap Jul 22, 2019
bd1b94a
95878, convert TracingContext to static
chirlin-sap Jul 22, 2019
18d9440
95878, merge with remove
chirlin-sap Jul 22, 2019
66f482d
95878, merge with remote
chirlin-sap Jul 22, 2019
bf54328
98981, config verification unhandled exception merge
chirlin-sap Jul 22, 2019
48edecc
make the test more stable, service tester assinge unique prots
Jul 23, 2019
ae4bd92
95878, Reduce amount of fields dependent on EventSerializer population
chirlin-sap Jul 23, 2019
dfa3209
95878, improve port allocation in tests, avoid collision
chirlin-sap Jul 23, 2019
81f6e49
95878, disable request validator
chirlin-sap Jul 23, 2019
2ae31b1
stabilize tests
Jul 24, 2019
84c838d
95878, GrainAgeLimitInMins set validation of min value of 1.001 minute
chirlin-sap Jul 27, 2019
3f51260
95878, Enhance port allocation for tests
chirlin-sap Jul 27, 2019
dbe2922
Merge branch 'develop' into us/95878.infra.orleans.2_20.5
Jul 29, 2019
cdcfa78
95878, fix parent span Id.
chirlin-sap Jul 30, 2019
bc898c3
Merge branch 'us/95878.infra.orleans.2_20.5' of https://github.com/gi…
chirlin-sap Jul 30, 2019
59d0cc9
remove MarshalByRefObject on reqest Timings
Jul 31, 2019
04d9c86
improve preformence not creating RequestTimings when not needed
Jul 31, 2019
e3300f8
95878, Update Orleans to 2.4.0
chirlin-sap Aug 12, 2019
6692ab2
95878, Fix IsEnabled on log adapter to avoid write always in debug level
chirlin-sap Aug 12, 2019
c8c0feb
95878, Run Paket Update, Align Orleans to 2.4
chirlin-sap Aug 12, 2019
57a5e2b
95878, Add Orleans log level configuration override per class (category)
chirlin-sap Aug 13, 2019
2a54600
95878, Add ignore of .nuget related for infra converyor script
chirlin-sap Aug 13, 2019
19c4ad2
95878, Improve performance of category lookup
chirlin-sap Aug 14, 2019
3ebf4aa
95878, Disable xml comment warning 1591 in entrire solution
chirlin-sap Aug 15, 2019
65b6c6e
fix crash test handler
Aug 15, 2019
51f2950
95878, Port allocation, check http instead of https
chirlin-sap Aug 15, 2019
dd2a132
95878, refactor ServiceTester to avoid expose of rarely used addition…
chirlin-sap Aug 19, 2019
c343d2a
95878, refactor and return Silo metrics publish and update tests
chirlin-sap Aug 20, 2019
0329b3c
95878, Add workaround to de/serialize HttpRequestException to ensure …
chirlin-sap Aug 20, 2019
7297163
update orleance to 2.4.1
Aug 26, 2019
2373c23
make sure Regex Timeout Initializer occur only once in the app domain
Aug 26, 2019
2c63282
fix bug event not wirrten in all RPC Format (#251)
Sep 2, 2019
c393476
serverReq event add support for json as a parameter (#252)
Sep 3, 2019
d7a555c
update orleans to 2.4.2
Sep 9, 2019
d9abc98
Moved to netstandard2.0: Gigya.ServiceContract and Gigya.Microdot.Sha…
Sep 10, 2019
6de67e0
Moved to netstandard2.0: Gigya.Microdot.ServiceProxy and Gigya.Microd…
Sep 10, 2019
eda2228
Moved to netcoreapp2.0/netstandard2.0 (all remaining projects except …
Sep 10, 2019
39a8750
Made samples project load correctly
Sep 10, 2019
430fd9c
Added missing nugets to CalculatorService.Orleans
Sep 10, 2019
2596d97
Removed delay in CalculatorService.Client
Sep 10, 2019
d9a5b3f
Allow WorkloadMetrics only on Windows
Sep 10, 2019
4f9e1c4
Allow WorkloadMetrics only on Windows - more places in code are now p…
Sep 10, 2019
0838aba
Moved Gigya.Microdot.Testing.Shared and Gigya.Microdot.Testing to net…
Sep 10, 2019
52caf76
Moved Gigya.Microdot.UnitTests and Gigya.Microdot.Common.Tests to net…
Sep 10, 2019
e24bc8f
Moved remaining tests projects to netcoreapp2.0
Sep 11, 2019
8f36d2e
Enabled tests to run - 1140 tests pass, 9 tests fail, 6 tests skipped
Sep 11, 2019
104b190
Fixed Ninject tests - (FuncModule was not loaded into the kernel)
Sep 11, 2019
07d5826
Use SolutionVersion.cs as Linked item in all relevant projects and av…
Sep 11, 2019
4494b34
Restored AssemblyInfo files
Sep 11, 2019
53b31c5
Fixed PublishClientCallEvent test
Sep 11, 2019
060a1f9
Gigya.ServiceContract nuget package changes
Sep 15, 2019
a3b9901
Merge from develop
Sep 15, 2019
6be011a
Generate nuget on build
Sep 15, 2019
f7c5d5c
Undo some changes to reduce diff compared to develop branch
Sep 15, 2019
62aaf09
Added DataAnnotationsValidatorRecursive and made it .net standard 2
Sep 15, 2019
2adbca8
Make all project dot net standard instead of dot net core
Sep 15, 2019
3a52726
Updated nuget version
Sep 15, 2019
12b43a3
Added support for polling config for changes
Sep 26, 2019
0de2628
Updated numget versions
Sep 26, 2019
7a1733c
fixed casing issues for loadpaths.json and for EnvVars placeholders i…
Sep 26, 2019
a24ebcb
updated nuget version
Sep 26, 2019
f875def
JSON_COMPATIBILITY_SHIM
Sep 26, 2019
8d71fd3
nuget
Sep 26, 2019
a697825
AdjustJsonToDotNetFramework - handle null or empty strings (and also …
Sep 27, 2019
305901f
nuget version
Sep 27, 2019
3dd6fbd
Fixed ObjectDisposedException during shutdown
Oct 3, 2019
2a71724
updated nugets version
Oct 3, 2019
bfd7f48
Fixed ObjectDisposedException in tests
Oct 7, 2019
cf49ab6
ignroe OrleansSerialization_HttpRequestException_IsEquivalent until f…
Oct 7, 2019
a6dab22
Use context.Response.Close instead of 'using' due to connection refus…
Oct 9, 2019
4e317e1
Added docker support for samples
Oct 8, 2019
b50d870
nugets
Oct 8, 2019
ca4cd92
Merge remote-tracking branch 'origin/develop' into getting_develop
Oct 24, 2019
13df9d3
updated nuget version
Oct 24, 2019
eca5499
Fixed test OneHostHasNetworkErrorShouldMoveToNextHost
Oct 24, 2019
2dc9137
Moved AdjustJsonToDotNetFramework to SharedLogic and start using it i…
Oct 24, 2019
71f4e86
Changed nuget version to 7.0.21-beta
Oct 31, 2019
0c40900
AdjustJsonToDotNetFramework - On error return original text
Nov 4, 2019
0a111d1
updated nugets to 7.0.23-beta
Nov 6, 2019
9bdc2b7
ServiceTester - Allocate disposeble port only if BasePortOverride is …
Nov 7, 2019
c24424c
Solved issue with ProcessorAffinity in OSX
Jan 27, 2020
f50e3cc
Fix logic to determine OSX
Jan 27, 2020
ff395c9
Fixed bug in ProcessorAffinityList
Jan 27, 2020
74d24af
Updated PackageVersion to 7.0.23-beta
Mar 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace DataAnnotationsValidator.Tests
{
public class Child : IValidatableObject
{
[Required(ErrorMessage = "Child Parent is required")]
public Parent Parent { get; set; }

[Required(ErrorMessage = "Child PropertyA is required")]
[Range(0, 10, ErrorMessage = "Child PropertyA not within range")]
public int? PropertyA { get; set; }

[Required(ErrorMessage = "Child PropertyB is required")]
[Range(0, 10, ErrorMessage = "Child PropertyB not within range")]
public int? PropertyB { get; set; }

public IEnumerable<GrandChild> GrandChildren { get; set; }

[SaveValidationContext]
public bool HasNoRealValidation { get; set; }

public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (PropertyA.HasValue && PropertyB.HasValue && (PropertyA + PropertyB > 10))
yield return new ValidationResult("Child PropertyA and PropertyB cannot add up to more than 10");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace DataAnnotationsValidator.Tests
{
public class ClassWithDictionary
{
public List<Dictionary<string, Child>> Objects { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace DataAnnotationsValidator.Tests
{
public class ClassWithNullableEnumeration
{
public List<Child> Objects { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DataAnnotationsValidator\DataAnnotationsValidator.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using NUnit.Framework;

namespace DataAnnotationsValidator.Tests
{
[TestFixture]
public class DataAnnotationsValidatorTests
{
private IDataAnnotationsValidator _validator;

[SetUp]
public void Setup()
{
SaveValidationContextAttribute.SavedContexts.Clear();
_validator = new DataAnnotationsValidator();
}

[Test]
public void TryValidateObject_on_valid_parent_returns_no_errors()
{
var parent = new Parent { PropertyA = 1, PropertyB = 1 };
var validationResults = new List<ValidationResult>();

var result = _validator.TryValidateObject(parent, validationResults);

Assert.IsTrue(result);
Assert.AreEqual(0, validationResults.Count);
}

[Test]
public void TryValidateObject_when_missing_required_properties_returns_errors()
{
var parent = new Parent { PropertyA = null, PropertyB = null };
var validationResults = new List<ValidationResult>();

var result = _validator.TryValidateObject(parent, validationResults);

Assert.IsFalse(result);
Assert.AreEqual(2, validationResults.Count);
Assert.AreEqual(1, validationResults.Count(x => x.ErrorMessage == "Parent PropertyA is required"));
Assert.AreEqual(1, validationResults.Count(x => x.ErrorMessage == "Parent PropertyB is required"));
}

[Test]
public void TryValidateObject_calls_IValidatableObject_method()
{
var parent = new Parent { PropertyA = 5, PropertyB = 6 };
var validationResults = new List<ValidationResult>();

var result = _validator.TryValidateObject(parent, validationResults);

Assert.IsFalse(result);
Assert.AreEqual(1, validationResults.Count);
Assert.AreEqual("Parent PropertyA and PropertyB cannot add up to more than 10", validationResults[0].ErrorMessage);
}

[Test]
public void TryValidateObjectRecursive_returns_errors_when_child_class_has_invalid_properties()
{
var parent = new Parent { PropertyA = 1, PropertyB = 1 };
parent.Child = new Child { Parent = parent, PropertyA = null, PropertyB = 5 };
var validationResults = new List<ValidationResult>();

var result = _validator.TryValidateObjectRecursive(parent, validationResults);

Assert.IsFalse(result);
Assert.AreEqual(1, validationResults.Count);
Assert.AreEqual("Child PropertyA is required", validationResults[0].ErrorMessage);
}

[Test]
public void TryValidateObjectRecursive_ignored_errors_when_child_class_has_SkipRecursiveValidationProperty()
{
var parent = new Parent { PropertyA = 1, PropertyB = 1 };
parent.Child = new Child { Parent = parent, PropertyA = 1, PropertyB = 1 };
parent.SkippedChild = new Child { PropertyA = null, PropertyB = 1 };
var validationResults = new List<ValidationResult>();

var result = _validator.TryValidateObjectRecursive(parent, validationResults);

Assert.IsTrue(result);
}

[Test]
public void TryValidateObjectRecursive_calls_IValidatableObject_method_on_child_class()
{
var parent = new Parent { PropertyA = 1, PropertyB = 1 };
parent.Child = new Child { Parent = parent, PropertyA = 5, PropertyB = 6 };
var validationResults = new List<ValidationResult>();

var result = _validator.TryValidateObjectRecursive(parent, validationResults);

Assert.IsFalse(result);
Assert.AreEqual(1, validationResults.Count);
Assert.AreEqual("Child PropertyA and PropertyB cannot add up to more than 10", validationResults[0].ErrorMessage);
}

[Test]
public void TryValidateObjectRecursive_returns_errors_when_grandchild_class_has_invalid_properties()
{
var parent = new Parent { PropertyA = 1, PropertyB = 1 };
parent.Child = new Child
{
Parent = parent,
PropertyA = 1,
PropertyB = 1,
GrandChildren = new[] {new GrandChild {PropertyA = 11, PropertyB = 11}}
};
var validationResults = new List<ValidationResult>();

var result = _validator.TryValidateObjectRecursive(parent, validationResults);

Assert.IsFalse(result);
Assert.AreEqual(2, validationResults.Count);
Assert.AreEqual(1, validationResults.Count(x => x.ErrorMessage == "GrandChild PropertyA not within range"));
Assert.AreEqual(1, validationResults.Count(x => x.ErrorMessage == "GrandChild PropertyB not within range"));
}

[Test]
public void TryValidateObjectRecursive_passes_validation_context_items_to_all_validation_calls()
{
var parent = new Parent {Child = new Child {GrandChildren = new[] {new GrandChild()}}};
var validationResults = new List<ValidationResult>();

var contextItems = new Dictionary<object, object> { { "key", 12345 } };

_validator.TryValidateObjectRecursive(parent, validationResults, contextItems);

Assert.AreEqual(3, SaveValidationContextAttribute.SavedContexts.Count, "Test expects 3 validated properties in the object graph to have a SaveValidationContextAttribute");
Assert.That(SaveValidationContextAttribute.SavedContexts.Select(c => c.Items).All(items => items["key"] == contextItems["key"]));
}

[Test]
public void TryValidateObject_calls_grandchild_IValidatableObject_method()
{
var parent = new Parent { PropertyA = 1, PropertyB = 1 };
parent.Child = new Child
{
Parent = parent,
PropertyA = 1,
PropertyB = 1,
GrandChildren = new[] {new GrandChild {PropertyA = 5, PropertyB = 6}}
};
var validationResults = new List<ValidationResult>();

var result = _validator.TryValidateObjectRecursive(parent, validationResults);

Assert.IsFalse(result);
Assert.AreEqual(1, validationResults.Count);
Assert.AreEqual(1, validationResults.Count(x => x.ErrorMessage == "GrandChild PropertyA and PropertyB cannot add up to more than 10"));
}

[Test]
public void TryValidateObject_includes_errors_from_all_objects()
{
var parent = new Parent { PropertyA = 5, PropertyB = 6 };
parent.Child = new Child
{
Parent = parent,
PropertyA = 5,
PropertyB = 6,
GrandChildren = new[] {new GrandChild {PropertyA = 5, PropertyB = 6}}
};
var validationResults = new List<ValidationResult>();

var result = _validator.TryValidateObjectRecursive(parent, validationResults);

Assert.IsFalse(result);
Assert.AreEqual(3, validationResults.Count);
Assert.AreEqual(1, validationResults.Count(x => x.ErrorMessage == "Parent PropertyA and PropertyB cannot add up to more than 10"));
Assert.AreEqual(1, validationResults.Count(x => x.ErrorMessage == "Child PropertyA and PropertyB cannot add up to more than 10"));
Assert.AreEqual(1, validationResults.Count(x => x.ErrorMessage == "GrandChild PropertyA and PropertyB cannot add up to more than 10"));
}

[Test]
public void TryValidateObject_modifies_membernames_for_nested_properties()
{
var parent = new Parent { PropertyA = 1, PropertyB = 1 };
parent.Child = new Child { Parent = parent, PropertyA = null, PropertyB = 5 };
var validationResults = new List<ValidationResult>();

var result = _validator.TryValidateObjectRecursive(parent, validationResults);

Assert.IsFalse(result);
Assert.AreEqual(1, validationResults.Count);
Assert.AreEqual("Child PropertyA is required", validationResults[0].ErrorMessage);
Assert.AreEqual("Child.PropertyA", validationResults[0].MemberNames.First());
}

[Test]
public void TryValidateObject_object_with_dictionary_does_not_fail()
{
var parent = new Parent { PropertyA = 1, PropertyB = 1 };
var classWithDictionary = new ClassWithDictionary
{
Objects = new List<Dictionary<string, Child>>
{
new Dictionary<string, Child>
{
{ "key",
new Child
{
Parent = parent,
PropertyA = 1,
PropertyB = 2
}
}
}
}
};
var validationResults = new List<ValidationResult>();

var result = _validator.TryValidateObjectRecursive(classWithDictionary, validationResults);

Assert.IsTrue(result);
Assert.IsEmpty(validationResults);
}

[Test]
public void TryValidateObject_object_with_null_enumeration_values_does_not_fail()
{
var parent = new Parent { PropertyA = 1, PropertyB = 1 };
var classWithNullableEnumeration = new ClassWithNullableEnumeration
{
Objects = new List<Child>
{
null,
new Child
{
Parent = parent,
PropertyA = 1,
PropertyB = 2
}
}
};
var validationResults = new List<ValidationResult>();

var result = _validator.TryValidateObjectRecursive(classWithNullableEnumeration, validationResults);

Assert.IsTrue(result);
Assert.IsEmpty(validationResults);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace DataAnnotationsValidator.Tests
{
public class GrandChild : IValidatableObject
{
[Required]
[Range(0, 10, ErrorMessage = "GrandChild PropertyA not within range")]
public int? PropertyA { get; set; }

[Required]
[Range(0, 10, ErrorMessage = "GrandChild PropertyB not within range")]
public int? PropertyB { get; set; }

[SaveValidationContext]
public bool HasNoRealValidation { get; set; }

public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (PropertyA.HasValue && PropertyB.HasValue && (PropertyA + PropertyB > 10))
yield return new ValidationResult("GrandChild PropertyA and PropertyB cannot add up to more than 10");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace DataAnnotationsValidator.Tests
{
public class Parent : IValidatableObject
{
[Required(ErrorMessage = "Parent PropertyA is required")]
[Range(0, 10, ErrorMessage = "Parent PropertyA not within range")]
public int? PropertyA { get; set; }

[Required(ErrorMessage = "Parent PropertyB is required")]
[Range(0, 10, ErrorMessage = "Parent PropertyB not within range")]
public int? PropertyB { get; set; }

public Child Child { get; set; }

[SkipRecursiveValidation]
public Child SkippedChild { get; set; }

[SaveValidationContext]
public bool HasNoRealValidation { get; set; }

IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
if (PropertyA.HasValue && PropertyB.HasValue && (PropertyA + PropertyB > 10))
yield return new ValidationResult("Parent PropertyA and PropertyB cannot add up to more than 10");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace DataAnnotationsValidator.Tests
{
public class SaveValidationContextAttribute: ValidationAttribute
{
public static IList<ValidationContext> SavedContexts = new List<ValidationContext>();

protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
SavedContexts.Add(validationContext);
return ValidationResult.Success;
}
}
}
Loading