public void Handle_CreateStudentCommand_WhenCalled_CreateStudent()
        {
            var studentHandler = new StudentHandler(
                _studentRepository.Object,
                _classroomRepository.Object,
                _addressRepository.Object);

            studentHandler.Handle(_createStudentCommand);

            Assert.That(_createStudentCommand.Valid, Is.True);
        }
        public void Handle_UpdateStudentCommand_WhenStudentIsNull_ReturnInvalid()
        {
            _studentRepository.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(It.IsAny <Student>);

            var studentHandler = new StudentHandler(
                _studentRepository.Object,
                _classroomRepository.Object,
                _addressRepository.Object);
            var result = studentHandler.Handle(_updateStudentCommand);

            Assert.That(!result.Success);
        }
        public void Handle_AddClassroomCommand_WhenStudentNotExists_ThrowsException()
        {
            _studentRepository.Setup(r => r.GetById(It.IsAny <Guid>())).Throws <Exception>();
            _classroomRepository.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(_classroom);

            var studentHandler = new StudentHandler(
                _studentRepository.Object,
                _classroomRepository.Object,
                _addressRepository.Object);

            Assert.That(() => studentHandler.Handle(_addClassroomCommand), Throws.Exception);
        }
        public void Handle_AddAddressCommand_WhenCalled_AddAddressToStudent()
        {
            _studentRepository.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(_student);
            _classroomRepository.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(_classroom);

            var studentHandler = new StudentHandler(
                _studentRepository.Object,
                _classroomRepository.Object,
                _addressRepository.Object);

            studentHandler.Handle(_addAddressCommand);
            Assert.That(_addAddressCommand.Valid, Is.True);
        }
        public void Handle_RemoveStudentCommand_RemoveStudent()
        {
            _studentRepository.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(_student);
            _studentRepository.Setup(r => r.Remove(_student));

            var studentHandler = new StudentHandler(
                _studentRepository.Object,
                _classroomRepository.Object,
                _addressRepository.Object);

            var result = studentHandler.Handle(_removeStudentCommand);

            Assert.That(result.Success);
        }
        public void Handle_UpdateAddressCommand_UpdateAddress()
        {
            _studentRepository.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(_student);
            _addressRepository.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(_student.Address);
            _addressRepository.Setup(r => r.Update(_student.Address));

            var studentHandler = new StudentHandler(
                _studentRepository.Object,
                _classroomRepository.Object,
                _addressRepository.Object);

            var result = studentHandler.Handle(_updateAddressCommand);

            Assert.That(result.Success);
        }
예제 #7
0
 public ICommandResult Post([FromBody] CreateStudentCommand command)
 {
     return(_handler.Handle(command));
 }