Beispiel #1
0
        public void AddEventTest()
        {
            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();

            DateTime from = DateTime.Now;
            DateTime to = DateTime.Now;

            string name = "Test event";
            string text = "Description of test event...";

            target.AddEvent(mockUser, null, from, to, name, text);
            Event actual = DBEntities.EventSet.Single(e => e.Name == name);

            Assert.AreEqual(mockUser, actual.User);
            Assert.IsNull(actual.Group);
            Assert.AreEqual(from, actual.From);
            Assert.AreEqual(to, actual.To);
            Assert.AreEqual(name, actual.Name);
            Assert.AreEqual(text, actual.Text);

            DBEntities.EventSet.DeleteObject(actual);
            DBEntities.UserSet.DeleteObject(mockUser);
            DBEntities.SaveChanges();
        }
Beispiel #2
0
        public void FindByIdTest()
        {
            FelBookDBEntities DbEntities = new FelBookDBEntities();
            MessageService target = new MessageService(DbEntities);

            int ID = 0;
            Message expected = null;
            Message actual = target.FindById(ID);
            Assert.AreEqual(expected, actual);

            expected = new Message();
            User mockUser = User.CreateUser(0, "test", "test",
                DateTime.Now, "mail", "test user", "");

            expected.Recievers.Add(mockUser);
            expected.Sender = mockUser;
            expected.Text = "text";
            expected.Created = DateTime.Now;

            DbEntities.MessageSet.AddObject(expected);
            DbEntities.SaveChanges();
            ID = expected.Id;
            actual = target.FindById(ID);
            Assert.AreEqual(expected.Text, actual.Text);

            DbEntities.MessageSet.DeleteObject(expected);
            DbEntities.UserSet.DeleteObject(mockUser);
            DbEntities.SaveChanges();
        }
Beispiel #3
0
        public void AddSubGroupTest()
        {
            FelBookDBEntities DBEntities = new FelBookDBEntities();
            IWallService wallService = null;
            GroupService target = new GroupService(DBEntities, wallService);

            User user = User.CreateUser(0, "group", "creator", DateTime.Now,
                "mail", "groupCreator", "1234");
            DBEntities.UserSet.AddObject(user);

            Group parentGroup = Group.CreateGroup(0, "parentGroup", "parentGroupDescription");
            user.CreatedGroups.Add(parentGroup);
            user.AdminedGroups.Add(parentGroup);
            user.JoinedGroups.Add(parentGroup);
            DBEntities.GroupSet.AddObject(parentGroup);
            DBEntities.SaveChanges();

            Group childGroup = Group.CreateGroup(1, "childGroup", "childGroupDescription");
            target.AddSubGroup(user, parentGroup, childGroup);

            Assert.AreEqual(user, childGroup.Creator);
            Assert.IsTrue(childGroup.Administrators.Contains(user));
            Assert.IsTrue(childGroup.Users.Contains(user));

            Assert.IsTrue(user.AdminedGroups.Contains(childGroup));
            Assert.IsTrue(user.CreatedGroups.Contains(childGroup));
            Assert.IsTrue(user.JoinedGroups.Contains(childGroup));

            Assert.AreEqual(parentGroup, childGroup.Parent);
            Assert.IsTrue(parentGroup.Children.Contains(childGroup));

            DBEntities.GroupSet.DeleteObject(childGroup);
            DBEntities.GroupSet.DeleteObject(parentGroup);
            DBEntities.UserSet.DeleteObject(user);
            DBEntities.SaveChanges();
        }
