public async Task Should_return_ok_result_updating_item()
        {
            var item1 = new JudiciaryPersonRequest {
                Id = Guid.NewGuid(), Email = "*****@*****.**", Fullname = "a", Surname = "b", Title = "c", KnownAs = "d", PersonalCode = "123", PostNominals = "nom1", HasLeft = true
            };
            var retrievedPerson1 = new JudiciaryPerson(item1.Id, item1.PersonalCode, item1.Title, item1.KnownAs, item1.Surname, item1.Fullname, item1.PostNominals, item1.Email, item1.HasLeft);
            var request          = new List <JudiciaryPersonRequest> {
                item1
            };

            _queryHandlerMock
            .Setup(x => x.Handle <GetJudiciaryPersonByExternalRefIdQuery, JudiciaryPerson>(It.IsAny <GetJudiciaryPersonByExternalRefIdQuery>()))
            .ReturnsAsync(retrievedPerson1);

            var result = await _controller.BulkJudiciaryPersonsAsync(request);

            result.Should().NotBeNull();
            var objectResult = result as ObjectResult;

            objectResult.Should().NotBeNull();
            objectResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var data = objectResult.Value as BulkJudiciaryPersonResponse;

            data.Should().NotBeNull();
            data.ErroredRequests.Count.Should().Be(0);

            _commandHandlerMock.Verify(c => c.Handle(It.Is <UpdateJudiciaryPersonByExternalRefIdCommand>
                                                     (
                                                         c => c.Email == item1.Email && c.Fullname == item1.Fullname && c.Surname == item1.Surname &&
                                                         c.Title == item1.Title && c.KnownAs == item1.KnownAs && c.PersonalCode == item1.PersonalCode &&
                                                         c.PostNominals == item1.PostNominals && c.ExternalRefId == item1.Id
                                                     )));
        }
Beispiel #2
0
        public async Task Should_return_ok_result_updating_leaver_item()
        {
            var id = Guid.NewGuid();
            var judiciaryPerson = new JudiciaryPerson(id, "*****@*****.**", "a", "b", "c", "d", "123", "nom1", false);
            var item1           = new JudiciaryLeaverRequest {
                Id = id.ToString(), Leaver = true, LeftOn = DateTime.Now.AddDays(-100).ToLongDateString()
            };

            var request = new List <JudiciaryLeaverRequest> {
                item1
            };

            _queryHandlerMock
            .Setup(x => x.Handle <GetJudiciaryPersonByExternalRefIdQuery, JudiciaryPerson>(It.IsAny <GetJudiciaryPersonByExternalRefIdQuery>()))
            .ReturnsAsync(judiciaryPerson);

            var result = await _controller.BulkJudiciaryLeaversAsync(request);

            result.Should().NotBeNull();
            var objectResult = result as ObjectResult;

            objectResult.Should().NotBeNull();
            objectResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var data = objectResult.Value as BulkJudiciaryLeaverResponse;

            data.Should().NotBeNull();
            data.ErroredRequests.Count.Should().Be(0);

            _commandHandlerMock.Verify(c => c.Handle(It.Is <UpdateJudiciaryLeaverByExternalRefIdCommand>
                                                     (
                                                         c => c.ExternalRefId.ToString() == item1.Id && c.HasLeft == item1.Leaver
                                                     )), Times.Once);
        }
        public async Task RemoveJudiciaryPersonAsync(JudiciaryPerson judiciaryPerson)
        {
            await using var db = new BookingsDbContext(_dbContextOptions);

            db.JudiciaryPersons.Remove(judiciaryPerson);

            await db.SaveChangesAsync();
        }
        public void Should_update_the_leaver_person()
        {
            var person = new JudiciaryPerson(Guid.NewGuid(), "123", "Mr", "Steve", "Allen", "Steve Allen", "nom1", "*****@*****.**", false);

            person.Update(true);

            person.HasLeft.Should().BeTrue();
        }
        public async Task Handle(AddJudiciaryPersonByExternalRefIdCommand command)
        {
            var judiciaryPerson = new JudiciaryPerson(command.ExternalRefId, command.PersonalCode, command.Title, command.KnownAs, command.Surname, command.Fullname, command.PostNominals, command.Email, command.HasLeft);

            await _context.JudiciaryPersons.AddAsync(judiciaryPerson);

            await _context.SaveChangesAsync();
        }
 public PersonResponse MapJudiciaryPersonToResponse(JudiciaryPerson person)
 {
     return(new PersonResponse
     {
         Id = person.Id,
         Title = person.Title,
         FirstName = person.KnownAs,
         LastName = person.Surname,
         Username = person.Email,
     });
 }
        public void Should_update_person()
        {
            var person = new JudiciaryPerson(Guid.NewGuid(), "123", "Mr", "Steve", "Allen", "Steve Allen", "nom1", "*****@*****.**", true);

            person.Update("PersonalCode", "Title", "KnownAs", "Surname", "FullName", "PostNominals", "Email", true);

            person.PersonalCode.Should().Be("PersonalCode");
            person.Title.Should().Be("Title");
            person.KnownAs.Should().Be("KnownAs");
            person.Surname.Should().Be("Surname");
            person.Fullname.Should().Be("FullName");
            person.PostNominals.Should().Be("PostNominals");
            person.Email.Should().Be("Email");
            person.HasLeft.Should().BeTrue();
        }
        public JudiciaryPersonBuilder(Guid?externalRefId = null)
        {
            var settings = new BuilderSettings();

            _judiciaryPerson = new Builder(settings).CreateNew <JudiciaryPerson>().WithFactory(() =>
                                                                                               new JudiciaryPerson(
                                                                                                   externalRefId ?? Guid.NewGuid(),
                                                                                                   $"{RandomNumber.Next(0, 1000)}",
                                                                                                   Name.Prefix(),
                                                                                                   $"Automation_{Name.First()}",
                                                                                                   $"Automation_{Name.Last()}",
                                                                                                   Name.FullName(),
                                                                                                   $"{RandomNumber.Next(1000, 100000)}",
                                                                                                   $"Automation_{RandomNumber.Next()}@hmcts.net"
                                                                                                   , false))
                               .Build();
        }