GetEvents() public method

public GetEvents ( User user ) : IEnumerable
user User
return IEnumerable
Ejemplo n.º 1
0
        public void GetEventsTest()
        {
            FelBookDBEntities DBEntities = new FelBookDBEntities();
            EventService target = new EventService(DBEntities);

            User mockUser = User.CreateUser(0, "test", "test",
               DateTime.Now, "mail", "test user", "");
            DBEntities.UserSet.AddObject(mockUser);
            DBEntities.SaveChanges();

            IEnumerable<Event> actual = target.GetEvents(mockUser);
            Assert.AreEqual(0, actual.ToList().Count);

            DateTime from = DateTime.Now;
            DateTime to = DateTime.Now;
            string name = "Test event 1";
            string text = "Description of test event...";

            Event firstEvent = Event.CreateEvent(0, from, to, name, text);
            firstEvent.User = mockUser;
            DBEntities.EventSet.AddObject(firstEvent);
            DBEntities.SaveChanges();

            actual = target.GetEvents(mockUser);
            Assert.AreEqual(1, actual.ToList().Count);
            Assert.IsTrue(actual.ToList().Contains(firstEvent));

            Event secondEvent = Event.CreateEvent(0, from, to, name, text);
            secondEvent.User = mockUser;
            DBEntities.EventSet.AddObject(secondEvent);
            DBEntities.SaveChanges();

            actual = target.GetEvents(mockUser);
            Assert.AreEqual(2, actual.ToList().Count);
            Assert.IsTrue(actual.ToList().Contains(firstEvent));
            Assert.IsTrue(actual.ToList().Contains(secondEvent));

            DBEntities.EventSet.DeleteObject(secondEvent);
            DBEntities.EventSet.DeleteObject(firstEvent);
            DBEntities.UserSet.DeleteObject(mockUser);
            DBEntities.SaveChanges();
        }