Exemplo n.º 1
0
        public void DeleteEventFromDbShouldDeleteCorrectEvent()
        {
            var options = new DbContextOptionsBuilder <TaskPlannerDbContext>()
                          .UseInMemoryDatabase(databaseName: "TimeSheet_DeleteEvent_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);

            service.DeleteEventFromDb(newEvent.Id);

            dbContext.SaveChanges();

            var actual = dbContext.DailyAgendas.Count();

            Assert.Equal(0, actual);
        }
Exemplo n.º 2
0
        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 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 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 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);
        }
Exemplo n.º 6
0
        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());
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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());
        }
Exemplo n.º 10
0
        public void EditCurrentUserProfile(ProfileEditPostViewModel viewModel)
        {
            var user = this.userService.GetCurrentUserFromDb(viewModel.Id);

            user.Email    = viewModel.Email;
            user.FullName = viewModel.FullName;

            var image = this.userService.GetUserImage(viewModel.Id);

            if (image == null)
            {
                image = new Image();
            }

            image.ImageUrl = viewModel.Id + ".jpg";

            user.Images.Add(image);

            dbContext.SaveChanges();
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
 public void PromoteUser(ApplicationUser user)
 {
     user.IsPromoted = true;
     dbContext.SaveChanges();
 }