public ActivityStopDtoValidator(TimeTrackerDbContext context) { _context = context; RuleFor(x => x.TimeEnd.Value) .Must(HaveCurrentlyRunningActivity).WithMessage("There is no Activity currently running.").When(x => x.TimeEnd != null); }
public TimeTrackerService() { try { InitializeComponent(); eventLog = new EventLog { Source = ServiceName, Log = "Application" }; systemActivityService = new SystemActivityService(); windowActivityService = new WindowActivityService(); dbContext = new TimeTrackerDbContext(); dbContext.Database.EnsureCreated(); userSystemEventRepository = new UserSystemEventRepository(dbContext); userWindowEventRepository = new UserWindowEventRepository(dbContext); windowsAppRepository = new WindowsAppRepository(dbContext); } catch (Exception ex) { Log(ex.ToString()); } }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); MainWindow = new MainWindow(userSystemEventRepository, userWindowEventRepository, windowsAppRepository); MainWindow.Closing += MainWindow_Closing; _notifyIcon = new SWF.NotifyIcon(); _notifyIcon.DoubleClick += (s, args) => ShowMainWindow(); _notifyIcon.Icon = BackgroundApp.Properties.Resources.time; _notifyIcon.Visible = true; systemActivityService = new SystemActivityService(); windowActivityService = new WindowActivityService(); dbContext = new TimeTrackerDbContext(); dbContext.Database.EnsureCreated(); userSystemEventRepository = new UserSystemEventRepository(dbContext); userWindowEventRepository = new UserWindowEventRepository(dbContext); windowsAppRepository = new WindowsAppRepository(dbContext); systemActivityService.SystemActivitySnapshot += SystemActivityService_SystemActivitySnapshot; windowActivityService.WindowActivitySnapshot += WindowActivityService_WindowActivitySnapshot; systemActivityService.Start(); windowActivityService.Start(); CreateContextMenu(); }
public TimeEntriesController( TimeTrackerDbContext dbContext, ILogger <TimeEntriesController> logger) { _dbContext = dbContext; _logger = logger; }
public AdminReportServiceTest() { InMemoryDatabaseWithProjectsAndUsers inMemoryDatabase = new InMemoryDatabaseWithProjectsAndUsers(); database = inMemoryDatabase.Database; adminReportService = new AdminReportService(database); }
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 InMemoryDatabaseWithProjectsAndUsers() { Database = new TimeTrackerDbContext(TestHelpers.BuildInMemoryDatabaseOptions(Guid.NewGuid().ToString())); Database.AddAutonomicAsClientAndProject(); Database.AddTestUsers(); }
public async Task SaveGoogleInfo_savesExpectedData() { var options = TestHelpers.BuildInMemoryDatabaseOptions("users-2"); string slackUsername = "******"; string slackUserId = "userId"; string googleId = Guid.NewGuid().ToString(); string first = "first"; string last = "last"; string email = "*****@*****.**"; using (var context = new TimeTrackerDbContext(options)) { var sut = new UserService(context); var userCreated = await sut.FindOrCreateSlackUser(slackUserId, slackUsername); await sut.SaveGoogleInfo(slackUserId, googleId, first, last, email); } using (var context = new TimeTrackerDbContext(options)) { var dbUser = context.Users.FirstOrDefault(x => x.SlackUserId == slackUserId); dbUser.LastName.Should().Be(last); dbUser.FirstName.Should().Be(first); dbUser.GoogleIdentifier.Should().Be(googleId); dbUser.OrganizationEmail.Should().Be(email); } }
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); }
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 ProjectsController( TimeTrackerDbContext dbContext, ILogger <ProjectsController> logger) { _dbContext = dbContext; _logger = logger; }
public TimeEntryServiceTest() { var inMemoryDatabase = new InMemoryDatabaseWithProjectsAndUsers(); database = inMemoryDatabase.Database; timeEntryService = new TimeEntryService(userId, database); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (IServiceScope scope = host.Services.CreateScope()) { try { ITimeTrackerDbContext abstractContext = scope.ServiceProvider.GetService <ITimeTrackerDbContext>(); TimeTrackerDbContext context = (TimeTrackerDbContext)abstractContext; context.Database.Migrate(); IWebHostEnvironment environment = scope.ServiceProvider.GetService <IWebHostEnvironment>(); if (environment.IsDevelopment()) { TimeTrackerDbInitializer.Seed(context); } } catch (Exception e) { Console.WriteLine(e); } } host.Run(); }
public ClientsController( TimeTrackerDbContext dbContext, ILogger <ClientsController> logger) { _dbContext = dbContext; _logger = logger; }
public WebReportServiceTest() { InMemoryDatabaseWithProjectsAndUsers inMemoryDatabase = new InMemoryDatabaseWithProjectsAndUsers(); database = inMemoryDatabase.Database; webReportService = new WebReportService(database); userId = database.Users.First(x => x.UserId != null).UserId; }
public static void Seed(TimeTrackerDbContext context) { if (context.Projects.FirstOrDefault() != null) { return; } var initializer = new TimeTrackerDbInitializer(); initializer.SeedEverything(context); }
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 static Task <int> AddAutonomicAsBillingClientAndProject(this TimeTrackerDbContext db) { db.Database.EnsureCreated(); db.BillingClients.Add(new BillingClient() { BillingClientId = 1, Name = "Autonomic" }); db.Projects.Add(new Project() { ProjectId = 1, BillingClientId = 1, Name = "au" }); return(db.SaveChangesAsync()); }
public void GetUserInfoTest() { using (new TransactionScope(TransactionScopeOption.RequiresNew)) using (TimeTrackerDbContext dbContext = CreateTestContext()) { // Arrange string domainName = @"CORP\Maxim.Rozhkov"; int userId = 1091; string email = "*****@*****.**"; var app = new UsersApp(new UsersRepository(dbContext)); // Act var rc = app.GetUserInfo(domainName); //Assert Assert.AreEqual(userId, rc.Id); Assert.AreEqual(domainName, rc.DomainDame); Assert.AreEqual(email, rc.Email); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, TimeTrackerDbContext dbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseMiddleware <ErrorHandlingMiddleware>(); //app.UseMiddleware<LimitingMiddleware>(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); // NOTE: this is just for demo purpose! Usually, you should limit access to a specific origin // More info: https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-3.0 app.UseCors( builder => builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); app.UseOpenApi(); app.UseSwaggerUi3(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapHealthChecks("/live"); }); app.ApplyMigrations(dbContext); }
public async Task GetUserIdFromGoogleId_getsCorrectGuid() { var options = TestHelpers.BuildInMemoryDatabaseOptions("users-3"); string googleId = Guid.NewGuid().ToString(); string first = "first"; string last = "last"; string email = "*****@*****.**"; string slackUserId = "id"; using (var context = new TimeTrackerDbContext(options)) { var userService = new UserService(context); var user = userService.FindOrCreateSlackUser(slackUserId, "username"); await userService.SaveGoogleInfo(slackUserId, googleId, first, last, email); var userId = await userService.GetUserIdFromGoogleId(googleId); userId.Should().Be(user.Result.UserId); } }
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); } }
public void SetVacationTest() { using (new TransactionScope(TransactionScopeOption.RequiresNew)) using (TimeTrackerDbContext dbContext = CreateTestContext()) { // Arrange string domainName = @"CORP\Maxim.Rozhkov"; DateTime from = new DateTime(2018, 08, 24); DateTime to = new DateTime(2018, 09, 12); var app = new VacationsApp(new UsersRepository(dbContext), new VacationsRepository(dbContext)); // Act app.SetVacation(new VacationInfo { DomainName = domainName, Interval = new TimeInterval(from, to), }); //Assert var vacation = dbContext.Vacations .Where(x => x.User.UserName == domainName && x.DateFrom == from && x.DateTo == to); Assert.IsNotNull(vacation); } }
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 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(); }
public async Task FindOrCreateSlackUser_savesNewUserAndReturnsExisting() { var options = TestHelpers.BuildInMemoryDatabaseOptions("users"); User userCreated; var slackUsername = "******"; using (var context = new TimeTrackerDbContext(options)) { var sut = new UserService(context); userCreated = await sut.FindOrCreateSlackUser("userId", slackUsername); var userFound = await sut.FindOrCreateSlackUser("userId", "whatever"); userFound.UserId.Should().Be(userCreated.UserId); } using (var context = new TimeTrackerDbContext(options)) { var firstUserDb = context.Users.FirstOrDefault(x => x.UserName == slackUsername); userCreated.UserId.Should().Be(firstUserDb.UserId); } }
static void Main(string[] args) { SystemActivityService systemActivityService = new SystemActivityService(); WindowActivityService windowActivityService = new WindowActivityService(); dbContext = new TimeTrackerDbContext(); dbContext.Database.EnsureCreated(); userSystemEventRepository = new UserSystemEventRepository(dbContext); userWindowEventRepository = new UserWindowEventRepository(dbContext); windowsAppRepository = new WindowsAppRepository(dbContext); systemActivityService.SystemActivitySnapshot += SystemActivityService_SystemActivitySnapshot; windowActivityService.WindowActivitySnapshot += WindowActivityService_WindowActivitySnapshot; systemActivityService.Start(); windowActivityService.Start(); while (true) { Thread.Sleep(10); } }
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(); }
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(); }