Beispiel #4
0
        public void SignIn(string userName, bool createPersistentCookie)
        {
            if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");

            FelBookDBEntities db = new FelBookDBEntities();

            db.UserSet.Single(u => u.Username == userName).LastLogged = DateTime.Now;
            db.SaveChanges();

            FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
        }
        public void ValidateUserTest2()
        {
            FelBookDBEntities db = new FelBookDBEntities();
            IMembershipService MembershipService = new FelbookAccountMembershipService(db);
            bool result;

            // TODO - vytvoření uživatele "good user" s heslem "good passwod"
            // pokud existuje, tak je zálohován původní a nahrazen testovacím
            User user = User.CreateUser(0, "Ota", "Sandr",
                DateTime.Now, "mail", "good user", "");
            user.ChangePassword("good password");
            db.UserSet.AddObject(user);
            db.SaveChanges();

            result = MembershipService.ValidateUser("good user", "good password");
            Assert.IsTrue(result);

            result = MembershipService.ValidateUser("good user", "bad password");
            Assert.IsFalse(result);

            db.UserSet.DeleteObject(user);
            db.SaveChanges();

            // TODO - odstranění uživatele "good user" a vrácení původního, byl-li tam
            // TODO - pokud existuje uživatel "bad user", tak se vyjme z DB

            result = MembershipService.ValidateUser("bad user", "bad password");
            Assert.IsFalse(result);

            // TODO - pokud existoval předtím uživatel "bad user", tak ho tam vrať
        }
        public void CreateUserTest2()
        {
            FelBookDBEntities db = new FelBookDBEntities();
            IMembershipService MembershipService = new FelbookAccountMembershipService(db);
            MembershipCreateStatus result;

            // vytvoření duplicateUser
            User user = User.CreateUser(0, "Ota", "Sandr",
                DateTime.Now, "mail", "duplicateUser", "");
            user.ChangePassword("good password");
            db.UserSet.AddObject(user);
            db.SaveChanges();

            result = MembershipService.CreateUser("duplicateUser", "password", "*****@*****.**");
            Assert.AreEqual(MembershipCreateStatus.DuplicateUserName, result);

            // smazání duplicateUser
            db.UserSet.DeleteObject(user);
            db.SaveChanges();

            // zálohování normalUser

            result = MembershipService.CreateUser("normalUser", "password", "*****@*****.**");
            Assert.AreEqual(MembershipCreateStatus.Success, result);

            // smazání normalUser a případná obnova zálohy
            User user2 = db.UserSet.Single(u => u.Username == "normalUser");
            db.UserSet.DeleteObject(user2);
            db.SaveChanges();
        }
        public void CreateUserTest1()
        {
            FelBookDBEntities db = new FelBookDBEntities();
            IMembershipService MembershipService = new FelbookAccountMembershipService(db);

            #region usernameTests
            try
            {
                MembershipService.CreateUser(null, "some password", "some email");
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("Value cannot be null or empty." + Environment.NewLine + "Parameter name: userName", ex.Message);
            }

            try
            {
                MembershipService.CreateUser("", "some password", "some email");
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("Value cannot be null or empty." + Environment.NewLine + "Parameter name: userName", ex.Message);
            }
            #endregion

            #region passwordTests
            try
            {
                MembershipService.CreateUser("some username", null, "some email");
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("Value cannot be null or empty." + Environment.NewLine + "Parameter name: password", ex.Message);
            }

            try
            {
                MembershipService.CreateUser("some username", "", "some email");
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("Value cannot be null or empty." + Environment.NewLine + "Parameter name: password", ex.Message);
            }
            #endregion

            #region emailTests
            try
            {
                MembershipService.CreateUser("some username", "some password", null);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("Value cannot be null or empty." + Environment.NewLine + "Parameter name: email", ex.Message);
            }

            try
            {
                MembershipService.CreateUser("some username", "some password", "");
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("Value cannot be null or empty." + Environment.NewLine + "Parameter name: email", ex.Message);
            }
            #endregion

            try
            {
                MembershipService.CreateUser("some username", "some password", "some email");
                User user = db.UserSet.Single(u => u.Username == "some username");
                db.UserSet.DeleteObject(user);
                db.SaveChanges();
            }
            catch (ArgumentException)
            {
                Assert.Fail();
            }
        }
        public void ChangePasswordTest2()
        {
            FelBookDBEntities db = new FelBookDBEntities();
            IMembershipService MembershipService = new FelbookAccountMembershipService(db);
            bool result;

            // záloha badUser

            result = MembershipService.ChangePassword("badUser", "old password", "new password");
            Assert.IsFalse(result);

            // případné obnovení badUser

            // vytvoření someUser s goodPassword
            User user = User.CreateUser(0, "Ota", "Sandr",
                DateTime.Now, "mail", "someUser", "");
            user.ChangePassword("goodPassword");
            db.UserSet.AddObject(user);
            db.SaveChanges();

            result = MembershipService.ChangePassword("someUser", "bad password", "new password");
            Assert.IsFalse(result);

            result = MembershipService.ChangePassword("someUser", "goodPassword", "new password");
            Assert.IsTrue(result);

            // odstranění someUser
            db.UserSet.DeleteObject(user);
            db.SaveChanges();
        }
Beispiel #9
0
        public void FindByNameTest()
        {
            FelBookDBEntities DBEntities = new FelBookDBEntities();
            IWallService wallService = null;
            GroupService target = new GroupService(DBEntities, wallService);

            Group actual;
            try
            {
                actual = target.FindByName(null);
                Assert.Fail();
            }
            catch (InvalidOperationException)
            { }

            User user = User.CreateUser(0, "group", "creator", DateTime.Now,
                "mail", "groupCreator", "1234");
            DBEntities.UserSet.AddObject(user);

            Group expected = Group.CreateGroup(0, "newGroup", "groupDescription");
            user.CreatedGroups.Add(expected);
            user.AdminedGroups.Add(expected);
            user.JoinedGroups.Add(expected);
            DBEntities.GroupSet.AddObject(expected);
            DBEntities.SaveChanges();

            actual = target.FindByName(expected.Name);
            Assert.AreEqual(expected, actual);

            DBEntities.GroupSet.DeleteObject(expected);
            DBEntities.UserSet.DeleteObject(user);
            DBEntities.SaveChanges();
        }
