public Speciality Create(CreateSpecialityCommand command) { var speciality = new Speciality(command.Name, command.Description); speciality.Validate(); _repository.Create(speciality); if (Commit()) { return(speciality); } return(null); }
public async Task ThrowDuplicateException_WhenSpecialityCodeExists() { var request = new CreateSpecialityCommand { Code = 101, Name = "Test Speciality 3" }; var handler = new CreateSpecialityCommandHandler(Context); var exception = Assert.ThrowsAsync <DuplicateException>(async() => await handler.Handle(request, CancellationToken.None)); Assert.AreEqual(exception.Message, ExceptionMessagesBuilderHelper.GetDuplicateExceptionMessage(nameof(Speciality), "Code", request.Code)); }
public async Task CreateSpeciality() { var request = new CreateSpecialityCommand { Code = 103, Name = "Test Speciality 3" }; var handler = new CreateSpecialityCommandHandler(Context); var result = await handler.Handle(request, CancellationToken.None); Assert.IsTrue(Context.Specialities.Where(x => x.Id == result).Count() == 1); }
public async Task <IActionResult> Create([FromBody] CreateSpecialityCommand command) { var productId = await Mediator.Send(command); return(CreatedAtAction("Get", new { id = productId })); }