public async Task GivenTwoCompaniesShouldFindCompanyByName() { var settingsBuilder = new CompanySettingsBuilder(); var config = settingsBuilder.GetSettings(); var options = new DbContextOptionsBuilder <CompanyContext>() .UseInMemoryDatabase(databaseName: "ShouldFindCompanyByAddress") .Options; using (var context = new CompanyContext(options)) { await context.Database.EnsureCreatedAsync(); var repository = new CompanyRepository(context); var company1 = mock.MockCompany("ABC"); var company2 = mock.MockCompany("XYZ"); await repository.Add(company1); await repository.Add(company2); var matchingCompanies = await repository.SearchForCompaniesByName("AB", config.SearchForCompanyByNameRecordCount); Assert.NotNull(matchingCompanies); Assert.Single(matchingCompanies); var company = matchingCompanies.First(); Assert.Equal("ABC", company.Name); } }
public async void ShouldAddTrip() { //Given var now = DateTime.Now; var companyName = "New One"; var calendar = await CalendarRepository.Add(now); var company = await CompanyRepository.Add(new Company { Name = companyName }, true); var vehicle = await VehicleRepository.Add(new Vehicle { Name = "Vehicle" }, true); var vehicleType = await VehicleTypeRepository.Add(new VehicleType { Name = "VehicleType" }, true); var neighborhood = await NeighborhoodRepository.Add(new Neighborhood { Name = "Neighborhood" }, true); var patternArea = await PatternAreaRepository.Add(new PatternArea { Name = "Pattern Area" }, true); var paymentType = await PaymentTypeRepository.Add(new PaymentType { Name = "Payment" }, true); var controller = new TripController( new Mock <ILogger <TripController> >().Object, TripRepository, CalendarRepository, CompanyRepository, VehicleRepository ); var tripDTO = new TripDTO { StartTime = now, EndTime = now.AddHours(2), CompanyName = companyName, VehicleName = vehicle.Name, VehicleTypeKey = Convert.ToByte(vehicleType.Key), NeighborhoodStartKey = neighborhood.Key, NeighborhoodEndKey = neighborhood.Key, PatternAreaStartKey = patternArea.Key, PatternAreaEndKey = patternArea.Key, PaymentTypeKey = Convert.ToByte(paymentType.Key), PaymentAccessKey = Convert.ToByte(paymentType.Key) }; //When var result = await controller.PostAsync(tripDTO); var dbTrip = await TripRepository.Find(1); //Then var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsType <TripDTO>(viewResult.Value); Assert.NotNull(model); Assert.Equal(tripDTO.EndTime.TimeOfDay, dbTrip.EndTime); }
public void Should_Create_Company() { try { var personContext = new PersonsContext(); var uow = new UnitOfWork<PersonsContext>(); var companyRepository = new CompanyRepository(uow); var company = new Company { Name = "P", Email = "*****@*****.**" }; companyRepository.Add(company); Assert.IsNotNull(personContext.Companies.FirstOrDefault(c => c.Name == "P")); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Console.WriteLine(("Property: {0} Error: {1}"), validationError.PropertyName, validationError.ErrorMessage); } } } }
public JsonResult AddCompanies(CompanyViewModel model) { Company _company = new Company(); if (model != null && model.CompanyID == 0) { _company.Address = model.Address; _company.CityId = model.CityID; _company.CompanyName = model.CompanyName; _company.Active = true; _company.WebsiteURL = model.WebsiteUrl; _company.Phone = model.PhoneNo; rep.Add(_company); return(Json(new { success = true, message = "Save Successfully" }, JsonRequestBehavior.AllowGet)); } else { _company.Address = model.Address; _company.CityId = model.CityID; _company.CompanyName = model.CompanyName; _company.Active = true; _company.WebsiteURL = model.WebsiteUrl; _company.Phone = model.PhoneNo; _company.CompanyId = model.CompanyID; rep.Update(_company); return(Json(new { success = true, message = "Update Successfully" }, JsonRequestBehavior.AllowGet)); } return(null); }
public ActionResult Create([Bind(Include = "SID, IDCOMPANY, COMPANYNAME, ADDRESS1, ADDRESS2, COUNTRY, PROVINCE, CITY, TELEPHONE1, TELEPHONE2, FAX1, FAX2, EMAIL, WEBSITE, POSCODE, INPUTBY, INPUTDATE, UPDATEBY, UPDATEDATE")] Company company) { if (ModelState.IsValid) { ICP.Add(company); TempData["successmessage"] = "Saved successfully"; return(RedirectToAction("Create")); } else { company.GetSelectListCountry = GetSelectListCountry(); company.GetSelectListProvince = GetSelectListProvince(); company.GetSelectListCity = GetSelectListCity(); return(View(company)); } }
public ActionResult Create(CompanyCreateEditViewModel company) { if (ModelState.IsValid) { // Dodanie nowej firmy i zapisanie w bazie danych if (TryUpdateModel(company)) { // Ustawienie daty umieszczenia firmy company.Company.PostedDate = DateTime.Now; // Ustawienie użytkownika dodającego firmę oraz adresu IP company.Company.UserId = WebSecurity.CurrentUserId; company.Company.IPAddress = Request.UserHostAddress; company.Company.WebPage = ChangeUrlAddress(company.Company.WebPage); company.Company.AbsolventWebPage = ChangeUrlAddress(company.Company.AbsolventWebPage); company.Company.GoldenLineWebPage = ChangeUrlAddress(company.Company.GoldenLineWebPage); company.Company.GoworkWebPage = ChangeUrlAddress(company.Company.GoworkWebPage); // Dodanie nowej firmy i zapisanie zmian _companyRepo.Add(company.Company); _companyRepo.SaveChanges(); return(RedirectToAction("Details", new { id = company.Company.Id })); } // Pobranie listy kategorii firm i umieszczenie jej w obiekcie ViewData ViewData["Categories"] = GetCategoriesList(); return(View(company)); } TempData["Error"] = "Wystąpił błąd podczas dodawania wpisu!"; return(RedirectToAction("Index")); }
private void btnAddButton_Click(object sender, EventArgs e) { Company company = new Company(); CompanyForm frmCompanyForm = new CompanyForm(company); frmCompanyForm.MdiParent = MdiParent; frmCompanyForm.AddButton.Enabled = false; frmCompanyForm.EditButton.Enabled = false; frmCompanyForm.DeleteButton.Enabled = false; frmCompanyForm.Show(); frmCompanyForm.Text = "Szczegóły firmy - Dodaj firmę"; frmCompanyForm.SaveButton.Click += delegate { company = frmCompanyForm.Company; string errorText = string.Empty; CompanyRepository companyRepository = new CompanyRepository(); if (Validation.ValidateCompany(company, ref errorText)) { companyRepository.Add(company); frmCompanyForm.Close(); } else { ShowErrorMessage(errorText); } bsCompanies.DataSource = companyRepository.FindAll(); grdCompanies.Refresh(); }; }
public void RemoveTest() { IZipCodeRepository r = new ZipCodeRepository(); var list = r.GetAll().GetEnumerator(); list.MoveNext(); Empresa item = new Empresa() { Nome = "company01", CNPJ = "12345678901234", InscricaoEstadual = "Isento", Complemento = "Ao lado do mercado", Numero = 10, Cep = list.Current }; ICompanyRepository target = new CompanyRepository(); target.Add(item); target.Remove(item); // use session to try to load the product using (ISession session = NHibernateHelper.OpenSession()) { var fromDb = session.Get <Empresa>(item.Id); Assert.IsNull(fromDb); Assert.AreNotSame(item, fromDb); } }
public bool InsertNewCompany(Company company) { company.JoinCompanyBod = new List <JoinCompanyBoardMember>(); company.JoinCompanyExchanges = new List <JoinCompanyStockExchange>(); company.Ipos = new List <IPODetails>(); company.CurrentPrices = new List <StockPrice>(); return(repository.Add(company)); }
private void Add() { var company = new ClassLibrary.Objects.Company { Name = this.NameTextBox.Text.Trim() }; var repository = new CompanyRepository(); repository.Add(company); this.CompanyIdField = company.Id; }
public bool IsInserted(Company company) { if (company.Name.Length < 3) { throw new Exception("Name must be greater than 3 character"); } bool isAdded = companyRepository.Add(company); return(isAdded); }
public async void ShouldAddCollision() { //Given var now = DateTime.Now; var calendar = await CalendarRepository.Add(Calendars[0].Date); await CompanyRepository.Add(Companies[0], true); await TripRepository.Add(Trips[0]); await VehicleRepository.Add(Vehicles[0], true); var status = await StatusRepository.Add(new Status { Name = "Open" }, true); var location = new Point(new Coordinate(-122.3456, 45.67890)); var collisionDTO = new CollisionDTO { Date = Calendars[0].Date + now.TimeOfDay, Location = location.ToGeoJson <GeoJSON.Net.Geometry.Point>(), CompanyName = Companies[0].Name, VehicleName = Vehicles[0].Name, TripAlternateKey = Trips[0].AlternateKey, VehicleTypeKey = 4, OtherVehicleTypeKey = 1, ClaimStatusKey = Convert.ToByte(status.Key) }; //When var result = await Controller.PostAsync(collisionDTO); var dbCollision = await CollisionRepository.Find(1); //Then var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsType <CollisionDTO>(viewResult.Value); Assert.NotNull(model); Assert.Equal(collisionDTO.Date, model.Date); Assert.True(dbCollision.FirstSeen == dbCollision.LastSeen); }
public async void ShouldAddComplaint() { //Given var now = DateTime.Now; var calendar = await CalendarRepository.Add(Calendars[0].Date); await CompanyRepository.Add(Companies[0], true); await TripRepository.Add(Trips[0]); await VehicleRepository.Add(Vehicles[0], true); var status = await StatusRepository.Add(new Status { Name = "Open" }, true); var location = new Point(new Coordinate(-122.3456, 45.67890)); var complaintDTO = new ComplaintDTO { SubmittedDate = Calendars[0].Date + now.TimeOfDay, Location = location.ToGeoJson <GeoJSON.Net.Geometry.Point>(), CompanyName = Companies[0].Name, VehicleName = Vehicles[0].Name, VehicleTypeKey = 1, ComplaintTypeKey = 8, ComplaintDetails = "Vehicle component issue", Complaints = new string[] { } }; //When var result = await Controller.PostAsync(complaintDTO); var dbCollision = await ComplaintRepository.Find(1); //Then var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsType <ComplaintDTO>(viewResult.Value); Assert.NotNull(model); Assert.Equal(complaintDTO.SubmittedDate, model.SubmittedDate); Assert.True(dbCollision.FirstSeen == dbCollision.LastSeen); }
public bool Add(Company company) { if (company == null && company.Name.Length < 2) { throw new Exception("Sorry, Invalid Name Inserted!"); } bool isAdded = _repository.Add(company); return(isAdded); }
public void Add(Company company) { try { companyRepository.Add(company); } catch (Exception ex) { throw ex; } }
public ActionResult Add(CompanyViewModel worker) { if (!ModelState.IsValid) { repo.Add(CopyToModel(worker), GetId() + 1); return(RedirectToAction("GetAll", "Company")); } else { return(View(worker)); } }
//CREATE COMPANIES - ADD TO REPO public Company CreateNewCompany() { ICompanyRepository repoCompany = new CompanyRepository(db); var company = new Company { ABN = "100100", Name = "Redcat" }; repoCompany.Add(company); return(company); }
public void Add(CompanyModel entity) { var company = new Company() { Code = entity.Code, Logo = entity.Logo, Name = entity.Name, PhoneNo = entity.PhoneNo }; _companyRepository.Add(company); }
public bool Add(Company company, out string strResult) { strResult = string.Empty; bool result = false; var comp = new Company(); var parent = CompanyRepository.GetQueryable().FirstOrDefault(p => p.ID == company.ParentCompanyID); var comExist = CompanyRepository.GetQueryable().FirstOrDefault(c => c.CompanyCode == company.CompanyCode); if (comExist == null) { if (comp != null) { try { comp.ID = Guid.NewGuid(); comp.CompanyCode = company.CompanyCode; comp.CompanyName = company.CompanyName; comp.CompanyType = company.CompanyType; comp.Description = company.Description; comp.ParentCompany = parent ?? comp; comp.UniformCode = company.UniformCode; comp.WarehouseCapacity = company.WarehouseCapacity; comp.WarehouseCount = company.WarehouseCount; comp.WarehouseSpace = company.WarehouseSpace; comp.SortingCount = company.SortingCount; comp.IsActive = company.IsActive; comp.UpdateTime = DateTime.Now; CompanyRepository.Add(comp); CompanyRepository.SaveChanges(); //组织机构上报 //DataSet ds = this.Insert(comp); //Upload.UploadOrganization (ds); result = true; } catch (Exception ex) { strResult = "原因:" + ex.Message; } } else { strResult = "原因:找不到当前登陆用户!请重新登陆!"; } } else { strResult = "原因:该编号已存在!"; } return(result); }
public async void ShouldUpdateDeployment() { //Given var now = DateTime.Now; var companyName = "New One"; var calendar = await CalendarRepository.Add(now); await CompanyRepository.Add(new Company { Name = companyName }, true); var dbDeployment = new Deployment { Key = 1, StartDateKey = calendar.Key, StartTime = now.TimeOfDay, EndDateKey = calendar.Key, EndTime = now.TimeOfDay.Add(TimeSpan.FromHours(1)) }; await DeploymentRepository.Add(dbDeployment); // since we are modifying directly and not scoping, we'll need this Context.Entry(dbDeployment).State = EntityState.Detached; var controller = new DeploymentController( new Mock <ILogger <DeploymentController> >().Object, DeploymentRepository, CalendarRepository, CompanyRepository, VehicleRepository ); var deploymentDTO = new DeploymentDTO { Key = 1, StartTime = now, EndTime = now.AddHours(2), CompanyName = companyName }; //When var result = await controller.Update(deploymentDTO.Key, deploymentDTO); dbDeployment = await DeploymentRepository.Find(1); //Then var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsType <DeploymentDTO>(viewResult.Value); Assert.NotNull(model); Assert.Equal(deploymentDTO.EndTime.Value.TimeOfDay, dbDeployment.EndTime); }
public void ConstructorSetsCorrectEfenkaContext() //done by checking if getbyid works { EfenkaContextTestFactory.Create(); _sut = new CompanyRepository(EfenkaContextTestFactory.EfenkaContext); var company = new Company(); _sut.Add(company); var companyFromDatabase = _sut.GetById(company.Id); Assert.That(companyFromDatabase, Is.EqualTo(company)); }
public static void MyClassInitialize(TestContext testContext) { IZipCodeRepository r = new ZipCodeRepository(); var list = r.GetAll().GetEnumerator(); list.MoveNext(); item = new Empresa() { Nome = "company", CNPJ = "12345678901234", InscricaoEstadual = "Isento", Complemento = "Ao lado do mercado", Numero = 10, Cep = list.Current }; ICompanyRepository target = new CompanyRepository(); target.Add(item); }
public bool Add(Company company) { DataTable dt = companyRepository.Show(); foreach (DataRow check in dt.Rows) { if (check["Name"].ToString() == company.CompanyName) { return(false); } } bool isAdded = companyRepository.Add(company); return(isAdded); }
public ActionResult Create(Company company) { if (Request.IsAjaxRequest()) { if (ModelState.IsValid) { _repository.Add(company); } else { return(PartialView("_CreatePartialView", company)); } } return(PartialView("_TablePartialView", _repository.GetAll(company.Relation))); }
public ActionResult Create(CompanyViewModel company) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values.SelectMany(a => a.Errors).Select(a => a.ErrorMessage))); } var companhia = _companyRepository.Add(_mapper.Map <Company>(company)); if (companhia == null) { return(BadRequest()); } return(Ok(_mapper.Map <CompanyViewModel>(companhia))); }
public ActionResult CreateCompany(string companyName) { if (string.IsNullOrEmpty(companyName)) { throw new Exception("Specify a company name"); } Company company = new Company() { CompanyName = companyName }; CompanyRepository companyRepository = new CompanyRepository(); companyRepository.Add(company); companyRepository.PersistChanges(); return(Content(JsonConvert.SerializeObject(company))); }
public void AddandDeleteTest() { List <Company> expected = Companies(); Company company = new Company() { CVR = 68598712, Name = "Wild hairy", Id = 7, ImageUrl = "https://stocklogos-pd.s3.amazonaws.com/styles/logo-medium-alt/logos/image/cb5719494a08e764c8e051cac90065d9.png?itok=kjyW4wJl", Address = "Spangsbjerg Kirkevej 100 A", WebSite = "www.Wildhair.dk", Tel = "+41626289", OpenHours = "8-7", MinPrice = 150, MaxPrice = 500, Description = "Dedicaded hair salon for the wildness in your hair.", Category = category8, Ratings = new List <Rating>() { rating11, rating12 }, Reviews = new List <Review>() { rev6 }, Tags = new List <Tag>() { tag3, tag4 }, NrRate = 2, Badges = new List <Badge> { } }; expected.Add(company); repo.Add(company); List <Company> actual = repo.ReadAll(); Company actuall = actual.Last(); Assert.IsTrue(comparer(company, actuall)); repo.Delete(company.Id); expected.Remove(company); Assert.IsTrue(listcomparer(repo.ReadAll(), expected)); }
public void Add_ShouldReturnSingleCompany_WhenJustOneWasAdded() { // Arrange var options = new DbContextOptionsBuilder <AlfavoxDbContext>() .UseInMemoryDatabase(databaseName: "AlfavoxDB") .Options; var context = new AlfavoxDbContext(options); var repository = new CompanyRepository(context); // Act repository.Add(new Company() { Name = "AlfavoxCompany" }); var result = repository.GetAll().ToList(); // Assert Assert.Single(result); }
public ActionResult AddingCompany(MallOfElectronics.Models.DataBase.Company company) { if (ModelState.IsValid) { CompanyRepository companyRepository = new CompanyRepository(); if (companyRepository.Add(company)) { ViewBag.Message = "This Company Has Been Added"; } else { ViewBag.ErrorMessage = "This Company Not Has Been Added"; } } else { ViewBag.ErrorMessage = "This Company Not Has Been Added"; } return(View()); }
public async Task GivenACompanyShouldFindCompanyByAddress() { var options = new DbContextOptionsBuilder <CompanyContext>() .UseInMemoryDatabase(databaseName: "ShouldFindCompanyByAddress") .Options; using (var context = new CompanyContext(options)) { await context.Database.EnsureCreatedAsync(); var repository = new CompanyRepository(context); var address = new Domain.Address { AddressId = Guid.NewGuid(), StreetNumber = "1112", StreetAddress = "Carissa Dr.", City = "TTown", State = "FL", ZipCode = "32308" }; var objectUnderTest = mock.MockCompany("FDHSMV", address); await repository.Add(objectUnderTest); var actualValue = await repository.SearchForCompaniesByAddress(address); Assert.NotNull(actualValue); Assert.Equal(objectUnderTest.Name, actualValue[0].Name); } }
public bool Add(Company company) { var comp = new Company(); var parent = CompanyRepository.GetQueryable().FirstOrDefault(p => p.ID == company.ParentCompanyID); comp.ID = Guid.NewGuid(); comp.CompanyCode = company.CompanyCode; comp.CompanyName = company.CompanyName; comp.CompanyType = company.CompanyType; comp.Description = company.Description; comp.ParentCompany = parent ?? comp; comp.UniformCode = company.UniformCode; comp.WarehouseCapacity = company.WarehouseCapacity; comp.WarehouseCount = company.WarehouseCount; comp.WarehouseSpace = company.WarehouseSpace; comp.SortingCount = company.SortingCount; comp.IsActive = company.IsActive; comp.UpdateTime = DateTime.Now; CompanyRepository.Add(comp); CompanyRepository.SaveChanges(); return(true); }
public void CreateCompany(Company company) { var repository = new CompanyRepository(_db); repository.Add(company); repository.Save(); }