Beispiel #10
0
        public void SendMessageToUsersTest()
        {
            FelBookDBEntities DbEntities = new FelBookDBEntities();
            MessageService target = new MessageService(DbEntities);

            User mockSender = User.CreateUser(0, "test", "test",
                DateTime.Now, "mail", "sender", "");
            DbEntities.UserSet.AddObject(mockSender);
            User mockReciever = User.CreateUser(0, "test", "test",
                DateTime.Now, "mail", "reciever", "");
            DbEntities.UserSet.AddObject(mockReciever);
            DbEntities.SaveChanges();

            ISet<User> recievers = new HashSet<User>();
            recievers.Add(mockReciever);
            Message prevMessage = null;
            string text = "some text";
            target.SendMessageToUsers(mockSender, recievers, prevMessage, text);

            Message message1 = DbEntities.MessageSet.Single(m => m.Sender.Username == mockSender.Username);
            Assert.AreEqual(mockSender, message1.Sender);
            Assert.IsTrue(message1.Recievers.Contains(mockReciever));
            Assert.AreEqual(text, message1.Text);
            Assert.IsNull(message1.ReplyTo);

            recievers = new HashSet<User>();
            recievers.Add(mockSender);
            prevMessage = message1;
            text = "some other text";
            target.SendMessageToUsers(mockReciever, recievers, prevMessage, text);

            Message message2 = DbEntities.MessageSet.Single(m => m.Sender.Username == mockReciever.Username);
            Assert.AreEqual(mockReciever, message2.Sender);
            Assert.IsTrue(message2.Recievers.Contains(mockSender));
            Assert.AreEqual(text, message2.Text);
            Assert.AreEqual(message1, message2.ReplyTo);

            DbEntities.MessageSet.DeleteObject(message2);
            DbEntities.MessageSet.DeleteObject(message1);
            DbEntities.UserSet.DeleteObject(mockReciever);
            DbEntities.UserSet.DeleteObject(mockSender);
            DbEntities.SaveChanges();
        }
Beispiel #11
0
        public void NumberOfUnreadMessagesTest()
        {
            FelBookDBEntities DbEntities = new FelBookDBEntities();
            MessageService target = new MessageService(DbEntities);

            User mockSender = User.CreateUser(0, "test", "test",
                DateTime.Now, "mail", "sender", "");
            DbEntities.UserSet.AddObject(mockSender);
            User mockReciever = User.CreateUser(0, "test", "test",
                DateTime.Now, "mail", "reciever", "");
            DbEntities.UserSet.AddObject(mockReciever);
            DbEntities.SaveChanges();

            Assert.AreEqual(target.NumberOfUnreadMessages(mockReciever), 0);

            Message msg1 = Message.CreateMessage(0, "Text", DateTime.Now);
            msg1.Sender = mockSender;
            msg1.Recievers.Add(mockReciever);
            DbEntities.MessageSet.AddObject(msg1);
            DbEntities.SaveChanges();

            Assert.AreEqual(target.NumberOfUnreadMessages(mockReciever), 1);

            Message msg2 = Message.CreateMessage(0, "Text", DateTime.Now);
            msg2.Sender = mockSender;
            msg2.Recievers.Add(mockReciever);
            DbEntities.MessageSet.AddObject(msg2);
            DbEntities.SaveChanges();

            Assert.AreEqual(target.NumberOfUnreadMessages(mockReciever), 2);

            msg2.Readers.Add(mockReciever);
            DbEntities.SaveChanges();
            Assert.AreEqual(target.NumberOfUnreadMessages(mockReciever), 1);

            msg1.Readers.Add(mockReciever);
            DbEntities.SaveChanges();
            Assert.AreEqual(target.NumberOfUnreadMessages(mockReciever), 0);

            msg1.Readers.Remove(mockReciever);
            msg2.Readers.Remove(mockReciever);
            DbEntities.SaveChanges();
            Assert.AreEqual(target.NumberOfUnreadMessages(mockReciever), 2);

            DbEntities.MessageSet.DeleteObject(msg1);
            DbEntities.MessageSet.DeleteObject(msg2);
            DbEntities.UserSet.DeleteObject(mockReciever);
            DbEntities.UserSet.DeleteObject(mockSender);
            DbEntities.SaveChanges();
        }
Beispiel #12
0
        public void AddTest()
        {
            FelBookDBEntities DBEntities = new FelBookDBEntities();
            IWallService wallService = null; // Snad ji zatím nepotřebuji
            GroupService target = new GroupService(DBEntities, wallService);

            User user = User.CreateUser(0, "group", "creator", DateTime.Now,
                "mail", "groupCreator", "1234");
            DBEntities.UserSet.AddObject(user);
            DBEntities.SaveChanges();

            Group group = Group.CreateGroup(0, "newGroup", "groupDescription");
            target.Add(user, group);

            Assert.IsTrue(DBEntities.GroupSet.ToList().Contains(group));
            Assert.AreEqual(user, group.Creator);
            Assert.IsTrue(group.Administrators.Contains(user));
            Assert.IsTrue(group.Users.Contains(user));

            Assert.IsTrue(user.AdminedGroups.Contains(group));
            Assert.IsTrue(user.CreatedGroups.Contains(group));
            Assert.IsTrue(user.JoinedGroups.Contains(group));

            DBEntities.GroupSet.DeleteObject(group);
            DBEntities.UserSet.DeleteObject(user);
            DBEntities.SaveChanges();
        }
