public override void OnActionExecuting(ActionExecutingContext context) { AssignmentsController controller = (AssignmentsController)context.Controller; ILogger logger = controller.GetLogger(); try { var id = Guid.Parse(CryptographicHelper.SymmetricDecrypt(context.ActionArguments["id"].ToString())); var loggedInUser = context.HttpContext.User.Identity.Name; IAssignmentsService assignmentsService = (IAssignmentsService)context.HttpContext.RequestServices.GetService(typeof(IAssignmentsService)); if (loggedInUser != assignmentsService.GetSubmission(id).Member.Email&& !context.HttpContext.User.IsInRole("Teacher")) { IPHostEntry iphostinfo = Dns.GetHostEntry(Dns.GetHostName()); string ipaddress = Convert.ToString(iphostinfo.AddressList.FirstOrDefault(address => address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)); logger.LogInformation(loggedInUser + " on IP " + ipaddress + " tried to access submission with id " + id + ". Access was denied"); context.Result = new UnauthorizedObjectResult("Access Denied"); } } catch (Exception ex) { logger.LogInformation("Bad request when user tried to access a file"); context.Result = new BadRequestObjectResult("Bad Request"); } base.OnActionExecuting(context); }
public AssignmentsControllerTests() { var mockedAssignmentsService = new Mock <IDataService <AssignmentViewModel> >(); mockedAssignmentsService.Setup(aS => aS.ListEntities()).Returns(Task.FromResult(testAssignments.AsEnumerable())); mockedAssignmentsService.Setup(aS => aS.GetEntity(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(testAssignments.First())); mockedAssignmentsService.Setup(aS => aS.CreateEntity(It.IsAny <AssignmentViewModel>())).Returns(Task.FromResult(newTestAssignment)); mockedAssignmentsService.Setup(aS => aS.UpdateEntity(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <AssignmentViewModel>())).Returns(Task.FromResult(newTestAssignment)); mockedAssignmentsService.Setup(aS => aS.DeleteEntity(It.IsAny <string>(), It.IsAny <string>())); this.assignmentsController = new AssignmentsController(mockedAssignmentsService.Object); }
public AssignmentsControllerTest() { var store = new Mock <IUserStore <User> >(); _internshipAssignmentMock = new Mock <IInternshipAssignments>(); _addressDataMock = new Mock <IAddressData>(); _companyDataMock = new Mock <ICompanyData>(); _introductionConditionDataMock = new Mock <IIntroductionConditionData>(); _environmentsDataMock = new Mock <IEnviromentsData>(); _userManagerMock = new Mock <UserManager <User> >(store.Object, null, null, null, null, null, null, null, null); _assignmentsController = new AssignmentsController(_internshipAssignmentMock.Object, _environmentsDataMock.Object, _introductionConditionDataMock.Object, _companyDataMock.Object, _userManagerMock.Object, _addressDataMock.Object); }
public void GetAssignmentsTest() { Mock <Models.IAssignmentRepository> assignmentRepository = new Mock <Models.IAssignmentRepository>(); Mock <Models.IEnrolementRepository> enrolementRepository = new Mock <Models.IEnrolementRepository>(); Mock <Models.IProblemRepository> problemRepository = new Mock <Models.IProblemRepository>(); AssignmentsController controller = new AssignmentsController(assignmentRepository.Object, enrolementRepository.Object, problemRepository.Object); assignmentRepository.Setup(repository => repository.GetAssignments()).Returns(new List <Models.Assignment>() { }); ActionResult <IEnumerable <Models.Assignment> > result = controller.GetAssignments(); Assert.AreEqual(0, result.Value.ToArray().Length, "result.Length"); }
public void SetUp() { _contextMock = new Mock <IDbContext>(); var scores = new Collection <Score> { new Score { Assignment = new Assignment { Id = 1 } } }; _controller = new AssignmentsController(_contextMock.Object, new Participant { Id = 1, Scores = scores }); MapperConfig.Configure(); }
public void Setup() { _stubAssignmentService = new Mock <IAssignmentService>(); _assignmentsController = new AssignmentsController(_stubAssignmentService.Object); }
public void SetConstructorWithoutGivenParticipantGivesInvalidOperationFromTest() { _controller = new AssignmentsController(_contextMock.Object); }
public void Setup() { _repository = new Mock <IAssignmentRepository>(); _mapper = new Mock <IMapper>(); _controller = new AssignmentsController(_repository.Object, _mapper.Object); }
static void Main(string[] args) { // GET ALL EXERCISES ExercisesController exercisesController = new ExercisesController(); var exercises = exercisesController.GetAllExercises(); exercises.ForEach(exercise => { Console.WriteLine($"{exercise.Id}: {exercise.ExerciseName} -- {exercise.ExerciseLanguage}"); Console.WriteLine(" "); }); Pause(); // Find all the exercises in the database where the language is JavaScript. var selectExercises = exercisesController.GetExerciseByLanguage("C#"); selectExercises.ForEach(exercise => { Console.WriteLine($"{exercise.Id}: {exercise.ExerciseName} -- {exercise.ExerciseLanguage}"); Console.WriteLine(" "); }); Pause(); // Insert a new exercise into the database. Exercise exerciseToAdd = new Exercise { ExerciseName = "Personal Website", ExerciseLanguage = "ReactJS" }; //exercisesController.AddExercise(exerciseToAdd); Pause(); // Insert a new instructor into the database. Assign the instructor to an existing cohort. InstructorsController instructorsController = new InstructorsController(); Instructor instructorToAdd = new Instructor { FirstName = "Todd", LastName = "Packer", SlackHandle = "@tpDaddy", CohortId = 2, Specialty = "Hitting on Women" }; instructorsController.AddInstructor(instructorToAdd); Pause(); // Assign an existing exercise to an existing student. AssignmentsController assignmentsController = new AssignmentsController(); Assignment assignmentToAssign = new Assignment { StudentId = 1, InstructorId = 2, ExerciseId = 3 }; assignmentsController.AssignExercise(assignmentToAssign); Pause(); // Find all the students in the database. Include each student's cohort AND each student's list of exercises. StudentsController studentsController = new StudentsController(); var students = studentsController.GetAllStudents(); // HOW TO ONLY SHOW STUDENTS ONCE??? students.ForEach(student => { Console.WriteLine($"{student.Id}: {student.FirstName}{student.LastName} [{student.cohort.Title}] -- "); Console.WriteLine("Exercises:"); exercises.ForEach(ex => { Console.WriteLine($"{ex.ExerciseName} -- {ex.ExerciseLanguage}"); }); }); Pause(); }