Beispiel #1
0
        public void DuplicateNoteTest(string name, string text, string createdDay, string createdMonth, string createdYear, string newDay, string newMonth, string newYear)
        {
            Note note = new Note(-1, -1, name, text, new DateTime(int.Parse(createdYear), int.Parse(createdMonth), int.Parse(createdDay)), DateTime.Now, true);

            DateTime before = DateTime.Now;
            Note     dNote  = helper.DuplicateNote(note, new DateTime(int.Parse(newYear), int.Parse(newMonth), int.Parse(newDay)));
            DateTime after  = DateTime.Now;

            Assert.AreNotEqual(note.Id, dNote.Id);
            ServerRealization.Database.Context.Note dbNote  = DBContext.Notes.Where(x => x.Id == note.Id).First();
            ServerRealization.Database.Context.Note DbDNote = DBContext.Notes.Where(x => x.Id == dNote.Id).First();

            Assert.AreEqual(name, dNote.Name);
            Assert.AreEqual(name, DbDNote.Name);
            Assert.AreEqual(text, dNote.Text);
            Assert.AreEqual(text, DbDNote.Text);
            Assert.AreEqual(dbNote.UserId, DbDNote.UserId);
            Assert.AreEqual(newDay, dNote.Created.Day.ToString());
            Assert.AreEqual(newDay, DbDNote.Created.Day.ToString());
            Assert.AreEqual(newMonth, dNote.Created.Month.ToString());
            Assert.AreEqual(newMonth, DbDNote.Created.Month.ToString());
            Assert.AreEqual(newYear, dNote.Created.Year.ToString());
            Assert.AreEqual(newYear, DbDNote.Created.Year.ToString());
            Assert.IsTrue(before <= dNote.LastChanged && dNote.LastChanged <= after);
            Assert.IsTrue(before <= DbDNote.LastChanged && DbDNote.LastChanged <= after);
        }
Beispiel #2
0
        public void CreateNoteTest(string name, string text)
        {
            Note note = new Note(-1, name, text, DateTime.Now, DateTime.Now);
            int  id   = helper.CreateNote(note);

            Thread.Sleep(500);

            ServerRealization.Database.Context.Note dbNote = DBContext.Notes.Where(x => x.Id == id).First();
            Assert.AreEqual(name, dbNote.Name);
            Assert.AreEqual(text, dbNote.Text);
        }
Beispiel #3
0
        public void InitializationTest(int id, string name, string text)
        {
            Random   random      = new Random();
            DateTime created     = DateTime.Now.AddDays(random.NextDouble() * -1);
            DateTime lastChanged = DateTime.Now;

            Note note1 = new Note(id, 0, name, text, created, lastChanged);
            Note note2 = new Note(0, name, text, created, lastChanged);

            ServerRealization.Database.Context.User user   = new ServerRealization.Database.Context.User("Name", "Login", "Password", DateTime.Now);
            ServerRealization.Database.Context.Note dbNote = new ServerRealization.Database.Context.Note(id, user, new ServerRealization.Database.Context.Collection(), name, text, created, lastChanged);

            Note note3 = new Note(dbNote.ToString());

            Assert.AreEqual(id, note1.Id);
            Assert.AreEqual(id, note3.Id);
            Assert.AreEqual(name, note1.Name);
            Assert.AreEqual(name, note2.Name);
            Assert.AreEqual(name, note3.Name);
            Assert.AreEqual(text, note1.Text);
            Assert.AreEqual(text, note2.Text);
            Assert.AreEqual(text, note3.Text);
            Assert.AreEqual(created, note1.Created);
            Assert.AreEqual(created, note2.Created);

            if (created > note3.Created)
            {
                Assert.IsTrue((created - note3.Created).TotalSeconds < 1);
            }
            else if (note3.Created > created)
            {
                Assert.IsTrue((note3.Created - created).TotalSeconds < 1);
            }

            Assert.AreEqual(lastChanged, note1.LastChanged);
            Assert.AreEqual(lastChanged, note2.LastChanged);

            if (lastChanged > note3.LastChanged)
            {
                Assert.IsTrue((lastChanged - note3.LastChanged).TotalSeconds < 1);
            }
            else if (note3.LastChanged > lastChanged)
            {
                Assert.IsTrue((note3.LastChanged - lastChanged).TotalSeconds < 1);
            }
        }
