public void ToStringTest(int id, int noteId, string name, string text) { User user = new User("Name", "Login", "Password", DateTime.Now); DBContext.Users.Add(user); Random random = new Random(); DateTime created = DateTime.Now.AddDays(random.NextDouble() * -1); DateTime lastChanged = DateTime.Now; Note note = new Note(noteId, user, new Collection(), name, text, created, lastChanged); DBContext.Notes.Add(note); DateTime start = new DateTime(random.Next()); DateTime end = new DateTime(random.Next()); if (start > end) { DateTime t = start; start = end; end = t; } Database.Context.Action action = new Database.Context.Action(id, note, start, end); Assert.AreEqual("\b<sa>\b" + id.ToString() + "\b<sa>\b" + note.ToString() + "\b<sa>\b" + (start - DateTime.MinValue).TotalDays.ToString() + "\b<sa>\b" + (end - DateTime.MinValue).TotalDays.ToString() + "\b<sa>\b", action.ToString()); }
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; } DBContext.Missions.Clear(); DBContext.Actions.Clear(); DBContext.Notes.Clear(); DBContext.Users.Clear(); DBContext.Progresses.Clear(); User user = new User("Name", "Login", "Password", DateTime.Now); DBContext.Users.Add(user); Note note = new Note(noteId, user, new Collection(), name, text, created, lastChanged); DBContext.Notes.Add(note); Database.Context.Action action = new Database.Context.Action(actionId, note, startT, endT); DBContext.Actions.Add(action); Progress progress = new Progress(start, current, end); DBContext.Progresses.Add(progress); Mission mission1 = new Mission(action, true, progress); Mission mission2 = new Mission(id, action, true, progress); DBContext.Missions.Add(mission1); DBContext.Missions.Add(mission2); Assert.AreEqual(id, mission2.Id); Assert.AreEqual(true, mission1.IsProgressType); Assert.AreEqual(true, mission2.IsProgressType); Assert.AreEqual(user, mission1.Action.Note.User); Assert.AreEqual(user, mission2.Action.Note.User); Assert.AreEqual(note, mission1.Action.Note); Assert.AreEqual(note, mission2.Action.Note); Assert.AreEqual(action, mission1.Action); Assert.AreEqual(action, mission2.Action); Assert.AreEqual(progress, mission1.Context); Assert.AreEqual(progress, mission2.Context); }
public void ToStringTestParagraph(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; } DBContext.Missions.Clear(); DBContext.Actions.Clear(); DBContext.Notes.Clear(); DBContext.Users.Clear(); DBContext.Points.Clear(); DBContext.Collections.Clear(); User user = new User("Name", "Login", "Password", DateTime.Now); DBContext.Users.Add(user); Note note = new Note(noteId, user, new Collection(), name, text, created, lastChanged); DBContext.Notes.Add(note); Database.Context.Action action = new Database.Context.Action(actionId, note, startT, endT); DBContext.Actions.Add(action); Collection paragraph = new Collection(points.Length); DBContext.Collections.Add(paragraph); for (int i = 0; i < points.Length; ++i) { Point point = new Point(paragraph, points[i], isCheckeds[i]); DBContext.Points.Add(point); } Mission mission = new Mission(id, action, false, paragraph); DBContext.Missions.Add(mission); Assert.AreEqual("\b<sm>\b" + (id * -1).ToString() + "\b<sm>\b" + action.ToString() + "\b<sm>\b" + paragraph.ToString() + "\b<sm>\b", mission.ToString()); }
private void GenerateNotes(string login, string password, int count, int dispDays) { const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; Random random = new Random(); int userId = -1; try { userId = DBContext.Users.Where(x => x.Login == login && x.Password == password).First().Id; } catch { return; } for (int i = 0; i < count; ++i) { DateTime created = DateTime.Now.AddDays(dispDays * (random.Next() % 2 == 0 ? 1 : -1) + random.NextDouble()), lastChanged = DateTime.Now.AddDays(dispDays * (random.Next() % 2 == 0 ? 1 : -1) + random.NextDouble()); if (created > lastChanged) { DateTime t = created; created = lastChanged; lastChanged = t; } Note note = new Note(userId, 1, new string(Enumerable.Repeat(chars, random.Next(10, 40)).Select(s => s[random.Next(s.Length)]).ToArray()), new string(Enumerable.Repeat(chars, random.Next(40, 120)).Select(s2 => s2[random.Next(s2.Length)]).ToArray()), created, lastChanged); DBContext.Notes.Add(note); if (random.Next() % 2 == 0) { DateTime start = DateTime.Now.AddDays(dispDays * (random.Next() % 2 == 0 ? 1 : -1) + random.NextDouble()), end = DateTime.Now.AddDays(dispDays * (random.Next() % 2 == 0 ? 1 : -1) + random.NextDouble()); if (start > end) { DateTime t = start; start = end; end = t; } Database.Context.Action action = new Database.Context.Action(note, start, end); DBContext.Actions.Add(action); Collection collection = new Collection(random.Next(0, 10)); DBContext.Collections.Add(collection); for (int j = 0; j < collection.Count; ++j) { Point point = new Point(collection, new string(Enumerable.Repeat(chars, random.Next(10, 70)).Select(s => s[random.Next(s.Length)]).ToArray()), random.Next() % 2 == 0); DBContext.Points.Add(point); } Mission mission = new Mission(action, false, collection); DBContext.Missions.Add(mission); } } }
public void InitializationTest(int id, int noteId, string name, string text) { DBContext.Actions.Clear(); User user = new User("Name", "Login", "Password", DateTime.Now); DBContext.Users.Add(user); Random random = new Random(); DateTime created = DateTime.Now.AddDays(random.NextDouble() * -1); DateTime lastChanged = DateTime.Now; Note note = new Note(noteId, user, new Collection(), name, text, created, lastChanged); DBContext.Notes.Add(note); DateTime start = new DateTime(random.Next()); DateTime end = new DateTime(random.Next()); if (start > end) { DateTime t = start; start = end; end = t; } Database.Context.Action action1 = new Database.Context.Action(note, start, end); DBContext.Actions.Add(action1); try { Database.Context.Action _ = new Database.Context.Action(note, end, start); Assert.Fail(); } catch (ArgumentException) { } Database.Context.Action action2 = new Database.Context.Action(id, note, start, end); try { Database.Context.Action _ = new Database.Context.Action(id, note, end, start); Assert.Fail(); } catch (ArgumentException) { } Assert.AreEqual(id, action2.Id); Assert.AreEqual(start, action1.Start); Assert.AreEqual(start, action2.Start); Assert.AreEqual(end, action1.End); Assert.AreEqual(end, action2.End); }
public void DuplicateParagraphMissionTest(string login, string password, string name, string text, string[] points, string createdDay, string createdMonth, string createdYear, string newDay, string newMonth, string newYear, string expectedResult) { string id = server.ExecuteCommand("cnpm", new string[] { correctLogin, correctPassword, name, text, createdDay, createdMonth, createdYear }); foreach (string point in points) { server.ExecuteCommand("aptpm", new string[] { correctLogin, correctPassword, id.Split('|')[2], point }); } DateTime before = DateTime.Now; string result = server.ExecuteCommand("dpm", new string[] { login, password, id.Split('|')[2], newDay, newMonth, newYear }); DateTime after = DateTime.Now; if (expectedResult != "[id]") { Assert.AreEqual(expectedResult, result); } else { string[] ids = id.Split('|'); Assert.IsTrue(ids.Length == 4); Assert.IsTrue(int.TryParse(ids[0], out int noteId)); Assert.IsTrue(int.TryParse(ids[1], out int actionId)); Assert.IsTrue(int.TryParse(ids[2], out int missionId)); Assert.IsTrue(int.TryParse(ids[3], out int paragraphId)); string[] newIds = result.Split('|'); Assert.IsTrue(newIds.Length == 4 + points.Length); Assert.IsTrue(int.TryParse(newIds[0], out int newNoteId)); Assert.IsTrue(int.TryParse(newIds[1], out int newActionId)); Assert.IsTrue(int.TryParse(newIds[2], out int newMissionId)); Assert.IsTrue(int.TryParse(newIds[3], out int newParagraphId)); Note noteDb = DBContext.Notes.Where(x => x.Id == noteId).First(); Note newNoteDb = DBContext.Notes.Where(x => x.Id == newNoteId).First(); Database.Context.Action actionDb = DBContext.Actions.Where(x => x.Id == actionId).First(); Database.Context.Action newActionDb = DBContext.Actions.Where(x => x.Id == newActionId).First(); Mission missionDb = DBContext.Missions.Where(x => x.Id == missionId).First(); Mission newMissionDb = DBContext.Missions.Where(x => x.Id == newMissionId).First(); Collection paragraphDb = DBContext.Collections.Where(x => x.Id == paragraphId).First(); Collection newParagraphDb = DBContext.Collections.Where(x => x.Id == newParagraphId).First(); List <Point> pointsDb = DBContext.Points.Where(x => x.ParagraphId == paragraphId).ToList(); List <Point> newPointsDb = DBContext.Points.Where(x => x.ParagraphId == newParagraphId).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); } for (int i = 4; i < newIds.Length; ++i) { Assert.IsTrue(DBContext.Points.Where(x => x.Id == int.Parse(newIds[i])).Count() == 1); } } }
public void CreateNewParagraphMissionTest(string login, string password, string name, string text, int year, int month, int day, string expectedResult) { DateTime before = DateTime.Now; string result = server.ExecuteCommand("cnpm", new string[] { login, password, name, text, day.ToString(), month.ToString(), year.ToString() }); DateTime after = DateTime.Now; if (expectedResult != "id") { Assert.AreEqual(expectedResult, result); } else { string[] ids = result.Split('|'); Assert.IsTrue(ids.Length == 4); Assert.IsTrue(int.TryParse(ids[0], out int noteId)); Assert.IsTrue(int.TryParse(ids[1], out int actionId)); Assert.IsTrue(int.TryParse(ids[2], out int missionId)); Assert.IsTrue(int.TryParse(ids[3], out int paragraphId)); Assert.IsTrue(DBContext.Notes.Where(x => x.Id == noteId).Count() == 1); Assert.IsTrue(DBContext.Actions.Where(x => x.Id == actionId).Count() == 1); Assert.IsTrue(DBContext.Missions.Where(x => x.Id == missionId).Count() == 1); Assert.IsTrue(DBContext.Collections.Where(x => x.Id == paragraphId).Count() == 1); Mission mission = DBContext.Missions.Where(x => x.Id == missionId).First(); Assert.AreEqual(mission.Action.NoteId, noteId); Assert.AreEqual(mission.Action.Id, actionId); Assert.AreEqual(mission.ContextId, paragraphId); Assert.IsFalse(mission.IsProgressType); Assert.AreEqual(0, ((Collection)mission.Context).Count); Database.Context.Action action = mission.Action; Assert.AreEqual(DateTime.MinValue, action.Start); Assert.AreEqual(DateTime.MaxValue, action.End); Note note = action.Note; Assert.AreEqual(name, note.Name); Assert.AreEqual(text, note.Text); bool hasCreated = false; DateTime created = DateTime.Now; try { created = new DateTime(day, month, year); hasCreated = true; } catch { } if (hasCreated) { Assert.IsTrue(new TimeSpan(0, 0, 1) < (created > note.Created ? created - note.Created : note.Created - created)); } else { Assert.IsTrue(before <= note.LastChanged && note.LastChanged <= after); } Assert.IsTrue(before <= note.LastChanged && note.LastChanged <= after); User user = note.User; Assert.AreEqual(login, user.Login); Assert.AreEqual(password, user.Password); } }