예제 #1
0
        public void Given_person_seen_is_an_employee_and_not_in_list_when_AddPersonSeen_then_added_to_list()
        {
            //GIVEN
            var checklist = new BusinessSafe.Domain.Entities.SafeCheck.Checklist();

            var employee = new Employee();
            employee.Id = Guid.NewGuid();
            employee.Forename = "Alester";
            employee.Surname = "Oakheart";
            employee.SetEmail("*****@*****.**",null);

            var personSeen = ChecklistPersonSeen.Create(employee);

            //WHEN
            checklist.AddPersonSeen(personSeen);


            //THEN
            Assert.That(checklist.PersonsSeen.Count, Is.EqualTo(1));
            Assert.That(checklist.PersonsSeen[0].Id, Is.Not.EqualTo(string.Empty));
            Assert.That(checklist.PersonsSeen[0].Employee.Id, Is.EqualTo(employee.Id));
            Assert.That(checklist.PersonsSeen[0].FullName, Is.EqualTo(employee.FullName));
            Assert.That(checklist.PersonsSeen[0].EmailAddress, Is.EqualTo(employee.GetEmail()));
            Assert.That(checklist.PersonsSeen[0].Checklist, Is.EqualTo(checklist));

        }
        public void Given_an_employee_is_a_persons_seen_to_be_removed_when_RemovePersonsSeenNotInList_then_removed_from_persons_seen_list()
        {
            //GIVEN
            var personSeen1 = ChecklistPersonSeen.Create(Guid.NewGuid(), "Diana Smith", "*****@*****.**");
            var personSeen2 = ChecklistPersonSeen.Create(Guid.NewGuid(), "Petyr Littlefinger", "*****@*****.**");
            var personSeenEmployee = ChecklistPersonSeen.Create(new Employee() { Id = Guid.NewGuid() });
            var checklist = new BusinessSafe.Domain.Entities.SafeCheck.Checklist();

            checklist.AddPersonSeen(personSeen1);
            checklist.AddPersonSeen(personSeen2);
            checklist.AddPersonSeen(personSeenEmployee);

            //WHEN
            checklist.RemovePersonsSeenNotInList(new List<ChecklistPersonSeen>() { personSeen1, personSeen2 });

            //THEN
            Assert.That(checklist.PersonsSeen.Count, Is.EqualTo(2));

        }
        public void Given_person_seen_is_not_an_employee_and_not_in_list_when_AddPersonSeen_then_added_to_list()
        {
            //GIVEN
            var checklist = new BusinessSafe.Domain.Entities.SafeCheck.Checklist();
            var personSeen = ChecklistPersonSeen.Create(Guid.NewGuid(), "Alester Oakheart", "*****@*****.**");
            var personSeenToRemove = ChecklistPersonSeen.Create(personSeen.Id, "Alester Oakheart", "*****@*****.**");
            checklist.AddPersonSeen(personSeen);

            //WHEN
            checklist.RemovePersonSeen(personSeenToRemove);

            //THEN
            Assert.That(checklist.PersonsSeen.Count, Is.EqualTo(0));
        }
        public void Given_person_seen_is_an_employee_and_in_list_when_RemovePersonSeen_then_removed_from_list()
        {
            //GIVEN
            var checklist = new BusinessSafe.Domain.Entities.SafeCheck.Checklist();

            var employee = new Employee();
            employee.Id = Guid.NewGuid();
            employee.Forename = "Alester";
            employee.Surname = "Oakheart";
            employee.SetEmail("*****@*****.**",null);

            var personSeenToRemove = ChecklistPersonSeen.Create(employee);
            var personSeen = ChecklistPersonSeen.Create(employee);
            checklist.AddPersonSeen(personSeen);

            //WHEN
            checklist.RemovePersonSeen(personSeenToRemove);


            //THEN
            Assert.That(checklist.PersonsSeen.Count, Is.EqualTo(0));
        }
예제 #5
0
        public void Given_a_checklist_with_an_non_employee_as_persons_seen_then_person_seen_model_is_correct()
        {
            //GIVEN
             var personSeen = ChecklistPersonSeen.Create(Guid.NewGuid(), "Prince of Dorne", "*****@*****.**");
             var checklist = new Checklist() { Id = Guid.NewGuid() };
             checklist.AddPersonSeen(personSeen);

             checklistRepo.Setup(x => x.GetById(It.IsAny<Guid>()))
                 .Returns(() => checklist);

             //when
             var target = new ChecklistController(dependencyFactory.Object);
             var result = target.GetChecklist(checklist.Id);

             //THEN
             Assert.That(result.PersonsSeen.Count, Is.EqualTo(1));

             Assert.That(result.PersonsSeen[0].EmployeeId, Is.EqualTo(Guid.Empty));
             Assert.That(result.PersonsSeen[0].FullName, Is.EqualTo(personSeen.FullName));
             Assert.That(result.PersonsSeen[0].EmailAddress, Is.EqualTo(personSeen.EmailAddress));
        }
