Example #1
0
 public void TeamTest()
 {
     Employee target = new Employee(); // TODO: Initialize to an appropriate value
     Team expected = null; // TODO: Initialize to an appropriate value
     Team actual;
     target.Team = expected;
     actual = target.Team;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Example #2
0
 public void EdsIdTest()
 {
     Employee target = new Employee(); // TODO: Initialize to an appropriate value
     string expected = string.Empty; // TODO: Initialize to an appropriate value
     string actual;
     target.EdsId = expected;
     actual = target.EdsId;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Example #3
0
 public void EmployeeConstructorTest()
 {
     Employee target = new Employee();
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
        public void UpsertResourceAllocations(IList<ResourceAllocationCsvItem> items)
        {
            _logger.Info("UpsertStatus called for {0} items", items.Count);

            // share the session - ugly
            this.TeamRepository.Session = this.ResourceRepository.Session = this.ResourceAllocationRepository.Session = this.ProjectRepository.Session = this.DepartmentRepository.Session;
            ITransaction transaction = this.ResourceAllocationRepository.BeginTransaction();
            try
            {
                // clear all entries for each resource / month combination before feeding the database
                var grpResourceMonths = items.GroupBy(item => new {item.Name, item.Month})
                    ;
                //.Select(group => new
                //                     {
                //                         EmployeeID = group.Key.EmployeeID,
                //                         Month = group.Key.Month
                //                     });

                grpResourceMonths.ToList().ForEach(
                    grm =>
                        {
                            var rm = grm.Key;

                            var firstEntry = grm.First();
                            // lookup resource id by external id
                            Employee resource = this.ResourceRepository.GetResourcesByName(rm.Name).FirstOrDefault() as Employee;
                            if (resource == null)
                            {
                                resource = this.ResourceRepository.Add(new Employee()
                                                                        {
                                                                            FullName = firstEntry.Name,
                                                                            EmailAddress =
                                                                                String.Format("{0}@test.com",
                                                                                              firstEntry.Name.Replace(" ",
                                                                                                                      "."))
                                                                        }) as Employee;
                                var tm = this.TeamRepository.GetTeamByName(firstEntry.ResourceTeam);
                                //if (tm == null)
                                //{
                                //    var department = this.DepartmentRepository.GetByName("Department");
                                //    if (department == null)
                                //    {
                                //        department = new Department() { Name = "Department", Manager = dummyResource as Employee };
                                //        this.DepartmentRepository.Add(department);
                                //    }
                                //    var lead = this.ResourceRepository.GetResourcesByName(firstEntry.ResourceTeamLead).SingleOrDefault() as Employee;
                                //    var t = new Team() { Name = firstEntry.Team, Lead = lead, Department = department};
                                //    this.TeamRepository.Add(t);
                                //}
                                ((Employee)resource).Team = tm;
                                this.ResourceRepository.Update(resource);
                                // resource = this.ResourceRepository.GetResourcesByName(firstEntry.Name).FirstOrDefault();
                            }
                            this.ResourceAllocationRepository.DeleteByResourceMonth(resource, rm.Month);

                            // add allocations now?
                            // loop through
                            grm.ToList().ForEach(item =>
                                                     {
                                                         // look up project first
                                                         var project =
                                                             this.ProjectRepository.GetProjectByName(item.Project);

                                                         if (project == null)
                                                         {
                                                             var pItem = firstEntry;
                                                             // var pTeam = this.TeamRepository.GetTeamByName() // not going to work with this file format as team id is made up

                                                             var pLead = this.ResourceRepository.GetResourcesByName(pItem.ResourceTeamLead).FirstOrDefault();
                                                             if (pLead == null)
                                                             {
                                                                 // create dummy resource
                                                                 Employee e = new Employee() { FullName = pItem.ResourceTeamLead };
                                                                 this.ResourceRepository.Add(e);
                                                             }

                                                             // create dummy department
                                                             var department = this.DepartmentRepository.GetByName("Department");
                                                             if (department == null)
                                                             {
                                                                 department = new Department() { Name = "Department", Manager = pLead as Employee };
                                                                 department = this.DepartmentRepository.Add(department);
                                                                 // department = this.DepartmentRepository.GetByName("Department");
                                                             }

                                                             var team = this.TeamRepository.GetTeamByName(item.Team);
                                                             if (team == null)
                                                             {
                                                                 team = new Team() { Name = firstEntry.Team, Lead = (Employee)pLead, Department = department};
                                                                 team = this.TeamRepository.Add(team);
                                                             }
                                                             project = new Project()
                                                             {
                                                                 Name = item.Project,
                                                                 Caption = item.ProjectType,
                                                                 Lead = pLead as Employee,
                                                                 Department = department,
                                                                 Type = item.BudgetType,
                                                                 Team = team
                                                             };

                                                             this.ProjectRepository.AddProject(project);
                                                             project = this.ProjectRepository.GetProjectByName(item.Project);
                                                         }
                                                         var allocation = new ResourceAllocation
                                                                              {
                                                                                  Month = item.Month,
                                                                                  Project = project,
                                                                                  Employee = resource,
                                                                                  Allocation = item.AllocationPercentage
                                                                              };
                                                         this.ResourceAllocationRepository.Add(allocation);
                                                     });
                        }
                    );
                this.ResourceAllocationRepository.CommitTransaction();
            }
            catch (Exception exc)
            {
                _logger.ErrorException("Unable to import from CsvResourceAllocation file", exc);
                this.ResourceAllocationRepository.RollbackTransaction();
                throw;
            }
            finally
            {
            }
        }
Example #5
0
        public static void MyClassInitialize(TestContext testContext)
        {
            _config.Configure();
            _kernel = new StandardKernel(new DefaultEtlNinjectModule(ConnString));
            var factory = _config.CreateSessionFactory();
            using (var session = factory.OpenSession())
            {
                _employee = new Employee
                                   {
                                       FirstName = "Dave",
                                       LastName = "Neigler",
                                       EmailAddress = "*****@*****.**"
                                   };
                _team = new Team
                               {
                                   Lead = _employee,
                                   Name = "Test Team"
                               };

                _department = new Department
                                     {
                                         Name = "Operations IT"
                                     };
                session.Save(_employee);
                session.Save(_team);
                session.Save(_department);
            }
        }
Example #6
0
        public void StatusReportCascadingPersistenceTest()
        {
            const string caption1 = "Status Item StatusReportCascadingPersistenceTest";
            const string caption2 = "2-Status Item StatusReportCascadingPersistenceTest";

            var factory = _config.CreateSessionFactory();
            int srId = 0;
            Project project = null;
            Topic topic2 = null;
            using (var session = factory.OpenSession())
            {
                using (var txn = session.BeginTransaction())
                {
                    var employee = new Employee
                                       {
                                           FirstName = "Dave",
                                           LastName = "Neigler",
                                           EmailAddress = "*****@*****.**"
                                       };
                    session.SaveOrUpdate(employee);

                    var team = new Team
                                   {
                                       Lead = employee,
                                       Name = "Test Team"
                                   };
                    session.SaveOrUpdate(team);

                    var department = new Department
                                         {
                                             Name = "Operations IT"
                                         };
                    session.SaveOrUpdate(department);

                    project = new Project
                                      {
                                          Name = "Test Project StatusReportCascadingPersistenceTest",
                                          StartDate = DateTime.Parse("01/01/2012"),
                                          EndDate = DateTime.Parse("07/01/2012"),
                                          Description = "Test project description",
                                          JiraProject = "TESTPROJ",
                                          Team = team,
                                          Type = ProjectType.Grow,
                                          Department = department
                                      };
                    session.SaveOrUpdate(project);

                    var topic1 = new JiraIssueTopic
                                     {
                                         JiraId = "BOTEST-StatusReportCascadingPersistenceTest",
                                         Caption = "This is the caption"
                                     };

                    session.SaveOrUpdate(topic1);
                    topic2 = new JiraIssueTopic
                    {
                        JiraId = "2-BOTEST-StatusReportCascadingPersistenceTest",
                        Caption = "This is the second caption"
                    };
                    session.SaveOrUpdate(topic2);
                    var sr = new StatusReport()
                                 {
                                     Caption = "Test Status Report 1",
                                     PeriodStart = new DateTime(2012, 1, 1),
                                     PeriodEnd = new DateTime(2012, 1, 7)
                                 };

                    sr.Items.Add(new StatusItem
                                     {
                                         Caption = caption1,
                                         Milestone =
                                             new Milestone()
                                                 {
                                                     ConfidenceLevel = MilestoneConfidenceLevels.Proposed,
                                                     Type = MilestoneTypes.OpenItem
                                                 },
                                         Topic = topic1,
                                         Project = project
                                     });
                    session.SaveOrUpdate(sr);
                    srId = sr.Id;
                    Assert.AreNotEqual(0, srId);
                    txn.Commit();
                }

                using (var txn = session.BeginTransaction())
                {
                    var sr = (from r in session.Query<StatusReport>()
                              where r.Id == srId
                              select r).FirstOrDefault();

                    var statusItem = (from si in session.Query<StatusItem>()
                                      where si.Caption.Equals(caption1)
                                      select si).FirstOrDefault();
                    Assert.IsNotNull(statusItem);

                    Assert.IsNotNull(statusItem.Project);

                    Assert.IsNotNull(statusItem.Topic);

                    // now we add more items and see if it updates properly
                    sr.Items.Add(new StatusItem
                                     {
                                         Caption = caption2,
                                         Milestone =
                                             new Milestone()
                                                 {
                                                     ConfidenceLevel = MilestoneConfidenceLevels.Proposed,
                                                     Type = MilestoneTypes.OpenItem
                                                 },
                                         Topic = topic2,
                                         Project = project
                                     });

                    session.SaveOrUpdate(sr);

                    var statusItem2 = (from si in session.Query<StatusItem>()
                                       where si.Caption.Equals(caption2)
                                       select si).FirstOrDefault();
                    Assert.IsNotNull(statusItem2);

                    Assert.IsNotNull(statusItem2.Project);

                    Assert.IsNotNull(statusItem2.Topic);
                    txn.Commit();
                }
            }
        }
        public void UpsertStatus(IList<StatusCsvItem> items)
        {
            _logger.Info("UpsertStatus called for {0} items", items.Count);

            // we'll be sharing a single unitofwork for this operation
            ITransaction transaction = this.StatusReportRepository.BeginTransaction();

            // share the session - ugly
            this.ResourceRepository.Session = this.ProjectRepository.Session = this.DepartmentRepository.Session = this.TeamRepository.Session = this.TopicRepository.Session = this.StatusReportRepository.Session;
            try
            {
                Resource dummyResource;
                Department department;
                InitializeHelper(out dummyResource, out department);

                // create all resources
                // ensure all resources are in place
                // for now, we put a stub resource in this
                var grpResources = items.GroupBy(item => item.TeamLead);
                foreach (var resourceG in grpResources)
                {
                    var resources = this.ResourceRepository.GetResourcesByName(resourceG.Key);

                    var resEmp = resourceG.First();

                    var emp = new Employee() { FullName = resEmp.TeamLead, EmailAddress = String.Format("{0}@test.com", resourceG.Key.Replace(" ", ".")) };

                    // group by team for resource
                    var resByTeam = resourceG.GroupBy(rg => rg.TeamName);
                    resByTeam.ToList().ForEach(rbt =>
                    {
                        // while grouping by team, we don't care for the key, it can be pulled from alloc entry
                        var res = rbt.First(); // resourceG.ToList().First();

                        var team = this.TeamRepository.GetTeamByName(res.TeamName);
                        if (team == null)
                        {
                            // pull the details of team name / lead from first item
                            // lookup lead by eamil address?
                            var t = new Team() { Name = res.TeamName, Lead = emp, Department = department };
                            t.Members.Add(emp);
                            team = this.TeamRepository.Add(t);
                            if (emp.Team == null)
                                emp.Team = team;
                            // this.ResourceRepository.Update(rmp);
                        }

                        if (resources.Count == 0)
                            this.ResourceRepository.AddResource(emp);
                    });

                }

                // things to check
                // all projects exist and project id's returned
                var grpProjects = items.GroupBy(item => item.Project);
                foreach (var projectG in grpProjects)
                {
                    var p = this.ProjectRepository.GetProjectByName(projectG.Key);
                    if (p == null)
                    {
                        var pItem = projectG.First(); // is it possible to miss anything this way?
                        var pTeam = this.TeamRepository.GetTeamByName(pItem.TeamName); // not going to work with this file format as team id is made up
                        var pLead = this.ResourceRepository.GetResourcesByName(pItem.TeamLead).First();
                        var project = new Project() {
                            Name = pItem.Project,
                            Caption = pItem.Project, // ProjectSummary appears to be the budget
                            Lead=pLead as Employee,
                            Department = department,
                            Team = pTeam
                        };
                        decimal b;
                        if (Decimal.TryParse(pItem.ProjectSummary, out b))
                            project.Budget = b;
                        this.ProjectRepository.AddProject(project);
                    }
                }

                // map JIRA ID's to topics in the new system
                var grpTopics = items.GroupBy(item => item.JiraID);

                grpTopics.ToList().ForEach(
                    gt =>
                    {
                        var jiraId = gt.Key;
                        // empty strings are inevitable, create new topics for them
                        Topic t = null;
                        if (jiraId != string.Empty)
                        {
                            t = this.TopicRepository.GetTopicByExternalId(jiraId);
                            if (t == null)
                            {
                                // steal the topic from the first item in list
                                var firstItem = gt.First();
                                this.TopicRepository.Add(new JiraIssueTopic() { JiraId = jiraId, Caption = firstItem.Note });
                            }
                        }
                        else
                        {
                            // all the empty topics will be grouped together, so if that is the case, create as new topics now
                            gt.ToList().ForEach(item => this.TopicRepository.Add(new Topic() { Caption = item.Note }));
                        }

                    });

                // get all status dates to see if we are overwriting an existing report, if so, delete the old one
                var grpStatusDates = items.GroupBy(item => item.StatusDate);

                // the following should be done in a transaction.
                grpStatusDates.ToList().ForEach(
                    gsd =>
                    {
                        var statusReportDate = gsd.Key;
                        try { this.StatusReportRepository.DeleteStatusReport(statusReportDate); }
                        catch (NullReferenceException) { }
                        var statusReport = StatusReport.Create(statusReportDate, String.Format("Status report for {0:MM/dd/yyyy}", statusReportDate));
                        statusReport.AuditInfo = new AuditInfo(dummyResource);
                        // iterate through each item for that date and add them
                        gsd.ToList().ForEach(statusReportItem =>
                                                 {
                                                     // we need to construct statusitem and topic for this
                                                     var statusItem = new StatusItem();
                                                     // we could use AutoMapper here - but doing manually for now as custom logic abound
                                                     statusItem.Topic = this.TopicRepository.GetTopicByExternalId(statusReportItem.JiraID);
                                                     if (statusItem.Topic == null)
                                                         statusItem.Topic = this.TopicRepository.GetTopicByCaption(statusReportItem.Note);

                                                     statusItem.Project = this.ProjectRepository.GetProjectByName(statusReportItem.Project);
                                                     statusItem.AuditInfo = new AuditInfo(dummyResource);
                                                     statusItem.Milestone = new Milestone()
                                                     {
                                                         ConfidenceLevel = statusReportItem.MilestoneConfidence ?? MilestoneConfidenceLevels.High,
                                                         Date = statusReportItem.MilestoneDate,
                                                         Type = statusReportItem.StatusType
                                                     };
                                                     statusItem.Caption = statusReportItem.Note; //.Caption;
                                                     statusItem.Notes.Add(new Note()
                                                                              {
                                                                                  AuditInfo = new AuditInfo(dummyResource),
                                                                                  Text = statusReportItem.Note
                                                                              });
                                                     if (statusItem.Topic != null)
                                                     {
                                                         statusReport.AddStatusItem(statusItem);
                                                         statusItem.StatusReport = statusReport;
                                                     }
                                                     else
                                                         _logger.Warn("Skilling statusitem {0} as no topic assigned", statusItem.Caption);
                                                 });
                        this.StatusReportRepository.AddStatusReport(statusReport);
                    });
                // import the new status report items

                this.StatusReportRepository.CommitTransaction();
            }
            catch (Exception exc)
            {
                _logger.ErrorException("Unable to import from CsvStatus file", exc);
                this.StatusReportRepository.RollbackTransaction();
                throw;
            }
            finally
            {
            }
        }
        private void InitializeHelper(out Resource dummyResource, out Department department)
        {
            var windowsIdentity = WindowsIdentity.GetCurrent();
            dummyResource = null;
            if (windowsIdentity != null)
            {
                var login = windowsIdentity.Name;
                dummyResource = new Employee()
                {
                    WindowsLogin = login,
                    EmailAddress = String.Format("{0}@test.com", login),
                    FullName = "First Last"
                };
            }
            else
                dummyResource = new Resource() { EmailAddress = "*****@*****.**", FirstName = "FN", LastName = "LN" };
            this.ResourceRepository.AddResource(dummyResource);

            // create dummy department
            department = this.DepartmentRepository.GetByName("Department");
            if (department == null)
            {
                department = new Department() { Name = "Department", Manager = dummyResource as Employee };
                this.DepartmentRepository.Add(department);
            }
        }