public void AddDuplicateSchoolClass()
            {
                var duplicateSchoolClass = new SchoolClassEntity {Name = "F", SchoolClassEntityId = 1, Year = 1};

                var mockContext = new Mock<DatabaseSession>();
                var mockDBset = new Mock<DbSet<SchoolClassEntity>>();

                MockHelper<SchoolClassEntity>.MockDbset(ref mockDBset, _schoolClassesInDatabase);

                mockContext.Setup(table => table.Context.SchoolClasses).Returns(mockDBset.Object);

                var schoolClassService = new SchoolClassService(mockContext.Object);

                schoolClassService.AddSchoolClass(duplicateSchoolClass);
            }
        public void TestDuplicateClass()
        {
            var mockContext = new Mock<DatabaseSession>();
            var mockDBset = new Mock<DbSet<SchoolClassEntity>>();
            var mockModel = new SchoolClassEntity
            {
                Name = "Duplicate",
                Year = 1
            };

            MockHelper<SchoolClassEntity>.MockDbset(ref mockDBset, _teachersInDatabase);

            mockContext.Setup(table => table.Context.SchoolClasses).Returns(mockDBset.Object);

            var schoolClassValidator = new SchoolClassServiceValidator<SchoolClassEntity>(mockContext.Object);

            var validationResult = schoolClassValidator.Validate(mockModel);

            Assert.AreEqual(validationResult[1], string.Format(ErrorMessages.E000001, Labels.SchoolClass));
        }
        public void TestValidClass()
        {
            var mockContext = new Mock<DatabaseSession>();
            var mockDBset = new Mock<DbSet<SchoolClassEntity>>();
            var mockModel = new SchoolClassEntity
            {
                Name = "F",
                SchoolClassEntityId = 1,
                Year = 1
            };

            MockHelper<SchoolClassEntity>.MockDbset(ref mockDBset, _teachersInDatabase);

            mockContext.Setup(table => table.Context.SchoolClasses).Returns(mockDBset.Object);

            var schoolClassValidator = new SchoolClassServiceValidator<SchoolClassEntity>(mockContext.Object);

            var validationResult = schoolClassValidator.Validate(mockModel);

            Assert.IsNull(validationResult);
        }
Example #4
0
 public void AddSchoolClass(SchoolClassEntity entity)
 {
     _databaseSession.Context.SchoolClasses.Add(entity);
     _databaseSession.Context.SaveChanges();
 }