Beispiel #4
0
        public void AutoTimingTest(string name, string text, string newName, string newText)
        {
            SocketSettings.SocketSettings settings = new SocketSettings.SocketSettings("192.168.0.107", 11221, 300);
            ServerProgram server = new ServerProgram(settings);

            server.Run();
            server.ExecuteCommand("rnu", new string[] { "Login", "Password", "Name" });
            DBHelper helper = new DBHelper(settings);

            DBHelper.Login    = "******";
            DBHelper.Password = "******";

            Note note = new Note(name, text, true);

            Thread.Sleep(500);

            Assert.AreEqual(name, note.Name);
            Assert.AreEqual(text, note.Text);
            Assert.IsTrue(DBContext.Notes.Where(x => x.Id == note.Id).Count() == 1);
            ServerRealization.Database.Context.Note dbNote = DBContext.Notes.Where(x => x.Id == note.Id).First();
            Assert.AreEqual(name, dbNote.Name);
            Assert.AreEqual(text, dbNote.Text);
            Assert.IsTrue(new TimeSpan(0, 0, 1) > (note.Created > dbNote.Created ? note.Created - dbNote.Created : dbNote.Created - note.Created));
            Assert.IsTrue(new TimeSpan(0, 0, 1) > (note.LastChanged > dbNote.LastChanged ? note.LastChanged - dbNote.LastChanged : dbNote.LastChanged - note.LastChanged));

            note.Name = newName;
            note.Text = newText;
            Thread.Sleep(7000);
            if (name != newName)
            {
                Assert.AreNotEqual(newName, dbNote.Name);
            }
            if (text != newText)
            {
                Assert.AreNotEqual(newText, dbNote.Text);
            }

            Thread.Sleep(3500);
            Assert.AreEqual(newName, dbNote.Name);
            Assert.AreEqual(newText, dbNote.Text);

            server.Stop();
            Thread.Sleep(1000);
        }
Beispiel #5
0
        public void SaveChangesTest(string name, string text, string newName, string newText)
        {
            Note note = new Note(-1, name, text, DateTime.Now, DateTime.Now);
            int  id   = helper.CreateNote(note);

            Thread.Sleep(500);

            List <KeyValuePair <string, string[]> > changes = Note.GetChanges(new Note(id, -1, newName, newText, DateTime.Now, DateTime.Now), note);

            Assert.IsTrue(helper.SaveChanges(changes));
            Thread.Sleep(500);

            ServerRealization.Database.Context.Note dbNote = DBContext.Notes.Where(x => x.Id == id).First();
            Assert.AreEqual(newName, dbNote.Name);
            Assert.AreEqual(newText, dbNote.Text);

            server.Stop();
            Thread.Sleep(1000);
        }
