Beispiel #1
0
        public async Task TryGetContractAsyncTestAsync()
        {
            // Arrange
            string contractNumber = "Test";
            int    version        = 1;

            Mock.Get(_contractsDataLogger)
            .Setup(p => p.LogInformation(It.IsAny <string>(), It.IsAny <object[]>()));

            var expectedContract = new Contract()
            {
                Id = 1, ContractVersion = 1, ContractNumber = "Test1"
            };

            string jsonString = JsonSerializer.Serialize(expectedContract);

            _mockHttpMessageHandler.Expect(TestBaseAddress + $"/api/contract?contractNumber={contractNumber}&versionNumber={version}").Respond("application/json", jsonString);

            ContractsDataService contractsDataService = CreateContractsDataService();

            //Act
            var result = await contractsDataService.TryGetContractAsync(contractNumber, version);

            // Assert
            result.Should().BeEquivalentTo(expectedContract);
            _mockHttpMessageHandler.VerifyNoOutstandingExpectation();
            VerifyAllMocks();
        }
Beispiel #2
0
        public async Task TryGetContractAsync_ShoulNotThrowNotFoundException_TestAsync()
        {
            // Arrange
            string contractNumber = "Test";
            int    version        = 1;

            Mock.Get(_contractsDataLogger)
            .Setup(p => p.LogInformation(It.IsAny <string>(), It.IsAny <object[]>()));

            Mock.Get(_contractsDataLogger)
            .Setup(p => p.LogError(It.IsAny <Exception>(), It.IsAny <string>(), It.IsAny <object[]>()));

            ContractsDataService contractsDataService = CreateContractsDataService();

            _mockHttpMessageHandler.Expect(TestBaseAddress + $"/api/contract?contractNumber={contractNumber}&versionNumber={version}").Respond(HttpStatusCode.NotFound);

            //Act
            var result = await contractsDataService.TryGetContractAsync(contractNumber, version);

            // Assert
            result.Should().BeNull();
            _mockHttpMessageHandler.VerifyNoOutstandingExpectation();
            VerifyAllMocks();
        }