// GET: Assignment
        public ActionResult Index(string sortingOrder)
        {
            var userID  = Guid.Parse(User.Identity.GetUserId());
            var service = new AssignmentService(userID);

            //var model = service.GetAllAssignments();

            ViewBag.SortingSchoolName = string.IsNullOrEmpty(sortingOrder) ? "SchoolName" : "";
            ViewBag.SortingScoutName  = string.IsNullOrEmpty(sortingOrder) ? "ScoutName" : "";
            ViewBag.SortingCompleted  = string.IsNullOrEmpty(sortingOrder) ? "Completed" : "";

            var assignments = from assignment in service.GetAllAssignments() select assignment;

            switch (sortingOrder)
            {
            case "SchoolName":
                assignments = assignments.OrderBy(assignment => assignment.School.SchoolName);
                break;

            case "ScoutName":
                assignments = assignments.OrderBy(assignment => assignment.Scout.LastName);
                break;

            case "Completed":
                assignments = assignments.OrderBy(assignment => assignment.Completed);
                break;
            }

            return(View(assignments.ToList()));

            //return View(model);
        }
예제 #2
0
        public HttpResponseMessage GetAllAssignments()
        {
            ItemsResponse <Assignment> response = new ItemsResponse <Assignment>();

            response.Items = AssignmentService.GetAllAssignments();

            return(Request.CreateResponse(response));
        }
예제 #3
0
        public void ReturnAssignments()
        {
            // Arrange
            var data = this.GetData();

            var mockedSet = new Mock <DbSet <Assignment> >();

            mockedSet.As <IQueryable <Assignment> >().Setup(m => m.Provider).Returns(data.Provider);
            mockedSet.As <IQueryable <Assignment> >().Setup(m => m.Expression).Returns(data.Expression);
            mockedSet.As <IQueryable <Assignment> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockedSet.As <IQueryable <Assignment> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var contextMock = new Mock <ApplicationDbContext>();

            contextMock.Setup(c => c.Assignments).Returns(mockedSet.Object);

            var service = new AssignmentService(contextMock.Object);

            // Act
            var result = service.GetAllAssignments();

            // Assert
            CollectionAssert.AreEqual(data.ToList(), result.ToList());
        }
예제 #4
0
        public void CallContextAssignmentsOnce()
        {
            // Arrange
            var data = this.GetData();

            var mockedSet = new Mock <DbSet <Assignment> >();

            mockedSet.As <IQueryable <Assignment> >().Setup(m => m.Provider).Returns(data.Provider);
            mockedSet.As <IQueryable <Assignment> >().Setup(m => m.Expression).Returns(data.Expression);
            mockedSet.As <IQueryable <Assignment> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockedSet.As <IQueryable <Assignment> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var contextMock = new Mock <ApplicationDbContext>();

            contextMock.Setup(c => c.Assignments).Returns(mockedSet.Object);

            var service = new AssignmentService(contextMock.Object);

            // Act
            service.GetAllAssignments();

            // Assert
            contextMock.Verify(s => s.Assignments, Times.Once);
        }