public async Task <IActionResult> Add([FromBody] CreateLanguageCommand createLanguage) { var result = await Mediator.Send(createLanguage); if (result.Success) { return(Ok(result.Message)); } return(BadRequest(result.Message)); }
public void LanguageIsNotCreatedWhenValidatorReturnsFalse() { var command = new CreateLanguageCommand(falseValidator, repo); var currentCount = context.Collection <LanguageEntity>().AsQueryable().ToList().Count; Assert.Throws <ArgumentException>(() => command.Execute(request)); var countAfterCreation = context.Collection <LanguageEntity>().AsQueryable().ToList().Count; Assert.IsTrue(countAfterCreation == currentCount); }
public void LanguageIsCreatedWithTrueValidation() { var command = new CreateLanguageCommand(trueValidator, repo); var currentCount = context.Collection <LanguageEntity>().AsQueryable().ToList().Count; command.Execute(request); var countAfterCreation = context.Collection <LanguageEntity>().AsQueryable().ToList().Count; Assert.IsTrue(countAfterCreation == currentCount + 1); }
public async Task Language_CreateCommand_NameAlreadyExist() { //Arrange CreateLanguageCommand command = new CreateLanguageCommand(); //propertyler buraya yazılacak //command.LanguageName = "test"; _languageRepository.Setup(x => x.Query()) .Returns(new List <Language> { new Language() /*TODO:propertyler buraya yazılacak LanguageId = 1, LanguageName = "test"*/ } { }.AsQueryable());
public LanguageController( GetLanguagesQuery getLanguagesCommand, GetLanguageByIdQuery getLanguageByIdCommand, CreateLanguageCommand createLanguageCommand, UpdateLanguageCommand updateLanguageCommand, DeleteLanguageCommand deleteLanguageCommand) { this.getLanguagesCommand = getLanguagesCommand; this.getLanguageByIdCommand = getLanguageByIdCommand; this.createLanguageCommand = createLanguageCommand; this.updateLanguageCommand = updateLanguageCommand; this.deleteLanguageCommand = deleteLanguageCommand; }
public async Task Language_CreateCommand_Success() { Language rt = null; //Arrange CreateLanguageCommand command = new CreateLanguageCommand(); //propertyler buraya yazılacak //command.LanguageName = "deneme"; _languageRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <Language, bool> > >())) .ReturnsAsync(rt); _languageRepository.Setup(x => x.Add(It.IsAny <Language>())).Returns(new Language()); CreateLanguageCommandHandler handler = new CreateLanguageCommandHandler(_languageRepository.Object, _mediator.Object); var x = await handler.Handle(command, new System.Threading.CancellationToken()); _languageRepository.Verify(x => x.SaveChangesAsync()); Assert.That(x.Success, Is.True); Assert.That(x.Message, Is.EqualTo(Messages.Added)); }
public async Task <IActionResult> Add([FromBody] CreateLanguageCommand createLanguage) { return(GetResponseOnlyResultMessage(await Mediator.Send(createLanguage))); }
private async Task Handle(CreateLanguageCommand command) { await HandleCommand(command, async uow => { }); }
public async Task <ActionResult <bool> > Create([FromBody] CreateLanguageCommand request) { return(Ok(await Mediator.Send(request))); }
public async Task <IActionResult> Create([FromForm] CreateLanguageCommand command) { return(await SendCommand(DispatcherActorsNames.LanguageCommandActor, command)); }