public async Task UpdateCompanyAsync_ValidUpdate_ShouldReturnUpdatedCompany() { // Arrange await this.fixture.ClearFactroInstanceAsync(); var companyApi = this.fixture.GetService <ICompanyApi>(); var existingCompany = await this.fixture.CreateTestCompanyAsync(companyApi); var updatedName = $"{BaseTestFixture.TestPrefix}{Guid.NewGuid().ToString()}"; var updateCompanyRequest = new UpdateCompanyRequest { Name = updatedName, }; var updateCompanyResponse = new UpdateCompanyResponse(); // Act Func <Task> act = async() => updateCompanyResponse = await companyApi.UpdateCompanyAsync(existingCompany.Id, updateCompanyRequest); // Assert await act.Should().NotThrowAsync(); using (new AssertionScope()) { var companies = (await companyApi.GetCompaniesAsync()) .Where(x => x.Name.StartsWith(BaseTestFixture.TestPrefix)).ToList(); companies.Should().ContainEquivalentOf(updateCompanyResponse); companies.Single(x => x.Id == existingCompany.Id).Name.Should().Be(updatedName); } await this.fixture.ClearFactroInstanceAsync(); }
public void UpdateCompany() { moq::Mock <CompanyService.CompanyServiceClient> mockGrpcClient = new moq::Mock <CompanyService.CompanyServiceClient>(moq::MockBehavior.Strict); UpdateCompanyRequest request = new UpdateCompanyRequest { Company = new Company(), }; Company expectedResponse = new Company { CompanyName = CompanyName.FromProjectTenantCompany("[PROJECT]", "[TENANT]", "[COMPANY]"), DisplayName = "display_name137f65c2", ExternalId = "external_id9442680e", Size = CompanySize.Mini, HeadquartersAddress = "headquarters_address64cd7eb7", HiringAgency = true, EeoText = "eeo_text70a1a576", WebsiteUri = "website_urid0c5dfce", CareerSiteUri = "career_site_uri62d45b74", ImageUri = "image_urieba3b1bc", KeywordSearchableJobCustomAttributes = { "keyword_searchable_job_custom_attributese72ec77c", }, DerivedInfo = new Company.Types.DerivedInfo(), Suspended = true, }; mockGrpcClient.Setup(x => x.UpdateCompany(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); CompanyServiceClient client = new CompanyServiceClientImpl(mockGrpcClient.Object, null); Company response = client.UpdateCompany(request.Company); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async Task UpdateCompanyAsync_NotExistingCompanyId_ShouldThrowFactroApiException() { // Arrange await this.fixture.ClearFactroInstanceAsync(); var companyApi = this.fixture.GetService <ICompanyApi>(); var updatedName = $"{BaseTestFixture.TestPrefix}{Guid.NewGuid().ToString()}"; var updateCompanyRequest = new UpdateCompanyRequest { Name = updatedName, }; var updateCompanyResponse = default(UpdateCompanyResponse); // Act Func <Task> act = async() => updateCompanyResponse = await companyApi.UpdateCompanyAsync(Guid.NewGuid().ToString(), updateCompanyRequest); // Assert await act.Should().ThrowAsync <FactroApiException>(); using (new AssertionScope()) { var companies = (await companyApi.GetCompaniesAsync()) .Where(x => x.Name.StartsWith(BaseTestFixture.TestPrefix)).ToList(); companies.All(x => x.Name != updatedName).Should().BeTrue(); updateCompanyResponse.Should().BeNull(); } await this.fixture.ClearFactroInstanceAsync(); }
public async Task <IActionResult> UpdateCompanyInfo([FromBody] UpdateCompanyRequest company) { company.Email = User.Identity.Name; await _companyBusinessLogic.UpdateCompany(company); return(this.OkResult()); }
public void UpdateCompany2() { Mock <CompanyService.CompanyServiceClient> mockGrpcClient = new Mock <CompanyService.CompanyServiceClient>(MockBehavior.Strict); UpdateCompanyRequest request = new UpdateCompanyRequest { Company = new Company(), }; Company expectedResponse = new Company { Name = "name3373707", DisplayName = "displayName1615086568", ExternalId = "externalId-1153075697", HeadquartersAddress = "headquartersAddress-1879520036", HiringAgency = false, EeoText = "eeoText-1652097123", WebsiteUri = "websiteUri-2118185016", CareerSiteUri = "careerSiteUri1223331861", ImageUri = "imageUri-877823864", Suspended = false, }; mockGrpcClient.Setup(x => x.UpdateCompany(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); CompanyServiceClient client = new CompanyServiceClientImpl(mockGrpcClient.Object, null); Company response = client.UpdateCompany(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async Task UpdateCompanyAsync2() { Mock <CompanyService.CompanyServiceClient> mockGrpcClient = new Mock <CompanyService.CompanyServiceClient>(MockBehavior.Strict); UpdateCompanyRequest request = new UpdateCompanyRequest { Company = new Company(), }; Company expectedResponse = new Company { CompanyNameOneof = CompanyNameOneof.From(new CompanyOldName("[PROJECT]", "[COMPANY]")), DisplayName = "displayName1615086568", ExternalId = "externalId-1153075697", HeadquartersAddress = "headquartersAddress-1879520036", HiringAgency = false, EeoText = "eeoText-1652097123", WebsiteUri = "websiteUri-2118185016", CareerSiteUri = "careerSiteUri1223331861", ImageUri = "imageUri-877823864", Suspended = false, }; mockGrpcClient.Setup(x => x.UpdateCompanyAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <Company>(Task.FromResult(expectedResponse), null, null, null, null)); CompanyServiceClient client = new CompanyServiceClientImpl(mockGrpcClient.Object, null); Company response = await client.UpdateCompanyAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async Task UpdateCompanyAsync_InvalidUpdate_ShouldNotUpdateCompany() { // Arrange await this.fixture.ClearFactroInstanceAsync(); var companyApi = this.fixture.GetService <ICompanyApi>(); var existingCompany = await this.fixture.CreateTestCompanyAsync(companyApi); const string updatedName = null; var updateCompanyRequest = new UpdateCompanyRequest { Name = updatedName, }; // Act Func <Task> act = async() => await companyApi.UpdateCompanyAsync(existingCompany.Id, updateCompanyRequest); // Assert await act.Should().NotThrowAsync(); using (new AssertionScope()) { var companies = (await companyApi.GetCompaniesAsync()) .Where(x => x.Name.StartsWith(BaseTestFixture.TestPrefix)).ToList(); companies.Single(x => x.Id == existingCompany.Id).Should().BeEquivalentTo(existingCompany); } await this.fixture.ClearFactroInstanceAsync(); }
public async Task <bool> Handle(UpdateCompanyRequest message, IOutputPort <UpdateCompanyResponse> outputPort) { var response = await _companyRepository.Update(message.Id, new Domain.Entities.Company(message.CompanyName, message.YearEstablished, message.Employees)); outputPort.Handle(response.Success ? new UpdateCompanyResponse(true) : new UpdateCompanyResponse(response.Errors)); return(response.Success); }
public static Task <UpdateCompanyResponse> UpdateCompanyResponseAsync(Company company, IEndpointInstance endpointInstance) { var message = new UpdateCompanyRequest(company); var sendOptions = new SendOptions(); sendOptions.SetDestination("NServiceBusCore.Server"); var responseTask = endpointInstance .Request <UpdateCompanyResponse>(message, sendOptions); return(responseTask); }
public async Task <ActionResult <string> > Update([FromBody] UpdateCompanyRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(new JsonResult( Mapper.Map <CompanyViewModel>( await CompanyService.UpdateCompanyAsync( Mapper.Map <Company>(request))))); }
public async Task UpdateCompanyAsync_InvalidCompanyId_ShouldThrowArgumentNullException(string companyId) { // Arrange var companyApi = this.fixture.GetCompanyApi(); var updateCompanyRequest = new UpdateCompanyRequest(); // Act Func <Task> act = async() => await companyApi.UpdateCompanyAsync(companyId, updateCompanyRequest); // Assert await act.Should().ThrowAsync <ArgumentNullException>(); }
/// <inheritdoc /> public async Task <Company> UpdateCompanyAsync( long companyId, UpdateCompanyRequest request, CancellationToken cancellationToken = default) { if (request == null) { throw new ArgumentNullException(nameof(request), "Request must not be null"); } return(await _freshdeskClient .ApiOperationAsync <Company, UpdateCompanyRequest>(HttpMethod.Put, $"/api/v2/companies/{companyId}", request, cancellationToken) .ConfigureAwait(false)); }
/// <summary>Snippet for UpdateCompany</summary> public void UpdateCompany_RequestObject() { // Snippet: UpdateCompany(UpdateCompanyRequest,CallSettings) // Create client CompanyServiceClient companyServiceClient = CompanyServiceClient.Create(); // Initialize request argument(s) UpdateCompanyRequest request = new UpdateCompanyRequest { Company = new Company(), }; // Make the request Company response = companyServiceClient.UpdateCompany(request); // End snippet }
private string UpdateCompany() { string msg = ""; ServiceManager sm = new ServiceManager(); using (LP2ServiceClient service = sm.StartServiceClient()) { UpdateCompanyRequest req = new UpdateCompanyRequest(); req.hdr = new ReqHdr(); req.hdr.SecurityToken = "SecurityToken"; //todo:check dummy data if (CurrUser != null) { req.hdr.UserId = this.CurrUser.iUserID; } UpdateCompanyResponse respone = null; try { respone = service.UpdateCompany(req); if (respone.hdr.Successful) { msg = "Saved successfully."; return msg; } else { if (respone.hdr.StatusInfo == "") respone.hdr.StatusInfo = " Marketing Manager is not running."; msg = "Failed to update company, reason:" + respone.hdr.StatusInfo; return msg; } } catch (System.ServiceModel.EndpointNotFoundException ee) { LPLog.LogMessage(ee.Message); msg = "Failed to update copmany , reason: Marketing Manager is not running."; return msg; } catch (Exception exception) { LPLog.LogMessage(exception.Message); msg = "Failed to update company, reason:" + exception.Message; return msg; } } }
/// <summary>Snippet for UpdateCompanyAsync</summary> public async Task UpdateCompanyAsync_RequestObject() { // Snippet: UpdateCompanyAsync(UpdateCompanyRequest,CallSettings) // Additional: UpdateCompanyAsync(UpdateCompanyRequest,CancellationToken) // Create client CompanyServiceClient companyServiceClient = await CompanyServiceClient.CreateAsync(); // Initialize request argument(s) UpdateCompanyRequest request = new UpdateCompanyRequest { Company = new Company(), }; // Make the request Company response = await companyServiceClient.UpdateCompanyAsync(request); // End snippet }
// [END get_company] // [START update_company] public static Company UpdateCompany(String companyName, Company companyToBeUpdated) { try { UpdateCompanyRequest updateCompanyRequest = new UpdateCompanyRequest() { Company = companyToBeUpdated }; Company companyUpdated = jobServiceClient.Projects.Companies.Patch(updateCompanyRequest, companyName).Execute(); Console.WriteLine("Company updated: " + ToJsonString(companyUpdated)); return(companyUpdated); } catch (Exception e) { Console.WriteLine("Got exception while updating company"); throw e; } }
public async Task UpdateCompanyAsync_ValidRequest_ShouldReturnUpdatedCompany() { // Arrange var existingCompany = new GetCompanyPayload { Id = Guid.NewGuid().ToString(), Name = "TestName", }; var updateCompanyRequest = new UpdateCompanyRequest { Name = "NewName", }; var expectedUpdatedCompany = new UpdateCompanyResponse { Id = existingCompany.Id, Name = updateCompanyRequest.Name, }; var expectedResponseContent = new StringContent(JsonConvert.SerializeObject(expectedUpdatedCompany, this.fixture.JsonSerializerSettings)); var expectedResponse = new HttpResponseMessage { Content = expectedResponseContent, }; var companyApi = this.fixture.GetCompanyApi(expectedResponse); var updateCompanyResponse = new UpdateCompanyResponse(); // Act Func <Task> act = async() => updateCompanyResponse = await companyApi.UpdateCompanyAsync(existingCompany.Id, updateCompanyRequest); // Assert await act.Should().NotThrowAsync(); using (new AssertionScope()) { updateCompanyResponse.Id.Should().Be(existingCompany.Id); updateCompanyResponse.Name.Should().Be(expectedUpdatedCompany.Name); } }
public async Task <IActionResult> UpdateAsync([FromRoute] int companyId, [FromBody] UpdateCompanyRequest request) { Company company = (await _companyService.GetAsync(x => x.Id == companyId)).FirstOrDefault(); if (company == null) { return(NotFound(new NotFoundObjectResult($"There is no Company with Id {companyId}. Please try with another CompanyId"))); } company.Name = request.Name; var updated = await _companyService.UpdateAsync(company); if (!updated) { return(NotFound(new NotFoundObjectResult($"Company was not updated."))); } return(Ok(new Response <CompanyResponse>(_mapper.Map <CompanyResponse>(company)))); }
public IHttpActionResult PutCompany(int id, UpdateCompanyRequest companyRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var existingCompany = _companyService.Get(id); if (existingCompany == null) { return(NotFound()); } existingCompany.Name = companyRequest.Name; existingCompany.Tva = companyRequest.Tva; _companyService.Update(existingCompany); return(StatusCode(HttpStatusCode.NoContent)); }
public bool Update(Company el) { IRequest request = new UpdateCompanyRequest(el); try { using (var connection = new SqlConnection(connectionString)) { connection.Open(); using (var transaction = connection.BeginTransaction()) { connection.Execute(request.Sql, transaction: transaction); transaction.Commit(); } } return(true); } catch (Exception e) { return(false); } }
public async stt::Task UpdateCompanyRequestObjectAsync() { moq::Mock <CompanyService.CompanyServiceClient> mockGrpcClient = new moq::Mock <CompanyService.CompanyServiceClient>(moq::MockBehavior.Strict); UpdateCompanyRequest request = new UpdateCompanyRequest { Company = new Company(), UpdateMask = new wkt::FieldMask(), }; Company expectedResponse = new Company { CompanyName = CompanyName.FromProjectCompany("[PROJECT]", "[COMPANY]"), DisplayName = "display_name137f65c2", ExternalId = "external_id9442680e", Size = CompanySize.Mini, HeadquartersAddress = "headquarters_address64cd7eb7", HiringAgency = true, EeoText = "eeo_text70a1a576", WebsiteUri = "website_urid0c5dfce", CareerSiteUri = "career_site_uri62d45b74", ImageUri = "image_urieba3b1bc", KeywordSearchableJobCustomAttributes = { "keyword_searchable_job_custom_attributese72ec77c", }, DerivedInfo = new Company.Types.DerivedInfo(), Suspended = true, }; mockGrpcClient.Setup(x => x.UpdateCompanyAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Company>(stt::Task.FromResult(expectedResponse), null, null, null, null)); CompanyServiceClient client = new CompanyServiceClientImpl(mockGrpcClient.Object, null); Company responseCallSettings = await client.UpdateCompanyAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); Company responseCancellationToken = await client.UpdateCompanyAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
// PUT api/companies/5 public HttpResponseMessage Put(string id, [FromBody] UpdateCompanyRequest values) { if (!ModelState.IsValid) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent("The company data contains some invalid data. Please correct for errors and try again.") }); } var parameters = _identityProvider.SetUserIdentity(values.Map().To <UpdateCompanyParameters>()); parameters.CompanyKey = id; var result = _companyService.UpdateCompany(parameters); result.EnsureSuccessWithHttpResponseException(HttpVerbs.Put); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = Get(id).ToJSONContent() }); }
public async Task UpdateCompanyAsync_UnsuccessfulRequest_ShouldThrowCompanyApiException() { // Arrange var companyId = Guid.NewGuid().ToString(); var updateCompanyRequest = new UpdateCompanyRequest(); var expectedResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, RequestMessage = new HttpRequestMessage { RequestUri = new Uri("http://www.mock-web-address.com"), }, }; var companyApi = this.fixture.GetCompanyApi(expectedResponse); // Act Func <Task> act = async() => await companyApi.UpdateCompanyAsync(companyId, updateCompanyRequest); // Assert await act.Should().ThrowAsync <FactroApiException>(); }
public UpdateCompanyResponse UpdateCompany(UpdateCompanyRequest request) { UpdateCompanyResponse response = new UpdateCompanyResponse(); response.ExceptionState = false; Company company = new Company(); company.Id = request.Id; company.Name = request.Name.ToUpper(new CultureInfo("tr-TR")); company.Description = string.IsNullOrEmpty(request.Description) ? string.Empty : request.Description.ToUpper(new CultureInfo("tr-TR")); company.IsActive = request.IsActive; company.CompanyType = _companyTypeRepository.FindBy(request.CompanyTypeId); company.ParentCompany = _companyRepository.FindBy(request.ParentCompanyId ?? 0); Query query = new Query(); if (company.ParentCompany == null) { query.Add(Criterion.Create<Company>(c => c.Id, company.Id, CriteriaOperator.NotEqual)); query.Add(Criterion.Create<Company>(c => c.ParentCompany, null, CriteriaOperator.IsNull)); if (_companyRepository.FindBy(query).Count() > 0) { response.ExceptionState = true; response.ExceptionMessage = @"Zaten bir ana firma var. Lütfen oluşturmaya çalıştığınız firmanın bağlı olduğu firmayı seçiniz."; return response; } } if (company.Name != _companyRepository.FindBy(request.Id).Name) { query = new Query(); query.Add(Criterion.Create<Company>(c => c.Name, company.Name, CriteriaOperator.Equal)); if (_companyRepository.FindBy(query).Count() > 0) { response.ExceptionState = true; response.ExceptionMessage = @"Bu isimde bir firma zaten var. Lütfen firma adını benzersiz bir isim olarak düzenleyin."; response.Company = company.ConvertToCompanyView(); return response; } } _companyRepository.Save(company); _unitOfWork.Commit(); response.Company = company.ConvertToCompanyView(); return response; }
public UpdateCompanyResponse UpdateCompany(UpdateCompanyRequest request) { Dictionary<string, string> data = new Dictionary<string, string>(); data["id"] = request.Id.ToString(); data["name"] = request.Name; data["address"] = request.Address; data["city"] = request.City; data["state"] = request.State; data["zip"] = request.Zip; data["phone1"] = request.Phone1; data["phone2"] = request.Phone2; data["url"] = request.Url; data["key_technologies"] = request.KeyTechnologies; data["notes"] = request.Notes; if (request.EnteredBy != -1) { data["entered_by"] = request.EnteredBy.ToString(); } if (request.Owner != -1) { data["owner"] = request.Owner.ToString(); } if (request.DateCreated != DateTime.MinValue) { data["date_created"] = DateTimeToUnixTimestamp(request.DateCreated); } if (request.DateModified != DateTime.MinValue) { data["date_modified"] = DateTimeToUnixTimestamp(request.DateModified); } if (request.IsHot != null) { data["is_hot"] = request.IsHot.ToString().ToLower(); } data["fax_number"] = request.FaxNumber; if (request.Country != -1) { data["country"] = request.Country.ToString(); } Dictionary<string, string> files = new Dictionary<string, string>(); if (request.File != String.Empty) { files.Add("file", request.File); } UpdateCompanyResponse response = new UpdateCompanyResponse( MakeRequest("update_company", data, files) ); return response; }
public async Task <UpdateCompanyResponse> UpdateCompanyAsync(string companyId, UpdateCompanyRequest updateCompanyRequest) { if (string.IsNullOrWhiteSpace(companyId)) { throw new ArgumentNullException(nameof(companyId), $"{nameof(companyId)} can not be null, empty or whitespace."); } if (updateCompanyRequest == null) { throw new ArgumentNullException(nameof(updateCompanyRequest), $"{nameof(updateCompanyRequest)} can not be null."); } var requestRoute = CompanyApiEndpoints.Base.Update(companyId); var requestString = JsonConvert.SerializeObject(updateCompanyRequest, this.jsonSerializerSettings); var requestContent = ApiHelpers.GetStringContent(requestString); var response = await this.httpClient.PutAsync(requestRoute, requestContent); if (!response.IsSuccessStatusCode) { throw new FactroApiException( $"Could not update company with id '{companyId}'.", response.RequestMessage.RequestUri.ToString(), response.StatusCode, response.Content == null ? null : await response.Content.ReadAsStringAsync()); } var responseContentString = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <UpdateCompanyResponse>( responseContentString, this.jsonSerializerSettings); return(result); }
public async Task UpdateCompany(UpdateCompanyRequest company) { var companyModel = Mapper.Map <Company>(company); await _mongoDbRepository.Replace(companyModel); }