Beispiel #13
0
        public void SearchGroupsTest()
        {
            FelBookDBEntities DBEntities = new FelBookDBEntities();
            IWallService wallService = null;
            GroupService target = new GroupService(DBEntities, wallService);

            User user = User.CreateUser(0, "group", "creator", DateTime.Now,
                "mail", "groupCreator", "1234");
            DBEntities.UserSet.AddObject(user);

            Group group1 = Group.CreateGroup(0, "foo", "description");
            user.CreatedGroups.Add(group1);
            user.AdminedGroups.Add(group1);
            user.JoinedGroups.Add(group1);
            DBEntities.GroupSet.AddObject(group1);

            Group group2 = Group.CreateGroup(0, "foo2", "description");
            user.CreatedGroups.Add(group2);
            user.AdminedGroups.Add(group2);
            user.JoinedGroups.Add(group2);
            DBEntities.GroupSet.AddObject(group2);

            Group group3 = Group.CreateGroup(0, "moo", "description");
            user.CreatedGroups.Add(group3);
            user.AdminedGroups.Add(group3);
            user.JoinedGroups.Add(group3);
            DBEntities.GroupSet.AddObject(group3);

            DBEntities.SaveChanges();

            List<Group> actual = target.SearchGroups("2").ToList();
            Assert.IsFalse(actual.Contains(group1));
            Assert.IsTrue(actual.Contains(group2));
            Assert.IsFalse(actual.Contains(group3));

            actual = target.SearchGroups("foo").ToList();
            Assert.IsTrue(actual.Contains(group1));
            Assert.IsTrue(actual.Contains(group2));
            Assert.IsFalse(actual.Contains(group3));

            actual = target.SearchGroups("moo").ToList();
            Assert.IsFalse(actual.Contains(group1));
            Assert.IsFalse(actual.Contains(group2));
            Assert.IsTrue(actual.Contains(group3));

            actual = target.SearchGroups("abcdef").ToList();
            Assert.IsFalse(actual.Contains(group1));
            Assert.IsFalse(actual.Contains(group2));
            Assert.IsFalse(actual.Contains(group3));

            actual = target.SearchGroups("oo").ToList();
            Assert.IsTrue(actual.Contains(group1));
            Assert.IsTrue(actual.Contains(group2));
            Assert.IsTrue(actual.Contains(group3));

            DBEntities.GroupSet.DeleteObject(group1);
            DBEntities.GroupSet.DeleteObject(group2);
            DBEntities.GroupSet.DeleteObject(group3);
            DBEntities.UserSet.DeleteObject(user);
            DBEntities.SaveChanges();
        }
Beispiel #14
0
        public void GetUsersTest()
        {
            FelBookDBEntities DBEntities = new FelBookDBEntities();
            IWallService wallService = null;
            GroupService target = new GroupService(DBEntities, wallService);

            User creator = User.CreateUser(0, "group", "creator", DateTime.Now,
                "mail", "groupCreator", "1234");
            DBEntities.UserSet.AddObject(creator);
            User member = User.CreateUser(0, "group", "member", DateTime.Now,
                "mail", "groupMember", "1234");
            DBEntities.UserSet.AddObject(member);

            Group group = Group.CreateGroup(0, "newGroup", "groupDescription");
            creator.CreatedGroups.Add(group);
            creator.AdminedGroups.Add(group);
            creator.JoinedGroups.Add(group);
            DBEntities.GroupSet.AddObject(group);
            DBEntities.SaveChanges();

            List<User> actual = target.GetUsers(group).ToList();
            Assert.AreEqual(1, actual.Count);
            Assert.IsTrue(actual.Contains(creator));
            Assert.IsFalse(actual.Contains(member));

            group.Users.Add(member);
            DBEntities.SaveChanges();

            actual = target.GetUsers(group).ToList();
            Assert.AreEqual(2, actual.Count);
            Assert.IsTrue(actual.Contains(creator));
            Assert.IsTrue(actual.Contains(member));

            group.Users.Remove(member);
            group.Users.Remove(creator);
            DBEntities.SaveChanges();

            actual = target.GetUsers(group).ToList();
            Assert.AreEqual(0, actual.Count);
            Assert.IsFalse(actual.Contains(creator));
            Assert.IsFalse(actual.Contains(member));

            DBEntities.GroupSet.DeleteObject(group);
            DBEntities.UserSet.DeleteObject(member);
            DBEntities.UserSet.DeleteObject(creator);
            DBEntities.SaveChanges();
        }
Beispiel #15
0
        public void FindEventByIdTest()
        {
            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);

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

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

            int id = expected.Id;

            Event actual = target.FindEventById(id);
            Assert.AreEqual(expected, actual);

            Assert.IsNull(target.FindEventById(-1));

            DBEntities.EventSet.DeleteObject(actual);
            DBEntities.UserSet.DeleteObject(mockUser);
            DBEntities.SaveChanges();
        }
