示例#1
0
        public void Registering_a_valid_contract_should_succeed()
        {
            var contract = FluentContract
                           .Create()
                           .ApplyDefaults()
                           .Save(this);

            var expectedResponse = new RegistrationAPIResponse(Guid.NewGuid());

            var ruleProcessor = GetRuleProcessor(_ruleProcessorUrl, expectedResponse);

            var response = ruleProcessor.RegisterContractItem(contract);

            Assert.AreEqual(RegistrationAPIState.Registered, response.State);
            Assert.AreEqual(expectedResponse.RegistrationReference, response.RegistrationReference);

            var trackingReferences = PreliminaryContractRepository.GetAll <ContractTrackingReference>().ToList();

            Assert.AreEqual(1, trackingReferences.Count);
            Assert.AreEqual(expectedResponse.RegistrationReference.ToString(), trackingReferences[0].ItemReference);
            Assert.AreEqual(ContractTrackingState.EvaluationPending, trackingReferences[0].State);
            Assert.AreNotEqual(0, trackingReferences[0].Id);
            Assert.AreNotEqual(default(DateTime), trackingReferences[0].CreatedAt);
            Assert.AreNotEqual(default(DateTime), trackingReferences[0].UpdatedAt);
        }
示例#2
0
        private Mock <ILimitsRuleProcessorClient> GetClientMock(RegistrationAPIResponse expectedResponse = null, bool throwOnNullResponse = true)
        {
            var clientMock = new Mock <ILimitsRuleProcessorClient>();

            if (expectedResponse != null && throwOnNullResponse)
            {
                clientMock
                .Setup(a => a.RegisterItem(It.Is <ItemRegistration>(i => i.SystemReference == _systemReference)))
                .Returns(Task.FromResult(expectedResponse));
            }
            else
            {
                var setup = clientMock
                            .Setup(a => a.RegisterItem(It.IsAny <ItemRegistration>()));

                if (throwOnNullResponse)
                {
                    setup.Throws(new Exception(_clientFailureMsg));
                }
            }

            return(clientMock);
        }
示例#3
0
        public PreliminaryContractRuleProcessor GetRuleProcessor(string ruleProcessorUrl, RegistrationAPIResponse expectedResponse = null, bool throwOnNullResponse = true, bool isRegistered = true)
        {
            var dshsMock = new Mock <IDataServiceHostSettings>();

            var settingsMock = new Mock <IPreliminaryContractSettings>();

            settingsMock
            .SetupGet(s => s.RuleProcessorUrl)
            .Returns(ruleProcessorUrl);

            var systemRegistrationMock = new Mock <IPreliminaryContractSystemRegistration>();

            systemRegistrationMock
            .Setup(r => r.GetSystemReference())
            .Returns(isRegistered ? _systemReference : Guid.Empty);

            systemRegistrationMock
            .SetupGet(r => r.IsRegistered)
            .Returns(isRegistered);

            var clientMock        = GetClientMock(expectedResponse, throwOnNullResponse);
            var clientFactoryMock = GetClientFactoryMock(clientMock);

            var ruleProcessor = new PreliminaryContractRuleProcessor(_logger.Object, authorisation, dshsMock.Object, settingsMock.Object, PreliminaryContractRepository, PreliminaryContractDataService, systemRegistrationMock.Object, clientFactoryMock.Object);

            return(ruleProcessor);
        }