public static PersonsSeenViewModel Map(this ChecklistPersonSeen personSeen) { var personSeenViewModel = new PersonsSeenViewModel() { Id = personSeen.Id, EmployeeId = personSeen.Employee == null ? Guid.Empty : personSeen.Employee.Id, FullName = personSeen.FullName, EmailAddress = personSeen.EmailAddress }; return personSeenViewModel; }
public void Given_multiple_person_seen_Then_comma_separate_list_of_persons_added_to_view_model() { // GIVEN var personSeen1 = new PersonsSeenViewModel() { EmailAddress = "*****@*****.**", EmployeeId = Guid.NewGuid(), FullName = "Cain", Id = Guid.NewGuid() }; var personSeen2 = new PersonsSeenViewModel() { EmailAddress = "*****@*****.**", EmployeeId = Guid.NewGuid(), FullName = "Able", Id = Guid.NewGuid() }; ChecklistViewModel chkModel = CreateChecklistViewModel(); chkModel.PersonsSeen.Add(personSeen1); chkModel.PersonsSeen.Add(personSeen2); // WHEN var target = GetTarget(); var model = target.GetViewModel(chkModel); // THEN Assert.That(model.PersonsSeen, Is.EqualTo("Cain, Able")); }
public void Given_a_person_Then_person_seen_name_added_to_view_model() { // GIVEN var personSeen = new PersonsSeenViewModel() { EmailAddress = "*****@*****.**", EmployeeId = Guid.NewGuid(), FullName = "test this", Id = Guid.NewGuid() }; ChecklistViewModel chkModel = CreateChecklistViewModel(); chkModel.PersonsSeen.Add(personSeen); // WHEN var target = GetTarget(); var model = target.GetViewModel(chkModel); // THEN Assert.That(model.PersonsSeen, Is.EqualTo(personSeen.FullName)); }
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)); }
public void Given_employee_is_a_persons_seen_WHEN_PostChecklist_then_employee_added_to_persons_seen_list() { //GIVEN var employee = new Employee() {Id = Guid.NewGuid(), Forename = "Ser Lorus", Surname = "Tyrell"}; var personsSeenViewModel = new PersonsSeenViewModel() { Id = Guid.NewGuid(), EmployeeId = employee.Id, EmailAddress = employee.GetEmail(), FullName = employee.FullName }; var viewModel = new ChecklistViewModel(); viewModel.Id = Guid.NewGuid(); viewModel.SiteId = 123; viewModel.ClientId = 7227; viewModel.Status = Checklist.STATUS_DRAFT; viewModel.PersonsSeen.Add(personsSeenViewModel); _employeeRespository .Setup(x => x.GetById(personsSeenViewModel.EmployeeId.Value)) .Returns(() => new Employee() { Id = personsSeenViewModel.EmployeeId.Value, Forename = "Ser Lorus", Surname = "Tyrell"}); _checklistRepository .Setup(x => x.GetById(viewModel.Id)) .Returns(() => new Checklist { Id = viewModel.Id, Status = Checklist.STATUS_DRAFT }); 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)); Assert.That(savedChecklist.PersonsSeen[0].Employee.Id, Is.EqualTo(personsSeenViewModel.EmployeeId)); Assert.That(savedChecklist.PersonsSeen[0].FullName, Is.EqualTo(personsSeenViewModel.FullName)); Assert.That(savedChecklist.PersonsSeen[0].EmailAddress, Is.EqualTo(personsSeenViewModel.EmailAddress)); }
public void Given_a_non_employee_is_a_persons_seen_and_is_being_updated_WHEN_PostChecklist_then_persons_seen_list_updated() { //GIVEN var personsSeenViewModel = new PersonsSeenViewModel() { Id = Guid.NewGuid(), EmployeeId = Guid.Empty, EmailAddress = "*****@*****.**", FullName = "Ser Lorus" }; 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(personsSeenViewModel.Id, "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)); Assert.That(savedChecklist.PersonsSeen[0].Employee, Is.EqualTo(null)); Assert.That(savedChecklist.PersonsSeen[0].Id, Is.EqualTo(personsSeenViewModel.Id)); Assert.That(savedChecklist.PersonsSeen[0].FullName, Is.EqualTo(personsSeenViewModel.FullName)); Assert.That(savedChecklist.PersonsSeen[0].EmailAddress, Is.EqualTo(personsSeenViewModel.EmailAddress)); }