public void ShouldDeleteEmployee() { // Arrange using (IEmployeeContext employeeContext = new EmployeeContext(new DropCreateDatabaseAlways<EmployeeContext>())) { IEmployeeRepository employeeRepository = new EmployeeRepository(employeeContext); var employee1 = CreateEntity.Employee1; var employee2 = CreateEntity.Employee2; employeeRepository.Add(employee1); employeeRepository.Add(employee2); var numberOfAdds = +employeeContext.SaveChanges(); // Act employeeRepository.Remove(employee2); var numberOfDeletes =+ employeeContext.SaveChanges(); // Assert numberOfAdds.Should().Be(2); numberOfDeletes.Should().Be(1); var allEmployees = employeeRepository.GetAll().ToList(); allEmployees.Should().HaveCount(1); allEmployees.ElementAt(0).ShouldBeEquivalentTo(employee1, options => options.IncludingAllDeclaredProperties()); } }
public string CreateEmployee(Employees employee) { //if (!ModelState.IsValid) return "Model is invalid"; employee.Password = _db.EncodePassword(employee.Password); _db.Add(employee); return("Employee is created"); }
public void ShouldDeleteEmployee() { // Arrange using (IEmployeeContext employeeContext = new EmployeeContext(new DropCreateDatabaseAlways <EmployeeContext>())) { IEmployeeRepository employeeRepository = new EmployeeRepository(employeeContext); var employee1 = CreateEntity.Employee1; var employee2 = CreateEntity.Employee2; employeeRepository.Add(employee1); employeeRepository.Add(employee2); var numberOfAdds = +employeeContext.SaveChanges(); // Act employeeRepository.Remove(employee2); var numberOfDeletes = +employeeContext.SaveChanges(); // Assert numberOfAdds.Should().Be(2); numberOfDeletes.Should().Be(1); var allEmployees = employeeRepository.GetAll().ToList(); allEmployees.Should().HaveCount(1); allEmployees.ElementAt(0).ShouldBeEquivalentTo(employee1, options => options.IncludingAllDeclaredProperties()); } }
public void ShouldAddDepartment() { // Arrange using (IEmployeeContext employeeContext = new EmployeeContext()) { IEmployeeRepository employeeRepository = new EmployeeRepository(employeeContext); employeeRepository.Add(CreateEntity.Employee1); employeeRepository.Add(CreateEntity.Employee2); employeeRepository.Add(CreateEntity.Employee3); employeeContext.SaveChanges(); IDepartmentRepository departmentRepository = new DepartmentRepository(employeeContext); var department = CreateEntity.Department1; // Act departmentRepository.Add(department); var numberOfChangesCommitted = employeeContext.SaveChanges(); // Assert numberOfChangesCommitted.Should().BeGreaterThan(0); var allDepartments = departmentRepository.GetAll().ToList(); allDepartments.Should().HaveCount(1); allDepartments.ElementAt(0).ShouldBeEquivalentTo(department, options => options.IncludingAllDeclaredProperties()); } }
public void TestInit() { EmployeeRepository repository = GetEmployeeRepository(); repository.FindAll().Clear(); repository.Add(EmployeeTest.GetEmployee()); repository.Add(EmployeeTest.GetEmployee1()); }
public void CreateEmployee_WhenDuplicatedEmail_ThrowsException() { _repository = new EmployeeRepository(); _repository.Add(_newEmployee); Assert.That(() => _repository.Add(_newEmployee), Throws.ArgumentException); }
/// <summary> /// CreateEntiy /// </summary> /// <param name="product">The entity.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> public bool CreateEntiy(EmployeeDto t) { var dbEntity = typeAdapter.ConvertDtoToEntities(t); entiesrepository.Add(dbEntity); entiesrepository.Save(); return(true); }
public void GetAllEmployees_WhenCalled_ReturnsAllEmployees() { _repository = new EmployeeRepository(); _repository.Add(_firstEmployee); _repository.Add(_secondEmployee); Assert.That(_repository.GetAllEmployees().Count, Is.EqualTo(2)); }
public void FindEmployeeByEmail_WhenCalledWithExistingEmail_ReturnsEmployee() { _repository = new EmployeeRepository(); _repository.Add(_firstEmployee); _repository.Add(_newEmployee); var result = _repository.FindEmployeeByEmail("*****@*****.**"); Assert.That(result.ToString(), Is.EqualTo("Youssef Elhakim [email protected] Male 19 6000.00 PermanentEmployee")); }
public void DeleteEmployeeByName_WhenCalledWithExistingEmail_RemovesEmployee() { _repository = new EmployeeRepository(); _repository.Add(_firstEmployee); _repository.Add(_secondEmployee); _repository.DeleteByName("Mohamed Elhakim"); Assert.That(_repository.GetAllEmployees().Count, Is.EqualTo(1)); }
public ActionResult Create(IFormCollection collection) { try { // TODO: Add insert logic here int departmentId = 0; if (int.TryParse(collection["DepartmentId"], out departmentId)) { var findDepartment = departmentRepository.FindById(departmentId); if (findDepartment != null) { var newEmployee = new SmartIT.Employee.MockDB.Employee() { Name = collection["Name"], Gender = collection["Gender"], DepartmentId = departmentId }; employeeRepository.Add(newEmployee); } } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
private void button2_Click(object sender, EventArgs e) { try { Employee newEmployee = new Employee(); newEmployee.Username = textBox1.Text; newEmployee.Password = ""; newEmployee.FirstName = textBox2.Text; newEmployee.LastName = textBox3.Text; newEmployee.Email = textBox4.Text; newEmployee.Telephone = textBox5.Text; newEmployee.OfficeNumber = int.Parse(textBox6.Text); if (employeeRepository.GetEmployeeByName(newEmployee.Username) == null) { employeeRepository.Add(newEmployee); DialogResult = DialogResult.OK; Dispose(); } else { MessageBox.Show("User with given username already exists!"); } } catch (FormatException) { MessageBox.Show("Office number must be integer number!"); } }
/// <summary> /// Manage Employee Action on Database /// </summary> /// <param name="action">action (GetAll, Get, Create, Delete)</param> /// <param name="id">int id of employee</param> /// <param name="page">int actual page</param> /// <param name="limit">int page limit</param> /// <param name="employee">object employee</param> /// <returns>Depending of action, returns list of employees, object employee or status messages</returns> private IHttpActionResult ManageEmployee(int action, int?id, int?page, int?limit, Employee employee) { try { using (EmployeeRepository repo = new EmployeeRepository()) { switch (action) { case (int)_action.GetAll: return(Ok(repo.GetAll((int)page, (int)limit))); case (int)_action.Get: return(Ok(repo.Get((int)id))); case (int)_action.Create: repo.Add(employee); return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Created, "Employee Created"))); case (int)_action.Delete: repo.Delete((int)id); return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.OK, "Employee Deleted"))); default: return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "An error occurred, try again"))); } } } catch (Exception e) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e.Message))); } }
public void Add(EmployeeDetailDTO item) { List <string> users = new List <string>(); users = new SecurityHelper().GetAllUsernames(); users = users.Where(u => u.Equals(item.Username)).ToList <string>(); if (users.Count > 0) { throw new Exception("This username already exists."); } else { string password = Membership.GeneratePassword(12, 1); WebSecurity.CreateUserAndAccount(item.Username, password); MailMessage message = new MailMessage(); message.From = new MailAddress("*****@*****.**"); message.To.Add(new MailAddress(item.Email)); message.Subject = "LinkTracker Account Created"; message.Body = "" + password; SmtpClient client = new SmtpClient(); client.Send(message); Roles.AddUserToRole(item.Username, "Employee"); repo.Add(item); } }
public async Task Add_Range_Should_Post_Once_By_Time() { var fakeEmployees = new Employee[2]; var httpClientProxyMock = new Mock <IHttpClientProxy>(); httpClientFactoryMock.Setup(h => h.GetHttpClient(It.IsAny <TimeSpan?>())).Returns(httpClientProxyMock.Object); var httpClientHandlerMock = new Mock <HttpClientHandler>(); using var requestResult = new HttpResponseMessage(HttpStatusCode.OK); requestResult.Content = new StringContent("OK"); httpClientHandlerMock .Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(requestResult); var httpClient = new HttpClient(httpClientHandlerMock.Object); httpClientProxyMock.Setup(h => h.GetHttpClient()).Returns(httpClient); await employeeRepository.Add(fakeEmployees); httpClientHandlerMock.Protected().Verify("SendAsync", Times.Exactly(fakeEmployees.Count()), ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()); httpClientHandlerMock.VerifyNoOtherCalls(); httpClientProxyMock.Verify(h => h.GetHttpClient(), Times.Exactly(2)); httpClientProxyMock.VerifyNoOtherCalls(); httpClientFactoryMock.VerifyNoOtherCalls(); }
public void Test_EmployeeRepository_Update() { // arrange Employee employee = this.CreateNewEmployee(); EmployeeRepository employRepository = RepositoryHelper.GetEmployeeRepository(); // act employRepository.Add(employee); employRepository.Save(); // assert IEnumerable <Employee> employeelist = RepositoryHelper.GetEmployeeRepository().Repository.Find(e => e.EmployeeID == employee.EmployeeID); Assert.NotNull(employeelist); Employee employee2 = employeelist.SingleOrDefault(); Assert.NotNull(employee2); employee.Title = "ProjectManager"; employRepository.Save(); Employee employee3 = RepositoryHelper.GetEmployeeRepository().Repository.Find(e => e.EmployeeID == employee2.EmployeeID). FirstOrDefault(); Assert.NotNull(employee3); Assert.Equal(employee3.Title, "ProjectManager"); employRepository.Delete(employee); employRepository.Save(); }
public void CreateOrganization(CreateOrganizationViewModel orgViewModel) { Organization organization = new Organization() { Id = Guid.NewGuid().ToString(), Name = orgViewModel.OrganizationName }; Employee employee = new Employee() { Id = Guid.NewGuid().ToString(), FirstName = orgViewModel.CeoFirstName, LastName = orgViewModel.CeoLastName, Email = orgViewModel.Email, Password = orgViewModel.Password, DoB = orgViewModel.DoB, OrganizationId = organization.Id }; OrganizationRepository organizationRepository = new OrganizationRepository(); EmployeeRepository employeeRepository = new EmployeeRepository(); using (TransactionScope transactionScope = new TransactionScope()) { try { organizationRepository.Add(organization); employeeRepository.Add(employee); transactionScope.Complete(); } catch { throw new Exception("Transaction failed"); } } }
private void ImportEmployeesFromListToDataBase(IEnumerable <Employee> employees) { var empList = employees; var isNewEmployee = false; foreach (var item in empList) { var employee = _employeeRepository.GetOne(item.BarCode); if (employee == null) { employee = item; isNewEmployee = true; } else { employee.FirstName = item.FirstName; employee.LastName = item.LastName; employee.Patronymic = item.Patronymic; employee.PostId = item.PostId; } if (isNewEmployee) { _employeeRepository.Add(employee); } else { _employeeRepository.Update(employee); } } }
public ActionResult AddEmployee(Employee employee, HttpPostedFileBase resim) { //TODO: Dosya yolunu değiştiremiyorum ve güncellenmede resim kayboluyor employee.Photo = ImageUploader.UploadImage("~/Pictures/", resim); eRep.Add(employee); return(RedirectToAction("EmployeeList")); }
public void Should_Not_Mark_As_Delete_Twice() { //Arrange const string employeeName = "Funcionario-Test"; var employee = new Employee { Name = employeeName, LastName = "Testeee" }; var employeeRepository = new EmployeeRepository(_uow); employeeRepository.Add(employee); _uow.Save(); var employeeExpected = employeeRepository.GetEmployeeByName(employee.Name); //Act employeeRepository.Remove(employeeExpected.Id); _uow.Save(); employeeRepository.Remove(employeeExpected.Id); _uow.Save(); //Assert Assert.IsNotNull(employeeExpected); Assert.IsTrue(employeeExpected.IsDeleted); Assert.AreEqual(employeeName + " (Excluido)", employeeExpected.Name); employeeRepository.DeleteEntityPermanently(employeeExpected); _uow.Save(); Assert.IsNull(employeeRepository.GetEmployeeByName(employee.Name)); }
private void btnAddButton_Click(object sender, EventArgs e) { Employee employee = new Employee(); EmployeeForm frmEmployeeForm = new EmployeeForm(employee, Company); frmEmployeeForm.MdiParent = MdiParent; frmEmployeeForm.CompanyComboBox.Enabled = false; frmEmployeeForm.Show(); frmEmployeeForm.SaveButton.Click += delegate { employee = frmEmployeeForm.Employee; string errorText = string.Empty; EmployeeRepository employeeRepository = new EmployeeRepository(); if (Validation.ValidateEmployee(employee, ref errorText)) { employeeRepository.Add(employee); frmEmployeeForm.Close(); } else { ShowErrorMessage(errorText); } bsEmployees.DataSource = employeeRepository.FindByCompanyId(Company.Id); grdEmployees.DataSource = bsEmployees; grdEmployees.Refresh(); }; }
private static void SingleEmployeeQueries() { var repository = new EmployeeRepository(); var query1 = (from e in repository.GetAll() where e.DepartmentID < 3 && e.ID < 10 orderby e.DepartmentID descending, e.Name ascending select e).ToList(); var query2 = repository.GetAll() .Where(e => e.DepartmentID < 3 && e.ID < 10) .OrderByDescending(e => e.DepartmentID) .OrderBy(e => e.Name); Write(query1); repository.Add(new Employee { ID = 7, DepartmentID = 2, Name = "Andy" }); Write(query1); Write(query2); }
public void TestUow() { Employees employ = new Employees { company = "Alibaba", first_name = "Jack", last_name = "Ma", city = "Hangzhou" }; IEmployeeRepository employeeRepository = new EmployeeRepository(_uowcontext); //UoW employ.AddDomainEvent(new TestEvent("addEvent")); var id = employeeRepository.Add(employ); var employee = employeeRepository.GetAsync(id).Result; employee.job_title = "CEO"; employee.AddDomainEvent(new TestEvent("changeEvent")); employeeRepository.Update(employee); employeeRepository.UnitOfWork.SaveEntitiesAsync(); }
public void Post([FromBody] Employee emp) { if (ModelState.IsValid) { employeeRepository.Add(emp); } }
//Calling repository method (Add) to add a new employee protected void Insert(object sender, EventArgs e) { try { if (!ValidateForm()) { return; } string employeeLastName = txtLastName.Text; string employeeFirstName = txtFirstName.Text; string employeePhone = txtPhone.Text; string employeeZip = txtZip.Text; DateTime hireDate = DateTime.ParseExact(txtHireDate.Text, "MM/dd/yyyy", null); db.Add( new Employee { EmployeeFirstName = employeeFirstName, EmployeeLastName = employeeLastName, EmployeePhone = employeePhone, EmployeeZip = employeeZip, HireDate = hireDate }); CleanForm(); ShowMessage("Employee added successfully!"); } catch (Exception ex) { ShowMessage(ex.Message); } this.BindGrid(); }
public IActionResult Signup(Employee item) { EmployeeRepository repository = new EmployeeRepository(); repository.Add(item); return(RedirectToAction("Login")); }
private void FillEmployee() { PasswordEncode passwordEncode = new PasswordEncode(); var employees = new[] { new Employee { Fullname = "Admin", Email = "*****@*****.**", Password = passwordEncode.EncodePasswordToBase64("123456"), RoleId = 1 }, new Employee { Fullname = "Manager", Email = "*****@*****.**", Password = passwordEncode.EncodePasswordToBase64("123456"), RoleId = 2 }, new Employee { Fullname = "employee1", Email = "*****@*****.**", Password = passwordEncode.EncodePasswordToBase64("123456"), RoleId = 3 }, new Employee { Fullname = "employee2", Email = "*****@*****.**", Password = passwordEncode.EncodePasswordToBase64("123456"), RoleId = 3 }, new Employee { Fullname = "employee3", Email = "*****@*****.**", Password = passwordEncode.EncodePasswordToBase64("123456"), RoleId = 3 }, new Employee { Fullname = "employee4", Email = "*****@*****.**", Password = passwordEncode.EncodePasswordToBase64("123456"), RoleId = 3 } }; EmployeeRepository employeeRepository = new EmployeeRepository(); foreach (Employee employee in employees) { employeeRepository.Add(employee); } }
public void Call() { var employee = new Employee(); Console.WriteLine("First name:"); employee.FirstName = Console.ReadLine(); Console.WriteLine("Last Name:"); employee.LastName = Console.ReadLine(); var result = _employeeRepository.Add(employee); if (result == ResponseResultType.Success) { PrintHelpers.PrintEmployee(employee); } if (result == ResponseResultType.NoChanges) { Console.WriteLine("No changes have been applied"); } Console.ReadLine(); Console.Clear(); }
// POST /api/employees/ // body: JSON public IHttpActionResult Post([FromBody] dynamic data) { int venueId = (int)data.Venue.Id.Value; BookiAPI.DataAccessLayer.Models.Employee employee = new DataAccessLayer.Models.Employee { Name = data.Employee.Name.Value, Phone = data.Employee.Phone.Value, Email = data.Employee.Email.Value.ToLower(), Password = data.Employee.Password.Value, EmployeeNo = (int)data.Employee.EmployeeNo.Value, Title = data.Employee.Title.Value, Salt = data.Employee.Salt.Value }; int employeeId = _employeeRepository.Add(employee); if (employeeId > 0) { if (_venueEmployeesController.Post(venueId, employeeId)) { return(Ok("Employee was created")); } } return(BadRequest("Something went wrong ..")); }
public void DeleteTest() { using (var context = new EmployeeDbContext(_fixure.DbContextOptions)) { context.Database.OpenConnection(); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); // arrange var employeeRepository = new EmployeeRepository(context); var employeeToAdd = new Employee { FirstName = "aaa", LastName = "bbb", Boss = "boss 1", Address = "address 1", DateOfBirth = DateTime.Today.AddDays(-1), Salary = 1_000_000.0 }; var employeeId = employeeRepository.Add(employeeToAdd); var employeeToDelete = employeeRepository.Get(employeeId); employeeRepository.Delete(employeeToDelete); // act var deletedEmployee = employeeRepository.Get(employeeId); // assert Assert.Null(deletedEmployee); } } }
static void Main(string[] args) { //TodoRepository _todoRepository = new TodoRepository(); //var todoList = _todoRepository.GetAll(); //todoList.CDump("_todoRepository.GetAll()"); //var findById = _todoRepository.FindById(2); //findById.CDump("_todoRepository.FindById(2)"); //var newTodo = _todoRepository.Add(new Todo { Name = "Call a friend" }); //_todoRepository.GetAll().CDump("Check if Call a friend todo added?"); //newTodo.Name = newTodo.Name + " Updated"; //_todoRepository.Update(newTodo); //_todoRepository.GetAll().CDump("Check if Call a friend todo updated with Updated?"); //_todoRepository.Delete(_todoRepository.FindById(1)); //_todoRepository.GetAll().CDump("Check if Id=1 todo is Deleted?"); //Use below Employee repository to created CRUD operation EmployeeRepository _employeeRepository = new EmployeeRepository(); _employeeRepository.Add(new Employee() { Name = "Mat Stone", Gender = "Male", DepartmentId = 2, Salary = 8000 }); _employeeRepository.CDump("Employees"); // DebugHelper.cs(29): Employees //{ "Items":[{"Id":1,"Name":"Mike","Gender":"Male","Salary":8000,"DepartmentId":1,"Department":null}, //{"Id":2,"Name":"Adam","Gender":"Male","Salary":5000,"DepartmentId":1,"Department":null}, //{"Id":3,"Name":"Jacky","Gender":"Female","Salary":9000,"DepartmentId":1,"Department":null}, //{"Id":4,"Name":"Mat Stone","Gender":"Male","Salary":8000,"DepartmentId":2,"Department":null}],"Count":4} Console.ReadLine(); }
public IActionResult Create(Employee emp) { EmployeeRepository erepository = new EmployeeRepository(); erepository.Add(emp); return(RedirectToAction("Login")); }
public void AddEmployee() { var ctx = new CompanyCtx(); var employeeRepo = new EmployeeRepository(ctx); var e1 = new Employee { EmployeeCode = "E88", FirstName = "Jonelle", LastName = "Castaneda",DepartmentCode="D01" }; employeeRepo.Add(e1); }