Beispiel #16
0
        public void MarkMessageReadByTest()
        {
            FelBookDBEntities DbEntities = new FelBookDBEntities();
            MessageService target = new MessageService(DbEntities);

            User mockSender = User.CreateUser(0, "test", "test",
                DateTime.Now, "mail", "sender", "");
            DbEntities.UserSet.AddObject(mockSender);
            User mockReciever = User.CreateUser(0, "test", "test",
                DateTime.Now, "mail", "reciever", "");
            DbEntities.UserSet.AddObject(mockReciever);
            DbEntities.SaveChanges();

            Message msg1 = Message.CreateMessage(0, "Text", DateTime.Now);
            msg1.Sender = mockSender;
            msg1.Recievers.Add(mockReciever);
            DbEntities.MessageSet.AddObject(msg1);
            DbEntities.SaveChanges();

            Assert.IsFalse(mockReciever.ReadMessages.Contains(msg1));
            Assert.IsFalse(msg1.Readers.Contains(mockReciever));

            target.MarkMessageReadBy(msg1, mockReciever);

            Assert.IsTrue(mockReciever.ReadMessages.Contains(msg1));
            Assert.IsTrue(msg1.Readers.Contains(mockReciever));

            target.MarkMessageReadBy(msg1, mockReciever);

            Assert.IsTrue(mockReciever.ReadMessages.Contains(msg1));
            Assert.IsTrue(msg1.Readers.Contains(mockReciever));

            DbEntities.MessageSet.DeleteObject(msg1);
            DbEntities.UserSet.DeleteObject(mockReciever);
            DbEntities.UserSet.DeleteObject(mockSender);
            DbEntities.SaveChanges();
        }
Beispiel #17
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();
        }
