Пример #1
0
        public ClusterCoordinator AssignClusterCoordinator(int disasterId, int clusterId, int personId)
        {
            if (clusterId == 0 || personId == 0)
            {
                return(null);
            }

            var doesCoordinatorExist = DoesCoordinatorExist(disasterId, clusterId, personId);

            if (!doesCoordinatorExist)
            {
                AddClusterCoordinator(disasterId, clusterId, personId);
            }

            var result = _dataService.ClusterCoordinators.Include(x => x.Person).Include(x => x.Disaster).Include(x => x.Cluster)
                         .Where(x => x.DisasterId == disasterId &&
                                x.ClusterId == clusterId &&
                                x.PersonId == personId)
                         .Select(x => new
            {
                Id           = x.Id,
                PersonId     = x.Person.Id,
                DisasterId   = x.Disaster.Id,
                ClusterId    = x.Cluster.Id,
                FirstName    = x.Person.FirstName,
                LastName     = x.Person.LastName,
                ClusterName  = x.Cluster.Name,
                DisasterName = x.Disaster.Name
            }).First();

            var coordinator = new ClusterCoordinator
            {
                Id         = result.Id,
                PersonId   = result.PersonId,
                DisasterId = result.DisasterId,
                ClusterId  = result.ClusterId,
                Person     = new Person
                {
                    Id        = result.PersonId,
                    FirstName = result.FirstName,
                    LastName  = result.LastName
                },
                Cluster = new Cluster
                {
                    Id   = result.ClusterId,
                    Name = result.ClusterName
                },
                Disaster = new Disaster
                {
                    Id   = result.DisasterId,
                    Name = result.DisasterName
                }
            };

            if (!doesCoordinatorExist) // if the coordinator didn't originally exist when we started (so it was added), we want to add the log entry.
            {
                AppendLogEntry(coordinator);
            }
            return(coordinator);
        }
Пример #2
0
        public void Init()
        {
            _clusterCoordinator = new ClusterCoordinator()
            {
                ClusterId  = 9,
                DisasterId = 12,
                PersonId   = 15,
            };
            _disaster = new Disaster {
                Id = _clusterCoordinator.DisasterId, IsActive = true, Name = "Sharknado"
            };
            _cluster = new Cluster {
                Id = _clusterCoordinator.ClusterId, Name = "Red Zone"
            };
            _person = new Person {
                Id = _clusterCoordinator.PersonId, FirstName = "John", LastName = "Doe"
            };

            _dataService = new Mock <IDataService>();
            _dataService.Setup(x => x.Disasters).Returns(new EnumerableQuery <Disaster>(new[] { _disaster }));
            _dataService.Setup(x => x.Clusters).Returns(new EnumerableQuery <Cluster>(new[] { _cluster }));
            _dataService.Setup(x => x.Persons).Returns(new EnumerableQuery <Person>(new[] { _person }));

            _clusterCoordinatorService = new Services.ClusterCoordinatorService(_dataService.Object);
        }
Пример #3
0
        public void GetVolunteersByDate_FiltersToOnlyCheckedInClusterCoordinators()
        {
            var checkedInNonCoordinatorCommitment = new Commitment
            {
                DisasterId = disasterWithCommitments.Id,
                PersonId   = personWithNoCommitmentsID,
                Id         = 102,
                StartDate  = new DateTime(2013, 8, 10),
                EndDate    = new DateTime(2013, 8, 15)
            };

            var clusterCoordinator = new ClusterCoordinator
            {
                Id         = 1001,
                DisasterId = disasterWithCommitments.Id,
                PersonId   = checkedInPersonID,
            };

            initializeDisasterCollection(disasterWithCommitments);
            initializeVolunteerCollection(personWithCommitments, checkedInPerson, personWithNoCommitments);
            initializeCommitmentCollection(commitment, checkedInCommitment, checkedInNonCoordinatorCommitment);
            mockService.Setup(ds => ds.ClusterCoordinators).Returns(new[] { clusterCoordinator }.AsQueryable());

            var underTest = new AdminService(mockService.Object);

            var result = underTest.GetVolunteersForDate(disasterWithCommitments, new DateTime(2013, 08, 12), clusterCoordinatorsOnly: true, checkedInOnly: true);

            Assert.AreEqual(1, result.Count());
        }
