コード例 #1
0
            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");
            }
コード例 #2
0
            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");
            }
コード例 #3
0
            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);
            }
コード例 #4
0
            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");
            }
コード例 #5
0
            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");
            }
コード例 #6
0
            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"));
            }