Example #1
0
        public void ByValueAsync_Queryable_CanDisallowNull()
        {
            var data = new[]
            {
                new EmailAddress {
                    Value = FakeData.Email(),
                },
                new EmailAddress {
                    Value = FakeData.Email(),
                },
                new EmailAddress {
                    Value = FakeData.Email(),
                },
            };
            var dbSet = new Mock <DbSet <EmailAddress> >(MockBehavior.Strict).SetupDataAsync(data.AsQueryable());

            dbSet.Object.AsQueryable().ByValueAsync(data[0].Value, false).Result.ShouldNotBeNull();

            var exception = Assert.Throws <InvalidOperationException>(() =>
                                                                      dbSet.Object.AsQueryable().ByValueAsync(FakeData.Email(), false).Result);

            Assert.NotNull(exception);
            exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture)
            .ShouldEqual(0);
        }
        public void ByVerifiedEmail_Enumerable_CanDisallowNull()
        {
            var data = new[]
            {
                new LocalMembership {
                    User = new User {
                        Name = FakeData.String()
                    },
                },
                new LocalMembership {
                    User = new User {
                        Name = FakeData.String()
                    },
                },
                new LocalMembership {
                    User = new User {
                        Name = FakeData.String()
                    },
                },
            };

            foreach (var localMembership in data)
            {
                for (var i = 0; i < 3; i++)
                {
                    var emailAddress = new EmailAddress
                    {
                        Value      = FakeData.Email(),
                        IsVerified = true,
                    };
                    localMembership.User.EmailAddresses.Add(emailAddress);
                }
            }
            var existingEmailValue = data[0].User.EmailAddresses.First().Value;

            data.AsEnumerable().ByVerifiedEmail(existingEmailValue, false).ShouldNotBeNull();

            var exception = Assert.Throws <InvalidOperationException>(() =>
                                                                      data.AsEnumerable().ByVerifiedEmail(FakeData.Email(), false));

            Assert.NotNull(exception);
            exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture)
            .ShouldEqual(0);
        }