public async Task CreateCompanyShouldSaveCorrectData() { // Arrange var db = this.GetDatabase(); const int Id = 1; const string Name = "Star Sechko"; const string Information = "Some company information."; var companyService = new CompanyService(db); var model = new CompanyRequestModel { Id = 1, Name = Name, Founded = DateTime.MaxValue, Information = Information, }; // Act await companyService.Create(model); var result = await db.Companys.FindAsync(Id); // Assert Assert.Equal(Id, result.Id); Assert.Equal(Name, result.Name); Assert.Equal(Information, result.Information); }
public async Task <ActionResult <CompanyResponseModel> > Delete(CompanyRequestModel input) { await this.companiesService.DeleteAsync(input.CompanyId); return(new CompanyResponseModel { }); }
public async Task <ActionResult <CompanyResponseModel> > Create(CompanyRequestModel input) { await this.companiesService.AddAsync(input.CompanyName); return(new CompanyResponseModel { }); }
public async Task <IActionResult> RequestCompany() { await GetLoggedInUser(); var model = new CompanyRequestModel() { OfficialEmail = _configuration["Company:OfficialEmail"] }; return(View(model)); }
public async Task <IActionResult> Create([FromBody] CompanyRequestModel model) { try { var response = await _companyService.Create(model); return(Created("companies", response)); } catch (Exception ex) { return(HandleControllerErrors(ex)); } }
public async Task <IActionResult> Put([FromBody] CompanyRequestModel model) { var companyExists = await this.companyService.Exists(model.Id); if (!companyExists) { this.ModelState.AddModelError(nameof(CompanyRequestModel.Name), "Company name does not exists"); return(BadRequest(this.ModelState)); } await this.companyService.Update(model); return(this.Ok()); }
public async Task Create(CompanyRequestModel model) { var company = new Company { Name = model.Name, Founded = model.Founded, Information = model.Information, }; await this.db.Companys.AddAsync(company); await this.db.SaveChangesAsync(); }
public async Task <IActionResult> Post([FromBody] CompanyRequestModel model) { var categoryNameExists = await this.companyService.Exists(model.Name); if (categoryNameExists) { this.ModelState.AddModelError(nameof(CompanyRequestModel.Name), "Company name already exists."); return(BadRequest(this.ModelState)); } await this.companyService.Create(model); return(this.Ok()); }
public async Task ChangeCompany(int id, CompanyRequestModel companyRequest) { Company company = await this.unitOfWorkManager.Companies.GetSingleAsync(x => x.Id == id); if (company == null) { throw new IsNotRegisteredException("company not found"); } company.MarketId = companyRequest.MarketId; company.Price = companyRequest.Price; company.Name = companyRequest.Name; company.ChangeDate = DateTime.Now; this.unitOfWorkManager.Companies.Update(company); this.unitOfWorkManager.Complete(); }
public async Task ShouldReturnErrorMustBeInformedAtCreateCompany() { var companyRequest = new CompanyRequestModel() { Name = "S", }; var expectedErrors = new HashSet <string>(); expectedErrors.Add("The company name length must have between 2 and 50 characters"); _repository.CompanyExists(companyRequest.Name).Returns(false); var ex = await Record.ExceptionAsync(() => _service.Create(companyRequest)) as BadRequestException; ex.Errors.Should().BeEquivalentTo(expectedErrors); }
public async Task <int> CreateCompany(CompanyRequestModel companyRequest) { Company comapny = await this.unitOfWorkManager.Companies.GetSingleAsync(x => x.Name == companyRequest.Name); Market market = await this.unitOfWorkManager.Markets.FindAsync(companyRequest.MarketId); if (comapny != null) { throw new IsRegisteredException("company is registered"); } if (market == null) { throw new IsRegisteredException("market not found"); } await this.unitOfWorkManager.BeginTransactionAsync(); try { Company newCompany = new Company { MarketId = companyRequest.MarketId, Price = companyRequest.Price, Name = companyRequest.Name }; await this.unitOfWorkManager.Companies.AddAsync(newCompany); await this.unitOfWorkManager.CompleteAsync(); this.unitOfWorkManager.CommitTransaction(); return(newCompany.Id); } catch (Exception) { this.unitOfWorkManager.RollbackTransaction(); throw; } }
public async Task <IActionResult> RequestCompany(CompanyRequestModel model) { if (ModelState.IsValid) { var user = await _userManager.GetUserAsync(HttpContext.User); var request = new CompanyRequest() { UserId = user.Id, Description = model.Description, RequestDate = DateTime.Now, RequestStatus = CompanyRequestStatus.Pending.ToString() }; await _companyRequestService.CreateAsync(request); return(RedirectToAction("UserCompany", "Company")); } return(View(model)); }
public async Task ShouldCreateCompany() { var companyRequest = new CompanyRequestModel() { Name = "SERASA" }; var companyResponse = new CompanyResponseModel(0, "SERASA", 50); _companyService.Create(companyRequest).Returns(companyResponse); var responseController = await _controller.Create(companyRequest) as ObjectResult; var response = responseController.Value as CompanyResponseModel; await _companyService.Received(1) .Create(Arg.Is <CompanyRequestModel> (x => x.Name == "SERASA")); Assert.AreEqual((int)HttpStatusCode.Created, responseController.StatusCode); companyResponse.Should().BeEquivalentTo(response); }
public async Task Update(CompanyRequestModel model) { var company = await this.db.Companys.FindAsync(model.Id); if (company == null) { return; } if (company.Name != model.Name || company.Information != model.Information || company.Founded != model.Founded) { company.Id = model.Id; company.Name = model.Name; company.Founded = model.Founded; company.Information = model.Information; await this.db.SaveChangesAsync(); } }
public async Task ShouldReturnErrorUniqueValeuConstraintAtCreateCompany() { var companyRequest = new CompanyRequestModel() { Name = "SERASA", }; var expectedErrors = new HashSet <string>(); expectedErrors.Add("This company name already exists"); _repository.CompanyExists("SERASA").Returns(true); var ex = await Record.ExceptionAsync(() => _service.Create(companyRequest)) as BadRequestException; await _repository .Received(1) .CompanyExists(Arg.Is <string>(x => x == "SERASA")); ex.Errors.Should().BeEquivalentTo(expectedErrors); }
public async Task <CompanyResponseModel> Create(CompanyRequestModel companyRequest) { var company = CompanyMap.CompanyRequestToCompany(companyRequest); company.FormatProps(); if (!company.IsValid()) { AddErrors(company.GetErrors()); } if (await _companyRepository.CompanyExists(company.Name)) { AddError("This company name already exists"); } HandlerErrors(); await _companyRepository.Create(company); await _companyRepository.Save(); return(CompanyMap.CompanyToCompanyResponse(company)); }
public async Task ShouldCreateCompany() { var expectedCompany = new Company("SERASA"); var companyRequest = new CompanyRequestModel() { Name = "SERASA", }; _repository.CompanyExists(expectedCompany.Name).Returns(false); var response = await _service.Create(companyRequest); await _repository .Received(1) .Create(Arg.Is <Company>(x => x.Name == "SERASA")); await _repository .Received(1) .CompanyExists(Arg.Is <string>(x => x == "SERASA")); expectedCompany.Should().BeEquivalentTo(response); }
public async Task ShouldReturnErrorAtCreateCompany() { var companyRequest = new CompanyRequestModel() { Name = "" }; var expectedErrors = new HashSet <string>(); expectedErrors.Add("The company name length must have between 2 and 50 characters"); _companyService.Create(companyRequest).Throws(new BadRequestException(expectedErrors)); var responseController = await _controller.Create(companyRequest) as BadRequestObjectResult; var responseErrors = responseController.Value as HashSet <string>; await _companyService.Received(1) .Create(Arg.Is <CompanyRequestModel> (x => x.Name == "")); Assert.AreEqual((int)HttpStatusCode.BadRequest, responseController.StatusCode); expectedErrors.Should().BeEquivalentTo(responseErrors); }
public static Company CompanyRequestToCompany(CompanyRequestModel companyRequest) { return(AutoMapperFunc.ChangeValues <CompanyRequestModel, Company>(companyRequest)); }
public async Task <IActionResult> Change(int id, [FromBody] CompanyRequestModel request) { await this.companyService.ChangeCompany(id, request); return(Ok()); }
public async Task <IActionResult> Add([FromBody] CompanyRequestModel request) { int Id = await this.companyService.CreateCompany(request); return(Ok(Id)); }