Пример #4
0
        public void AssignClusterCoordinator_appends_a_ClusterCoordinatorLogEntry()
        {
            var clusterCoordinator = new ClusterCoordinator
            {
                Id         = 1,
                DisasterId = _disaster.Id,
                ClusterId  = _cluster.Id,
                PersonId   = _person.Id,
                Person     = _person,
                Cluster    = _cluster,
                Disaster   = _disaster
            };
            var coordinatorList = new List <ClusterCoordinator>();

            _dataService.Setup(x => x.ClusterCoordinators).Returns(coordinatorList.AsQueryable());
            _dataService.Setup(
                x => x.AddClusterCoordinator(It.Is <ClusterCoordinator>(cc => cc.DisasterId == _disaster.Id &&
                                                                        cc.ClusterId == _cluster.Id &&
                                                                        cc.PersonId == _person.Id)))
            .Callback(() => coordinatorList.Add(clusterCoordinator));

            _clusterCoordinatorService.AssignClusterCoordinator(clusterCoordinator.DisasterId, clusterCoordinator.ClusterId, clusterCoordinator.PersonId);

            _dataService.Verify(x => x.AddClusterCoordinator(It.IsAny <ClusterCoordinator>()), Times.Once());
            _dataService.Verify(x => x.AppendClusterCoordinatorLogEntry(
                                    It.Is <ClusterCoordinatorLogEntry>(cc => cc.DisasterId == clusterCoordinator.DisasterId &&
                                                                       cc.DisasterName == clusterCoordinator.Disaster.Name &&
                                                                       cc.ClusterId == clusterCoordinator.ClusterId &&
                                                                       cc.ClusterName == clusterCoordinator.Cluster.Name &&
                                                                       cc.PersonId == clusterCoordinator.PersonId &&
                                                                       cc.PersonName == clusterCoordinator.Person.FullName &&
                                                                       cc.Event == ClusterCoordinatorEvents.Assigned)));
        }
Пример #5
0
        public void AssignClusterCoordinator_saves_a_new_ClusterCoordinatorRecord()
        {
            var clusterCoordinator = new ClusterCoordinator
            {
                Id         = 1,
                DisasterId = _disaster.Id,
                ClusterId  = _cluster.Id,
                PersonId   = _person.Id,
                Person     = _person,
                Cluster    = _cluster,
                Disaster   = _disaster
            };
            var coordinatorList = new List <ClusterCoordinator>();

            _dataService.Setup(x => x.ClusterCoordinators).Returns(coordinatorList.AsQueryable());
            _dataService.Setup(x => x.AddClusterCoordinator(It.Is <ClusterCoordinator>(cc => cc.DisasterId == _disaster.Id &&
                                                                                       cc.ClusterId == _cluster.Id &&
                                                                                       cc.PersonId == _person.Id)))
            .Callback(() => coordinatorList.Add(clusterCoordinator));

            _clusterCoordinatorService.AssignClusterCoordinator(clusterCoordinator.DisasterId, clusterCoordinator.ClusterId, clusterCoordinator.PersonId);

            _dataService.Verify(x => x.AddClusterCoordinator(It.IsAny <ClusterCoordinator>()), Times.Once());
            _dataService.Verify(x => x.AddClusterCoordinator(It.Is <ClusterCoordinator>(cc => cc.DisasterId == clusterCoordinator.DisasterId &&
                                                                                        cc.ClusterId == clusterCoordinator.ClusterId &&
                                                                                        cc.PersonId == clusterCoordinator.PersonId)));
        }
Пример #6
0
        public void Arrange()
        {
            _dataService               = new DataService(new CrisisCheckin(), new CrisisCheckinMembership());
            _dataAccessHelper          = new DataAccessHelper(_dataService);
            _clusterCoordinatorService = new ClusterCoordinatorService(_dataService);
            var disaster  = _dataAccessHelper.Create_a_disaster();
            var person    = _dataAccessHelper.Create_a_volunteer();
            var clusterId = person.ClusterId.GetValueOrDefault();

            _clusterCoordinator = _clusterCoordinatorService.AssignClusterCoordinator(disaster.Id, clusterId, person.Id);
        }
