public void Should_Throw_When_Creating_Monitor_With_Existing_Name() { MockExternalLinks(); var userAndOrg = new UserAndOrganizationDto { OrganizationId = 2, UserId = "1" }; var monitor = new MonitorDto { Name = "Test1" }; var ex = Assert.ThrowsAsync <ValidationException>(async() => await _monitorService.CreateMonitorAsync(monitor, userAndOrg)); Assert.That(ex.ErrorCode, Is.EqualTo(ErrorCodes.DuplicatesIntolerable)); }
public async Task <IHttpActionResult> CreateMonitor(CreateMonitorViewModel monitor) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newMonitorDto = _mapper.Map <CreateMonitorViewModel, MonitorDto>(monitor); try { await _monitorService.CreateMonitorAsync(newMonitorDto, GetUserAndOrganization()); } catch (ValidationException e) { return(BadRequestWithError(e)); } return(Ok()); }