Ejemplo n.º 1
0
        private static void SeedProjects(
            ProjectsDbContext projectsDb,
            out IEnumerable<Project> projetcs)
        {
            var customer = projectsDb.Companies.Skip(1).FirstOrDefault();
            if (customer == null)
            {
                throw new ArgumentNullException(
                    "company",
                    "Accounting module must be seeded first. Make sure the even CompaniesCreated is triggered and at least two companies are seeded.");
            }

            var employees = projectsDb.Set<Employee>().ToList();
            if (employees == null || employees.Count() < 2)
            {
                throw new ArgumentNullException(
                    "employees",
                    "Company module must be seeded first. Make sure the even EmployeesCreated is triggered and at least two employees are seeded.");
            }

            var ivan = employees.First();
            var project = Project.Create(
                "Apartment complex - Sofia",
                new DateTime(2017, 2, 25),
                new DateTime(2017, 10, 25),
                ivan.Id,
                customer.Id);

            projetcs = new List<Project>()
            {
                project
            };

            projectsDb.Set<Project>().AddRange(projetcs);
        }
Ejemplo n.º 2
0
        private static void PopulateDb()
        {
            using (var ctx = new ProjectsDbContext())
            {
                Project p1 = ctx.Projects.Add(new Project()).Entity;
                Project p2 = ctx.Projects.Add(new Project()).Entity;

                ctx.Subprojects.Add(new Subproject()
                {
                    Area = 100, Project = p1
                });
                ctx.Subprojects.Add(new Subproject()
                {
                    Area = 200, Project = p1
                });
                ctx.Subprojects.Add(new Subproject()
                {
                    Area = 350, Project = p2
                });
                ctx.Subprojects.Add(new Subproject()
                {
                    Area = 450, Project = p2
                });
                ctx.Subprojects.Add(new Subproject()
                {
                    Area = 10000, Project = p2
                });

                ctx.SaveChanges();
            }
        }
Ejemplo n.º 3
0
 private static void ValidateDb()
 {
     using (var ctx = new ProjectsDbContext())
     {
         try
         {
             ctx.Database.EnsureCreated();
             if (ctx.Projects.Count() != 2 || ctx.Subprojects.Count() != 5)
             {
                 ClearDb();
                 PopulateDb();
             }
         }
         catch (Exception)
         {
             try
             {
                 ClearDb();
             }
             catch (Exception)
             {
             }
             PopulateDb();
         }
     }
 }
 public ProjectItemRepository(
     ProjectsDbContext context,
     IProjectStatusesService projectStatusesService)
 {
     _context = context;
     _projectStatusesService = projectStatusesService;
 }
Ejemplo n.º 5
0
 public void ProjectingExpressionByNonStaticMethodWithLogic_Test()
 {
     ValidateDb();
     using (var ctx = new ProjectsDbContext())
     {
         var projects = (from p in ctx.Projects.AsExpressionProjectable()
                         select new
         {
             Project = p,
             AEA = GetProjectAverageEffectiveAreaSelectorWithLogic(false).Project <double>()
         }).ToArray();
         Assert.AreEqual(150, projects[0].AEA);
         Assert.AreEqual(3600, projects[1].AEA);
     }
     using (var ctx = new ProjectsDbContext())
     {
         var projects = (from p in ctx.Projects.AsExpressionProjectable()
                         select new
         {
             Project = p,
             AEA = GetProjectAverageEffectiveAreaSelectorWithLogic(true).Project <double>()
         }).ToArray();
         Assert.AreEqual(150, projects[0].AEA);
         Assert.AreEqual(400, projects[1].AEA);
     }
 }
Ejemplo n.º 6
0
        private static void Seed(ProjectsDbContext db)
        {
            if (db.Users.Any())
            {
                return;
            }

            var user = new User()
            {
                Email = "*****@*****.**",
                Name  = "Oscar"
            };

            db.Users.Add(user);

            var team = new Team()
            {
                Name    = "Mega team",
                Members = new[] { user }
            };

            db.Teams.Add(team);

            var project = new Project()
            {
                Description = "test project",
                Team        = team
            };

            db.Projects.Add(project);

            db.SaveChanges();
        }
