public void AddSubforumPersistencyTest() { string newForumName = "Persistency Test Forum" + DateTime.Now; try { IForumService sc = new ServerNetworkAdaptor(); sc.Login("admin", "admin"); Assert.AreEqual(Result.OK, sc.AddSubforum("admin", "admin", newForumName)); } catch (Exception e) { Console.WriteLine("Got exception while running test: " + e.Message); Console.WriteLine(e.InnerException.Message); Assert.Fail(); } //ReloadServer(); string[] subforums; try { IForumService sc = new ServerNetworkAdaptor(); subforums = sc.GetSubforumsList(); Assert.True(subforums.Contains<string>(newForumName), "The subforum was not found after reloading DB!"); Assert.AreEqual(Result.OK, sc.RemoveSubforum("admin", "admin", newForumName), "Could not remove the subforum"); subforums = sc.GetSubforumsList(); Assert.False(subforums.Contains<string>(newForumName), "The sub forum was not removed from the DB"); } catch (Exception e) { Console.WriteLine("Got exception while running test: " + e.Message); Console.WriteLine(e.InnerException.Message); Assert.Fail(); } //ReloadServer(); try { IForumService sc = new ServerNetworkAdaptor(); subforums = sc.GetSubforumsList(); Assert.False(subforums.Contains<string>(newForumName), "The subforum exists in DB after reload!!"); } catch (Exception e) { Console.WriteLine("Got exception while running test: " + e.Message); Console.WriteLine(e.InnerException.Message); Assert.Fail(); } }
public void PostingPersistencyTest() { string[] subforums; int totalNumOfPosts = 0; try { IForumService sc = new ServerNetworkAdaptor(); sc.Login("admin", "admin"); subforums = sc.GetSubforumsList(); Assert.True(subforums.Length > 0, "No subforums in DB, can't run the test!"); foreach (string s in subforums) { totalNumOfPosts += sc.ReportSubForumTotalPosts("admin", "admin", s); } Postkey pk = new Postkey("admin", DateTime.Now); Post p = new Post(pk, "Persistency Test Post" + DateTime.Now, "Just a random post", null, subforums[0]); Assert.AreEqual(Result.OK, sc.Post(subforums[0], p), "Can't post!!! Test failed.."); Postkey replyKey = new Postkey("admin", DateTime.Now); Post reply = new Post(replyKey, "Persistency Test Reply" + DateTime.Now, "Just a random reply", pk, subforums[0]); Assert.AreEqual(Result.OK, sc.Reply(pk, reply), "Can't reply!!! Test failed.."); } catch (Exception e) { Console.WriteLine("Got exception while running test: " + e.Message); Console.WriteLine(e.InnerException.Message); Assert.Fail(); } //ReloadServer(); try { int newNumOfPosts = 0; IForumService sc = new ServerNetworkAdaptor(); sc = new ServerNetworkAdaptor(); subforums = sc.GetSubforumsList(); foreach (string s in subforums) { newNumOfPosts += sc.ReportSubForumTotalPosts("admin", "admin", s); } Assert.True(newNumOfPosts - totalNumOfPosts == 1, "Wrong number of posts in DB. expected: " + (totalNumOfPosts + 2) + ", but got: " + newNumOfPosts); } catch (Exception e) { Console.WriteLine("Got exception while running test: " + e.Message); Console.WriteLine(e.InnerException.Message); Assert.Fail(); } //TODO fetch the posts and see they exist. }