public Course CreateCourse(string name, int credits)
        {
            var course = new Course
            {
                Name = name.Crop(50),
                Credits = credits,
            };

            using (var db = _contextFactory.CreateContext())
            {
                db.Courses.Add(course);
                db.Save();
                return course;
            }
        }
        public void NotValidIfNameIsGreaterThan50()
        {
            // Arrange
            var entity = new Course
            {
                Name = new string('A', 51)
            };

            // Act
            var validationResults = new List<ValidationResult>();
            var isValid = Validator.TryValidateObject(entity, new ValidationContext(entity), validationResults, true);

            // Assert
            Assert.False(isValid);
            Assert.Single(validationResults);
            Assert.Single(validationResults[0].MemberNames);
            Assert.Equal("Name", validationResults[0].MemberNames.ElementAt(0));
        }
        public void NotValidIfCreditsAreLessThanZero()
        {
            // Arrange
            var entity = new Course
            {
                Name = "Test course",
                Credits = -1
            };

            // Act
            var validationResults = new List<ValidationResult>();
            var isValid = Validator.TryValidateObject(entity, new ValidationContext(entity), validationResults, true);

            // Assert
            Assert.False(isValid);
            Assert.Single(validationResults);
            Assert.Single(validationResults[0].MemberNames);
            Assert.Equal("Credits", validationResults[0].MemberNames.ElementAt(0));
        }
        public void IsValid()
        {
            // Arrange
            var entity = new Course
            {
                Id = 1,
                Name = "Test course",
                Credits = 5
            };

            // Act
            var validationResults = new List<ValidationResult>();
            var isValid = Validator.TryValidateObject(entity, new ValidationContext(entity), validationResults, true);

            // Assert
            Assert.True(isValid);
            Assert.NotNull(validationResults);
            Assert.Empty(validationResults);
        }
        public void DefaultValues()
        {
            // Arrange
            var entity = new Course
            {
                Name = "Test course"
            };

            // Act
            var validationResults = new List<ValidationResult>();
            var isValid = Validator.TryValidateObject(entity, new ValidationContext(entity), validationResults, true);

            // Assert
            Assert.True(isValid);
            Assert.NotNull(validationResults);
            Assert.Empty(validationResults);
            Assert.Equal(0, entity.Id);
            Assert.Equal(0, entity.Credits);
        }