Ejemplo n.º 7
0
 private static void ClearDb()
 {
     using (var ctx = new ProjectsDbContext())
     {
         foreach (var subproject in ctx.Subprojects)
         {
             ctx.Subprojects.Remove(subproject);
         }
         foreach (var project in ctx.Projects)
         {
             ctx.Projects.Remove(project);
         }
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 8
0
 public void ProjectingExpressionByNonStaticField_Test()
 {
     ValidateDb();
     using (var ctx = new ProjectsDbContext())
     {
         var projects = (from p in ctx.Projects.AsExpressionProjectable()
                         select new
         {
             Project = p,
             AEA = _projectAverageEffectiveAreaSelector.Project <double>()
         }).ToArray();
         Assert.AreEqual(150, projects[0].AEA);
         Assert.AreEqual(400, projects[1].AEA);
     }
 }
Ejemplo n.º 9
0
        public void ProjectingExpressionFailsOnNormalCases_Test()
        {
            ValidateDb();
            Expression <Func <Project, double> > localSelector =
                proj => proj.Subprojects.Where(sp => sp.Area < 1000).Average(sp => sp.Area);

            using (var ctx = new ProjectsDbContext())
            {
                var v = (from p in ctx.Projects
                         select new
                {
                    Project = p,
                    AEA = localSelector
                }).ToArray();
            }
        }
Ejemplo n.º 10
0
        public void ProjectingExpressionByParameterizedInternalVariable_Test()
        {
            ValidateDb();

            using (var ctx = new ProjectsDbContext())
            {
                var projects = (from p in ctx.Projects.AsExpressionProjectable()
                                select new
                {
                    Project = p,
                    AEA = localSelector(p.ID).Project <double>()
                }).ToArray();
                Assert.AreEqual(150, projects[0].AEA);
                Assert.AreEqual(400, projects[1].AEA);
            }
        }
Ejemplo n.º 11
0
        public ProjectsDbContext CreateContext(bool serverEvaluation = true)
        {
            if (_connection == null)
            {
                _connection = new SqliteConnection("DataSource=:memory:");
                _connection.Open();

                var options = CreateOptions(serverEvaluation);
                using (var context = new ProjectsDbContext(options))
                {
                    context.Database.EnsureCreated();
                }
            }

            return(new ProjectsDbContext(CreateOptions(serverEvaluation)));
        }
Ejemplo n.º 12
0
        public void ProjectingExpressionFailsWithProjectionNotMatchingLambdaReturnType_Test()
        {
            ValidateDb();
            Expression <Func <Project, double> > localSelector =
                proj => proj.Subprojects.Where(sp => sp.Area < 1000).Average(sp => sp.Area);

            using (var ctx = new ProjectsDbContext())
            {
                var projects = (from p in ctx.Projects.AsExpressionProjectable()
                                select new
                {
                    Project = p,
                    AEA = localSelector.Project <int>()
                }).ToArray();
                Assert.AreEqual(150, projects[0].AEA);
                Assert.AreEqual(400, projects[1].AEA);
            }
        }
Ejemplo n.º 13
0
        public void ProjectingExpressionFailsWithWrongLambdaParameterType_Test()
        {
            ValidateDb();
            Expression <Func <Subproject, double> > localSelector =
                sp => sp.Area;

            using (var ctx = new ProjectsDbContext())
            {
                var projects = (from p in ctx.Projects.AsExpressionProjectable()
                                select new
                {
                    Project = p,
                    AEA = localSelector.Project <double>()
                }).ToArray();
                Assert.AreEqual(150, projects[0].AEA);
                Assert.AreEqual(400, projects[1].AEA);
            }
        }
        private void PopulateDb(ProjectsDbContext ctx)
        {
            User user1 = ctx.Users.Add(new User {
                Name = "user1"
            }).Entity;
            User user2 = ctx.Users.Add(new User {
                Name = "user2"
            }).Entity;
            User user3 = ctx.Users.Add(new User {
                Name = "user3"
            }).Entity;
            User user4 = ctx.Users.Add(new User {
                Name = "user4"
            }).Entity;

            ctx.SaveChanges();

            Project p1 = ctx.Projects.Add(new Project {
                CreatedBy = user1, ModifiedBy = user3
            }).Entity;
            Project p2 = ctx.Projects.Add(new Project {
                CreatedBy = user2, ModifiedBy = user4
            }).Entity;

            ctx.Subprojects.Add(new Subproject {
                Area = 100, Project = p1
            });
            ctx.Subprojects.Add(new Subproject {
                Area = 200, Project = p1
            });
            ctx.Subprojects.Add(new Subproject {
                Area = 350, Project = p2
            });
            ctx.Subprojects.Add(new Subproject {
                Area = 450, Project = p2
            });
            ctx.Subprojects.Add(new Subproject {
                Area = 10000, Project = p2
            });

            ctx.SaveChanges();
        }
        public ProjectItemRepositoryTest()
        {
            //TODO: For simplification we can use inmemory Db instead of Mock
            //In real app we would have service layer with logic, which uses interfaces of repository layer
            //For testing we would mock that interfaces
            var options = new DbContextOptionsBuilder <ProjectsDbContext>()
                          .UseInMemoryDatabase(databaseName: "ProjectsDatabase")
                          .Options;

            // Insert seed data into the database using one instance of the context
            using (var context = new ProjectsDbContext(options))
            {
                SeedData(context);
            }

            // Use a clean instance of the context to run the test
            _context = new ProjectsDbContext(options);

            _service = new ProjectItemRepository(_context, _projectStatusesServiceMock.Object);
        }
Ejemplo n.º 16
0
 public ProjectsController(ProjectsDbContext context, RabbitMQManager rabbitMQ)
 {
     _context      = context;
     this.rabbitMQ = rabbitMQ;
 }
Ejemplo n.º 17
0
 public TasksRepository(ProjectsDbContext dbContext)
     : base(dbContext.Tasks, dbContext)
 {
 }
 public AuthentificationController(ProjectsDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 19
0
 public ProjectsRepository(ProjectsDbContext dbContext) :
     base(dbContext.Projects, dbContext)
 {
 }
Ejemplo n.º 20
0
 public UtilisateursController(ProjectsDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 21
0
 public TachesController(ProjectsDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 22
0
 public ProjectQueries(ProjectsDbContext projectsDbContext)
 {
     _projectsDbContext = projectsDbContext;
 }
        private void SeedData(ProjectsDbContext context)
        {
            if (context.ProjectItems.Any())
            {
                return;   // DB has been seeded
            }

            var p1 = new ProjectItem {
                ParentId = null, Name = "1. Project 1", StartDate = new DateTime(2020, 06, 01), EndDate = new DateTime(2020, 06, 30), Type = ItemType.Project
            };

            context.ProjectItems.Add(p1);
            context.SaveChanges();

            var p11 = new ProjectItem {
                ParentId = p1.Id, Name = "1.1. SubProject 1", StartDate = new DateTime(2020, 06, 01), EndDate = new DateTime(2020, 06, 10), Type = ItemType.Project
            };

            context.ProjectItems.Add(p11);
            context.SaveChanges();

            var p111 = new ProjectItem {
                ParentId = p11.Id, Name = "1.1.1. Task 1", StartDate = new DateTime(2020, 06, 01), EndDate = new DateTime(2020, 06, 10), Type = ItemType.Task
            };
            var p112 = new ProjectItem {
                ParentId = p11.Id, Name = "1.1.2. Task 2", StartDate = new DateTime(2020, 06, 01), EndDate = new DateTime(2020, 06, 10), Type = ItemType.Task
            };
            var p113 = new ProjectItem {
                ParentId = p11.Id, Name = "1.1.3. Task 3", StartDate = new DateTime(2020, 06, 01), EndDate = new DateTime(2020, 06, 10), Type = ItemType.Task
            };

            context.ProjectItems.Add(p111);
            context.ProjectItems.Add(p112);
            context.ProjectItems.Add(p113);
            context.SaveChanges();

            var p1131 = new ProjectItem {
                ParentId = p113.Id, Name = "1.1.3.1 Task 3.1", StartDate = new DateTime(2020, 06, 01), EndDate = new DateTime(2020, 06, 10), Type = ItemType.Task
            };

            context.ProjectItems.Add(p1131);
            context.SaveChanges();

            var p12 = new ProjectItem {
                ParentId = p1.Id, Name = "1.2. SubProject 2", StartDate = new DateTime(2020, 06, 01), EndDate = new DateTime(2020, 06, 10), Type = ItemType.Project
            };
            var p13 = new ProjectItem {
                ParentId = p1.Id, Name = "1.3. SubProject 3", StartDate = new DateTime(2020, 06, 01), EndDate = new DateTime(2020, 06, 10), Type = ItemType.Project
            };

            context.ProjectItems.Add(p12);
            context.ProjectItems.Add(p13);
            context.SaveChanges();

            var p131 = new ProjectItem {
                ParentId = p13.Id, Name = "1.3.1. Task 1", StartDate = new DateTime(2020, 06, 01), EndDate = new DateTime(2020, 06, 10), Type = ItemType.Task
            };

            context.ProjectItems.Add(p131);
            context.SaveChanges();
        }
 public ProjectStatusesService(ProjectsDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 25
0
 public GenericRepository(ProjectsDbContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <TEntity>();
 }
 public TimesheetsController(ProjectsDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 27
0
 public UnitOfWork(ProjectsDbContext projectDbContext)
 {
     context = projectDbContext;
 }