Exemple #1
0
 public void WhereExpressionMethodConstParameter()
 {
     using (new SoodaTransaction())
     {
         IEnumerable <ContactType> te = ContactType.Linq().Where(t => Contact.Linq().Where(c => c.Type == t).Any(GetNameEndsWith("er")));
         CollectionAssert.AreEquivalent(new ContactType[] { ContactType.Manager, ContactType.Customer }, te);
     }
 }
Exemple #2
0
 public void AnyFiltered()
 {
     using (new SoodaTransaction())
     {
         IEnumerable <ContactType> te = ContactType.Linq().Where(t => Contact.Linq().Any(c => c.Type == t && c.LastSalary.Value == 123));
         CollectionAssert.AreEquivalent(new ContactType[] { ContactType.Customer }, te);
     }
 }
Exemple #3
0
 public void WhereExpressionProperty()
 {
     using (new SoodaTransaction())
     {
         IEnumerable <ContactType> te = ContactType.Linq().Where(t => Contact.Linq().Where(SalaryIs345).Any(c => c.Type == t));
         CollectionAssert.AreEquivalent(new ContactType[] { ContactType.Employee }, te);
     }
 }
Exemple #4
0
 public void SingleOrDefaultFiltered()
 {
     using (new SoodaTransaction())
     {
         IEnumerable <ContactType> te = ContactType.Linq().Where(t => Contact.Linq().SingleOrDefault(c => c.Type == t && c.LastSalary.Value < 0) != null);
         CollectionAssert.AreEquivalent(new ContactType[] { ContactType.Customer }, te);
     }
 }
Exemple #5
0
 public void FirstOrDefault()
 {
     using (new SoodaTransaction())
     {
         IEnumerable <ContactType> te = ContactType.Linq().Where(t => Contact.Linq().Where(c => c.Type == t).Select(c => c.Name).FirstOrDefault().EndsWith("er"));
         CollectionAssert.AreEquivalent(new ContactType[] { ContactType.Manager, ContactType.Customer }, te);
     }
 }
Exemple #6
0
 public void OrderByGetLabelNone()
 {
     using (new SoodaTransaction())
     {
         IEnumerable <ContactType> ce = ContactType.Linq().OrderBy(t => t.GetLabel(false));
         CollectionAssert.AreEquivalent(ContactType.GetList(true), ce);
     }
 }
Exemple #7
0
 public void FirstOrDefaultFiltered()
 {
     using (new SoodaTransaction())
     {
         IEnumerable <ContactType> te = ContactType.Linq().Where(t => Contact.Linq().Where(c => c.Type == t).FirstOrDefault(c => c.Name.EndsWith("er")) == null);
         CollectionAssert.AreEquivalent(new ContactType[] { ContactType.Employee }, te);
     }
 }
Exemple #8
0
 public void SelectSum()
 {
     using (new SoodaTransaction())
     {
         IEnumerable <ContactType> te = ContactType.Linq().Where(t => Contact.Linq().Where(c => c.Type == t).Select(c => c.LastSalary.Value).Sum() == 234 + 345);
         CollectionAssert.AreEquivalent(new ContactType[] { ContactType.Employee }, te);
     }
 }
Exemple #9
0
 public void SumEmpty()
 {
     using (new SoodaTransaction())
     {
         IEnumerable <ContactType> te = ContactType.Linq().Where(t => Contact.Linq().Where(c => c.Type == t && c.ContactId > 1).Sum(c => c.LastSalary.Value) == 0);
         CollectionAssert.AreEquivalent(new ContactType[] { ContactType.Manager }, te);
     }
 }
Exemple #10
0
 public void SelectAverageIntFractional()
 {
     using (new SoodaTransaction())
     {
         IEnumerable <ContactType> te = ContactType.Linq().Where(t => Contact.Linq().Where(c => c.Type == t).Select(c => c.ContactId).Average() == 51.5);
         CollectionAssert.AreEquivalent(new ContactType[] { ContactType.Customer }, te);
     }
 }
Exemple #11
0
 public void Contains()
 {
     using (new SoodaTransaction())
     {
         IEnumerable <ContactType> te = ContactType.Linq().Where(t => Contact.Linq().Where(c => c.Type == t).Contains(Contact.Ed));
         CollectionAssert.AreEquivalent(new ContactType[] { ContactType.Employee }, te);
     }
 }
Exemple #12
0
 public void TypeIs()
 {
     using (new SoodaTransaction())
     {
         IEnumerable <ContactType> te = ContactType.Linq().Where(t => Contact.Linq().Any(c => TypeIs(c, t) && c.LastSalary.Value == 345));
         CollectionAssert.AreEquivalent(new ContactType[] { ContactType.Employee }, te);
     }
 }
