コード例 #1
0
        public void UpdateLastEmailReminderSentAndLastUpdatedAtAsync_Test(HttpStatusCode httpStatusCode)
        {
            // Arrange
            Mock.Get(_contractsDataLogger)
            .Setup(p => p.LogInformation(It.IsAny <string>(), It.IsAny <object[]>()));

            if (httpStatusCode != HttpStatusCode.OK)
            {
                Mock.Get(_contractsDataLogger)
                .Setup(p => p.LogError(It.IsAny <ApiGeneralException>(), It.IsAny <string>(), It.IsAny <object[]>()));
            }

            var expectedContractRequest = new ContractReminderItem {
                Id = 1, ContractVersion = 1, ContractNumber = "Test1"
            };
            ContractsDataService contractsDataService = CreateContractsDataService();

            SetUpHttpMessageHandler(expectedContractRequest, httpStatusCode, $"/api/contractReminder", HttpMethod.Patch);

            //Act
            Func <Task> action = async() => await contractsDataService.UpdateContractReminderAsync(expectedContractRequest);

            // Assert
            switch (httpStatusCode)
            {
            case HttpStatusCode.OK:
                action.Should().NotThrow();
                break;

            case HttpStatusCode.BadRequest:
                action.Should().Throw <ContractBadRequestClientException>();
                break;

            case HttpStatusCode.NotFound:
                action.Should().Throw <ContractNotFoundClientException>();
                break;

            case HttpStatusCode.PreconditionFailed:
                action.Should().Throw <ContractStatusClientException>();
                break;

            case HttpStatusCode.Conflict:
                action.Should().Throw <ContractUpdateConcurrencyClientException>();
                break;

            default:
                throw new NotImplementedException();
            }

            _mockHttpMessageHandler.VerifyNoOutstandingExpectation();
            VerifyAllMocks();
        }
        public void UpdateLastEmailReminderSentAndLastUpdatedAtAsync_MockHttp()
        {
            // Arrange
            UpdateLastEmailReminderSentRequest request = new UpdateLastEmailReminderSentRequest()
            {
                Id = 1, ContractVersion = 1, ContractNumber = "Test1"
            };

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

            _mockHttpMessageHandler.Expect(TestBaseAddress + $"/api/contractReminder").Respond(HttpStatusCode.OK);

            ContractsDataService contractsDataService = CreateContractsDataService();

            //Act
            Func <Task> act = async() => await contractsDataService.UpdateContractReminderAsync(request);

            // Assert
            act.Should().NotThrow();
            _mockHttpMessageHandler.VerifyNoOutstandingExpectation();
            VerifyAllMocks();
        }
        public void UpdateLastEmailReminderSentAndLastUpdatedAtAsync_Mock404Http()
        {
            // Arrange
            UpdateLastEmailReminderSentRequest request = new UpdateLastEmailReminderSentRequest()
            {
                Id = 1, ContractVersion = 1, ContractNumber = "Test1"
            };

            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>()));

            ContractsDataService contractsDataService = CreateContractsDataService();

            //Act
            Func <Task> act = async() => await contractsDataService.UpdateContractReminderAsync(request);

            // Assert
            act.Should().Throw <ApiGeneralException>().Where(e => e.ResponseStatusCode == HttpStatusCode.NotFound);
            _mockHttpMessageHandler.VerifyNoOutstandingExpectation();
            VerifyAllMocks();
        }