Beispiel #6
0
        public void InitializationTestParagraph(int id, int actionId, int noteId, string name, string text, string[] points, bool[] isCheckeds)
        {
            Random   random      = new Random();
            DateTime created     = DateTime.Now.AddDays(random.NextDouble() * -1);
            DateTime lastChanged = DateTime.Now;
            DateTime startT      = new DateTime(random.Next());
            DateTime endT        = new DateTime(random.Next());

            if (startT > endT)
            {
                DateTime t = startT;
                startT = endT;
                endT   = t;
            }

            ServerRealization.Database.Context.User dbUser = new ServerRealization.Database.Context.User("Name", "Login", "Password", DateTime.Now);
            DBContext.Users.Add(dbUser);
            ServerRealization.Database.Context.Note dbNote = new ServerRealization.Database.Context.Note(noteId, dbUser, new ServerRealization.Database.Context.Collection(), name, text, created, lastChanged);
            DBContext.Notes.Add(dbNote);
            ServerRealization.Database.Context.Action dbAction = new ServerRealization.Database.Context.Action(actionId, dbNote, startT, endT);
            DBContext.Actions.Add(dbAction);
            ServerRealization.Database.Context.Collection dbParagraph = new ServerRealization.Database.Context.Collection(points.Length);
            DBContext.Collections.Add(dbParagraph);
            for (int i = 0; i < points.Length; ++i)
            {
                ServerRealization.Database.Context.Point dbPoint = new ServerRealization.Database.Context.Point(dbParagraph, points[i], isCheckeds[i]);
                DBContext.Points.Add(dbPoint);
            }
            ServerRealization.Database.Context.Mission dbMission = new ServerRealization.Database.Context.Mission(id, dbAction, false, dbParagraph);

            ParagraphMission mission = (ParagraphMission)Mission.CreateNew(dbMission.ToString());

            Assert.AreEqual(id, mission.Id);
            Assert.AreEqual(actionId, mission.ActionId);
            Assert.AreEqual(noteId, mission.NoteId);
            Assert.AreEqual(name, mission.Name);
            Assert.AreEqual(text, mission.Text);
            Assert.AreEqual(points.Length, mission.Paragraph.Count);
            for (int i = 0; i < mission.Paragraph.Count; ++i)
            {
                Assert.AreEqual(points[i], mission.Paragraph.Items[i].Text);
                Assert.AreEqual(isCheckeds[i], mission.Paragraph.Items[i].IsChecked);
            }

            if (created > mission.Created)
            {
                Assert.IsTrue((created - mission.Created).TotalSeconds < 1);
            }
            else if (mission.Created > created)
            {
                Assert.IsTrue((mission.Created - created).TotalSeconds < 1);
            }

            if (lastChanged > mission.LastChanged)
            {
                Assert.IsTrue((lastChanged - mission.LastChanged).TotalSeconds < 1);
            }
            else if (mission.LastChanged > lastChanged)
            {
                Assert.IsTrue((mission.LastChanged - lastChanged).TotalSeconds < 1);
            }

            if (startT > mission.Start)
            {
                Assert.IsTrue((startT - mission.Start).TotalSeconds < 1);
            }
            else if (mission.Start > startT)
            {
                Assert.IsTrue((mission.Start - startT).TotalSeconds < 1);
            }

            if (endT > mission.End)
            {
                Assert.IsTrue((endT - mission.End).TotalSeconds < 1);
            }
            else if (mission.End > endT)
            {
                Assert.IsTrue((mission.End - endT).TotalSeconds < 1);
            }
        }
Beispiel #7
0
        public void InitializationTestProgress(int id, int actionId, int noteId, string name, string text, int start, int current, int end)
        {
            Random   random      = new Random();
            DateTime created     = DateTime.Now.AddDays(random.NextDouble() * -1);
            DateTime lastChanged = DateTime.Now;
            DateTime startT      = new DateTime(random.Next());
            DateTime endT        = new DateTime(random.Next());

            if (startT > endT)
            {
                DateTime t = startT;
                startT = endT;
                endT   = t;
            }

            ServerRealization.Database.Context.User    dbUser    = new ServerRealization.Database.Context.User("Name", "Login", "Password", DateTime.Now);
            ServerRealization.Database.Context.Note    dbNote    = new ServerRealization.Database.Context.Note(noteId, dbUser, new ServerRealization.Database.Context.Collection(), name, text, created, lastChanged);
            ServerRealization.Database.Context.Action  dbAction  = new ServerRealization.Database.Context.Action(actionId, dbNote, startT, endT);
            ServerRealization.Database.Context.Mission dbMission = new ServerRealization.Database.Context.Mission(id, dbAction, true, new ServerRealization.Database.Context.Progress(start, current, end));

            ProgressMission mission = (ProgressMission)Mission.CreateNew(dbMission.ToString());

            Assert.AreEqual(id, mission.Id);
            Assert.AreEqual(actionId, mission.ActionId);
            Assert.AreEqual(noteId, mission.NoteId);
            Assert.AreEqual(name, mission.Name);
            Assert.AreEqual(text, mission.Text);
            Assert.AreEqual(start, ((Progress)mission.Context).Start);
            Assert.AreEqual(current, mission.Context.Count);
            Assert.AreEqual(end, ((Progress)mission.Context).End);

            if (created > mission.Created)
            {
                Assert.IsTrue((created - mission.Created).TotalSeconds < 1);
            }
            else if (mission.Created > created)
            {
                Assert.IsTrue((mission.Created - created).TotalSeconds < 1);
            }

            if (lastChanged > mission.LastChanged)
            {
                Assert.IsTrue((lastChanged - mission.LastChanged).TotalSeconds < 1);
            }
            else if (mission.LastChanged > lastChanged)
            {
                Assert.IsTrue((mission.LastChanged - lastChanged).TotalSeconds < 1);
            }

            if (startT > mission.Start)
            {
                Assert.IsTrue((startT - mission.Start).TotalSeconds < 1);
            }
            else if (mission.Start > startT)
            {
                Assert.IsTrue((mission.Start - startT).TotalSeconds < 1);
            }

            if (endT > mission.End)
            {
                Assert.IsTrue((endT - mission.End).TotalSeconds < 1);
            }
            else if (mission.End > endT)
            {
                Assert.IsTrue((mission.End - endT).TotalSeconds < 1);
            }
        }