예제 #6
0
        public void Given_a_checklist_with_an_employee_as_persons_seen_then_person_seen_model_is_correct()
        {
            //GIVEN
             var employee1 = new Employee() { Id = Guid.NewGuid(), Forename = "Ilyn", Surname = "Payne"};
             employee1.SetEmail("*****@*****.**", null);
             var employee2 = new Employee() {Id = Guid.NewGuid() };

             var checklist = new Checklist() {Id = Guid.NewGuid()};
             checklist.AddPersonSeen(ChecklistPersonSeen.Create(employee1));
             checklist.AddPersonSeen(ChecklistPersonSeen.Create(employee2));

             checklistRepo.Setup(x => x.GetById(It.IsAny<Guid>()))
                 .Returns(() => checklist);

             //when
             var target = new ChecklistController(dependencyFactory.Object);
             var result = target.GetChecklist(checklist.Id);

             //THEN
            Assert.That(result.PersonsSeen.Count,Is.EqualTo(2));

            Assert.That(result.PersonsSeen[0].EmployeeId, Is.EqualTo(employee1.Id));
            Assert.That(result.PersonsSeen[0].FullName, Is.EqualTo(employee1.FullName));
            Assert.That(result.PersonsSeen[0].EmailAddress, Is.EqualTo(employee1.GetEmail()));
        }
예제 #7
0
        public void Given_an_employee_is_a_persons_seen_and_is_removed_WHEN_PostChecklist_then_removed_from_persons_seen_list()
        {
            //GIVEN
            var employee1 = new Employee() { Id = Guid.Parse("11111111-ef43-4bc6-87a6-8cf48f1fcae7"), Forename = "Ser Lorus", Surname = "Tyrell"  };
            var employee2 = new Employee() { Id = Guid.Parse("22222222-ef43-4bc6-87a6-8cf48f1fcae7"), Forename = "Maid", Surname = "of Tarth" };

            var personsSeenViewModel = new PersonsSeenViewModel() { Id = Guid.NewGuid(), EmployeeId = employee2.Id, EmailAddress = employee2.GetEmail(), FullName = employee2.FullName };

            var viewModel = new ChecklistViewModel();
            viewModel.Id = Guid.NewGuid();
            viewModel.SiteId = 123;
            viewModel.ClientId = 7227;
            viewModel.Status = Checklist.STATUS_DRAFT;
            viewModel.PersonsSeen.Add(personsSeenViewModel);

            var checklist = new Checklist { Id = viewModel.Id, Status = Checklist.STATUS_DRAFT };
            checklist.AddPersonSeen(ChecklistPersonSeen.Create(employee1));

            _employeeRespository
                .Setup(x => x.GetById(It.IsAny<Guid>()))
                .Returns<Guid>((id) => new Employee() {Id = id});

            _checklistRepository
               .Setup(x => x.GetById(viewModel.Id))
               .Returns(() => checklist);

            Checklist savedChecklist = null;
            _checklistRepository.Setup(x => x.SaveOrUpdate(It.IsAny<Checklist>()))
                .Callback(
                    delegate(Checklist x)
                    {
                        savedChecklist = x;
                    }
                );

            var controller = GetTarget();
            controller.Request = new HttpRequestMessage();
            controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            //WHEN
            controller.PostChecklist(viewModel.Id, viewModel);

            //THEN
            Assert.That(savedChecklist.PersonsSeen.Count, Is.EqualTo(1));
        }
예제 #8
0
        public void Given_a_non_employee_is_a_persons_seen_and_is_removed_WHEN_PostChecklist_then_removed_from_persons_seen_list()
        {
            //GIVEN
            var nonEmployeeId = Guid.NewGuid();
            var viewModel = new ChecklistViewModel();
            viewModel.Id = Guid.NewGuid();
            viewModel.SiteId = 123;
            viewModel.ClientId = 7227;
            viewModel.Status = Checklist.STATUS_DRAFT;
            viewModel.PersonsSeen.Add( new PersonsSeenViewModel() { Id = nonEmployeeId, EmployeeId = Guid.Empty, EmailAddress = "do not remove me email address", FullName = "do not remove me" });

            var checklist = new Checklist { Id = viewModel.Id, Status = Checklist.STATUS_DRAFT };
            checklist.AddPersonSeen(ChecklistPersonSeen.Create(nonEmployeeId, "do not remove me", "do not remove me email address"));
            checklist.AddPersonSeen(ChecklistPersonSeen.Create(Guid.NewGuid(), "old full name", "old email address"));

            _checklistRepository
               .Setup(x => x.GetById(viewModel.Id))
               .Returns(() => checklist);

            Checklist savedChecklist = null;
            _checklistRepository.Setup(x => x.SaveOrUpdate(It.IsAny<Checklist>()))
                .Callback(
                    delegate(Checklist x)
                    {
                        savedChecklist = x;
                    }
                );

            var controller = GetTarget();
            controller.Request = new HttpRequestMessage();
            controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            //WHEN
            controller.PostChecklist(viewModel.Id, viewModel);

            //THEN
            Assert.That(savedChecklist.PersonsSeen.Count, Is.EqualTo(1));
        }
예제 #9
0
        private void AddRemovePersonsSeen(Checklist checklist, List<PersonsSeenViewModel> personsSeen)
        {
            var checklistPersonsSeen = new List<ChecklistPersonSeen>();
            //add to checklist
            personsSeen.ForEach(x =>
            {
                ChecklistPersonSeen checklistPersonSeen = null;

                if (x.EmployeeId.HasValue && x.EmployeeId != Guid.Empty)
                {
                    var employee = _employeeRespository.GetById(x.EmployeeId.Value);
                    checklistPersonSeen = ChecklistPersonSeen.Create(employee);
                    checklistPersonSeen.EmailAddress = x.EmailAddress;
                }
                else
                {
                    checklistPersonSeen = ChecklistPersonSeen.Create(x.Id, x.FullName, x.EmailAddress);
                }

                checklist.AddPersonSeen(checklistPersonSeen);
                checklistPersonsSeen.Add(checklistPersonSeen);
            });

            checklist.RemovePersonsSeenNotInList(checklistPersonsSeen);
        }