public async Task GetByContractNumberAndVersionAsync_MockHttp()
        {
            // 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.GetContractByContractNumberAndVersionAsync(contractNumber, version);

            // Assert
            result.Should().BeEquivalentTo(expectedContract);
            _mockHttpMessageHandler.VerifyNoOutstandingExpectation();
            VerifyAllMocks();
        }
示例#2
0
        public void WithdrawAsyncTest(HttpStatusCode httpStatusCode, ContractStatus withdrawalType)
        {
            // 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 WithdrawalRequest
            {
                ContractNumber  = "Test",
                ContractVersion = 1,
                FileName        = "sample-blob-file.xml",
                Id             = 1,
                WithdrawalType = withdrawalType
            };

            ContractsDataService contractsDataService = CreateContractsDataService();

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

            //Act
            Func <Task> action = async() => await contractsDataService.WithdrawAsync(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();
        }
示例#3
0
        public void CreateContractAsync_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 CreateRequest {
                ContractNumber = "Test"
            };
            ContractsDataService contractsDataService = CreateContractsDataService();

            SetUpHttpMessageHandler(expectedContractRequest, httpStatusCode, $"/api/contract", HttpMethod.Post);

            //Act
            Func <Task> action = async() => await contractsDataService.CreateContractAsync(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 <ContractWithHigherVersionAlreadyExistsClientException>();
                break;

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

            default:
                throw new NotImplementedException();
            }

            _mockHttpMessageHandler.VerifyNoOutstandingExpectation();
            VerifyAllMocks();
        }
示例#4
0
        public async Task GetContractRemindersAsync_MockHttp()
        {
            // Arrange
            int reminderInterval      = 14;
            int pageNumber            = 1;
            int pageSize              = 2;
            ContractSortOptions sort  = ContractSortOptions.LastUpdatedAt;
            SortDirection       order = SortDirection.Asc;

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

            var contractList = new List <ContractReminderItem>()
            {
                new ContractReminderItem()
                {
                    Id = 1, ContractVersion = 1, ContractNumber = "Test1"
                },
                new ContractReminderItem()
                {
                    Id = 2, ContractVersion = 1, ContractNumber = "Test2"
                }
            };
            var expectedContractReminders = new ContractReminders {
                Contracts = contractList
            };

            expectedContractReminders.Paging = new Paging()
            {
                CurrentPage = pageNumber, PageSize = pageSize, TotalCount = 2, TotalPages = 1, HasNextPage = false, HasPreviousPage = false, NextPageUrl = string.Empty, PreviousPageUrl = string.Empty
            };

            string jsonString = JsonSerializer.Serialize(expectedContractReminders);

            _mockHttpMessageHandler.Expect(TestBaseAddress + $"/api/contractReminders?reminderInterval={reminderInterval}&page={pageNumber}&count={pageSize}&sort={sort}&order={order}").Respond("application/json", jsonString);

            ContractsDataService contractsDataService = CreateContractsDataService();

            //Act
            var result = await contractsDataService.GetContractRemindersAsync((uint)reminderInterval, (uint)pageNumber, (uint)pageSize, sort, order);

            // Assert
            result.Should().BeEquivalentTo(expectedContractReminders);
            _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();
        }
示例#7
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();
        }