private void createAuClientAndProject() { var auClient = new BillingClient { BillingClientId = 2, Name = "Au", AddressLine1 = "123 Street", AddressLine2 = "", CityStateZip = "DetroitMI48226", Email = "*****@*****.**" }; database.BillingClients.Add(auClient); var vsmProject = new Project { ProjectId = 5, Name = "VSM", BillingClientId = 2, Start = DateTime.Now, End = DateTime.UtcNow, BillingClient = auClient }; database.Projects.Add(vsmProject); database.SaveChanges(); }
public int PostEmployeeTimeRecord(EmployeeTimeRecord employeeTimeRecord) { var count = _timeTrackerDbContext.EmployeeTimeRecord.Count(); employeeTimeRecord.ID = ++count; _timeTrackerDbContext.EmployeeTimeRecord.Add(employeeTimeRecord); _timeTrackerDbContext.SaveChanges(); return(1); }
public void RemoveActivity(int activityId) { // handle Activity object by its ID var activity = new Activity { ActivityID = activityId }; _context.Activities.Remove(activity); _context.SaveChanges(); }
public int CreateProject(ProjectCreateDto project) { var entity = new Project { Name = project.Name }; _context.Projects.Add(entity); _context.SaveChanges(); return(entity.ProjectID); }
public UsersControllerTests() { var options = new DbContextOptionsBuilder <TimeTrackerDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var dbContext = new TimeTrackerDbContext(options); dbContext.Users.Add(new User { Id = 1, Name = "User 1", HourRate = 15 }); dbContext.Users.Add(new User { Id = 2, Name = "User 2", HourRate = 25 }); dbContext.Users.Add(new User { Id = 3, Name = "User 3", HourRate = 35 }); dbContext.SaveChanges(); var logger = new FakeLogger <UsersController>(); _controller = new UsersController(dbContext, logger); }
private void SetUpAuProjectAndClient() { BillingClient au = new BillingClient { BillingClientId = 9, Name = "au", AddressLine1 = null, AddressLine2 = null, CityStateZip = null, Email = null }; Project vsm = new Project { ProjectId = 9, Name = "vsm", Start = null, End = null, BillingClientId = 9, BillingClient = au }; database.Projects.Add(vsm); database.SaveChanges(); }
public async Task FindProjectFromName_returnsExistingProject() { var options = TestHelpers.BuildInMemoryDatabaseOptions("projects"); var projectName = "bobby"; using (var context = new TimeTrackerDbContext(options)) { context.Add(new Project() { BillingClientId = 1, Name = projectName }); context.SaveChanges(); } using (var context = new TimeTrackerDbContext(options)) { var sut = new ProjectService(context); var project = await sut.FindProjectFromName(projectName); project.Should().NotBeNull(); project.Name.Should().Be(projectName); } }
public static void AddTimeOff(this TimeTrackerDbContext dbContext) { dbContext.TimeEntries.AddRange( new TimeEntry() { Date = new DateTime(2018, 12, 1), IsBillable = false, Hours = 2, TimeEntryId = Guid.NewGuid(), TimeEntryType = TimeEntryTypeEnum.Sick, UserId = dbContext.Users.First().UserId, NonBillableReason = "sick" }, new TimeEntry() { Date = new DateTime(2018, 12, 2), IsBillable = false, Hours = 8, TimeEntryId = Guid.NewGuid(), TimeEntryType = TimeEntryTypeEnum.Vacation, UserId = dbContext.Users.Last().UserId, NonBillableReason = "sick2" } ); dbContext.SaveChanges(); }
public static void AddAutonomicAsClientAndProject(this TimeTrackerDbContext dbContext) { dbContext.BillingClients.Add(new BillingClient() { BillingClientId = 1, Name = "Autonomic" }); dbContext.Projects.Add(new Project() { ProjectId = 1, BillingClientId = 1, Name = "au" }); dbContext.SaveChanges(); }
public void GetVacationInfoTest() { using (new TransactionScope(TransactionScopeOption.RequiresNew)) using (TimeTrackerDbContext dbContext = CreateTestContext()) { // Arrange int userId = 1091; string domainName = @"CORP\Maxim.Rozhkov"; DateTime from = new DateTime(2018, 08, 24); DateTime to = new DateTime(2018, 09, 12); dbContext.Vacations.Add(new Vacation(userId, from, to)); dbContext.SaveChanges(); var app = new VacationsApp(new UsersRepository(dbContext), new VacationsRepository(dbContext)); // Act var rc = app.GetVacationInfo(domainName, new DateTime(2018, 08, 27)); //Assert Assert.AreEqual(rc.Interval.Start, from); Assert.AreEqual(rc.Interval.End, to); } }
private void SeedIssues(TimeTrackerDbContext context) { _issues.Add(1, new Issue { Title = "Harry Potter and philosopher's stone", Project = _projects[1] }); _issues.Add(2, new Issue { Title = "JavaScript Promises", Project = _projects[2] }); foreach (Issue issue in _issues.Values) { context.Issues.Add(issue); issue.Identifier = $"{issue.Project.Prefix}-{issue.Id}"; } context.SaveChanges(); }
public UsersControllerTests() { var options = new DbContextOptionsBuilder <TimeTrackerDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var dbContext = new TimeTrackerDbContext(options); var logger = new FakeLogger <UsersController>(); // HACK: EF Core Preview 6 has issues, adding new values here dbContext.Users.Add(new User { Id = 1, Name = "Test User 1", HourRate = 15 }); dbContext.Users.Add(new User { Id = 2, Name = "Test User 2", HourRate = 20 }); dbContext.Users.Add(new User { Id = 3, Name = "Test User 3", HourRate = 25 }); dbContext.SaveChanges(); _controller = new UsersController(dbContext, logger); }
private void SeedWorkLogs(TimeTrackerDbContext context) { var start = DateTime.Now; var end = start.AddHours(5); var worklogs = new WorkLog[] { new WorkLog { Issue = _issues[2], EndDate = end, StartDate = start, Duration = Convert.ToInt32((end - start).TotalMinutes) }, new WorkLog { Issue = _issues[2], StartDate = DateTime.Parse("04/05/2020 20:00:00") } }; context.WorkLogs.AddRange(worklogs); context.SaveChanges(); }
public static void AddTestUsers(this TimeTrackerDbContext dbContext) { dbContext.Users.AddRange(new User() { UserId = Guid.NewGuid(), LastName = "last1", FirstName = "first1", SlackUserId = "slackId1", UserName = "******", GoogleIdentifier = Guid.NewGuid().ToString() }, new User() { UserId = Guid.NewGuid(), LastName = "last2", FirstName = "first2", SlackUserId = "slackId2", UserName = "******", GoogleIdentifier = Guid.NewGuid().ToString() } ); dbContext.SaveChanges(); }
private async Task PopulateTimeEntries(DateTime date) { var timeEntryService = new TimeEntryService(userId, database); if (!database.Projects.Any(x => x.ProjectId == 1)) { database.Projects.Add(new Project() { ProjectId = 1, Name = "Ford" }); database.SaveChanges(); } //total hours = 18 await timeEntryService.CreateBillableTimeEntry(date, 8, 1); await timeEntryService.CreateBillableTimeEntry(date.AddDays(-5), 4, 1); await timeEntryService.CreateBillableTimeEntry(date.AddDays(-2), 4, 1); await timeEntryService.CreateBillableTimeEntry(date.AddDays(-2), 2, 1); //total hours = 13 await timeEntryService.CreateNonBillableTimeEntry(date.AddDays(-5), 4, null, TimeEntryTypeEnum.Vacation); await timeEntryService.CreateNonBillableTimeEntry(date.AddDays(-2), 2, "dr visit", TimeEntryTypeEnum.Sick); await timeEntryService.CreateNonBillableTimeEntry(date.AddDays(-7), 4, "pda", TimeEntryTypeEnum.NonBillable); await timeEntryService.CreateNonBillableTimeEntry(date.AddDays(-7), 3, "lunch and learn", TimeEntryTypeEnum.NonBillable); var randomGuid = Guid.NewGuid(); timeEntryService = new TimeEntryService(randomGuid, database); await timeEntryService.CreateBillableTimeEntry(date, 8, 1); }
private void SeedProjects(TimeTrackerDbContext context) { _projects.Add(1, new Project { Prefix = "ENG", Title = "English study" }); _projects.Add(2, new Project { Prefix = "JS", Title = "Javascript learning path" }); _projects.Add(3, new Project { Prefix = "EB", Title = "English books" }); foreach (Project project in _projects.Values) { context.Projects.Add(project); } context.SaveChanges(); }
public UsersControllerTests() { var options = new DbContextOptionsBuilder <TimeTrackerDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) // baza u memoriji sa random imenom .Options; // opcije za db kontekst var dbContext = new TimeTrackerDbContext(options); // kreiranje db kontext-a sa opcijama // dodavanje korisnika pjeske dbContext.Users.Add(new User { Id = 1, Name = "User 1", HourRate = 15 }); dbContext.Users.Add(new User { Id = 2, Name = "User 2", HourRate = 20 }); dbContext.Users.Add(new User { Id = 3, Name = "User 3", HourRate = 30 }); dbContext.SaveChanges(); var logger = new FakeLogger <UsersController>(); _controller = new UsersController(dbContext, logger); }