public void OptionNoneTeste() { var person = new Person { Name = "Robb Stark" }; var optionperson = Option.From(person); var logradouro = optionperson .Map(p => p.Address) .Map(e => e.City) .GetOrElse("Não informado"); logradouro.Should().Be("Não informado"); }
public void OptionSomeTeste() { var person = new Person { Name = "Robb Stark", Address = new Address { City = "Winterfell" } }; var optionperson = Option.From(person); var logradouro = optionperson .Map(p => p.Address) .Map(e => e.City) .GetOrElse("Não informado"); logradouro.Should().Be("Winterfell"); }
public void WhereOperatorWithFalsePredicate() { var person = new Person { Name = "Robb Stark" }; var res = from p in person.ToOption() where p.Name == "Jon Snow" select p; res.Should().Be(Option.None); }
public void WhereOperatorWithTruePredicate() { var person = new Person { Name = "Robb Stark" }; var res = from p in person.ToOption() where p.Name == "Robb Stark" select p.Name; res.GetOrElse("").Should().Be("Robb Stark"); }
public void LinqSelectManyWithNull() { var person = new Person { Name = "Robb Stark" }; var res = (from p in Option.From(person) from e in p.Address.ToOption() select e.City).GetOrElse("Sem endereco"); res.Should().Be("Sem endereco"); }
public void LinqSelectMany() { var person = new Person { Name = "Robb Stark", Address = new Address { City = "Winterfell" } }; var res = from p in Option.From(person) from e in p.Address.ToOption() select e.City; res.Should().Be(Option.From("Winterfell")); }