Exemplo n.º 1
0
        public void DDDGet()
        {
            testAction.UseFind <Person>((data, parameters) =>
            {
                object firstElement = parameters[0];
                if (firstElement is System.Guid)
                {
                    Guid id = (System.Guid)firstElement;
                    return(data.Where(x => x.EntityId == id).FirstOrDefault());
                }
                else if (firstElement is int)
                {
                    int id = (int)firstElement;
                    return(data.Where(x => x.Id == id).FirstOrDefault());
                }
                else if (firstElement is string)
                {
                    string id = (string)firstElement;
                    return(data.Where(x => x.Name == id).FirstOrDefault());
                }
                else if (firstElement is long)
                {
                    long id = (long)firstElement;
                    return(data.Where(x => x.IdLong == id).FirstOrDefault());
                }
                return(null);
            });

            int    peopleNumber = 1;
            Person p1           = new Person();

            p1.GenerateNewIdentity();
            p1.Id     = 1;
            p1.IdLong = 2L;
            p1.Name   = "Name";
            fpr.Add(p1);

            Person p2 = fpr.GetById(p1.EntityId);

            Assert.IsNotNull(p2, "Person not found by Guid.");

            Person p3 = fpr.GetById(p1.Id);

            Assert.IsNotNull(p3, "Person not found by Id.");

            Person p4 = fpr.GetById(p1.Name);

            Assert.IsNotNull(p4, "Person not found by Name.");

            Person p5 = fpr.GetById(p1.IdLong);

            Assert.IsNotNull(p5, "Person not found by IdLong.");

            Person p6 = fpr.GetById(Guid.Empty);

            Assert.IsNull(p6, "Person must be null by empty Guid.");

            IEnumerable <Person> people = fpr.All();

            Assert.AreEqual(people.ToList().Count, peopleNumber, "People set does not mismatch.");
        }