public void update_a_forum() { //Create forum Connection one = new Connection(); ForumRepo repo = new ForumRepo(new Connection()); ForumModel forum = new ForumModel(); forum.name = "testname"; forum.description = "testdescription"; int id = repo.store(forum); forum.id = id; //Give forum a new name forum.name = "new name!"; repo.update(forum); one.Connect(); SqlCommand sqlCommand = new SqlCommand("select * from forum where name = 'new name!'", one.getConnection()); SqlDataReader reader = sqlCommand.ExecuteReader(); Assert.AreEqual(true, reader.HasRows); one.disConnect(); repo.destroy(id); }
public async void AddAnswerAsyncShouldAdd() { // arrange var options = new DbContextOptionsBuilder <PH_DbContext>() .UseInMemoryDatabase("AddAnswerAsyncShouldAdd") .Options; using var actContext = new PH_DbContext(options); var repo = new ForumRepo(actContext); User newUser = new User() { FirstName = "Rando", LastName = "Random", Email = "*****@*****.**", Phone = "1231231234", //PointAvailable = 100 }; Answer newAnswer = new Answer() { Author = newUser }; // act await repo.AddAnswerAsync(newAnswer); //actContext.SaveChanges(); // assert using var assertContext = new PH_DbContext(options); var member = assertContext.Answers.Select(m => newAnswer); Assert.NotNull(member); }
[Fact]//ForumController.cs public void ForumControllerTest1() { ForumRepo frepo = new ForumRepo(hContext); ForumMethods fmethods = new ForumMethods(frepo); ForumController fcon = new ForumController(fmethods); Thread thread = new Thread(); thread.Description = "Just a test"; thread = fcon.NewThread(thread).Value; var actionVar = fcon.GetThreads(); var expected = "Just a test"; var actual = actionVar.Value.ToList()[0].Description; Assert.Equal(expected, actual); }
[Fact]//ForumController.cs public void ForumControllerTest2() { ForumRepo frepo = new ForumRepo(hContext); ForumMethods fmethods = new ForumMethods(frepo); ForumController fcon = new ForumController(fmethods); Message message = new Message(); message.MessageBody = "Just another test"; message.ThreadId = 1; message = fcon.NewMessage(message).Value.ToList()[0]; var actionVar = fcon.GetMessages(message.ThreadId); var expected = "Just another test"; var actual = actionVar.Value.ToList()[0].MessageBody; Assert.Equal(expected, actual); }
public async void AddAnswerAsyncShouldThrowExcpetion() { // arrange var options = new DbContextOptionsBuilder <PH_DbContext>() .UseInMemoryDatabase("AddAnswerAsyncShouldThrowExcpetion") .Options; using var actContext = new PH_DbContext(options); var repo = new ForumRepo(actContext); var newAnswer = new Answer(); try { await repo.AddAnswerAsync(newAnswer); } catch (InvalidOperationException ex) { Assert.Equal("There is no user logged in.", ex.Message); } }
public async void AddQuestionAsyncShouldAdd() { // arrange var options = new DbContextOptionsBuilder <PH_DbContext>() .UseInMemoryDatabase("AddQuestionAsyncShouldAdd") .Options; using var actContext = new PH_DbContext(options); var repo = new ForumRepo(actContext); Users newUsers = new Users() { FirstName = "Rando", LastName = "Random", Email = "*****@*****.**", Username = "******", Password = "******", Phone = "1231231234", //PointAvailable = 100 }; actContext.Add(newUsers); actContext.SaveChanges(); var newQuestion = new Question() { AuthorName = "randorandom" }; // act await repo.AddQuestionAsync(newQuestion); //actContext.SaveChanges(); // assert using var assertContext = new PH_DbContext(options); var ques = assertContext.Questions.Select(q => newQuestion); Assert.NotNull(ques); }
public void store_and_delete_a_forum() { Connection one = new Connection(); Connection two = new Connection(); ForumRepo repo = new ForumRepo(new Connection()); //Create forum ForumModel forum = new ForumModel(); forum.name = "testname"; forum.description = "testdescription"; int id = repo.store(forum); one.Connect(); SqlCommand sqlCommand = new SqlCommand("select * from forum where name = 'testname' and description ='testdescription'", one.getConnection()); SqlDataReader reader = sqlCommand.ExecuteReader(); Assert.AreEqual(true, reader.HasRows); one.disConnect(); repo.destroy(id); two.Connect(); //Delete forum SqlCommand sqlCommandTwo = new SqlCommand("select * from forum where name = 'testname' and description ='testdescription'", two.getConnection()); SqlDataReader readerTwo = sqlCommandTwo.ExecuteReader(); Assert.AreEqual(false, readerTwo.HasRows); one.disConnect(); }
public ForumMethods(ForumRepo forumrepo) { this._forumRepo = forumrepo; }