private ContractEvent GetContractEvent(ContractParentStatus parentStatus, ContractStatus contractStatus, ContractAmendmentType amendmentType) { return(new ContractEvent() { ParentStatus = parentStatus, Status = contractStatus, AmendmentType = amendmentType, ContractNumber = "ABC-0000", ContractVersion = 1, ContractEventXml = "sample-blob-file.xml" }); }
public void ProcessMessage_Approved_ReturnsLogAndExitResult(ContractParentStatus parentStatus, ContractStatus contractStatus, ContractAmendmentType amendmentType) { // Arrange var dummyContractEvent = GetContractEvent(parentStatus, contractStatus, amendmentType); var dummyContract = default(Contract); Mock.Get(_mockContractServiceLogger) .Setup(l => l.LogInformation(It.IsAny <string>())); Mock.Get(_mockContractServiceLogger) .Setup(l => l.LogWarning(It.IsAny <string>())); Mock.Get(_mockContractApprovalService) .Setup(s => s.ApproveAsync(It.IsAny <ContractEvent>(), It.IsAny <Contract>())) .ReturnsAsync(true) .Verifiable(); Mock.Get(_mockContractsDataService) .Setup(s => s.TryGetContractAsync(It.IsAny <string>(), It.IsAny <int>())) .ReturnsAsync(dummyContract) .Verifiable(); var contractService = new ContractService(_mockContractServiceLogger, _mockContractsDataService, _mockContractApprovalService, _mockContractsWithdrawService, _mockContractCreationService); // Act contractService.ProcessMessage(dummyContractEvent).GetAwaiter().GetResult(); // Assert Mock.Get(_mockContractsDataService) .Verify(s => s.TryGetContractAsync(It.IsAny <string>(), It.IsAny <int>()), Times.Once); Mock.Get(_mockContractApprovalService) .Verify(s => s.ApproveAsync(It.IsAny <ContractEvent>(), It.IsAny <Contract>()), Times.Never); Mock.Get(_mockContractServiceLogger).VerifyAll(); }
public void ProcessMessage_ThrowsException(ContractParentStatus parentStatus, ContractStatus contractStatus, ContractAmendmentType amendmentType) { // Arrange var dummyContractEvent = GetContractEvent(parentStatus, contractStatus, amendmentType); Mock.Get(_mockContractServiceLogger) .Setup(l => l.LogInformation(It.IsAny <string>())); Mock.Get(_mockContractApprovalService) .Setup(s => s.ApproveAsync(It.IsAny <ContractEvent>(), It.IsAny <Contract>())) .Returns(It.IsAny <Task <bool> >()) .Verifiable(); Mock.Get(_mockContractsWithdrawService) .Setup(s => s.WithdrawAsync(It.IsAny <ContractEvent>())) .Returns(It.IsAny <Task <bool> >()) .Verifiable(); // Act var contractService = new ContractService(_mockContractServiceLogger, _mockContractsDataService, _mockContractApprovalService, _mockContractsWithdrawService, _mockContractCreationService); Func <Task> act = async() => await contractService.ProcessMessage(dummyContractEvent); // Assert act.Should().Throw <NotImplementedException>(); Mock.Get(_mockContractServiceLogger).VerifyAll(); }
public void ProcessMessage_WhenWithdrawEventType_RequestsWithdrawl(ContractParentStatus parentStatus, ContractStatus contractStatus, ContractAmendmentType amendmentType) { // Arrange var dummyContractEvent = GetContractEvent(parentStatus, contractStatus, amendmentType); Mock.Get(_mockContractServiceLogger) .Setup(l => l.LogInformation(It.IsAny <string>())); Mock.Get(_mockContractsWithdrawService) .Setup(s => s.WithdrawAsync(It.IsAny <ContractEvent>())) .ReturnsAsync(true) .Verifiable(); var contractService = new ContractService(_mockContractServiceLogger, _mockContractsDataService, _mockContractApprovalService, _mockContractsWithdrawService, _mockContractCreationService); // Act Func <Task> act = async() => await contractService.ProcessMessage(dummyContractEvent); // Assert act.Should().NotThrow(); Mock.Get(_mockContractsWithdrawService) .Verify(s => s.WithdrawAsync(It.IsAny <ContractEvent>()), Times.Once); Mock.Get(_mockContractServiceLogger).VerifyAll(); Mock.Get(_mockContractApprovalService).VerifyAll(); Mock.Get(_mockContractsDataService).VerifyAll(); }
public async Task Deserilize_PartialXML_ValidateAmendmentTypeEnum_ReturnsExpectedResult(string amendment, ContractAmendmentType expectedAmendment) { // Arrange string xml = LoadPartialXMLFile(); var document = new XmlDocument(); document.LoadXml(xml); var ns = new XmlNamespaceManager(new NameTable()); ns.AddNamespace("c", Deserializer_v1103._contractEvent_Namespace); document.SelectSingleNode("/content/c:contract/c:contracts/c:contract/c:amendmentType", ns).InnerText = amendment; ILoggerAdapter_SetupLogInformation(); IContractValidationService_Setup_ValidateContractStatus(); IContractValidationService_Setup_ValidateFundingType(); IContractValidationService_Setup_ValidateXmlWithSchema(document); var expected = GeneratePocoForESIF9999(document); expected.First().ContractEvent.AmendmentType = expectedAmendment; var sut = GetDeserializer(); // Act var actual = await sut.DeserializeAsync(xml); // Assert actual.Should().BeEquivalentTo(expected, "Because the input XML has all required fields."); Verify_All(); }