public async Task <WorkMonth> GetWorkMonthAsync(string userId, int organisationId, int month, int year) { List <WorkMonth> workMonths; using (var _context = new TimeKeeperDbContext(_options)) { workMonths = await _context.WorkMonths.Where( x => x.UserId == userId && x.Month == month && x.Year == year && x.Organisation.Id == organisationId) .Include(x => x.Organisation) .Include(x => x.Deviations) .ThenInclude(x => x.DeviationType) .ToListAsync(); } if (workMonths.Count < 1) { return(null); } var result = workMonths.FirstOrDefault(); return(result); }
//[TestMethod] public void GetProjectFromDatabase_CheckTeam_ExistingTest() { TimeKeeperDbContext context = new TimeKeeperDbContext(); Project NasaProject = context.Projects.FirstOrDefault(x => x.Name == "NASA Project"); Assert.AreEqual("A", NasaProject.Team.Name); }
public void CheckWorkDays_ForEmployeeThatHasNoDays_FailingTest() { TimeKeeperDbContext context = new TimeKeeperDbContext(); ICollection <Day> FatimaWorkingDays = context.Employees.FirstOrDefault(x => x.FirstName == "Fatima").Days; //Assert }
public void CheckTotalWorkDays_ForEmployee_CountTest() { TimeKeeperDbContext context = new TimeKeeperDbContext(); int TotalDays = context.Employees.FirstOrDefault(x => x.FirstName == "Edo").Days.Count(); Assert.AreEqual(2, TotalDays); }
public static void PopulateDb(TimeKeeperDbContext context) { ApplicationUser user1 = new ApplicationUser { Id = "70658403-ade4-47cf-82a6-034e176290f0", Email = "*****@*****.**", UserName = "******", }; ApplicationUser user2 = new ApplicationUser { Id = "2f044b20-3c7f-4be1-b1b5-c55fbfc0c679", Email = "*****@*****.**", UserName = "******", }; // OrganisationId will be 1. Organisation org = new Organisation { Name = "Electronics Store", ManagerId = "70658403-ade4-47cf-82a6-034e176290f0", OrganisationUsers = new List <ApplicationUser> { user2 }, }; context.Add(user1); context.Add(user2); context.Add(org); context.SaveChanges(); }
public void NameOfTask_OfProject_NameTest() { TimeKeeperDbContext context = new TimeKeeperDbContext(); DAL.Entities.Task EngineOnTask = context.Tasks.Find(2); Assert.AreEqual("Commencing Countdown", EngineOnTask.Description); }
public void CheckProject_WithNoEndDate_FailingTest() { TimeKeeperDbContext context = new TimeKeeperDbContext(); var NasaProjectEndDate = context.Projects.FirstOrDefault(x => x.Name == "NASA Project").EndDate; //Assert Assert.AreEqual(null, NasaProjectEndDate); }
public void CheckSalary_OfEmployee_PassingTest() { TimeKeeperDbContext context = new TimeKeeperDbContext(); Employee E = (Employee)context.Employees.Find(2); Assert.AreEqual(6000, E.Roles.Mrate); }
public void EmployeeSoftDelete_PassingTest() { TimeKeeperDbContext context = new TimeKeeperDbContext(); context.Employees.Remove(context.Employees.First(x => x.FirstName == "Fatima")); context.SaveChanges(); Employee fatima = context.Employees.First(x => x.FirstName == "Fatima"); }
public void CheckId_OfEmployee_PassingTest() { TimeKeeperDbContext context = new TimeKeeperDbContext(); Employee EdoRole = (Employee)context.Employees.Find(2); Assert.AreEqual("TL", EdoRole.Roles.Id); }
public async Task <ApplicationUser> GetApplicationUserAsync(string id) { using (var _context = new TimeKeeperDbContext(_options)) { var user = await _context.AspNetUsers.Where(x => x.Id == id).Include("Organissations").FirstOrDefaultAsync(); return(user); } }
public async Task <Invitation> GetInvitationAsync(int id) { using (var context = new TimeKeeperDbContext(_options)) { Invitation invitation = await context.Invitations.Where(x => x.Id == id).FirstOrDefaultAsync(); return(invitation); } }
public async Task <IEnumerable <Invitation> > GetActiveInvitationsAsync(string userId) { using (var context = new TimeKeeperDbContext(_options)) { List <Invitation> invitations = await context.Invitations.Where(x => x.UserId == userId && x.requireAction == true).ToListAsync(); return(invitations); } }
public async Task <Organisation> GetOrganisationWithUsersAsync(int id) { using (var context = new TimeKeeperDbContext(_options)) { var organisation = await context.Organisation.Where(x => x.Id == id).Include("OrganisationUsers").FirstOrDefaultAsync(); return(organisation); } }
public async Task <IEnumerable <Organisation> > GetTopOrganisationsAsync(string userId) { using (var context = new TimeKeeperDbContext(_options)) { var organisations = await context.Organisation.Where(x => x.ManagerId == userId).Include("Section").ToListAsync(); return(organisations.Where(x => x.FK_Parent_OrganisationId == null)); } }
public async Task <int> GetNumberOfTopOrganisationsAsync(string userId) { using (var context = new TimeKeeperDbContext(_options)) { var organisations = await context.Organisation.Where(x => x.OrganisationOwner == userId && x.FK_Parent_OrganisationId == null).ToListAsync(); var nrOfOrganisations = organisations.Count(); return(nrOfOrganisations); } }
public void CountRoles_PassingTest() { //Arrange TimeKeeperDbContext context = new TimeKeeperDbContext(); //Act int roles = context.Roles.Count(); //Assert Assert.AreEqual(2, roles); }
public async Task <Invitation> UpdateInvitationAsync(Invitation invitation) { using (var context = new TimeKeeperDbContext(_options)) { context.Invitations.Update(invitation); await context.SaveChangesAsync(); return(invitation); } }
public async Task <WorkMonth> AddWorkMonth(WorkMonth workMonth) { using (var context = new TimeKeeperDbContext(_options)) { var result = context.Add(workMonth); await context.SaveChangesAsync(); return(result.Entity); } }
public async Task <ApplicationUser> UpdateApplicationUserAsync(ApplicationUser applicationUser) { using (var _context = new TimeKeeperDbContext(_options)) { _context.AspNetUsers.Update(applicationUser); await _context.SaveChangesAsync(); return(applicationUser); } }
public async Task <Deviation> AddDeviationAsync(Deviation deviation) { using (var _context = new TimeKeeperDbContext(_options)) { var result = _context.Add(deviation); await _context.SaveChangesAsync(); return(result.Entity); } }
public async Task <Organisation> AddOrganisationAsync(Organisation organisation) { using (var context = new TimeKeeperDbContext(_options)) { var result = context.Organisation.Add(organisation); await context.SaveChangesAsync(); return(result.Entity); } }
public async Task <WorkMonth> GetWorkMonthByIdAsync(int Id) { WorkMonth month; using (var _context = new TimeKeeperDbContext(_options)) { month = await _context.WorkMonths.FirstOrDefaultAsync(x => x.Id == Id); } return(month); }
public async Task <IEnumerable <DeviationType> > GetAllDeviationTypesAsync() { List <DeviationType> result; using (var _context = new TimeKeeperDbContext(_options)) { result = await _context.DeviationTypes.Where(x => x != null).ToListAsync(); } return(result); }
public async Task <IEnumerable <Organisation> > GetOrganisationsWhereUserIsMemberAsync(string userId) { using (var context = new TimeKeeperDbContext(_options)) { var organisations = await context.Organisation.Where(x => x.OrganisationUsers.Contains(new ApplicationUser { Id = userId })).ToListAsync(); return(organisations); } }
public void CheckTotalWorkHours_ForEmployee_CountTest() { TimeKeeperDbContext context = new TimeKeeperDbContext(); //ICollection<Day> EdosWorkingDays = context.Employees.FirstOrDefault(x => x.FirstName == "Edo").Days; var hours = context.Days.Where(x => x.Employee.FirstName == "Edo").Sum(x => x.Hours); //decimal TotalHours = 0M; Assert.AreEqual(16, hours); }
public void AddProjects_WithoutHours_ValidationTest() { TimeKeeperDbContext context = new TimeKeeperDbContext(); Project newProject = new Project() { Name = "IMT Rezervni Dijelovi za Bagere", Description = "Some IMT Project", Status = ProjectStatus.Finished, Pricing = PricingStatus.HourlyRate, Team = context.Teams.Find("A") }; context.Projects.Add(newProject); context.SaveChanges(); }
public void AddCustomer_ValidData_PassingTest() { TimeKeeperDbContext context = new TimeKeeperDbContext(); Customer Mistral = new Customer() { Name = "Mistral", Status = CustomerStatus.Client, Contact = "Mersed Camdzic", Email = "*****@*****.**", Phone = "062 212 213" }; context.Customers.Add(Mistral); context.SaveChanges(); Assert.AreEqual(3, context.Customers.Count()); }
public void CountHrate_OfRoles_PassingTest() { TimeKeeperDbContext context = new TimeKeeperDbContext(); int numberOfRoles = context.Roles.Count(); IQueryable <Role> roles = context.Roles; int sameHrate = 0; foreach (var role in roles) { if (role.Hrate == 30) { sameHrate++; } } Assert.AreEqual(1, sameHrate); }
public void NumberOfTasks_ByProject_CountTest() { TimeKeeperDbContext context = new TimeKeeperDbContext(); ICollection <DAL.Entities.Task> listOfTasks = context.Tasks.ToList(); int countNasaTasks = 0; foreach (var task in listOfTasks) { if (task.Project.Name == "NASA Project") { countNasaTasks++; } } Assert.AreEqual(2, countNasaTasks); }