Exemplo n.º 1
0
        public async Task GetCitizenByCitizenIdSuccess()
        {
            //Arrange
            var helperHttpClientMoq = new Mock <ICitizenHttpClientHelper>();
            var context             = GetContext();
            var citizenId           = "1234567890";
            var configurationMoq    = new Mock <IConfiguration>();

            var citizenData = new CitizenDataResponseModelBuilder().Build();

            var httpClientCitizenDataResponse = JsonConvert.SerializeObject(citizenData);

            helperHttpClientMoq.Setup(x => x.GetCitizenDataByCprOrCitizenIdFromMomentumCoreAsync($"citizens/{citizenId}"))
            .Returns(Task.FromResult(new ResultOrHttpError <string, Error>(httpClientCitizenDataResponse)));

            var citizenService = new CitizenService(helperHttpClientMoq.Object, configurationMoq.Object, context.Object);

            //Act
            var result = await citizenService.GetCitizenByIdAsync(citizenId).ConfigureAwait(false);

            //Asert
            result.Should().NotBeNull();
            result.IsError.Should().BeFalse();
            result.Result.Should().BeEquivalentTo(citizenData);
        }
Exemplo n.º 2
0
        public async Task GetCitizenByCitizenIdFails()
        {
            //Arrange
            var helperHttpClientMoq = new Mock <ICitizenHttpClientHelper>();
            var context             = GetContext();
            var citizenId           = "1234567890";
            var configurationMoq    = new Mock <IConfiguration>();

            var citizenData = new CitizenDataResponseModelBuilder().Build();

            var error = new Error("123456", new string[] { "Citizen with the supplied cpr no is not found" }, "MCA");

            helperHttpClientMoq.Setup(x => x.GetCitizenDataByCprOrCitizenIdFromMomentumCoreAsync($"citizens/{citizenId}"))
            .Returns(Task.FromResult(new ResultOrHttpError <string, Error>(error, HttpStatusCode.BadRequest)));

            var citizenService = new CitizenService(helperHttpClientMoq.Object, configurationMoq.Object, context.Object);

            //Act
            var result = await citizenService.GetCitizenByIdAsync(citizenId).ConfigureAwait(false);

            //Asert
            result.IsError.Should().BeTrue();
            result.Error.Errors[0].Should().Be("Citizen with the supplied cpr no is not found");
        }