public async Task Save_ReturnsCreatedResult() { //Arrange var str = "file"; DecisionWrapperDTO decisionWrapperDTO = new DecisionWrapperDTO() { Decision = new DecisionDTO() { Organization = new OrganizationDTO { OrganizationName = str } } }; _decisionService .Setup(x => x.SaveDecisionAsync(decisionWrapperDTO)) .ReturnsAsync(decisionWrapperDTO.Decision.ID); _decisionService .Setup(x => x.GetDecisionOrganizationAsync(decisionWrapperDTO.Decision.Organization)) .ReturnsAsync(decisionWrapperDTO.Decision.Organization); //Act var result = await _decisionsController.Save(decisionWrapperDTO); //Assert _decisionService.Verify(); Assert.IsNotNull(result); Assert.IsInstanceOf <ObjectResult>(result); }
public async Task Save_ReturnsCreatedResult() { //Arrange var governingBodyName = "SomeName"; DecisionWrapperDTO decisionWrapperDTO = new DecisionWrapperDTO() { Decision = new DecisionDTO() { GoverningBody = new GoverningBodyDTO { GoverningBodyName = governingBodyName } } }; _decisionService .Setup(x => x.SaveDecisionAsync(decisionWrapperDTO)) .ReturnsAsync(decisionWrapperDTO.Decision.ID); _decisionService .Setup(x => x.GetDecisionOrganizationAsync(decisionWrapperDTO.Decision.GoverningBody)) .ReturnsAsync(decisionWrapperDTO.Decision.GoverningBody); //Act var result = await _decisionsController.Save(decisionWrapperDTO); //Assert _decisionService.Verify(); Assert.IsNotNull(result); Assert.IsInstanceOf <ObjectResult>(result); }
/// <inheritdoc /> public async Task <int> SaveDecisionAsync(DecisionWrapperDTO decision) { decision.Decision.DecisionTarget = await CreateDecisionTargetAsync(decision.Decision.DecisionTarget.TargetName); var repoDecision = _mapper.Map <Decesion>(decision.Decision); _repoWrapper.Decesion.Attach(repoDecision); _repoWrapper.Decesion.Create(repoDecision); if (decision.FileAsBase64 != null) { repoDecision.FileName = Guid.NewGuid() + repoDecision.FileName; await UploadFileToBlobAsync(decision.FileAsBase64, repoDecision.FileName); } await _repoWrapper.SaveAsync(); return(decision.Decision.ID); }
public async Task <IActionResult> Save(DecisionWrapperDTO decisionWrapper) { if (decisionWrapper.FileAsBase64 == null && decisionWrapper.Decision.FileName != null) { return(BadRequest("Проблеми з завантаженням файлу")); } decisionWrapper.Decision.ID = await _decisionService.SaveDecisionAsync(decisionWrapper); var decisionOrganizations = (await _decisionService .GetDecisionOrganizationAsync(decisionWrapper.Decision.Organization)) .OrganizationName; return(Created("Decisions", new { decision = decisionWrapper.Decision, decisionOrganization = decisionOrganizations })); }
public async Task Save_ReturnsBadRequestResult() { //Arrange var decisionWrapper = new DecisionWrapperDTO() { Decision = new DecisionDTO { FileName = "string" }, FileAsBase64 = null }; //Act var result = await _decisionsController.Save(decisionWrapper); //Assert Assert.IsNotNull(result); Assert.IsInstanceOf <BadRequestObjectResult>(result); }
public async Task SaveDecisionTest(int decisionId) { _decisionService = CreateDecisionService(); var decision = new DecisionWrapperDTO { Decision = new DecisionDTO { ID = decisionId, DecisionTarget = new DecisionTargetDTO { ID = new Random().Next(), TargetName = Guid.NewGuid().ToString() } }, }; var actualReturn = await _decisionService.SaveDecisionAsync(decision); Assert.Equal(decisionId, actualReturn); }
public async Task SaveDecisionTest(int decisionId) { //Arrange var decision = new DecisionWrapperDTO { Decision = new DecisionDTO { ID = decisionId, DecisionTarget = new DecisionTargetDTO { ID = new Random().Next(), TargetName = Guid.NewGuid().ToString() } }, }; //Act var actualReturn = await _decisionService.SaveDecisionAsync(decision); //Assert Assert.AreEqual(decisionId, actualReturn); }