Exemplo n.º 1
0
        public void UpdateMark(Mark mark)
        {
            if (this.Subject != null)
            {
                mark.Subject = this.Subject;
            }

            //if (this.Value != null)
            //{
                mark.Value = this.Value;
            //}
        }
        public void AddingSingleMarkWithENullSubjectMustThrowArgumentExceptionTest()
        {
            const decimal VALUE = 2.00m;
            var mark = new Mark()
            {
                Subject = null,
                Value = VALUE
            };

            //act
            dbContext.Set<Mark>().Add(mark);
            dbContext.SaveChanges();
        }
        public void AddingSingleMarkEntryTest()
        {
            //arrange
            const string SUBJECT = "Math";
            const decimal VALUE = 2.00m;
            var mark = new Mark() 
            {
                Subject = SUBJECT,
                Value = VALUE
            };
            
            //act
            dbContext.Set<Mark>().Add(mark);
            dbContext.SaveChanges();

            //assert
            var actual = (mark.Subject == SUBJECT && mark.Value == VALUE && mark.MarkId > 0);
            var expected = true;
            Assert.AreEqual(expected,actual);
        }
        public void AddingSingleStudentEntryTest()
        {
            //arrange
            const string Subject = "Math";
            const decimal Value = 2.00m;
            const int Age = 10;
            const string FirstName = "Nikolay";
            const string LastName = "Kostadinov";
            const int Grade = 4;
            var mark = new Mark()
            {
                Subject = Subject,
                Value = Value
            };

            var student = new Student()
            {
                Age = Age,
                FirstName = FirstName,
                LastName = LastName,
                Grade = Grade,
                Marks = new List<Mark>() { mark },
            };

            //act
            dbContext.Set<Student>().Add(student);
            dbContext.SaveChanges();

            //assert
            var studentMarks = student.Marks.ToList();
            var actual =
                student.Age == Age &&
                student.Grade == Grade &&
                student.FirstName == FirstName &&
                student.LastName == LastName &&
                student.Marks.Count == 1 &&
                studentMarks[0].Subject == mark.Subject &&
                studentMarks[0].Value == mark.Value;
            Assert.IsTrue(actual);
        }
Exemplo n.º 5
0
        // PUT api/Marks/5
        public HttpResponseMessage Put(int id, Mark mark)
        {
            //var MarkEntity = db.Get(id);
            this.db.Update(id, mark);

            return Request.CreateResponse(HttpStatusCode.OK);
        }
        public void AddingSingleStudentEntryWithSchoolTest()
        {
            //arrange
            const string Subject = "Math";
            const decimal Value = 2.00m;
            const int Age = 10;
            const string FirstName = "Nikolay";
            const string LastName = "Kostadinov";
            const int Grade = 4;
            var mark = new Mark()
            {
                Subject = Subject,
                Value = Value
            };

            var school = new School()
            {
                Name = "Petko Rosen",
                Location = "Meden Rudnik",
            };

            var student = new Student()
            {
                Age = Age,
                FirstName = FirstName,
                LastName = LastName,
                Grade = Grade,
                Marks = new List<Mark>() { mark },
                School = school,
            };

            school.Students.Add(student);

            //act
            dbContext.Set<School>().Add(school);
            dbContext.Set<Student>().Add(student);
            dbContext.SaveChanges();

            //assert
            var studentMarks = student.Marks.ToList();
            var actual =
                student.Age == Age &&
                student.Grade == Grade &&
                student.FirstName == FirstName &&
                student.LastName == LastName &&
                student.Marks.Count == 1 &&
                studentMarks[0].Subject == mark.Subject &&
                studentMarks[0].Value == mark.Value;
            var expected = true;
            Assert.AreEqual(expected, actual);
        }
        public void AddingSingleStudentEntryWithSchoolThanDeleteStudentTest()
        {
            //arrange
            const string Subject = "Math";
            const decimal Value = 2.00m;
            const int Age = 10;
            const string FirstName = "Nikolay";
            const string LastName = "Kostadinov";
            const int Grade = 4;
            var mark = new Mark()
            {
                Subject = Subject,
                Value = Value
            };

            var school = new School()
            {
                Name = "Petko Rosen",
                Location = "Meden Rudnik",
            };

            var student = new Student()
            {
                Age = Age,
                FirstName = FirstName,
                LastName = LastName,
                Grade = Grade,
                Marks = new List<Mark>() { mark },
                School = school,
            };

            school.Students.Add(student);

            dbContext.Set<School>().Add(school);
            dbContext.Set<Student>().Add(student);
            dbContext.Set<Mark>().Add(mark);
            dbContext.SaveChanges();
            
            //act

            var actual = dbContext.Set<Student>().Where(x => x.StudentId == student.StudentId).FirstOrDefault();

            Assert.AreEqual(student, actual);

            dbContext.Set<Student>().Remove(student);
            dbContext.SaveChanges();
            
            //assert


            actual = dbContext.Set<Student>().Where(x => x.StudentId == student.StudentId).FirstOrDefault();   
            Assert.AreEqual(null, actual);
        }
        public void AddingSingleMarkWithOutOfHighRangeValueMustThrowArgumentExceptionTest()
        {
            const string SUBJECT = "Math";
            const decimal VALUE = 6.50m;
            var mark = new Mark()
            {
                Subject = SUBJECT,
                Value = VALUE
            };

            //act
            dbContext.Set<Mark>().Add(mark);
            dbContext.SaveChanges();
        }