Beispiel #18
0
        public static void Insert()
        {
            #region Insert test data

            FelBookDBEntities db = new FelBookDBEntities();

            #region Vymazání všech tabulek a resetování ID

            //vymazání tabulek které spojují
            db.ExecuteStoreCommand("DELETE FROM StatusInformationFiles");
            db.ExecuteStoreCommand("DELETE FROM StatusInformationImages");
            db.ExecuteStoreCommand("DELETE FROM StatusInformationLinks");
            db.ExecuteStoreCommand("DELETE FROM Followings");
            db.ExecuteStoreCommand("DELETE FROM GroupAdministration");
            db.ExecuteStoreCommand("DELETE FROM MessageRecievers");
            db.ExecuteStoreCommand("DELETE FROM MessageReaders");
            db.ExecuteStoreCommand("DELETE FROM UserGroupMembership");
            db.ExecuteStoreCommand("DELETE FROM WallItemSet");

            //vymazání tabulek které obsahují informace
            db.ExecuteStoreCommand("DELETE FROM ImageSet");
            db.ExecuteStoreCommand("DELETE FROM FileSet");
            db.ExecuteStoreCommand("DELETE FROM LinkSet");
            db.ExecuteStoreCommand("DELETE FROM CommentSet");
            db.ExecuteStoreCommand("DELETE FROM StatusSet");
            db.ExecuteStoreCommand("DELETE FROM MessageSet");
            db.ExecuteStoreCommand("DELETE FROM GroupSet");
            db.ExecuteStoreCommand("DELETE FROM UserSet");

            //resetování ID -> je spuštěno pouze na tabulky které mají klíč typu UNIQUE, INCREMENT=YES
            db.ExecuteStoreCommand("DBCC CHECKIDENT (CommentSet, RESEED, 0)");
            db.ExecuteStoreCommand("DBCC CHECKIDENT (FileSet, RESEED, 0)");
            db.ExecuteStoreCommand("DBCC CHECKIDENT (GroupSet, RESEED, 0)");
            db.ExecuteStoreCommand("DBCC CHECKIDENT (ImageSet, RESEED, 0)");
            db.ExecuteStoreCommand("DBCC CHECKIDENT (LinkSet, RESEED, 0)");
            db.ExecuteStoreCommand("DBCC CHECKIDENT (MessageSet, RESEED, 0)");
            db.ExecuteStoreCommand("DBCC CHECKIDENT (StatusSet, RESEED, 0)");
            db.ExecuteStoreCommand("DBCC CHECKIDENT (UserSet, RESEED, 0)");
            db.ExecuteStoreCommand("DBCC CHECKIDENT (WallItemSet, RESEED, 0)");

            #endregion

            #region naplnění UserSet

            User usr1 = new User();
            usr1.Name = "Jakub";
            usr1.Surname = "Novák";
            usr1.Created = new DateTime(2008, 3, 1, 7, 0, 0);
            usr1.LastLogged = DateTime.Now;
            usr1.Mail = "*****@*****.**";
            usr1.Username = "******";
            usr1.Title = "Ing.";
            usr1.TitleAfter = "CSc.";
            usr1.StudyProgramme = "STM";
            usr1.Phone = "0609112567";
            usr1.ICQ = "123456789";
            usr1.Specialization = "Software engineering";
            usr1.ChangePassword("123456");

            User usr2 = new User();
            usr2.Name = "Jan";
            usr2.Surname = "Novák";
            usr2.Created = new DateTime(2009, 9, 10, 10, 0, 0);
            usr2.LastLogged = new DateTime(2010, 10, 10, 10, 0, 0);
            usr2.Mail = "*****@*****.**";
            usr2.Username = "******";
            usr2.ChangePassword("123456");

            User usr3 = new User();
            usr3.Name = "Bedřich";
            usr3.Surname = "Červený";
            usr3.Created = new DateTime(2007, 4, 8, 11, 5, 4);
            usr3.LastLogged = new DateTime(2008, 7, 8, 9, 4, 3);
            usr3.Mail = "*****@*****.**";
            usr3.Username = "******";
            usr3.ChangePassword("123456");

            User usr4 = new User();
            usr4.Id = 4;
            usr4.Name = "Ondřej";
            usr4.Surname = "Zelený";
            usr4.Created = new DateTime(2004, 2, 2, 8, 8, 5);
            usr4.LastLogged = new DateTime(2006, 7, 8, 9, 4, 3);
            usr4.Mail = "*****@*****.**";
            usr4.Username = "******";
            usr4.ChangePassword("123456");

            User usr5 = new User();
            usr5.Id = 5;
            usr5.Name = "Jiří";
            usr5.Surname = "Mach";
            usr5.Created = new DateTime(2007, 5, 1, 5, 1, 5);
            usr5.LastLogged = new DateTime(2010, 8, 9, 12, 5, 7);
            usr5.Mail = "*****@*****.**";
            usr5.Username = "******";
            usr5.ChangePassword("123456");

            User usr6 = new User();
            usr6.Id = 6;
            usr6.Name = "Alena";
            usr6.Surname = "Bílá";
            usr6.Created = new DateTime(2008, 7, 2, 5, 4, 6);
            usr6.LastLogged = new DateTime(2009, 4, 1, 13, 4, 10);
            usr6.Mail = "*****@*****.**";
            usr6.Username = "******";
            usr6.ChangePassword("123456");

            User usr7 = new User();
            usr7.Id = 7;
            usr7.Name = "Květa";
            usr7.Surname = "Pampeliškova";
            usr7.Created = new DateTime(2007, 6, 3, 2, 2, 11);
            usr7.LastLogged = new DateTime(2008, 6, 2, 7, 8, 9);
            usr7.Mail = "*****@*****.**";
            usr7.Username = "******";
            usr7.ChangePassword("123456");

            User usr8 = new User();
            usr8.Id = 8;
            usr8.Name = "Zuzana";
            usr8.Surname = "Frydrychová";
            usr8.Created = new DateTime(2007, 6, 3, 2, 2, 11);
            usr8.LastLogged = new DateTime(2008, 6, 2, 7, 8, 9);
            usr8.Mail = "*****@*****.**";
            usr8.Username = "******";
            usr8.ChangePassword("123456");

            User usr9 = new User();
            usr9.Id = 9;
            usr9.Name = "Andrea";
            usr9.Surname = "Senová";
            usr9.Created = new DateTime(2004, 1, 6, 2, 9, 12);
            usr9.LastLogged = new DateTime(2005, 5, 1, 2, 6, 3);
            usr9.Mail = "*****@*****.**";
            usr9.Username = "******";
            usr9.ChangePassword("123456");

            User usr10 = new User();
            usr10.Id = 10;
            usr10.Name = "Simona";
            usr10.Surname = "Červená";
            usr10.Created = new DateTime(2006, 2, 6, 2, 9, 9);
            usr10.LastLogged = new DateTime(2007, 5, 8, 2, 1, 3);
            usr10.Mail = "*****@*****.**";
            usr10.Username = "******";
            usr10.ChangePassword("123456");

            User usr11 = new User();
            usr11.Id = 11;
            usr11.Name = "Michal";
            usr11.Surname = "Stach";
            usr11.Created = new DateTime(2005, 2, 6, 2, 10, 12);
            usr11.LastLogged = new DateTime(2006, 1, 2, 2, 8, 3);
            usr11.Mail = "*****@*****.**";
            usr11.Username = "******";
            usr11.ChangePassword("123456");

            User usr12 = new User();
            usr12.Id = 12;
            usr12.Name = "Vladimír";
            usr12.Surname = "Roubal";
            usr12.Created = new DateTime(2003, 8, 6, 4, 7, 9);
            usr12.LastLogged = new DateTime(2008, 1, 4, 2, 5, 3);
            usr12.Mail = "*****@*****.**";
            usr12.Username = "******";
            usr12.ChangePassword("123456");

            db.AddToUserSet(usr1);
            db.AddToUserSet(usr2);
            db.AddToUserSet(usr3);
            db.AddToUserSet(usr4);
            db.AddToUserSet(usr5);
            db.AddToUserSet(usr6);
            db.AddToUserSet(usr7);
            db.AddToUserSet(usr8);
            db.AddToUserSet(usr9);
            db.AddToUserSet(usr10);
            db.AddToUserSet(usr11);
            db.AddToUserSet(usr12);

            #endregion

            #region naplnění MessageSet

            Message msg1 = new Message();
            msg1.Sender = usr1;
            msg1.Text = "Ahoj jak se máš?";
            msg1.Recievers.Add(usr2);
            msg1.Created = new DateTime(2010, 10, 11, 12, 5, 7);

            Message msg2 = new Message();
            msg2.Sender = usr1;
            msg2.Recievers.Add(usr2);
            msg2.Recievers.Add(usr3);
            msg2.Recievers.Add(usr4);
            msg2.Recievers.Add(usr5);
            msg2.Text = "Nezapomeňte dodělat domácí úkol.";
            msg2.Created = new DateTime(2009, 3, 5, 8, 1, 2);

            Message msg3 = new Message();
            msg3.Sender = usr3;
            msg3.Recievers.Add(usr1);
            msg3.ReplyTo = msg2;
            msg3.Text = "Už jsem ten úkol odevzdal.";
            msg3.Created = new DateTime(2007, 12, 11, 10, 4, 4);

            Message msg4 = new Message();
            msg4.Sender = usr3;
            msg4.Recievers.Add(usr1);
            msg3.ReplyTo = msg2;
            msg4.Text = "Taky už jsem ho udělal a díky za ty materiály, zejtra vás zvu na pivo.";
            msg4.Created = new DateTime(2010, 12, 8, 10, 2, 2);

            Message msg5 = new Message();
            msg5.Sender = usr5;
            msg5.Recievers.Add(usr4);
            msg5.Text = "Podařilo se mi rozchodit ten server !!!";
            msg5.Created = new DateTime(2010, 1, 8, 7, 6, 2);

            db.AddToMessageSet(msg1);
            db.AddToMessageSet(msg2);
            db.AddToMessageSet(msg3);
            db.AddToMessageSet(msg4);
            db.AddToMessageSet(msg5);

            #endregion

            #region naplnění GroupSet
            Group grp1 = new Group();
            Group grp2 = new Group();
            Group grp3 = new Group();
            Group grp4 = new Group();
            Group grp5 = new Group();
            Group grp6 = new Group();
            Group grp7 = new Group();
            Group grp8 = new Group();
            Group grp9 = new Group();
            Group grp10 = new Group();
            Group grp11 = new Group();
            Group grp12 = new Group();
            Group grp13 = new Group();
            Group grp14 = new Group();
            Group grp15 = new Group();

            grp1.Name = "Svět";
            grp1.Description = "Řídíme svět";
            grp1.Creator = usr2;
            grp1.Children.Add(grp2);
            grp1.Children.Add(grp3);
            grp1.Users.Add(usr1);
            grp1.Users.Add(usr2);
            grp1.Users.Add(usr3);
            grp1.Users.Add(usr4);
            grp1.Users.Add(usr5);
            usr1.JoinedGroups.Add(grp1);
            usr2.JoinedGroups.Add(grp2);
            grp1.Administrators.Add(usr1);
            grp1.Administrators.Add(usr2);

            grp2.Name = "Asie";
            grp2.Description = "Řídíme asii";
            grp2.Parent = grp1;
            grp2.Creator = usr1;
            grp2.Administrators.Add(usr1);

            grp3.Name = "Evropa";
            grp3.Description = "Řídíme Evropu";
            grp3.Parent = grp2;
            grp3.Children.Add(grp4);
            grp3.Creator = usr1;
            grp3.Administrators.Add(usr1);

            grp4.Name = "Česká republika";
            grp4.Description = "Řídíme Českou republiku";
            grp4.Parent = grp3;
            grp4.Creator = usr1;
            grp4.Administrators.Add(usr1);

            grp5.Name = "Slunce";
            grp5.Description = "Jsme úplně jiná planeta";
            grp5.Creator = usr1;
            grp5.Administrators.Add(usr1);

            grp6.Name = "Katedra Kybernetiky";
            grp6.Description = "Řešíme hlavne nedeterministické algoritmy";
            grp6.Children.Add(grp7);
            grp6.Children.Add(grp8);
            grp6.Creator = usr5;
            grp6.Administrators.Add(usr5);

            grp7.Name = "Vytěžování dat";
            grp7.Description = "Zabíváme se tu dataminingem";
            grp7.Parent = grp6;
            grp7.Creator = usr5;
            grp7.Administrators.Add(usr5);

            grp8.Name = "Kybernetika a umělá inteligence";
            grp8.Description = "Jedná se o úvodní obecný předmět umožňující studentům pochopit cíle a metody kybernetiky a umělé inteligence.";
            grp8.Parent = grp6;
            grp8.Creator = usr5;
            grp8.Administrators.Add(usr5);

            grp9.Name = "Katedra matematiky";
            grp9.Description = "Stále něco počítáme.";
            grp9.Children.Add(grp10);
            grp9.Children.Add(grp11);
            grp9.Creator = usr7;
            grp9.Administrators.Add(usr7);

            grp10.Name = "Úvod do lineární algebry";
            grp10.Description = "Matice, zobrazení, polynomy atd";
            grp10.Parent = grp9;
            grp10.Creator = usr9;
            grp10.Administrators.Add(usr9);

            grp11.Name = "Matematická logika";
            grp11.Description = "PCNF, kvantifikátory, logické operátory atd";
            grp11.Parent = grp9;
            grp11.Creator = usr9;
            grp11.Administrators.Add(usr9);

            grp12.Name = "Diskrétní matematika";
            grp12.Description = "Počítání modulo a samá přirozená čísla.";
            grp12.Parent = grp9;
            grp12.Creator = usr9;
            grp12.Administrators.Add(usr9);

            grp13.Name = "Katedra počítačů";
            grp13.Description = "Programování a různé techniky při tvorbě softwaru to je naše.";
            grp13.Children.Add(grp14);
            grp13.Children.Add(grp15);
            grp12.Creator = usr10;
            grp13.Administrators.Add(usr10);

            grp14.Name = "Teoretická informatika";
            grp14.Description = "Teorie grafů a algoritmy ohledně teorie grafů to je hlavní náplň tohoto kurzu.";
            grp14.Parent = grp13;
            grp14.Creator = usr10;
            grp14.Administrators.Add(usr10);

            grp15.Name = "Softwarové inženýrství";
            grp15.Description = "Tak kvůli tomuhle předmětu jsem vůbec napsal tuhle větu :).";
            grp15.Parent = grp13;
            grp15.Creator = usr10;
            grp15.Administrators.Add(usr10);

            #endregion

            #region naplnění StatusSet a zároveň CommentSet
            Status st1 = new Status();
            st1.Text = "Dneska jsem udělal maturitu";
            st1.User = usr1;
            st1.Created = new DateTime(2010, 1, 1, 12, 3, 4);

            Status st2 = new Status();
            st2.Text = "Podařilo se mi tu maturitu dát s vyznamenáním";
            st2.User = usr2;
            st2.Created = new DateTime(2010, 2, 1, 12, 3, 4);

            Status st3 = new Status();
            st3.Text = "Tohle je zajímavá skupina";
            st3.User = usr2;
            st3.Group = grp1;
            st3.Created = new DateTime(2008, 9, 1, 6, 2, 1);

            Status st4 = new Status();
            st4.Text = "Tady v té skupině řešíme evropu";
            st4.User = usr2;
            st4.Group = grp3;
            st4.Created = new DateTime(2009, 10, 2, 4, 8, 8);

            Status st5 = new Status();
            st5.Text = "Kdo neskáče není čech !!";
            st5.User = usr4;
            st5.Group = grp4;
            st5.Created = new DateTime(2010, 2, 4, 7, 1, 2);

            Comment cmt1 = new Comment();
            cmt1.Author = usr3;
            cmt1.Text = "Ano také si to myslím !!";
            cmt1.Created = new DateTime(2008, 10, 10, 7, 2, 3);
            st3.Comments.Add(cmt1);

            Comment cmt2 = new Comment();
            cmt2.Author = usr5;
            cmt2.Text = "Tak to jsi frajer!";
            cmt2.Created = new DateTime(2010, 1, 1, 12, 20, 10);
            st1.Comments.Add(cmt2);

            db.AddToCommentSet(cmt1);
            db.AddToCommentSet(cmt2);

            db.AddToStatusSet(st1);
            db.AddToStatusSet(st2);
            db.AddToStatusSet(st3);
            db.AddToStatusSet(st4);
            db.AddToStatusSet(st5);

            db.SaveChanges();

            #endregion

            #endregion
        }
