public async Task DeleteQuestionsFormAssignmentAsync_QuestionsFormAssignmentIsDeleted()
        {
            // Arrange
            await db.AddRangeAsync(seedAssignments);

            await db.SaveChangesAsync();

            int questionId = 2;

            var deletedQuestionsFormAssignment = new QuestionsFormAssignments()
            {
                FormId = 1, QuestionOrderNum = 2, QuestionId = questionId, QuestionTypeOrderNum = 0
            };

            var expectedQuestionsFormAssignment = seedAssignments.Where(a => a.QuestionId != questionId);

            // Act
            await service.Delete(deletedQuestionsFormAssignment);

            // Assert
            var actualQuestionsFormAssignment = await db.QuestionsFormAssignments.ToListAsync();

            Assert.Equal(
                expectedQuestionsFormAssignment.OrderBy(o => o.QuestionId).Select(o => o.QuestionId),
                actualQuestionsFormAssignment.OrderBy(o => o.QuestionId).Select(o => o.QuestionId));
        }
コード例 #2
0
        public async Task <QuestionsFormAssignments> Add(QuestionsFormAssignments question)
        {
            _context.QuestionsFormAssignments.Add(question);
            await _context.SaveChangesAsync();

            return(question);
        }
コード例 #3
0
        public async Task <QuestionsFormAssignments> Delete(QuestionsFormAssignments question)
        {
            var deletedQuestion = await _context.QuestionsFormAssignments.FindAsync(question.FormId, question.QuestionOrderNum);

            _context.QuestionsFormAssignments.Remove(deletedQuestion);
            await _context.SaveChangesAsync();

            return(deletedQuestion);
        }
        public async Task AddQuestionsFormAssignmentAsync_QuestionsFormAssignmentAssignmentIsAdded()
        {
            // Arrange
            int formId             = 2;
            int qon                = 4;
            int questionId         = 7;
            var expectedAssignment = new QuestionsFormAssignments()
            {
                FormId = 2, QuestionOrderNum = 4, QuestionId = 7, QuestionTypeOrderNum = 0
            };

            // Act
            await service.Add(expectedAssignment);

            // Assert
            var actualAssignment = await db.QuestionsFormAssignments.FirstOrDefaultAsync(o => o.FormId == formId && o.QuestionOrderNum == qon && o.QuestionId == questionId);

            Assert.Equal(expectedAssignment, actualAssignment);
        }