public void CreateQuestionCreatesQuestion() { //arrange var options = new DbContextOptionsBuilder <DatLib.Entities.ecgbhozpContext>() .UseInMemoryDatabase("CreateQuestionCreatesQuestion") .Options; int questionId = 1; string questionString = "This is Question?"; int titleId = 1; var questionLog = new LogLibMod.Question { QuestionId = questionId, QuestionString = questionString, TitleId = titleId }; using var actContext = new DatLib.Entities.ecgbhozpContext(options); var repo = new CreateQuizRepository(actContext); //act repo.CreateQuestion(questionLog); repo.Save(); using var assertContext = new DatLib.Entities.ecgbhozpContext(options); var question = assertContext.Question.FirstOrDefault(); //assert Assert.Equal(expected: questionId + questionString + titleId, actual: question.QuestionId + question.QuestionString + question.TitleId); }
public void CreateTitleCreatesTitle() { //arrange var options = new DbContextOptionsBuilder <DatLib.Entities.ecgbhozpContext>() .UseInMemoryDatabase("SearchUsersReturnsAllCustomers") .Options; int titleId = 1; string titleString = "TitleString"; int creatorId = 1; var titleLog = new LogLibMod.Title() { TitleId = titleId, TitleString = titleString, CreatorId = creatorId }; using var actContext = new DatLib.Entities.ecgbhozpContext(options); var repo = new CreateQuizRepository(actContext); //act repo.CreateTitle(titleLog); repo.Save(); using var assertContext = new DatLib.Entities.ecgbhozpContext(options); var title = assertContext.Title.FirstOrDefault(); //assert Assert.Equal(expected: titleId + titleString + creatorId, actual: title.TitleId + title.TitleString + title.CreatorId); }
public void CreateCategoryCreatesCategory() { //arrange var options = new DbContextOptionsBuilder <DatLib.Entities.ecgbhozpContext>() .UseInMemoryDatabase("CreateCategoryCreatesCategory") .Options; int categoryId = 1; string categoryString = "CategoryString"; string categoryDescription = "Desc"; int titleId = 1; var categoryLog = new LogLibMod.Category { CategoryId = categoryId, CategoryString = categoryString, CategoryDescription = categoryDescription, TitleId = titleId }; using var actContext = new DatLib.Entities.ecgbhozpContext(options); var repo = new CreateQuizRepository(actContext); //act repo.CreateCategory(categoryLog); repo.Save(); using var assertContext = new DatLib.Entities.ecgbhozpContext(options); var category = assertContext.Category.FirstOrDefault(); //assert Assert.Equal(expected: categoryId + categoryString + categoryDescription + titleId, actual: category.CategoryId + category.CategoryString + category.CategoryDescription + category.TitleId); }
public void SearchUsersReturnsAllUsers() { //arrange //configure the context var options = new DbContextOptionsBuilder <DatLib.Entities.ecgbhozpContext>() .UseInMemoryDatabase("SearchUsersReturnsAllCustomers") .Options; //create the context variable and initialize using var arrangeContext = new DatLib.Entities.ecgbhozpContext(options); //make a test user arrangeContext.User.Add(userEnt); arrangeContext.SaveChanges(); using var actContext = new DatLib.Entities.ecgbhozpContext(options); var repo = new UserRepository(actContext /*, new NullLogger<UserRepository>()*/); //act List <LogLib.Models.User> actual = repo.SearchUsers().ToList(); //assert Assert.NotEmpty(actual); }
public void CreateAnswerCreatesAnswer() { //arrange var options = new DbContextOptionsBuilder <DatLib.Entities.ecgbhozpContext>() .UseInMemoryDatabase("CreateAnswerCreatesAnswer") .Options; int answerId = 1; string answerString = "Answer String"; int weight = 1; int categoryId = 1; int questionId = 1; var answerLog = new LogLibMod.Answer { AnswerId = answerId, AnswerString = answerString, Weight = weight, CategoryId = categoryId, QuestionId = questionId }; using var actContext = new DatLib.Entities.ecgbhozpContext(options); var repo = new CreateQuizRepository(actContext); //act repo.CreateAnswer(answerLog); repo.Save(); using var assertContext = new DatLib.Entities.ecgbhozpContext(options); var answer = assertContext.Answer.FirstOrDefault(); //assert Assert.Equal(expected: answerId + answerString + weight + categoryId + questionId, actual: answer.AnswerId + answer.AnswerString + answer.Weight + answer.CategoryId + answer.QuestionId); }
public void SearchUserByNameShouldReturnUser(string firstName, string lastName, bool pass) { //arrange var options = new DbContextOptionsBuilder <DatLib.Entities.ecgbhozpContext>() .UseInMemoryDatabase("SearchUserByNameShouldReturnUser") .Options; //create the context variable and initialize using var arrangeContext = new DatLib.Entities.ecgbhozpContext(options); //act if (!arrangeContext.User.Contains(userEnt)) { arrangeContext.User.Add(userEnt); arrangeContext.SaveChanges(); } using var actContext = new DatLib.Entities.ecgbhozpContext(options); var repo = new UserRepository(actContext /*, new NullLogger<UserRepository>()*/); List <LogLib.Models.User> actual = repo.SearchUsers(firstName, lastName).ToList(); //assert if (pass) { Assert.Equal(actual: actual.First().FirstName + actual.First().LastName, expected: userEnt.FirstName + userEnt.LastName); } else { Assert.Empty(actual); } }
public void DeleteUserThrowsErrorWhenUserNotFound() { //arrange var options = new DbContextOptionsBuilder <DatLib.Entities.ecgbhozpContext>() .UseInMemoryDatabase("DeleteUserThrowsErrorWhenUserNotFound") .Options; using var arrangeContext = new DatLib.Entities.ecgbhozpContext(options); int id = -101; //arrangeContext.User.Add(userEnt); arrangeContext.SaveChanges(); using var actContext = new DatLib.Entities.ecgbhozpContext(options); var repo = new UserRepository(actContext); //act Exception ex = Assert.Throws <ArgumentNullException>(() => repo.DeleteUser(id)); //repo.Save(); //assert //using var assertContext = new DatLib.Entities.ecgbhozpContext(options); Assert.Equal("Value cannot be null.", ex.Message); }
public void DeleteUserDeletesUser() { //arrange var options = new DbContextOptionsBuilder <DatLib.Entities.ecgbhozpContext>() .UseInMemoryDatabase("DeleteUserDeletesUser") .Options; using var arrangeContext = new DatLib.Entities.ecgbhozpContext(options); int id = userEnt.UserId; arrangeContext.User.Add(userEnt); arrangeContext.SaveChanges(); using var actContext = new DatLib.Entities.ecgbhozpContext(options); var repo = new UserRepository(actContext); //act repo.DeleteUser(id); repo.Save(); //assert using var assertContext = new DatLib.Entities.ecgbhozpContext(options); Assert.Null(assertContext.User.FirstOrDefault(u => u.UserId == id)); }
public void GetQuizByNameOrIdReturnsTitleByTitle() { //arrange var options = new DbContextOptionsBuilder <DatLib.Entities.ecgbhozpContext>() .UseInMemoryDatabase("GetQuizByNameOrIdReturnsTitleByTitle") .Options; using var arrangeContext = new DatLib.Entities.ecgbhozpContext(options); //int Id = 102; string testTitle = "TestTitle3"; arrangeContext.Title.Add(new DatLib.Entities.Title { TitleId = 101, TitleString = "TestTitle1", CreatorId = 51 }); arrangeContext.Title.Add(new DatLib.Entities.Title { TitleId = 102, TitleString = "testTitle2", CreatorId = 502 }); arrangeContext.Title.Add(new DatLib.Entities.Title { TitleId = 103, TitleString = testTitle, CreatorId = 53 }); arrangeContext.Title.Add(new DatLib.Entities.Title { TitleId = 104, TitleString = testTitle, CreatorId = 54 }); arrangeContext.SaveChanges();//save the changes before running the test! //act using var actContext = new DatLib.Entities.ecgbhozpContext(options); var repo = new TakeAQuizRepository(actContext); var actual = repo.GetQuizByNameOrId(title: testTitle).ToList(); //assert Assert.Equal(expected: 2, actual: actual.Count); }
public void GetQuizReturnsNullWithNoParams() { //arrange var options = new DbContextOptionsBuilder <DatLib.Entities.ecgbhozpContext>() .UseInMemoryDatabase("GetQuizReturnsNullWithNoParams") .Options; using var arrangeContext = new DatLib.Entities.ecgbhozpContext(options); using var actContext = new DatLib.Entities.ecgbhozpContext(options); var repo = new TakeAQuizRepository(actContext); //act var actual = repo.GetQuiz(); //assert Assert.Null(actual); }
public void GetResultsGetsResults() { //arrange //configure the context var options = new DbContextOptionsBuilder <DatLib.Entities.ecgbhozpContext>() .UseInMemoryDatabase("GetResultsGetsResults") .Options; using var arrangeContext = new DatLib.Entities.ecgbhozpContext(options); int resultId = 1; int score = 5; int takerId = 1; int titleId = 1; var resultEnt = new DatLib.Entities.Result { ResultId = resultId, Score = score, TakerId = takerId, TitleId = titleId }; arrangeContext.Result.Add(resultEnt); arrangeContext.SaveChanges(); using var actContext = new DatLib.Entities.ecgbhozpContext(options); var repo = new ResultRepository(actContext /*, new NullLogger<UserRepository>()*/); //act List <LogLib.Models.Result> actual = repo.GetResults(resultId).ToList(); //assert Assert.NotEmpty(actual); }
public void RegisterNewUserMakesNewUser() { //arrange var options = new DbContextOptionsBuilder <DatLib.Entities.ecgbhozpContext>() .UseInMemoryDatabase("RegisterNewUserMakesNewUser") .Options; //create the context variable and initialize using var actContext = new DatLib.Entities.ecgbhozpContext(options); //act var repo = new UserRepository(actContext); repo.RegisterNewUser(userLog); repo.Save(); var actual = actContext.User.FirstOrDefault(); //assert Assert.NotNull(actual); }