public void TestAddCompany() { DbContextMock.Setup(context => context.Companies) .ReturnsDbSet(new List <Company>()); var view = ViewFixture.BuildCompanyView("test"); var result = _companyService.Add(view); result.ShouldBeRight(right => right.Should().BeEquivalentTo(view)); DbContextMock.Verify(context => context.Companies); DbContextMock.Verify(context => context.Companies.Add(It.IsAny <Company>())); DbContextMock.Verify(context => context.SaveChanges()); }
/// <summary> /// Add /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAdd_Click(object sender, EventArgs e) { if (IsNameEmpty()) { return; } if (CompanyService.IsNameExisted(txtName.Text.Trim())) { MessageBox.Show("This " + txtName.Text.Trim() + " already exists."); } else { var Company = new Company() { Name = txtName.Text, Address = txtAddress.Text, TelephoneNumber = txtTelephoneNumber.Text, Fax = txtFax.Text, Email = txtEmail.Text, Website = txtWebsite.Text, FatherCompanyId = (int)cboFatherCompany.SelectedValue }; CompanyService.Add(Company); } ReloadForm(); }
//public Company GetCompany(int id) //{ // var company = companies.FirstOrDefault((p) => p.id == id); // if (company == null) // { // return new Company(); // //throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound,"Company not exists")); // } // return company; //} public HttpResponseMessage PostCompany(Company company) { HttpResponseMessage response; Company comp = new Company(); if (ModelState.IsValid) { if (company != null) { //comp = GetCompany(company.id); if (comp.Description == null) { companyService.Add(company); response = Request.CreateResponse(HttpStatusCode.OK); } else { response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Duplicate Company"); } } else { response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Invalid Payload"); } } else { response = Request.CreateResponse(HttpStatusCode.InternalServerError, " Modal state is invalid"); } return(response); }
private void btnSave_Click(object sender, EventArgs e) { if (!Helper.HasWriteAccess(ApplicationFroms.frmAddCompany)) { return; } if (txtCompanyName.Text == "") { Helper.ShowMessage("Please specify a company name", "Company Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (cmbLocation.SelectedIndex == -1) { Helper.ShowMessage("Please select your default location", "Select Default Location", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } Company company = new Company(); company.Address1 = txtAddress.Text; company.Address2 = txtAddress2.Text; company.Address3 = txtAddress3.Text; company.CompanyName = txtCompanyName.Text; company.Email = txtEmail.Text; company.FaxNumber = txtFax.Text; company.Location = txtLocation.Text; company.Logo = pbLogo.Image == null ? null : Helper.ImageToByteArray(pbLogo.Image); company.Misc = txtMisc.Text; company.Motto = txtMotto.Text; company.PhoneLine1 = txtPhone.Text; company.PhoneLine2 = txtPhone2.Text; company.PhoneLine3 = txtPhone3.Text; company.WebSite = txtWebsite.Text; company.City = txtCity.Text; company.Country = txtCountry.Text; company.DefaultLocation = cmbLocation.SelectedValue.ToInt(); try { if (_companyID == 0) { _companyService.Add(company); } else { company.CompanyID = _companyID; _companyService.Update(company); } this.Close(); } catch (Exception ex) { _logger.LogError(ex, "An error occurred", "frmAddCustomer", "btnSave"); Helper.ShowMessage("An error occured " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
// POST: Company?tenant_id public void Post(string tenant_id, [FromBody] Company Company) { //ID = AutoIncrement & Owner = tenant_id. Company.Owner = tenant_id; CompanyService.Add(Company); CompanyService.Commit(); }
public ActionResult Create(Company company) { if (ModelState.IsValid) { companyService.Add(company); } return(View("Index")); }
public ActionResult Add(CompanyObjLibrary obj) { ViewBag.Message = "Successfully Added"; CompanyService cb = new CompanyService(); obj.CompanyId = cb.Add(obj); return(View()); }
public IActionResult Add([FromBody] CompanyInfo company) { if (ModelState.IsValid) { var dbCompany = _companyService.Add(company); return(Ok(dbCompany)); } return(BadRequest(ModelState)); }
public bool AddCompany(Company request) { var company = _service.Add(request); if (company == null) { return(false); } return(true); }
public void ReturnFalse_WhenNullArgumentIsPassed() { //Arrange var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedMapper = new Mock <IMapper>(); var companyService = new CompanyService(mockedUnitOfWork.Object, mockedMapper.Object); //Act & Assert Assert.IsFalse(companyService.Add(null)); }
public ActionResult Add(Company company) { company = new Company { CId = 1, CName = "晨会", UserInfoId = "122" }; CompanyService.Add(company); return(Content("ok:hello")); }
public async Task List() { DbContextOptions <CompanyContext> options = GetConnectionOptions(); using (CompanyContext context = new CompanyContext(options)) { context.Database.EnsureCreated(); var service = new CompanyService(context, new CoinTypeService(context)); var company1 = JsonConvert.DeserializeObject <Company>(_JSON); var company2 = JsonConvert.DeserializeObject <Company>(_JSON); Company newCompany = await service.Add(company1); Company newCompany2 = await service.Add(company2); IEnumerable <Company> result = service.GetAll(); Assert.NotEmpty(result); Assert.Equal(2, result.Count()); } }
public async Task AddInvalidBlankCompany() { Company newCompany = new Company(); DbContextOptions <CompanyContext> options = GetConnectionOptions(); using (CompanyContext context = new CompanyContext(options)) { context.Database.EnsureCreated(); var service = new CompanyService(context, new CoinTypeService(context)); Exception ex = await Assert.ThrowsAnyAsync <Exception>(() => service.Add(newCompany)); } }
public async Task <ResponseDto> AddOrEditCompany(Company company, int isShare) { if (company.Id > 0) { result.data = await bll.Edit(company, isShare); } else { result.data = await bll.Add(company); } return(result); }
public ActionResult Create([Bind(Include = "CompanyID,CompanyName,Address,PhoneNumber,Country")] Company Company) { if (ModelState.IsValid) { Company.Owner = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value; CompanyService.Add(Company); CompanyService.Commit(); return(RedirectToAction("Index")); } return(View(Company)); }
public async Task AddInvalidCompanyMissingName() { Company newCompany = new Company(); DbContextOptions <CompanyContext> options = GetConnectionOptions(); // Run the test against one instance of the context using (CompanyContext context = new CompanyContext(options)) { context.Database.EnsureCreated(); var service = new CompanyService(context, new CoinTypeService(context)); Exception ex = await Assert.ThrowsAnyAsync <Exception>(() => service.Add(newCompany)); } }
public void ReturnFalse_WhenExceptionOccured() { //Arrange var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedMapper = new Mock <IMapper>(); var companyService = new CompanyService(mockedUnitOfWork.Object, mockedMapper.Object); var mockedCompanyModel = new Mock <CompanyModel>(); //Act mockedUnitOfWork.Setup(x => x.CompanyRepository).Throws(new Exception()); //Assert Assert.IsFalse(companyService.Add(mockedCompanyModel.Object)); }
public ActionResult Create(CompanyViewModelDD companyViewModelDD) { if (ModelState.IsValid) { var company = new Company(); CompanyService.PopulateCompany(companyViewModelDD, company); company.RegistrationDate = DateTime.Now; CompanyService.Add(company); return(RedirectToAction("Index")); } CompanyService.PopulateSelectLists(companyViewModelDD); return(View(companyViewModelDD)); }
public async Task AddInvalidCompanyMissingEmail() { Company newCompany = new Company("Teste", "32893956858", null, new Address("Araraquara", "Santana", "Jose Closel", "464", "14804-412", "")) { Email = null }; DbContextOptions <CompanyContext> options = GetConnectionOptions(); using (CompanyContext context = new CompanyContext(options)) { context.Database.EnsureCreated(); var service = new CompanyService(context, new CoinTypeService(context)); Exception ex = await Assert.ThrowsAnyAsync <Exception>(() => service.Add(newCompany)); } }
public string Add() { if (this.UserRole == Role.Company) { return(_companyService.Add(this)); } else if (this.UserRole == Role.Pharmacy) { return(_pharmacyService.Add(this)); } else { return(string.Empty); } }
public ActionResult Add(CUSTOMCOMPANY model) { try { ICompanyService svc = new CompanyService(); var result = svc.Add(model); this.AddNotification("Your Data Has Been Successfully Saved. ", NotificationType.SUCCESS); return(RedirectToAction("Index")); } catch (Exception ex) { general.AddLogError("Company Add", ex.Message, ex.StackTrace); this.AddNotification("ID exist", NotificationType.ERROR); return(View("~/Views/Master/Company/Add.cshtml")); } }
public ActionResult Create(CompanyModel company) { try { var x = company.ImageFile.InputStream; byte[] b = System.IO.File.ReadAllBytes(company.ImageFile.FileName); // TODO: Add insert logic here _companyService.Add(company); return(RedirectToAction("Index")); } catch (Exception ex) { return(View()); } }
public void CallMapperMapMethod_WhenInvokedWithValidArgs() { //Arrange var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedMapper = new Mock <IMapper>(); var companyService = new CompanyService(mockedUnitOfWork.Object, mockedMapper.Object); var mockedCompanyRepository = new Mock <IGenericRepository <Company> >(); var mockedCompany = new Mock <Company>(); var mockedCompanyModel = new Mock <CompanyModel>(); //Act mockedMapper.Setup(x => x.Map <Company>(mockedCompanyModel.Object)).Returns(mockedCompany.Object); companyService.Add(mockedCompanyModel.Object); //Assert mockedMapper.Verify(x => x.Map <Company>(mockedCompanyModel.Object), Times.Once); }
public ActionResult Add(CreateCompanyViewModel model) { if (!ModelState.IsValid) { return(View(model)); } if (_companyService.Get(model.Name) != null) { ModelState.AddModelError("Name", "Company's name already registered"); return(View(model)); } _companyService.Add(model.ToCompany()); return(RedirectToAction("Index")); }
public Result Add(Company company) { var result = new Result(); try { CompanyService compService = new CompanyService(); compService.Add(company); result.IsSuccess = true; } catch (Exception exception) { result.IsSuccess = false; result.ExceptionInfo = exception; } return(result); }
public async Task Add() { DbContextOptions <CompanyContext> options = GetConnectionOptions(); // Run the test against one instance of the context using (CompanyContext context = new CompanyContext(options)) { context.Database.EnsureCreated(); var service = new CompanyService(context, new CoinTypeService(context)); var company1 = JsonConvert.DeserializeObject <Company>(_JSON); company1 = await service.Add(company1); List <Company> result = service.GetAll().ToList(); Assert.Single(result); Assert.Equal(company1.Id, result.Single().Id); } }
public async Task AddCompany_Test() { // Arrange var companyService = new CompanyService(this.db); // Act await companyService.Add(new Company { Id = 1, Name = "Test Company", Information = "Test Info." }); var companies = this.db.Companies; // Assert Assert.AreEqual(1, companies.Count()); }
public void AddCompany() { //Arrange var companyToAdd = new Company(); var mockCompanySet = new Mock <DbSet <Data.Entities.Company> >(); var mockBenefitsContext = new Mock <BenefitsContext>(); mockBenefitsContext .Setup(b => b.Companies).Returns(mockCompanySet.Object); var companyService = new CompanyService(mockBenefitsContext.Object); //Act companyService.Add(companyToAdd); //Assert mockBenefitsContext.Verify(c => c.SaveChanges(), Times.Once); }
public void ExecuteMethodAndReturnTrue_WhenInvokedWithValidArgs() { //Arrange var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedMapper = new Mock <IMapper>(); var companyService = new CompanyService(mockedUnitOfWork.Object, mockedMapper.Object); var mockedCompany = new Mock <Company>(); var mockedCompanyModel = new Mock <CompanyModel>(); var mockedCompanyRepository = new Mock <IGenericRepository <Company> >(); //Act mockedMapper.Setup(x => x.Map <Company>(mockedCompanyModel.Object)).Returns(mockedCompany.Object); mockedUnitOfWork.Setup(x => x.CompanyRepository).Returns(mockedCompanyRepository.Object); mockedCompanyRepository.Setup(x => x.Update(mockedCompany.Object)); mockedUnitOfWork.Setup(x => x.SaveChanges()); //Assert Assert.IsTrue(companyService.Add(mockedCompanyModel.Object)); }
public virtual IHttpActionResult Add(CompanyAddRequest request) { var entity = new Company { }; var result = _companyService.Add(entity); if (result > 0) { return(Succeed(new CompanyAddResponse { Id = entity.Id }, "新增成功")); } else { return(Fail("新增失败")); } }