コード例 #1
0
        public void AddTest_AddOneVailid()
        {
            var subject = "Test subject";
            var mark = new Mark()
            {
                Subject = subject,
                StudentId = 1
            };

            var addedMark = this.marksRepo.Add(mark);
            var foundMark = this.dbContext.Set<Mark>().Find(addedMark.Id);
            Assert.IsNotNull(foundMark);
            Assert.AreEqual(subject, foundMark.Subject);
        }
コード例 #2
0
        public HttpResponseMessage PostStudents(StudentDetails model)
        {
            List<Mark> newMarks = new List<Mark>();
            foreach (var mark in model.Marks)
            {
                var markEntity = new Mark()
                {
                    Subject = mark.Subject,
                    Value = mark.Value
                };

                newMarks.Add(markEntity);

            }
           
            var entityToAdd = new Student()
            {
                FirstName = model.FirstName,
                LastName = model.LastName,
                Age = model.Age,
                Grade = model.Grade,
                SchoolId = model.SchoolId,
                Marks = newMarks
            };
            var createdEntity = this.studentsRepository.Add(entityToAdd);

            var createdModel = new StudentDetails()
            {
                Id = createdEntity.Id,
                FirstName = createdEntity.FirstName,
                LastName = createdEntity.LastName,
                Grade = createdEntity.Grade,
                Age = createdEntity.Age,
                SchoolId = createdEntity.SchoolId
            };

            

            var response = Request.CreateResponse<StudentDetails>(HttpStatusCode.Created, createdModel);
            var resourceLink = Url.Link("DefaultApi", new { id = createdModel.Id });

            response.Headers.Location = new Uri(resourceLink);
            return response;
        }
コード例 #3
0
        public StudentsController()
        {
            this.Students = new List<Student>();
            for (int i = 1; i < 15; i++)
            {
                Student student = new Student();
                student.Id = i;
                student.Name = "Student #" + i;
                student.Grade = i + rand.Next(5);

                List<Mark> marks = new List<Mark>();
                for (int j = 0; j < 4; j++)
                {
                    Mark mark = new Mark();
                    mark.Subject = "Subject #" + rand.Next(5);
                    mark.Score = j + rand.NextDouble();
                    marks.Add(mark);
                }

                student.Marks = marks;
                this.Students.Add(student);
            }
        }
コード例 #4
0
        public void AllTest_GetAll_WhereAllIs2()
        {
            int alreadyIn = this.marksRepo.All().Count();

            var subject = "Test subject";
            var mark = new Mark()
            {
                Subject = subject,
                StudentId = 1
            };

            var secondMark = new Mark()
            {
                Subject = subject,
                StudentId = 1
            };

            var addedMark = this.marksRepo.Add(mark);
            var secondAddedMark = this.marksRepo.Add(secondMark);

            var foundMarks = this.marksRepo.All().ToList();
            Assert.IsNotNull(foundMarks);
            Assert.AreEqual(alreadyIn + 2, foundMarks.Count);
        }
コード例 #5
0
        public void RemoveTest_OneAddOneRemove()
        {
            int alreadyIn = this.marksRepo.All().Count();

            var subject = "Test subject";
            var mark = new Mark()
            {
                Subject = subject,
                StudentId = 1
            };

            var addedMark = this.marksRepo.Add(mark);
            bool isDeleted = this.marksRepo.Delete(addedMark.Id);

            Assert.IsTrue(isDeleted);
            Assert.AreEqual(alreadyIn, this.marksRepo.All().Count());
        }