Beispiel #19
0
        public void DeleteEventTest()
        {
            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);

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

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

            int id = actual.Id;
            Assert.IsTrue(DBEntities.EventSet.ToList().Contains(actual));

            target.DeleteEvent(id);

            Assert.IsFalse(DBEntities.EventSet.ToList().Contains(actual));

            DBEntities.UserSet.DeleteObject(mockUser);
            DBEntities.SaveChanges();
        }
Beispiel #20
0
        public void EditTest()
        {
            FelBookDBEntities DBEntities = new FelBookDBEntities();
            IWallService wallService = null;
            GroupService target = new GroupService(DBEntities, wallService);

            User creator = User.CreateUser(0, "group", "creator", DateTime.Now,
                "mail", "groupCreator", "1234");
            DBEntities.UserSet.AddObject(creator);
            User member = User.CreateUser(0, "group", "member", DateTime.Now,
                "mail", "groupMember", "1234");
            DBEntities.UserSet.AddObject(member);

            Group group = Group.CreateGroup(0, "newGroup", "groupDescription");
            creator.CreatedGroups.Add(group);
            creator.AdminedGroups.Add(group);
            creator.JoinedGroups.Add(group);
            DBEntities.GroupSet.AddObject(group);
            DBEntities.SaveChanges();

            Assert.IsFalse(member.JoinedGroups.Contains(group));
            group.Users.Add(member);

            target.Edit(group);

            Assert.IsTrue(member.JoinedGroups.Contains(group));

            DBEntities.GroupSet.DeleteObject(group);
            DBEntities.UserSet.DeleteObject(member);
            DBEntities.UserSet.DeleteObject(creator);
            DBEntities.SaveChanges();
        }