public async System.Threading.Tasks.Task QuestionnairePostAlreadyPresent() { //Arrange var context = TestingUtilities.CreateInMemoryDatabaseContext("PostContext1"); var testEntity = new Questionnaire() { Id = 0, StudentId = 0, ClassId = 0 }; context.Questionnaires.Add(testEntity); context.SaveChanges(); //mockDbContext.Setup(x => x.Questionnaires).Returns(DbContextMock.GetQueryableMockDbSet(questionnaireList)); var qController = new QuestionnaireController(context); //Act var result = await qController.PostQuestionnaire(testEntity); //Assert Assert.IsType <ConflictResult>(result.Result); }
public async System.Threading.Tasks.Task QuestionnairePostSuccesfull() { //Arrange var mockDbContext = new Mock <IntegratedCourseSystemContext>(); var questionnaireList = new List <Questionnaire> { }; mockDbContext.Setup(x => x.Questionnaires).Returns(DbContextMock.GetQueryableMockDbSet(questionnaireList)); var qController = new QuestionnaireController(mockDbContext.Object); var qToAdd = new Questionnaire { Id = 1, ClassId = 1, StudentId = 1 }; //Act var result = await qController.PostQuestionnaire(qToAdd); var resValue = result.Value; var resResult = result.Result; //Assert Assert.IsType <CreatedAtActionResult>(result.Result); Assert.Equal(1, mockDbContext.Object.Questionnaires.Count()); Assert.Equal(qToAdd, mockDbContext.Object.Questionnaires.ToList()[0]); }