Exemple #13
0
 public void All()
 {
     using (new SoodaTransaction())
     {
         IEnumerable <ContactType> te = ContactType.Linq().Where(t => Contact.Linq().Where(c => c.Type == t).All(c => c.LastSalary.Value > 100));
         CollectionAssert.AreEquivalent(new ContactType[] { ContactType.Manager, ContactType.Employee }, te);
     }
 }
Exemple #14
0
 public void CountFiltered()
 {
     using (new SoodaTransaction())
     {
         IEnumerable <ContactType> te = ContactType.Linq().Where(t => Contact.Linq().Count(c => c.Type == t) > 1);
         CollectionAssert.AreEquivalent(new ContactType[] { ContactType.Employee, ContactType.Customer }, te);
     }
 }
Exemple #15
0
 public void AnyUnion()
 {
     using (new SoodaTransaction())
     {
         var q1 = ContactType.Linq().Where(t => Contact.Linq().Any(c => c.Type == t && c.LastSalary.Value == 123));
         var q2 = ContactType.Linq().Where(t => Contact.Linq().Any(c => c.Type == t && c.LastSalary.Value == 345));
         IEnumerable <ContactType> te = q1.Union(q2);
         CollectionAssert.AreEquivalent(new ContactType[] { ContactType.Customer, ContactType.Employee }, te);
     }
 }
Exemple #16
0
 public void FirstOrDefaultNullableDecimal()
 {
     using (new SoodaTransaction())
     {
         IEnumerable <ContactType> te = ContactType.Linq().Where(t =>
                                                                 (from c in Contact.Linq()
                                                                  where c.Type == t && c.LastSalary.Value > 123
                                                                  select c.LastSalary).FirstOrDefault().IsNull);
         CollectionAssert.AreEquivalent(new ContactType[] { ContactType.Customer }, te);
     }
 }
Exemple #17
0
        public void LastOrDefaultFiltered()
        {
            using (new SoodaTransaction())
            {
                IEnumerable <Contact> ce =
                    from t in ContactType.Linq()
                    orderby t.Code
                    select Contact.Linq().OrderBy(c => c.LastSalary.Value).LastOrDefault(c => c.Type == t);

                CollectionAssert.AreEqual(new Contact[] { Contact.GetRef(52), Contact.Eva, Contact.Mary }, ce);
            }
        }
Exemple #18
0
        public void GetLabelNone()
        {
            using (new SoodaTransaction())
            {
                string[] sa = ContactType.Linq().Select(t => t.GetLabel(false)).ToArray();
                Assert.AreEqual(3, sa.Length);
                Assert.IsNull(sa[0]);
                Assert.IsNull(sa[1]);
                Assert.IsNull(sa[2]);

                int c = ContactType.Linq().Count(t => t.GetLabel(false) == null);
                Assert.AreEqual(3, c);
            }
        }
Exemple #19
0
        public void LastOrDefault()
        {
            using (new SoodaTransaction())
            {
                IEnumerable <string> se =
                    from t in ContactType.Linq()
                    orderby t.Code
                    select
                        (from c in Contact.Linq()
                        where c.Type == t
                        orderby c.LastSalary.Value
                        select c.Name).LastOrDefault();

                CollectionAssert.AreEqual(new string[] { "Chris Customer", "Eva Employee", "Mary Manager" }, se);
            }
        }
Exemple #20
0
 public void TopSalaries()
 {
     using (new SoodaTransaction())
     {
         var l =
             (from t in ContactType.Linq()
              orderby Contact.Linq().Where(c => c.Type == t).Max(c => c.LastSalary.Value) descending
              select new {
             ContactType = t.Code,
             TopSalary = Contact.Linq().Where(c => c.Type == t).Max(c => c.LastSalary.Value),
             MostPaid =
                 (from c in Contact.Linq()
                  where c.Type == t
                  orderby c.LastSalary.Value descending
                  select c.Name).FirstOrDefault()
         }).ToList();
         CollectionAssert.AreEqual(new string[] { "Employee", "Manager", "Customer" }, l.Select(o => o.ContactType));
         CollectionAssert.AreEqual(new decimal[] { 345M, 123.123456789M, 123M }, l.Select(o => o.TopSalary));
         CollectionAssert.AreEqual(new string[] { "Eva Employee", "Mary Manager", "Chris Customer" }, l.Select(o => o.MostPaid));
     }
 }