public void Maybe_should_throw_an_exception_while_trying_to_extract_value_from_nothing() { string value = null; var context = Maybe.ApplyTo(value); Assert.Throws <NoneException>(() => context.GetValue()); }
public void Maybe_should_lift_null_value_into_the_ctx() { string value = null; var context = Maybe.ApplyTo(value); Assert.That(context.HasValue(), Is.EqualTo(false)); }
public void Maybe_should_lift_not_null_value_into_the_ctx() { const string value = "some string"; var context = Maybe.ApplyTo(value); Assert.That(context.HasValue(), Is.EqualTo(true)); Assert.That(context.GetValue(), Is.EqualTo(value)); }
public void Maybe_should_get_primary_value_when_extracting_from_something() { const string defaultValue = "default value"; string value = "another value"; var context = Maybe.ApplyTo(value); Assert.That(context.HasValue(), Is.EqualTo(true)); Assert.That(context.GetValueOr(defaultValue), Is.EqualTo(value)); }
public void Maybe_should_fallback_to_default_value_when_extracting_data_from_nothing() { const string defaultValue = "default value"; string value = null; var context = Maybe.ApplyTo(value); Assert.That(context.HasValue(), Is.EqualTo(false)); Assert.Throws <NoneException>(() => context.GetValue()); Assert.That(context.GetValueOr(defaultValue), Is.EqualTo(defaultValue)); }
public void Maybe_should_be_representable_as_monadic_comprehension() { const string defaultString = "__defaultString"; const int defaultInteger = 42; var ctx = from a in Maybe.ApplyTo(defaultInteger) from b in Maybe.ApplyTo(defaultString) select new { Left = a, Right = b }; Assert.That(ctx.HasValue(), Is.EqualTo(true)); Assert.That(ctx.GetValue().Left, Is.EqualTo(defaultInteger)); Assert.That(ctx.GetValue().Right, Is.EqualTo(defaultString)); }