public void AddNewContractor()
        {
            var contractor = ModelFakes.ContractorFake.Generate();
            var vendor     = dbContext.Vendor.FirstOrDefault();

            contractor.VendorId = vendor.Id;
            dbContext.Contractor.Add(contractor);
            dbContext.SaveChanges();

            Assert.AreNotEqual(0, contractor.Id);
        }
Esempio n. 2
0
        public void AddFileTypes()
        {
            var documentTypes = new List <DocumentType>
            {
                new DocumentType
                {
                    Name = "Invoice"
                },
                new DocumentType
                {
                    Name = "References"
                },
                new DocumentType
                {
                    Name = "Form I9"
                }
            };

            dbContext.DocumentType.AddRange(documentTypes);
            dbContext.SaveChanges();
        }
Esempio n. 3
0
        public static void Initialize(TestContext testContext)
        {
            var options = new DbContextOptionsBuilder <EFExamplesDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var context = new EFExamplesDbContext(options);

            var companies = new List <Company>();
            var vendors   = new List <Vendor>();

            for (var i = 0; i < numberOfCompanies; i++)
            {
                var companyFake = ModelFakes.CompanyFake.Generate();
                dbContext.Company.Add(companyFake);
                companies.Add(companyFake);
            }

            dbContext.SaveChanges();

            foreach (var company in companies)
            {
                for (var i = 0; i < numberOfVendorsPerCompany; i++)
                {
                    var vendor = ModelFakes.VendorFake.Generate();
                    vendor.Contractors = new List <Contractor>();

                    for (var c = 0; c < numberOfContractorsPerVendor; c++)
                    {
                        var contractor = ModelFakes.ContractorFake.Generate();
                        vendor.Contractors.Add(contractor);
                    }

                    dbContext.Vendor.Add(vendor);
                    vendors.Add(vendor);
                }

                dbContext.SaveChanges();

                foreach (var departmentName in departmentNames)
                {
                    var department = new Department
                    {
                        Name                  = departmentName,
                        DateCreated           = DateTime.Now,
                        DateUpdated           = DateTime.Now,
                        CompanyId             = company.Id,
                        Employees             = new List <Employee>(),
                        DepartmentContractors = new List <DepartmentContractor>()
                    };

                    for (var i = 0; i < numberOfEmployeesPerDepartment; i++)
                    {
                        var employee = ModelFakes.EmployeeFake.Generate();
                        employee.CompanyId         = company.Id;
                        employee.EmployeeDocuments = new List <EmployeeDocument>
                        {
                            new EmployeeDocument
                            {
                                FileDescription = new FileDescription
                                {
                                    ContentType    = ".PDF",
                                    FileName       = "Test File",
                                    Description    = "File description",
                                    DocumentTypeId = documentTypeIds.ElementAt(random.Next(documentTypeIds.Count))
                                }
                            }
                        };
                        department.Employees.Add(employee);
                    }

                    var vendor = vendors[random.Next(vendors.Count)];

                    for (var v = 0; v < numberOfContractorsPerDepartment; v++)
                    {
                        var contractor = vendor.Contractors.ElementAt(random.Next(vendor.Contractors.Count));

                        if (!department.DepartmentContractors.Any(m => m.ContractorId == contractor.Id))
                        {
                            department.DepartmentContractors.Add(new DepartmentContractor
                            {
                                ContractorId = contractor.Id
                            });
                        }
                        else
                        {
                            v--;
                        }
                    }

                    dbContext.Department.Add(department);
                }

                dbContext.SaveChanges();
            }
        }