示例#1
0
        public async Task GetMaterial()
        {
            RepositoryMaterial
            .Setup(x => x.FindFirstAsync(It.IsAny <ISpecification <DatabaseMaterial> >()))
            .ReturnsAsync(ModelsCreationHelper.CreateDatabaseMaterial(ownerId: 2));

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

            var material = await ServiceMaterial.GetMaterialAsync(999);

            Assert.Equal(2, material.OwnerId);

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

            material = await ServiceMaterial.GetMaterialAsync(999);

            Assert.Equal(2, material.OwnerId);

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

            material = await ServiceMaterial.GetMaterialAsync(999);

            Assert.Equal(2, material.OwnerId);
        }
 public async Task <IActionResult> GetMaterial([FromRoute] int id)
 {
     return(await Ok(() => _serviceMaterial.GetMaterialAsync(id)));
 }