public void GetAllProjectsByProjectNameShouldReturnCollectionOfAllProjectsWithSameName() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "Projects_GetAllProjects_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var project = new DailyAgenda { Project = "New Project" }; var project2 = new DailyAgenda { Project = "New Project" }; var project3 = new DailyAgenda { Project = "New Project" }; dbContext.DailyAgendas.AddRange(project, project2, project3); dbContext.SaveChanges(); var projectService = new ProjectService(dbContext, null, null); var collection = projectService.GetAllProjectsByProjectName(project.Project); Assert.Equal(3, collection.Count()); }
public void GetCurrentUserFromDbShouldReturnCorrectUser() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "Users_GetCurent_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var user = new ApplicationUser { Email = "*****@*****.**", FullName = "Pesho" }; dbContext.Users.Add(user); dbContext.SaveChanges(); var service = new UserService(dbContext); var actual = service.GetCurrentUserFromDb(user.Id); var expected = dbContext.Users.FirstOrDefault(u => u.Id == user.Id); Assert.Equal(expected, actual); }
public void UpdateEditedProjectShouldUpdateCorrectly() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "Projects_UpdateCategory_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var project = new Category { Name = "New Project" }; dbContext.Categories.Add(project); dbContext.SaveChanges(); var projectService = new ProjectService(dbContext, null, null); var newName = new ProjectViewModel { Id = project.Id, Name = "New Project Updated" }; projectService.UpdateEditedProject(newName); var actual = dbContext.Categories.FirstOrDefault(c => c.Id == project.Id); Assert.Equal(newName.Name, actual.Name); }
public void CreateCompanySouldCreateCompanyAndAddInDb() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "Company_CreateCompany_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var companyModel = new CompanyCreateViewModel { Name = "DataCenter", Address = "asd", FieldOfService = "IT" }; var user = new ApplicationUser { Email = "*****@*****.**", FullName = "Pesho Peshev" }; var companyService = new CompanyService(dbContext, null); companyService.CreateCompany(companyModel, user); var company = dbContext.Companies.FirstOrDefault(x => x.Name == companyModel.Name); Assert.Equal(companyModel.Name, company.Name); Assert.Equal(companyModel.Address, company.Address); Assert.Equal(companyModel.FieldOfService, company.FieldOfService); }
public void AddNewEventShouldAddEventInDatabase() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "TimeSheet_AddEvent_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var newEvent = new DailyAgenda { Description = "Nice short description", Project = "New Project", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddHours(1.1), ThemeColor = "red" }; dbContext.DailyAgendas.Add(newEvent); dbContext.SaveChanges(); var service = new TimeSheetService(dbContext); var actual = dbContext.DailyAgendas.FirstOrDefault(e => e.Id == newEvent.Id); Assert.Equal(newEvent.Project, actual.Project); Assert.Equal(newEvent.Description, actual.Description); Assert.Equal(newEvent.StartDate, actual.StartDate); Assert.Equal(newEvent.EndDate, actual.EndDate); Assert.Equal(newEvent.ThemeColor, actual.ThemeColor); }
public void GetEventFromIdShouldReturnCorrectEvent() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "TimeSheet_GetEventById_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var newEvent = new DailyAgenda { Description = "Nice short description", Project = "New Project", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddHours(1.1), ThemeColor = "red" }; dbContext.DailyAgendas.Add(newEvent); dbContext.SaveChanges(); var service = new TimeSheetService(dbContext); var actual = service.GetEventFromId(newEvent); Assert.Equal(newEvent, actual); }
public void GetAllUsersFromDbShouldCollectAllUserFromDatabase() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "Users_GetAll_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var user = new ApplicationUser { Email = "*****@*****.**", FullName = "Pesho" }; var user2 = new ApplicationUser { Email = "*****@*****.**", FullName = "Sasho" }; var user3 = new ApplicationUser { Email = "*****@*****.**", FullName = "Gosho" }; dbContext.Users.AddRange(user, user2, user3); dbContext.SaveChanges(); var service = new UserService(dbContext); var actual = service.GetAllUsersFromDb(); Assert.Equal(3, actual.Count); }
public void PromoteUserShouldReturnTrue() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "Users_Promote_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var user = new ApplicationUser { Email = "*****@*****.**", FullName = "Pesho" }; dbContext.Users.Add(user); dbContext.SaveChanges(); var service = new UserService(dbContext); service.PromoteUser(user); var actual = (ApplicationUser)dbContext.Users.FirstOrDefault(u => u.Id == user.Id); Assert.True(actual.IsPromoted); }
public void AddProjectShouldAddSuccessfullyProjects() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "Projects_AddProjects_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var user = new ApplicationUser { Email = "*****@*****.**", FullName = "Pesho Peshev" }; var company = new Company { Name = "DataCenter", Address = "asd", FieldOfService = "IT" }; dbContext.Users.Add(user); dbContext.Companies.Add(company); dbContext.SaveChanges(); var userService = new Mock <IUserService>(); userService.Setup(u => u.GetCurrentUserFromDb(user.Id)) .Returns((ApplicationUser)dbContext.Users.FirstOrDefault(x => x.Email == user.Email)); var companyService = new Mock <ICompanyService>(); companyService.Setup(c => c.GetCompanyByName(company.Name)) .Returns(dbContext.Companies.FirstOrDefault(c => c.Name == company.Name)); var projectService = new ProjectService(dbContext, companyService.Object, userService.Object); var projectModel = new ProjectCategoryAddViewModel { Name = "New Project" }; projectService.AddProject(projectModel, user.Id); var project = dbContext.Categories.FirstOrDefault(c => c.Name == projectModel.Name); Assert.Equal(projectModel.Name, project.Name); }
public void GetAllEventsOfUserFromDBShouldReturnCorrectEvents() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "TimeSheet_GetAllEventByUserId_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var newEvent = new DailyAgenda { Description = "Nice short description", Project = "New Project", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddHours(1.1), ThemeColor = "red" }; var newEvent2 = new DailyAgenda { Description = "Nice short description", Project = "New Project 2", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddHours(1.1), ThemeColor = "red" }; var user = new ApplicationUser { Email = "*****@*****.**", FullName = "Pesho" }; user.DailyAgendas.Add(newEvent); user.DailyAgendas.Add(newEvent2); dbContext.DailyAgendas.Add(newEvent); dbContext.Users.Add(user); dbContext.SaveChanges(); var service = new TimeSheetService(dbContext); var actual = service.GetAllEventsOfUserFromDB(user.Id); Assert.Equal(2, actual.Count()); }
public void CheckIfCompanyNameIsAvailableShouldReturnTrueIfCompanyExist() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "Company_CheckCompanyName_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var company = new Company { Name = "DataCenter", Address = "asd", FieldOfService = "IT" }; dbContext.Companies.Add(company); var companyService = new CompanyService(dbContext, null); var result = companyService.CheckIfCompanyNameIsAvailable(company.Name); Assert.True(result); }
public void GetCategoryByIdShouldReturnCorrectCategory() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "Projects_GetCategoryById_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var project = new Category { Name = "New Project" }; dbContext.Categories.Add(project); dbContext.SaveChanges(); var projectService = new ProjectService(dbContext, null, null); var actual = projectService.GetCategoryById(project.Id); Assert.Equal(project.Id, actual.Id); Assert.Equal(project.Name, actual.Name); }
public void JoinCompanyShouldFillGivenUserCompanyNameProp() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "Company_JoinCompany_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var company = new Company { Name = "DataCenter", Address = "asd", FieldOfService = "IT" }; var user = new ApplicationUser { Email = "*****@*****.**", FullName = "Pesho Peshev" }; dbContext.Companies.Add(company); dbContext.Users.Add(user); dbContext.SaveChanges(); var companyService = new CompanyService(dbContext, null); companyService.JoinCompany(user, company.Name); var userFromDb = (ApplicationUser)dbContext.Users.FirstOrDefault(u => u.Email == user.Email); var actual = userFromDb.CompanyName; var companyFromDb = dbContext.Companies.FirstOrDefault(c => c.Name == company.Name); Assert.Equal(company.Name, actual); Assert.Single(companyFromDb.TeamMembers); }
public void DeleteProjectByIdShouldDeleteTheCorrectProject() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "Projects_DeleteProject_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var project = new Category { Name = "New Project" }; dbContext.Categories.Add(project); dbContext.SaveChanges(); var projectService = new ProjectService(dbContext, null, null); projectService.DeleteProjectById(project.Id); var actual = dbContext.Categories.Count(); Assert.Equal(0, actual); }
public void GetCompanyByNameShouldReturnCorrectCompanyFromDb() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "Company_GetCompany_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var company = new Company { Name = "DataCenter", Address = "asd", FieldOfService = "IT" }; dbContext.Companies.Add(company); dbContext.SaveChanges(); var companyService = new CompanyService(dbContext, null); var actual = companyService.GetCompanyByName(company.Name); Assert.Equal(company, actual); }
public ProfileService(TaskPlannerDbContext dbContext, IUserService userService) { this.dbContext = dbContext; this.userService = userService; }
public CompanyService(TaskPlannerDbContext dbContext, IUserService userService) { this.dbContext = dbContext; this.userService = userService; }
public UserService(TaskPlannerDbContext dbContext) { this.dbContext = dbContext; }
public ProjectService(TaskPlannerDbContext dbContext, ICompanyService companyService, IUserService userService) { this.dbContext = dbContext; this.companyService = companyService; this.userService = userService; }
public TimeSheetService(TaskPlannerDbContext dbContext) { this.dbContext = dbContext; }