public void Get_GetAllTest_CheckForCorrectDescendingOrder() { FakeRepository<Thread> threadFakeRepository = new FakeRepository<Thread>(); FakeRepository<Category> categoryFakeRepository = new FakeRepository<Category>(); FakeRepository<User> userFakeRepository = new FakeRepository<User>(); User user = new User() { AuthCode = "0123456789012345678901234567890123456789", Username = "******", Nickname = "TestNickname", SessionKey = "0SuGqVGqRwitYtijDvHlVfHGotklitbwHdYFkgwIRcIQjRASPQ" }; for (int i = 1; i <= 5; i++) { Thread thread = new Thread() { Title = string.Format("Test title {0}", i), Creator = user, Content = string.Format("Test content {0}", i), DateCreated = DateTime.Now.AddDays(i) }; user.Threads.Add(thread); } userFakeRepository.entities.Add(user); ThreadsController threadsController = new ThreadsController( categoryFakeRepository, threadFakeRepository, userFakeRepository); SetupController(threadsController); var allThreads = threadsController.GetAll("0SuGqVGqRwitYtijDvHlVfHGotklitbwHdYFkgwIRcIQjRASPQ").ToArray<ThreadModel>(); for (int i = 0; i < allThreads.Length - 1; i++) { int result = allThreads[i].DateCreated.CompareTo(allThreads[i + 1].DateCreated); Assert.IsTrue(result > 0); } }
public void Get_GetAllTest_ValidExecutionOfTheMethod() { FakeRepository<Thread> threadFakeRepository = new FakeRepository<Thread>(); FakeRepository<Category> categoryFakeRepository = new FakeRepository<Category>(); FakeRepository<User> userFakeRepository = new FakeRepository<User>(); User user = new User() { AuthCode = "0123456789012345678901234567890123456789", Username = "******", Nickname = "TestNickname", SessionKey = "0SuGqVGqRwitYtijDvHlVfHGotklitbwHdYFkgwIRcIQjRASPQ" }; Thread thread = new Thread() { Title = "Test title", Creator = user, Content = "Test Content", DateCreated = DateTime.Now }; user.Threads.Add(thread); userFakeRepository.entities.Add(user); ThreadsController threadsController = new ThreadsController( categoryFakeRepository, threadFakeRepository, userFakeRepository); SetupController(threadsController); var allThreads = threadsController.GetAll("0SuGqVGqRwitYtijDvHlVfHGotklitbwHdYFkgwIRcIQjRASPQ").ToList<ThreadModel>(); int expectedThreadCount = 1; Assert.AreEqual(expectedThreadCount, allThreads.Count); }
public void Get_GetAllTest_InvalidSessionKey_NoUserWithSuchSessionKey() { FakeRepository<Thread> threadFakeRepository = new FakeRepository<Thread>(); FakeRepository<Category> categoryFakeRepository = new FakeRepository<Category>(); FakeRepository<User> userFakeRepository = new FakeRepository<User>(); ThreadsController threadsController = new ThreadsController( categoryFakeRepository, threadFakeRepository, userFakeRepository); SetupController(threadsController); User user = new User() { AuthCode = "0123456789012345678901234567890123456789", Username = "******", Nickname = "TestNickname", SessionKey = "0SuGqVGqRwitYtijDvHlVfHGotklitbwHdYFkgwIRcIQjRASPQ" }; userFakeRepository.entities.Add(user); threadsController.GetAll("1InvalidSessionKeyvHlVfHGotklitbwHdYFkgwIRcIQjRAPQ"); }