Beispiel #8
0
        public void DuplicateParagraphMissionTest(string name, string text, string[] points, bool[] isCheckeds, string createdDay, string createdMonth, string createdYear, string newDay, string newMonth, string newYear, string expectedResult)
        {
            ParagraphMission paragraphMission = new ParagraphMission(name, text, DateTime.Parse(createdDay + "." + createdMonth + "." + createdYear), true);

            int[] ids = new int[] { paragraphMission.NoteId, paragraphMission.ActionId, paragraphMission.Id, paragraphMission.Paragraph.Id };
            for (int i = 0; i < points.Length; ++i)
            {
                helper.AddPointToParagraphMission(paragraphMission, new Point(points[i], isCheckeds[i]));
            }

            DateTime         before            = DateTime.Now;
            ParagraphMission dParagraphMission = helper.DuplicateParagraphMission(paragraphMission, DateTime.Parse(newDay + "." + newMonth + "." + newYear));
            DateTime         after             = DateTime.Now;

            int[] newIds = new int[] { dParagraphMission.NoteId, dParagraphMission.ActionId, dParagraphMission.Id, dParagraphMission.Paragraph.Id };

            ServerRealization.Database.Context.Note         noteDb         = DBContext.Notes.Where(x => x.Id == ids[0]).First();
            ServerRealization.Database.Context.Note         newNoteDb      = DBContext.Notes.Where(x => x.Id == newIds[0]).First();
            ServerRealization.Database.Context.Action       actionDb       = DBContext.Actions.Where(x => x.Id == ids[1]).First();
            ServerRealization.Database.Context.Action       newActionDb    = DBContext.Actions.Where(x => x.Id == newIds[1]).First();
            ServerRealization.Database.Context.Mission      missionDb      = DBContext.Missions.Where(x => x.Id == ids[2]).First();
            ServerRealization.Database.Context.Mission      newMissionDb   = DBContext.Missions.Where(x => x.Id == newIds[2]).First();
            ServerRealization.Database.Context.Collection   paragraphDb    = DBContext.Collections.Where(x => x.Id == ids[3]).First();
            ServerRealization.Database.Context.Collection   newParagraphDb = DBContext.Collections.Where(x => x.Id == newIds[3]).First();
            List <ServerRealization.Database.Context.Point> pointsDb       = DBContext.Points.Where(x => x.ParagraphId == ids[3]).ToList();
            List <ServerRealization.Database.Context.Point> newPointsDb    = DBContext.Points.Where(x => x.ParagraphId == newIds[3]).ToList();

            Assert.AreNotEqual(noteDb.Id, newNoteDb.Id);
            Assert.AreEqual(noteDb.UserId, newNoteDb.UserId);
            Assert.AreEqual(noteDb.Name, newNoteDb.Name);
            Assert.AreEqual(noteDb.Text, newNoteDb.Text);
            Assert.AreNotEqual(noteDb.Created, newNoteDb.Created);
            Assert.AreEqual(newDay, newNoteDb.Created.Day.ToString());
            Assert.AreEqual(newMonth, newNoteDb.Created.Month.ToString());
            Assert.AreEqual(newYear, newNoteDb.Created.Year.ToString());
            Assert.IsTrue(before <= newNoteDb.LastChanged && newNoteDb.LastChanged <= after);

            Assert.AreNotEqual(actionDb.Id, newActionDb.Id);
            Assert.AreNotEqual(actionDb.NoteId, newActionDb.NoteId);
            Assert.AreEqual(newNoteDb.Id, newActionDb.NoteId);
            Assert.AreEqual(actionDb.Start, newActionDb.Start);
            Assert.AreEqual(actionDb.End, newActionDb.End);

            Assert.AreNotEqual(missionDb.Id, newMissionDb.Id);
            Assert.AreNotEqual(missionDb.ActionId, newMissionDb.ActionId);
            Assert.AreEqual(newActionDb.Id, newMissionDb.Id);
            Assert.AreEqual(false, newMissionDb.IsProgressType);
            Assert.AreNotEqual(missionDb.ContextId, newMissionDb.ContextId);
            Assert.AreEqual(newParagraphDb.Id, newMissionDb.ContextId);

            Assert.AreNotEqual(paragraphDb.Id, newParagraphDb.Id);
            Assert.AreEqual(paragraphDb.Count, newParagraphDb.Count);
            Assert.AreEqual(pointsDb.Count, newPointsDb.Count);
            for (int i = 0; i < pointsDb.Count; ++i)
            {
                Assert.AreNotEqual(pointsDb[i].Id, newPointsDb[i].Id);
                Assert.AreEqual(newParagraphDb.Id, newPointsDb[i].ParagraphId);
                Assert.AreEqual(pointsDb[i].Name, newPointsDb[i].Name);
                Assert.AreEqual(pointsDb[i].IsChecked, newPointsDb[i].IsChecked);
            }
        }
