public string InsertInstructor(Instructor instructor)
        {
            var errors = new List<string>();
            var repository = new InstructorRepository();
            var service = new InstructorService(repository);
            service.InsertInstructor(instructor, ref errors);
            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
        public void InsertInstructorTest()
        {
            //// Arrange
            var errors = new List<string>();
            var mockRepository = new Mock<IInstructorRepository>();
            var instructorService = new InstructorService(mockRepository.Object);

            //// Act
            instructorService.InsertInstructor(null, ref errors);

            //// Assert
            Assert.AreEqual(1, errors.Count);
        }
        public void InsertInstructorTest3()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<IInstructorRepository>();
            var instructorService = new InstructorService(mockRepository.Object);
            var instructor = new Instructor { FirstName = string.Empty };

            //// Act
            instructorService.InsertInstructor(instructor, ref errors);

            //// Assert
            Assert.AreEqual(1, errors.Count);
        }
Esempio n. 4
0
        public void InsertInstructorTest()
        {
            //// Arranage
            var errors = new List<string>();

            Mock<IInstructorRepository> mockRepository = new Mock<IInstructorRepository>();
            InstructorService iserv = new InstructorService(mockRepository.Object);

            Instructor ins = new Instructor { InstructorId = 99, FirstName = "Test", LastName = "test" };

            mockRepository.Setup(x => x.AddInstructor(ins, ref errors));
            mockRepository.Setup(x => x.IsNotDuplicateInstructor(ins, ref errors)).Returns(true);

            //// Act
            iserv.InsertInstructor(ins, ref errors);

            //// Assert
            mockRepository.Verify(x => x.AddInstructor(ins, ref errors), Times.Once());
        }
Esempio n. 5
0
        public void InsertInstructor()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<IInstructorRepository>();
            var instructorService = new InstructorService(mockRepository.Object);
            var instructor = new Instructor { InstructorId = 2, FirstName = "bb", LastName = "cc", Title = "nope" };

            mockRepository.Setup(x => x.AddInstructor(instructor, ref errors));
            mockRepository.Setup(x => x.IsNotDuplicateInstructor(instructor, ref errors)).Returns(true);

            //// Act
            instructorService.InsertInstructor(instructor, ref errors);

            //// Assert
            mockRepository.Verify(x => x.AddInstructor(instructor, ref errors), Times.Once());
        }