Пример #7
0
        public void RemoveClusterCoordinator(ClusterCoordinator clusterCoordinator)
        {
            // attach the coordinator to delete to the context, if needed. Otherwise the remove/delete won't work
            var coordinatorToDelete = context.ClusterCoordinators.Local.FirstOrDefault(cc => cc.Id == clusterCoordinator.Id);

            if (coordinatorToDelete == null)
            {
                context.ClusterCoordinators.Attach(clusterCoordinator);
            }

            context.ClusterCoordinators.Remove(coordinatorToDelete);
            context.SaveChanges();
        }
Пример #8
0
        private void AppendLogEntry(ClusterCoordinator coordinator)
        {
            var clusterCoordinatorLogEntry = new ClusterCoordinatorLogEntry
            {
                Event        = ClusterCoordinatorEvents.Assigned,
                TimeStampUtc = DateTime.UtcNow,
                ClusterId    = coordinator.ClusterId,
                ClusterName  = coordinator.Cluster.Name,
                DisasterId   = coordinator.DisasterId,
                DisasterName = coordinator.Disaster.Name,
                PersonId     = coordinator.PersonId,
                PersonName   = coordinator.Person.FullName,
            };

            _dataService.AppendClusterCoordinatorLogEntry(clusterCoordinatorLogEntry);
        }
Пример #9
0
        public void UnassignClusterCoordinator(ClusterCoordinator clusterCoordinator)
        {
            var clusterCoordinatorLogEntry = new ClusterCoordinatorLogEntry
            {
                Event        = ClusterCoordinatorEvents.Unassigned,
                TimeStampUtc = DateTime.UtcNow,
                ClusterId    = clusterCoordinator.ClusterId,
                ClusterName  = clusterCoordinator.Cluster.Name,
                DisasterId   = clusterCoordinator.DisasterId,
                DisasterName = clusterCoordinator.Disaster.Name,
                PersonId     = clusterCoordinator.PersonId,
                PersonName   = clusterCoordinator.Person.FullName
            };

            _dataService.RemoveClusterCoordinator(clusterCoordinator);
            _dataService.AppendClusterCoordinatorLogEntry(clusterCoordinatorLogEntry);
        }
        public void UnassignClusterCoordinator(ClusterCoordinator clusterCoordinator)
        {
            dataService.RemoveClusterCoordinator(clusterCoordinator);
            var clusterCoordinatorLogEntry = new ClusterCoordinatorLogEntry
            {
                Event        = ClusterCoordinatorEvents.Unassigned,
                TimeStampUtc = DateTime.UtcNow,
                ClusterId    = clusterCoordinator.ClusterId,
                ClusterName  = dataService.Clusters.Single(x => x.Id == clusterCoordinator.ClusterId).Name,
                DisasterId   = clusterCoordinator.DisasterId,
                DisasterName = dataService.Disasters.Single(x => x.Id == clusterCoordinator.DisasterId).Name,
                PersonId     = clusterCoordinator.PersonId,
                PersonName   = dataService.Persons.Single(x => x.Id == clusterCoordinator.PersonId).FullName,
            };

            dataService.AppendClusterCoordinatorLogEntry(clusterCoordinatorLogEntry);
        }
Пример #11
0
 public ClusterCoordinator AddClusterCoordinator(ClusterCoordinator clusterCoordinator)
 {
     context.ClusterCoordinators.Add(clusterCoordinator);
     context.SaveChanges();
     return(clusterCoordinator);
 }
Пример #12
0
 public void RemoveClusterCoordinator(ClusterCoordinator clusterCoordinator)
 {
     context.ClusterCoordinators.Remove(clusterCoordinator);
     context.SaveChanges();
 }
Пример #13
0
        public void RemoveClusterCoordinator(ClusterCoordinator clusterCoordinator)
        {
            // attach the coordinator to delete to the context, if needed. Otherwise the
            // remove/delete won't work
            var coordinatorToDelete = context.ClusterCoordinators.Local.FirstOrDefault(cc => cc.Id == clusterCoordinator.Id);
            if (coordinatorToDelete == null)
                context.ClusterCoordinators.Attach(clusterCoordinator);

            context.ClusterCoordinators.Remove(coordinatorToDelete);
            context.SaveChanges();
        }
Пример #14
0
 public ClusterCoordinator AddClusterCoordinator(ClusterCoordinator clusterCoordinator)
 {
     context.ClusterCoordinators.Add(clusterCoordinator);
     context.SaveChanges();
     return clusterCoordinator;
 }