public async Task addLessonPlanAddsDeleteAssignmentDeletes()
        {
            //Double Test of Insert and Delete. Not ideal, see above.
            //arrange
            var newLessonPlan = new LessonPlanDTO()
            {
                StudentID = 5000,
                StartDate = DateTime.Now,
                EndDate   = DateTime.Now.AddMinutes(30)
            };

            //Act
            var addedLesson = await _repo.AddLessonPlan(newLessonPlan);

            //Assert
            //TODO: Build an equality function for this
            Assert.Equal(newLessonPlan.StudentID, addedLesson.StudentID);
            Assert.Equal(newLessonPlan.StartDate, addedLesson.StartDate);
            Assert.Equal(newLessonPlan.EndDate, addedLesson.EndDate);

            //Act2
            await _repo.DeleteAssignment(addedLesson.LessonID);

            var deletedLesson = await _repo.GetAssignment(addedLesson.LessonID);

            //Assert
            Assert.Null(deletedLesson);
        }
示例#2
0
        public async Task <IActionResult> PostLessonPlan([FromBody] LessonPlanDTO lessonPlan)
        {
            _logger.LogInformation($"PostLessonPlan() method called: {lessonPlan.StudentID}, {lessonPlan.StartDate.ToString()}, {lessonPlan.EndDate.ToString()}");
            var newLessonPlan = await _manager.InsertLessonPlan(lessonPlan);

            newLessonPlan.Links = BuildLessonPlanLinks(newLessonPlan);

            return(Created(newLessonPlan.Links.Where(p => p.Rel == "self").FirstOrDefault().Href, newLessonPlan));
        }
 public async Task InsertLessonPlanInvalidLessonPlanThrowsError()
 {
     //Arrange
     var lp = new LessonPlanDTO()
     {
         StudentID = -1
     };
     //Act/Assert
     await Assert.ThrowsAsync <HttpResponseException>(async() => await _manager.InsertLessonPlan(lp));
 }
        public async Task <LessonPlan> InsertLessonPlan(LessonPlanDTO lessonPlanDTO)
        {
            var lessonPlan = GetLessonPlanFromDTO(lessonPlanDTO, null);

            if (lessonPlan.IsValid())
            {
                var returnData = await _repo.AddLessonPlan(GetDTOFromLessonPlan(lessonPlan));

                return(GetLessonPlanFromDTO(returnData, null));
            }
            throw new HttpResponseException()
                  {
                      Status = 400, Value = "LessonPlan data is invalid. You should fix it and try again."
                  };
        }
        public async Task InsertLessonPlanInsertsValidLessonPlan()
        {
            //Arrange
            var lp = new LessonPlanDTO()
            {
                StudentID = 1,
                StartDate = DateTime.Now
            };

            //Act
            var returnedLP = await _manager.InsertLessonPlan(lp);

            //Assert
            Assert.NotNull(returnedLP);
        }
示例#6
0
        public async Task <LessonPlanDTO> AddLessonPlan(LessonPlanDTO lessonPlan)
        {
            //TODO: Data should validate prior to insert

            int            id;
            DateTimeOffset?startWithOffset = DateTimeOffsetConversion(lessonPlan.StartDate);
            DateTimeOffset?endWithOffset   = DateTimeOffsetConversion(lessonPlan.EndDate);

            using (var conn = new SqliteConnection(_connString))
            {
                id = conn.QuerySingle <int>(@"Insert into lessonPlan(studentID, startDate, endDate)
                                            values(@StudentID, @StartDate, @EndDate);
                                            select last_insert_rowid()", new { StudentID = lessonPlan.StudentID, StartDate = startWithOffset, EndDate = endWithOffset });
            }
            return(await this.GetLessonPlan(id));
        }
        public void GetLessonPlanFromDTOReturnsLessonPlan()
        {
            //Arrange
            var dto = new LessonPlanDTO()
            {
                LessonID  = 1,
                StartDate = DateTime.Now,
                EndDate   = DateTime.Now,
                StudentID = 1
            };

            //Act
            var lessonPlan = _manager.GetLessonPlanFromDTO(dto, null);

            //Assert
            Assert.IsType <LessonPlan>(lessonPlan);
        }
        //Convert a lessonPlanDTO to a lessonPlan
        public LessonPlan GetLessonPlanFromDTO(LessonPlanDTO lessonPlanDTO, IEnumerable <AssignmentDTO> assignmentDTOs)
        {
            //don't map it if null
            if (lessonPlanDTO == null)
            {
                return(null);
            }

            //Provide Custom Mapping Here
            var plan = new LessonPlan()
            {
                Id        = lessonPlanDTO.LessonID,
                StudentID = lessonPlanDTO.StudentID,
                StartDate = lessonPlanDTO.StartDate,
                EndDate   = lessonPlanDTO.EndDate,
            };

            //plan.Assignments.AddRange(MapAllAssignmentsFromDTOs(assignmentDTOs.Where(p => p.lessonID == plan.Id)));
            plan.Assignments.AddRange(MapAllAssignmentsFromDTOs(assignmentDTOs));
            return(plan);
        }
        public void GetLessonPlanFromDTOMapsDataProperly()
        {
            //Arrange
            var dto = new LessonPlanDTO()
            {
                LessonID  = 1,
                StartDate = DateTime.Now,
                EndDate   = DateTime.Now,
                StudentID = 1
            };
            var assignements = new List <AssignmentDTO>()
            {
                new AssignmentDTO()
                {
                    assignmentID = 1, lessonID = 1
                },
                new AssignmentDTO()
                {
                    assignmentID = 2, lessonID = 1
                },
                new AssignmentDTO()
                {
                    assignmentID = 3, lessonID = 2
                },
            };


            //Act
            var lessonPlan = _manager.GetLessonPlanFromDTO(dto, assignements.AsEnumerable());

            //Assert
            Assert.Equal(dto.LessonID, lessonPlan.Id);
            Assert.Equal(dto.StudentID, lessonPlan.StudentID);
            Assert.Equal(dto.StartDate, lessonPlan.StartDate);
            Assert.Equal(dto.EndDate, lessonPlan.EndDate);
            Assert.Equal(3, lessonPlan.Assignments.Count);
            Assert.Equal(2, lessonPlan.Assignments.Where(p => p.Id == 3).Select(s => s.LessonID).First()); //assignment = 3 when lesson = 2
        }