public async Task GetQuestion_Lecturer_NoAccess()
        {
            Context
            .Setup(x => x.GetCurrentUserAsync())
            .ReturnsAsync(ModelsCreationHelper.CreateStudent);

            RepositoryQuestion
            .Setup(x => x.FindFirstAsync(It.IsAny <ISpecification <DatabaseQuestion> >()))
            .ReturnsAsync(ModelsCreationHelper.CreateDatabaseQuestion(lecturerId: 1));

            await Assert.ThrowsAsync <EducationSystemPublicException>
                (() => ServiceQuestion.GetQuestionAsync(999));
        }
Пример #2
0
        public async Task DeleteMaterial_Lecturer_NoAccess()
        {
            Context
            .Setup(x => x.GetCurrentUserAsync())
            .ReturnsAsync(ModelsCreationHelper.CreateLecturer);

            RepositoryMaterial
            .Setup(x => x.FindFirstAsync(It.IsAny <ISpecification <DatabaseMaterial> >()))
            .ReturnsAsync(ModelsCreationHelper.CreateDatabaseMaterial(ownerId: 1));

            await Assert.ThrowsAsync <EducationSystemPublicException>
                (() => ServiceMaterial.DeleteMaterialAsync(999));
        }
        private static DatabaseQuestion CreateDatabaseQuestion(int id, QuestionType type)
        {
            var question = new DatabaseQuestion
            {
                Id    = id,
                Type  = type,
                Theme = new DatabaseTheme {
                    Discipline = ModelsCreationHelper.CreateDatabaseDiscipline(),
                    ThemeTests = ModelsCreationHelper.CreateDatabaseTestThemes()
                }
            };

            question.Theme.ThemeTests.ForEach(x => x.Test = new DatabaseTest {
                IsActive = true
            });

            return(question);
        }
Пример #4
0
        public async Task GetTest_Student_NoAccess()
        {
            Context
            .Setup(x => x.GetCurrentUserAsync())
            .ReturnsAsync(ModelsCreationHelper.CreateStudent);

            RepositoryTest
            .Setup(x => x.FindFirstAsync(It.IsAny <ISpecification <DatabaseTest> >()))
            .ReturnsAsync(ModelsCreationHelper.CreateDatabaseTest(isActive: true, studentId: 1));

            await Assert.ThrowsAsync <EducationSystemPublicException>
                (() => ServiceTest.GetTestAsync(999));

            RepositoryTest
            .Setup(x => x.FindFirstAsync(It.IsAny <ISpecification <DatabaseTest> >()))
            .ReturnsAsync(ModelsCreationHelper.CreateDatabaseTest());

            await Assert.ThrowsAsync <EducationSystemPublicException>
                (() => ServiceTest.GetTestAsync(999));
        }
Пример #5
0
        public async Task DeleteTest()
        {
            Context
            .Setup(x => x.GetCurrentUserAsync())
            .ReturnsAsync(ModelsCreationHelper.CreateAdmin);

            RepositoryTest
            .Setup(x => x.FindFirstAsync(It.IsAny <ISpecification <DatabaseTest> >()))
            .ReturnsAsync(ModelsCreationHelper.CreateDatabaseTest());

            await ServiceTest.DeleteTestAsync(999);

            Context
            .Setup(x => x.GetCurrentUserAsync())
            .ReturnsAsync(ModelsCreationHelper.CreateLecturer);

            RepositoryTest
            .Setup(x => x.FindFirstAsync(It.IsAny <ISpecification <DatabaseTest> >()))
            .ReturnsAsync(ModelsCreationHelper.CreateDatabaseTest());

            await ServiceTest.DeleteTestAsync(999);
        }
        public async Task GetDiscipline()
        {
            RepositoryDiscipline
            .Setup(x => x.FindFirstAsync(It.IsAny <ISpecification <DatabaseDiscipline> >()))
            .ReturnsAsync(ModelsCreationHelper.CreateDatabaseDiscipline());

            Context
            .Setup(x => x.GetCurrentUserAsync())
            .ReturnsAsync(ModelsCreationHelper.CreateAdmin);

            await ServiceDiscipline.GetDisciplineAsync(999);

            Context
            .Setup(x => x.GetCurrentUserAsync())
            .ReturnsAsync(ModelsCreationHelper.CreateLecturer);

            await ServiceDiscipline.GetDisciplineAsync(999);

            Context
            .Setup(x => x.GetCurrentUserAsync())
            .ReturnsAsync(ModelsCreationHelper.CreateStudent);

            await ServiceDiscipline.GetDisciplineAsync(999);
        }
Пример #7
0
        public async Task DeleteMaterial_Admin()
        {
            var material  = ModelsCreationHelper.CreateDatabaseMaterial(ownerId: 2);
            var materials = new List <DatabaseMaterial> {
                material
            };

            Context
            .Setup(x => x.GetCurrentUserAsync())
            .ReturnsAsync(ModelsCreationHelper.CreateAdmin);

            RepositoryMaterial
            .Setup(x => x.FindFirstAsync(It.IsAny <ISpecification <DatabaseMaterial> >()))
            .ReturnsAsync(material);

            RepositoryMaterial
            .Setup(x => x.RemoveAsync(material, true))
            .Callback(() => materials.Remove(material))
            .Returns(Task.CompletedTask);

            await ServiceMaterial.DeleteMaterialAsync(999);

            Assert.Empty(materials);
        }