예제 #1
0
        public string UpdateInstructor(Instructor instructor)
        {
            var errors = new List<string>();
            var repository = new InstructorRepository(this.entities);
            var service = new InstructorService(repository);
            service.UpdateInstructor(instructor, ref errors);

            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
예제 #2
0
        public void UpdateInstructorTest()
        {
            //// 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.UpdateInstructor(ins, ref errors));

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

            //// Assert
            mockRepository.Verify(x => x.UpdateInstructor(ins, ref errors), Times.Once());
        }
예제 #3
0
        public void UpdateInstructorErrorTest1()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<IInstructorRepository>();
            var instructorService = new InstructorService(mockRepository.Object);

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

            //// Assert instructor object not null
            Assert.AreEqual(1, errors.Count);
        }
예제 #4
0
        public void UpdateInstructorErrorTest3()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<IInstructorRepository>();
            var instructorService = new InstructorService(mockRepository.Object);
            var instructor = new Instructor { FirstName = "nick", LastName = string.Empty };

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

            //// Assert last name cannot be empty
            Assert.AreEqual(1, errors.Count);
        }
예제 #5
0
        public void UpdateInstructor()
        {
            //// 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 = "zz", Title = "NOPE" };

            mockRepository.Setup(x => x.UpdateInstructor(instructor, ref errors));

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

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