In addition to @palacsint's advice, namely you should make the implicit dependencies of system under test explicit, I'll add a few more.
In my experience easiest way to make a business method that uses system time testable is to just pass the current time as a parameter. "Time" is not part of your domain after all. This refactoring is a form of Replace Static Variable with Parameter This will also save you the trouble of setting up a mock time provider service for test scenarios.
The following means
org.RelatedOrganizationUnit
is some kind of collectionif (org.RelatedOrganizationUnit != null) { foreach (... in org.RelatedOrganizationUnit)
Make it default to an empty list, and you would not need to check for nulls. Less if
s, less test cases needed.
Factor out the repeating chunks about related organizations and
EducationIndicator
out smaller units are easier to test.Duplication is bad in itself. The following two snippets look like they were copy/pasted; then an error was fixed, for just one copy.
// this should throw NullReferenceException if org.UserArea is null if (!org.UserArea.Equals(null)) if (org.UserArea != null)
I'll add a few more points when I've time...