-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrote tests that reported on potentially null dereferences.
- Loading branch information
Showing
18 changed files
with
247 additions
and
282 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
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
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
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
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,93 @@ | ||
namespace Identifiers.Id_specs; | ||
|
||
public class Create | ||
{ | ||
[Test] | ||
public void string_from_null_is_empty() | ||
=> StringId.Create(null).Should().Be(StringId.Empty); | ||
|
||
[Test] | ||
public void Guid_from_null_is_empty() | ||
=> CustomGuid.Create(null).Should().Be(CustomGuid.Empty); | ||
[Test] | ||
public void long_from_null_is_empty() | ||
=> Int64Id.Create(null).Should().Be(Int64Id.Empty); | ||
} | ||
|
||
public class Casts_from | ||
{ | ||
[Test] | ||
public void GUID_to_GUID_based_id() | ||
{ | ||
var guid = Guid.Parse("AD38ECD4-020F-475C-9318-DFF2067DA1D4"); | ||
var casted = (CustomGuid)guid; | ||
casted.Should().Be(CustomGuid.Parse("AD38ECD4-020F-475C-9318-DFF2067DA1D4")); | ||
} | ||
|
||
[Test] | ||
public void GUID_to_string_based_id() | ||
{ | ||
var guid = Guid.Parse("ad38ecd4-020f-475c-9318-dff2067da1d4"); | ||
var casted = (StringId)guid; | ||
casted.Should().Be(StringId.Parse("ad38ecd4-020f-475c-9318-dff2067da1d4")); | ||
} | ||
|
||
[Test] | ||
public void long_to_long_based_id() | ||
{ | ||
var id = 12345L; | ||
var casted = (Int64Id)id; | ||
casted.Should().Be(Int64Id.Create(12345L)); | ||
} | ||
|
||
[Test] | ||
public void long_to_string_based_id() | ||
{ | ||
var id = 12345L; | ||
var casted = (StringId)id; | ||
casted.Should().Be(StringId.Parse("12345")); | ||
} | ||
|
||
[Test] | ||
public void string_to_long_based_id() | ||
{ | ||
var id = "12345"; | ||
var casted = (Int64Id)id; | ||
casted.Should().Be(Int64Id.Create(12345L)); | ||
} | ||
} | ||
|
||
public class Can_not_cast_from | ||
{ | ||
[Test] | ||
public void invalid_string_for_long() | ||
=> "NaN".Invoking(Int64Id.Create) | ||
.Should().Throw<InvalidCastException>() | ||
.WithMessage("Cast from string to Qowaiv.Identifiers.Id<Qowaiv.TestTools.ForInt64> is not valid."); | ||
|
||
[Test] | ||
public void non_numeric_string_to_long() | ||
=> "ABC".Invoking(id => (Int64Id)id) | ||
.Should().Throw<InvalidCastException>(); | ||
|
||
[Test] | ||
public void GUID_to_long() | ||
=> Guid.NewGuid().Invoking(id => (Int64Id)id) | ||
.Should().Throw<InvalidCastException>(); | ||
|
||
[Test] | ||
public void non_GUID_string_to_GUID() | ||
=> "ABC".Invoking(id => (CustomGuid)id) | ||
.Should().Throw<InvalidCastException>(); | ||
|
||
[Test] | ||
public void long_to_GUID() | ||
=> ((object)123546L).Invoking(id => (CustomGuid)id) | ||
.Should().Throw<InvalidCastException>(); | ||
|
||
[Test] | ||
public void invalid_JSON_input() | ||
=> (-1L).Invoking(Int64Id.FromJson) | ||
.Should().Throw<InvalidCastException>(); | ||
} | ||
|
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
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
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
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
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
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,87 @@ | ||
using Qowaiv.Threading; | ||
using System.Threading; | ||
|
||
namespace Threading.Thread_domain_specs; | ||
|
||
public class Gets | ||
{ | ||
[Test] | ||
public void Country_based_on_current_culture() | ||
{ | ||
using (TestCultures.pt_PT.Scoped()) | ||
{ | ||
ThreadDomain.Current.Get<Country>().Should().Be(Country.PT); | ||
} | ||
} | ||
|
||
[Test] | ||
public void default_value_for_type_without_registered_factory() | ||
=> ThreadDomain.Current.Get<InternationalBankAccountNumber>() | ||
.Should().Be(default); | ||
|
||
[Test] | ||
public void value_that_has_been_set_for_the_current_thread() | ||
{ | ||
ThreadDomain.Current.Set(Currency.ALL); | ||
|
||
ThreadDomain.Current.Get<Currency>() | ||
.Should().Be(Currency.ALL); | ||
} | ||
|
||
[Test] | ||
public void value_only_for_current_thread() | ||
{ | ||
ThreadDomain.Current.Set(3.1418.Percent()); | ||
|
||
Task.Factory.StartNew | ||
( | ||
() => ThreadDomain.Current.Get<Percentage>().Should().Be(0.Percent(), because: "Retrieved in another thread.") | ||
); | ||
|
||
ThreadDomain.Current.Get<Percentage>().Should().Be(3.1418.Percent(), because: "This thread has a set value."); | ||
} | ||
|
||
[Test] | ||
public void Gets_updated_value_when_overwritten() | ||
{ | ||
using (TestCultures.nl_BE.Scoped()) | ||
{ | ||
Thread.CurrentThread.GetValue<Country>().Should().Be(Country.BE, because: "Default for current thread."); | ||
Thread.CurrentThread.SetValue(Country.PT); | ||
Thread.CurrentThread.GetValue<Country>().Should().Be(Country.PT, because: "Default has been overwritten."); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Gets_default_value_when_reset() | ||
{ | ||
using (TestCultures.nl_BE.Scoped()) | ||
{ | ||
Thread.CurrentThread.SetValue(Country.PT); | ||
Thread.CurrentThread.GetValue<Country>().Should().Be(Country.PT, because: "Default has been overwritten."); | ||
Thread.CurrentThread.RemoveValue(typeof(Country)); | ||
Thread.CurrentThread.GetValue<Country>().Should().Be(Country.BE, because: "Default for current thread."); | ||
} | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() => ThreadDomain.Current.Clear(); | ||
} | ||
|
||
public class Does_not_support | ||
{ | ||
[Test] | ||
public void Getting_a_nulable_value() | ||
=> ThreadDomain.Current.Invoking(c => c.Get<decimal?>()) | ||
.Should().Throw<NotSupportedException>() | ||
.WithMessage("Type must be a none generic type."); | ||
|
||
[Test] | ||
public void Getting_an_type_without_a_string_converter() | ||
=> ThreadDomain.Current.Invoking(c => c.Get<object>()) | ||
.Should().Throw<NotSupportedException>() | ||
.WithMessage("Converter can not convert from System.String."); | ||
|
||
[TearDown] | ||
public void TearDown() => ThreadDomain.Current.Clear(); | ||
} |
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
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
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
Oops, something went wrong.