Beispiel #9
0
        public void InitializationTest(int id, int noteId, string name, string text)
        {
            Random   random      = new Random();
            DateTime created     = DateTime.Now.AddDays(random.NextDouble() * -1);
            DateTime lastChanged = DateTime.Now;
            DateTime start       = new DateTime(random.Next());
            DateTime end         = new DateTime(random.Next());

            if (start > end)
            {
                DateTime t = start;
                start = end;
                end   = t;
            }

            Action action1 = new Action(id, noteId, 0, name, text, created, lastChanged, start, end);

            Note   note2   = new Note(noteId, 0, name, text, created, lastChanged);
            Action action2 = new Action(id, note2, start, end);

            ServerRealization.Database.Context.User   user     = new ServerRealization.Database.Context.User("Name", "Login", "Password", DateTime.Now);
            ServerRealization.Database.Context.Note   dbNote   = new ServerRealization.Database.Context.Note(noteId, user, new ServerRealization.Database.Context.Collection(), name, text, created, lastChanged);
            ServerRealization.Database.Context.Action dbAction = new ServerRealization.Database.Context.Action(id, dbNote, start, end);
            Action action3 = new Action(dbAction.ToString());

            Assert.AreEqual(id, action1.Id);
            Assert.AreEqual(id, action2.Id);
            Assert.AreEqual(id, action3.Id);
            Assert.AreEqual(noteId, action1.NoteId);
            Assert.AreEqual(noteId, action2.NoteId);
            Assert.AreEqual(noteId, action3.NoteId);
            Assert.AreEqual(name, action1.Name);
            Assert.AreEqual(name, action2.Name);
            Assert.AreEqual(name, action3.Name);
            Assert.AreEqual(text, action1.Text);
            Assert.AreEqual(text, action2.Text);
            Assert.AreEqual(text, action3.Text);
            Assert.AreEqual(created, action1.Created);
            Assert.AreEqual(created, action2.Created);
            Assert.AreEqual(lastChanged, action1.LastChanged);
            Assert.AreEqual(lastChanged, action2.LastChanged);
            Assert.AreEqual(start, action1.Start);
            Assert.AreEqual(start, action2.Start);
            Assert.AreEqual(end, action1.End);
            Assert.AreEqual(end, action2.End);

            if (created > action3.Created)
            {
                Assert.IsTrue((created - action3.Created).TotalSeconds < 1);
            }
            else if (action3.Created > created)
            {
                Assert.IsTrue((action3.Created - created).TotalSeconds < 1);
            }

            if (lastChanged > action3.LastChanged)
            {
                Assert.IsTrue((lastChanged - action3.LastChanged).TotalSeconds < 1);
            }
            else if (action3.LastChanged > lastChanged)
            {
                Assert.IsTrue((action3.LastChanged - lastChanged).TotalSeconds < 1);
            }

            if (start > action3.Start)
            {
                Assert.IsTrue((start - action3.Start).TotalSeconds < 1);
            }
            else if (action3.Start > start)
            {
                Assert.IsTrue((action3.Start - start).TotalSeconds < 1);
            }

            if (end > action3.End)
            {
                Assert.IsTrue((end - action3.End).TotalSeconds < 1);
            }
            else if (action3.End > end)
            {
                Assert.IsTrue((action3.End - end).TotalSeconds < 1);
            }
        }