Esempio n. 1
0
        public async Task TestPatientExistsArgumentPropertyNull(string firstName, string lastName)
        {
            // Arrange
            var patient = new PatientDTO
            {
                FirstName = firstName,
                LastName  = lastName
            };

            var cache = new MemoryCache(new MemoryCacheOptions());

            var mockLogger = new Mock <ILogger <ExternalPatientApiService> >();

            mockLogger.Setup(l => l.Log(
                                 LogLevel.Information,
                                 It.IsAny <EventId>(),
                                 It.IsAny <It.IsAnyType>(),
                                 It.IsAny <Exception>(),
                                 (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()))
            .Verifiable();

            var service = new ExternalPatientApiService(cache, Mock.Of <IHttpClientFactory>(), Mock.Of <IOptions <ExternalPatientApiOptions> >(), mockLogger.Object);

            // Act
            async Task TestAction() => await service.PatientExists(null);

            // Assert
            var ex = await Assert.ThrowsAsync <ArgumentNullException>(TestAction);
        }
Esempio n. 2
0
        public async Task TestPatientExistsArgumentNull()
        {
            // Arrange
            var service = new ExternalPatientApiService(Mock.Of <IMemoryCache>(), Mock.Of <IHttpClientFactory>(), Mock.Of <IOptions <ExternalPatientApiOptions> >(), Mock.Of <ILogger <ExternalPatientApiService> >());

            // Act
            async Task TestAction() => await service.PatientExists(null);

            // Assert
            var ex = await Assert.ThrowsAsync <ArgumentNullException>(TestAction);
        }
Esempio n. 3
0
        public async Task TestPatientExists()
        {
            // Arrange
            var testPatient = new PatientDTO
            {
                FirstName   = "Test",
                LastName    = "McTest",
                DateOfBirth = new DateTime(2000, 1, 1)
            };

            var cache = new MemoryCache(new MemoryCacheOptions());

            var mockFactory            = new Mock <IHttpClientFactory>();
            var mockHttpMessageHandler = new Mock <HttpMessageHandler>();

            mockHttpMessageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(),
                                                 ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(true.ToString()),
            });

            var client = new HttpClient(mockHttpMessageHandler.Object);

            mockFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client);

            var expectedUri =
                new Uri(
                    $"https://localhost:5003/api/patient/exists?firstName={testPatient.FirstName}&lastName={testPatient.LastName}&dateOfBirth={testPatient.DateOfBirth.ToShortDateString()}");

            var mockLogger = new Mock <ILogger <ExternalPatientApiService> >();

            mockLogger.Setup(l => l.Log(
                                 LogLevel.Information,
                                 It.IsAny <EventId>(),
                                 It.IsAny <It.IsAnyType>(),
                                 It.IsAny <Exception>(),
                                 (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()))
            .Verifiable();

            var service = new ExternalPatientApiService(cache, mockFactory.Object, _options, mockLogger.Object);

            // Act
            var result = await service.PatientExists(testPatient);

            // Assert
            Assert.True(result);

            mockHttpMessageHandler
            .Protected()
            .Verify(
                "SendAsync",
                Times.Once(),
                ItExpr.Is <HttpRequestMessage>(req =>
                                               req.Method == HttpMethod.Get &&
                                               req.RequestUri == expectedUri
                                               ),
                ItExpr.IsAny <CancellationToken>()
                );
        }