コード例 #1
0
        protected static void Establish_context()
        {
            broker = BrokerData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(broker);
            client = new HttpClient();
        }
コード例 #2
0
        public void EntityNotFound()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var cd = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails {
                Name = "Test"
            };
            var nexus = new EnergyTrading.Mdm.Contracts.SystemData {
                StartDate = new DateTime(2012, 1, 1)
            };
            var contract = new EnergyTrading.MDM.Contracts.Sample.Broker {
                Details = cd, MdmSystemData = nexus
            };

            validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.MDM.Contracts.Sample.Broker>(), It.IsAny <IList <IRule> >())).Returns(true);

            // Act
            var response = service.Update(1, 1, contract);

            // Assert
            Assert.IsNotNull(response, "Response is null");
            Assert.IsFalse(response.IsValid, "Response is valid");
            Assert.AreEqual(ErrorType.NotFound, response.Error.Type, "ErrorType differs");
        }
コード例 #3
0
 protected static void Establish_context()
 {
     entity = BrokerData.CreateBasicEntity();
     var notAMapping = new EnergyTrading.MDM.Contracts.Sample.Broker();
     content = HttpContentExtensions.CreateDataContract(notAMapping);
     client = new HttpClient();
 }
コード例 #4
0
        public void EarlierVersionRaisesVersionConflict()
        {
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.MDM.Contracts.Sample.Broker>(), It.IsAny <IList <IRule> >())).Returns(true);

            var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var cd = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails {
                Name = "Test"
            };
            var nexus = new EnergyTrading.Mdm.Contracts.SystemData {
                StartDate = new DateTime(2012, 1, 1)
            };
            var contract = new EnergyTrading.MDM.Contracts.Sample.Broker {
                Details = cd, MdmSystemData = nexus
            };

            var details = new BrokerDetails {
                Id = 2, Name = "Test"
            };
            var entity = new Broker();

            entity.AddDetails(details);

            repository.Setup(x => x.FindOne <Broker>(1)).Returns(entity);

            // Act
            service.Update(1, 1, contract);
        }
コード例 #5
0
        public static EnergyTrading.MDM.Contracts.Sample.Broker CreateContractForEntityCreation()
        {
            var contract = new EnergyTrading.MDM.Contracts.Sample.Broker();

            AddDetailsToContract(contract);
            return(contract);
        }
コード例 #6
0
        protected static void Establish_context()
        {
            broker = BrokerData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(broker);
            client  = new HttpClient();
        }
コード例 #7
0
        protected static void Establish_context()
        {
            entity = BrokerData.CreateBasicEntity();
            var notAMapping = new EnergyTrading.MDM.Contracts.Sample.Broker();

            content = HttpContentExtensions.CreateDataContract(notAMapping);
            client  = new HttpClient();
        }
コード例 #8
0
        protected static void Establish_context()
        {
            client = new HttpClient();
            entity = BrokerData.CreateBasicEntity();
            var getResponse = client.Get(ServiceUrl["Broker"] + entity.Id);

            updatedContract = getResponse.Content.ReadAsDataContract <EnergyTrading.MDM.Contracts.Sample.Broker>();
            content         = HttpContentExtensions.CreateDataContract(BrokerData.MakeChangeToContract(updatedContract));
        }
コード例 #9
0
        protected static void Establish_context()
        {
            client = new HttpClient();
            entity = BrokerData.CreateBasicEntity();
            var getResponse = client.Get(ServiceUrl["Broker"] + entity.Id);

            updatedContract = getResponse.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Broker>();
            content = HttpContentExtensions.CreateDataContract(BrokerData.MakeChangeToContract(updatedContract));
        }
コード例 #10
0
 protected static void Because_of()
 {
     using (var client = new HttpClient(ServiceUrl["Broker"] +
         broker.Id))
     {
         using (HttpResponseMessage response = client.Get())
         {
             returnedBroker = response.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Broker>();
         }
     }
 }
コード例 #11
0
        public void OverlapsRangeFails()
        {
            // Assert
            var start    = new DateTime(1999, 1, 1);
            var finish   = new DateTime(2020, 12, 31);
            var validity = new DateRange(start, finish);
            var system   = new MDM.SourceSystem {
                Name = "Test"
            };
            var brokerMapping = new PartyRoleMapping {
                System = system, MappingValue = "1", Validity = validity
            };

            var list = new List <PartyRoleMapping> {
                brokerMapping
            };
            var repository = new Mock <IRepository>();

            repository.Setup(x => x.Queryable <PartyRoleMapping>()).Returns(list.AsQueryable());

            var systemList       = new List <MDM.SourceSystem>();
            var systemRepository = new Mock <IRepository>();

            systemRepository.Setup(x => x.Queryable <MDM.SourceSystem>()).Returns(systemList.AsQueryable());

            var overlapsRangeIdentifier = new EnergyTrading.Mdm.Contracts.MdmId
            {
                SystemName = "Test",
                Identifier = "1",
                StartDate  = start.AddHours(10),
                EndDate    = start.AddHours(15)
            };

            var identifierValidator = new NexusIdValidator <PartyRoleMapping>(repository.Object);
            var validatorEngine     = new Mock <IValidatorEngine>();

            validatorEngine.Setup(x => x.IsValid(It.IsAny <EnergyTrading.Mdm.Contracts.MdmId>(), It.IsAny <IList <IRule> >()))
            .Returns((EnergyTrading.Mdm.Contracts.MdmId x, IList <IRule> y) => identifierValidator.IsValid(x, y));
            var validator = new BrokerValidator(validatorEngine.Object, repository.Object);

            var broker = new Broker {
                Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList {
                    overlapsRangeIdentifier
                }
            };

            // Act
            var violations = new List <IRule>();
            var result     = validator.IsValid(broker, violations);

            // Assert
            Assert.IsFalse(result, "Validator succeeded");
        }
コード例 #12
0
        public void InvalidContractNotSaved()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var contract = new EnergyTrading.MDM.Contracts.Sample.Broker();

            validatorFactory.Setup(x => x.IsValid(It.IsAny <object>(), It.IsAny <IList <IRule> >())).Returns(false);

            // Act
            service.Create(contract);
        }
コード例 #13
0
        public void InvalidContractNotSaved()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var contract = new EnergyTrading.MDM.Contracts.Sample.Broker();

            validatorFactory.Setup(x => x.IsValid(It.IsAny<object>(), It.IsAny<IList<IRule>>())).Returns(false);

            // Act
            service.Create(contract);
        }
コード例 #14
0
        private static void AddDetailsToContract(EnergyTrading.MDM.Contracts.Sample.Broker contract)
        {
            var entity = ObjectMother.Create <Broker>();

            repository.Add(entity);
            repository.Flush();

            contract.Details = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails()
            {
                Name  = entity.LatestDetails.Name,
                Phone = (entity.LatestDetails as BrokerDetails).Phone,
                Fax   = (entity.LatestDetails as BrokerDetails).Fax,
                Rate  = (entity.LatestDetails as BrokerDetails).Rate,
            };

            contract.Party = entity.Party.CreateNexusEntityId(() => "");
        }
コード例 #15
0
        public void Map()
        {
            // Arrange
            var start = new DateTime(2010, 1, 1);
            var end   = DateUtility.MaxDate;
            var range = new DateRange(start, end);

            var id = new EnergyTrading.Mdm.Contracts.MdmId {
                SystemName = "Test", Identifier = "A"
            };
            var contractDetails = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails();
            var contract        = new EnergyTrading.MDM.Contracts.Sample.Broker
            {
                Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList {
                    id
                },
                Details       = contractDetails,
                MdmSystemData = new EnergyTrading.Mdm.Contracts.SystemData {
                    StartDate = start, EndDate = end
                },
                Party = ObjectMother.Create <Party>().CreateNexusEntityId(() => "")
            };

            // NB Don't assign validity here, want to prove SUT sets it
            var details = new BrokerDetails();

            var mapping = new PartyRoleMapping();

            var mappingEngine = new Mock <IMappingEngine>();
            var repository    = new Mock <IRepository>();

            mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, PartyRoleMapping>(id)).Returns(mapping);
            mappingEngine.Setup(x => x.Map <EnergyTrading.MDM.Contracts.Sample.BrokerDetails, BrokerDetails>(contractDetails)).Returns(details);
            repository.Setup(x => x.FindOne <Party>(int.Parse(contract.Party.Identifier.Identifier))).Returns(ObjectMother.Create <Party>());

            var mapper = new BrokerMapper(mappingEngine.Object, repository.Object);

            // Act
            var candidate = mapper.Map(contract);

            // Assert
            //Assert.AreEqual(1, candidate.Details.Count, "Detail count differs");
            Assert.AreEqual(1, candidate.Mappings.Count, "Mapping count differs");
            Assert.AreEqual("Broker", candidate.PartyRoleType);
            Check(range, details.Validity, "Validity differs");
        }
コード例 #16
0
        public void ValidBrokerPasses()
        {
            // Assert
            var start  = new DateTime(1999, 1, 1);
            var system = new MDM.SourceSystem {
                Name = "Test"
            };

            var systemList = new List <MDM.SourceSystem> {
                system
            };
            var systemRepository = new Mock <IRepository>();
            var repository       = new StubValidatorRepository();

            systemRepository.Setup(x => x.Queryable <MDM.SourceSystem>()).Returns(systemList.AsQueryable());

            var identifier = new EnergyTrading.Mdm.Contracts.MdmId
            {
                SystemName = "Test",
                Identifier = "1",
                StartDate  = start.AddHours(-10),
                EndDate    = start.AddHours(-5)
            };

            var validatorEngine = new Mock <IValidatorEngine>();
            var validator       = new BrokerValidator(validatorEngine.Object, repository);

            var broker = new Broker {
                Details = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails {
                    Name = "Test"
                }, Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList {
                    identifier
                }
            };

            this.AddRelatedEntities(broker);

            // Act
            var violations = new List <IRule>();
            var result     = validator.IsValid(broker, violations);

            // Assert
            Assert.IsTrue(result, "Validator failed");
            Assert.AreEqual(0, violations.Count, "Violation count differs");
        }
コード例 #17
0
        public static EnergyTrading.MDM.Contracts.Sample.Broker MakeChangeToContract(EnergyTrading.MDM.Contracts.Sample.Broker currentContract)
        {
            var entity = ObjectMother.Create <Broker>();

            repository.Add(entity);
            repository.Flush();

            currentContract.Details = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails()
            {
                Name  = entity.LatestDetails.Name,
                Phone = (entity.LatestDetails as BrokerDetails).Phone,
                Fax   = (entity.LatestDetails as BrokerDetails).Fax,
                Rate  = (entity.LatestDetails as BrokerDetails).Rate,
            };

            currentContract.MdmSystemData.StartDate = currentContract.MdmSystemData.StartDate.Value.AddDays(2);
            return(currentContract);
        }
コード例 #18
0
        public void Map()
        {
            // Arrange
            var start = new DateTime(2010, 1, 1);
            var end = DateUtility.MaxDate;
            var range = new DateRange(start, end);

            var id = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "A" };
            var contractDetails = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails();
            var contract = new EnergyTrading.MDM.Contracts.Sample.Broker
            {
                Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { id },
                Details = contractDetails,
                MdmSystemData = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = start, EndDate = end },
                Party = ObjectMother.Create<Party>().CreateNexusEntityId(() => "")
            };

            // NB Don't assign validity here, want to prove SUT sets it
            var details = new BrokerDetails();

            var mapping = new PartyRoleMapping();

            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, PartyRoleMapping>(id)).Returns(mapping);
            mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.BrokerDetails, BrokerDetails>(contractDetails)).Returns(details);
            repository.Setup(x => x.FindOne<Party>(int.Parse(contract.Party.Identifier.Identifier))).Returns(ObjectMother.Create<Party>());

            var mapper = new BrokerMapper(mappingEngine.Object, repository.Object);

            // Act
            var candidate = mapper.Map(contract);

            // Assert
            //Assert.AreEqual(1, candidate.Details.Count, "Detail count differs");
            Assert.AreEqual(1, candidate.Mappings.Count, "Mapping count differs");
            Assert.AreEqual("Broker", candidate.PartyRoleType);
            Check(range, details.Validity, "Validity differs");
        }
コード例 #19
0
        public void ValidContractIsSaved()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var broker = new Broker();
            var contract = new EnergyTrading.MDM.Contracts.Sample.Broker();

            validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Broker>(), It.IsAny<IList<IRule>>())).Returns(true);
            mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.Broker, Broker>(contract)).Returns(broker);

            // Act
            var expected = service.Create(contract);

            // Assert
            Assert.AreSame(expected, broker, "Broker differs");
            repository.Verify(x => x.Add(broker));
            repository.Verify(x => x.Flush());
        }
コード例 #20
0
        public void ValidContractIsSaved()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var broker   = new Broker();
            var contract = new EnergyTrading.MDM.Contracts.Sample.Broker();

            validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.MDM.Contracts.Sample.Broker>(), It.IsAny <IList <IRule> >())).Returns(true);
            mappingEngine.Setup(x => x.Map <EnergyTrading.MDM.Contracts.Sample.Broker, Broker>(contract)).Returns(broker);

            // Act
            var expected = service.Create(contract);

            // Assert
            Assert.AreSame(expected, broker, "Broker differs");
            repository.Verify(x => x.Add(broker));
            repository.Verify(x => x.Flush());
        }
コード例 #21
0
        public void BadSystemFails()
        {
            // Assert
            var start = new DateTime(1999, 1, 1);
            var finish = new DateTime(2020, 12, 31);
            var validity = new DateRange(start, finish);
            var system = new MDM.SourceSystem { Name = "Test" };
            var brokerMapping = new PartyRoleMapping { System = system, MappingValue = "1", Validity = validity };

            var list = new List<PartyRoleMapping> { brokerMapping };
            var repository = new Mock<IRepository>();
            repository.Setup(x => x.Queryable<PartyRoleMapping>()).Returns(list.AsQueryable());

            var badSystemIdentifier = new EnergyTrading.Mdm.Contracts.MdmId
            {
                SystemName = "Jim",
                Identifier = "1",
                StartDate = start.AddHours(-10),
                EndDate = start.AddHours(-5)
            };

            var identifierValidator = new NexusIdValidator<PartyRoleMapping>(repository.Object);
            var validatorEngine = new Mock<IValidatorEngine>();
            validatorEngine.Setup(x => x.IsValid(It.IsAny<EnergyTrading.Mdm.Contracts.MdmId>(), It.IsAny<IList<IRule>>()))
                           .Returns((EnergyTrading.Mdm.Contracts.MdmId x, IList<IRule> y) => identifierValidator.IsValid(x, y));
            var validator = new BrokerValidator(validatorEngine.Object, repository.Object);

            var broker = new Broker { Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { badSystemIdentifier } };

            // Act
            var violations = new List<IRule>();
            var result = validator.IsValid(broker, violations);

            // Assert
            Assert.IsFalse(result, "Validator succeeded");
        }
コード例 #22
0
        public void EarlierVersionRaisesVersionConflict()
        {
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Broker>(), It.IsAny<IList<IRule>>())).Returns(true);

            var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var cd = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails { Name = "Test" };
            var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) };
            var contract = new EnergyTrading.MDM.Contracts.Sample.Broker { Details = cd, MdmSystemData = nexus };

            var details = new BrokerDetails { Id = 2, Name = "Test" };
            var entity = new Broker();
            entity.AddDetails(details);

            repository.Setup(x => x.FindOne<Broker>(1)).Returns(entity);

            // Act
            service.Update(1, 1, contract);
        }
コード例 #23
0
        public void EntityNotFound()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var cd = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails { Name = "Test" };
            var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) };
            var contract = new EnergyTrading.MDM.Contracts.Sample.Broker { Details = cd, MdmSystemData = nexus };

            validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Broker>(), It.IsAny<IList<IRule>>())).Returns(true);

            // Act
            var response = service.Update(1, 1, contract);

            // Assert
            Assert.IsNotNull(response, "Response is null");
            Assert.IsFalse(response.IsValid, "Response is valid");
            Assert.AreEqual(ErrorType.NotFound, response.Error.Type, "ErrorType differs");
        }
コード例 #24
0
 protected static void Establish_context()
 {
     client = new HttpClient();
     var broker = new EnergyTrading.MDM.Contracts.Sample.Broker();
     content = HttpContentExtensions.CreateDataContract(broker);
 }
コード例 #25
0
 public static EnergyTrading.MDM.Contracts.Sample.Broker CreateContractForEntityCreation()
 {
     var contract = new EnergyTrading.MDM.Contracts.Sample.Broker();
     AddDetailsToContract(contract);
     return contract;
 }
コード例 #26
0
        protected static void Because_of()
        {
            asof = Script.baseDate.AddSeconds(1);
            client =
                new HttpClient(ServiceUrl["Broker"] + string.Format("{0}?as-of={1}",
                    broker.Id.ToString(), asof.ToString(DateFormatString)));

            HttpResponseMessage response = client.Get();
            returnedBroker = response.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Broker>();
        }
コード例 #27
0
        public void ValidBrokerPasses()
        {
            // Assert
            var start = new DateTime(1999, 1, 1);
            var system = new MDM.SourceSystem { Name = "Test" };

            var systemList = new List<MDM.SourceSystem> { system };
            var systemRepository = new Mock<IRepository>();
            var repository = new StubValidatorRepository();

            systemRepository.Setup(x => x.Queryable<MDM.SourceSystem>()).Returns(systemList.AsQueryable());

            var identifier = new EnergyTrading.Mdm.Contracts.MdmId
            {
                SystemName = "Test",
                Identifier = "1",
                StartDate = start.AddHours(-10),
                EndDate = start.AddHours(-5)
            };

            var validatorEngine = new Mock<IValidatorEngine>();
            var validator = new BrokerValidator(validatorEngine.Object, repository);

            var broker = new Broker { Details = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails{Name = "Test"}, Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { identifier } };
            this.AddRelatedEntities(broker);

            // Act
            var violations = new List<IRule>();
            var result = validator.IsValid(broker, violations);

            // Assert
            Assert.IsTrue(result, "Validator failed");
            Assert.AreEqual(0, violations.Count, "Violation count differs");
        }
コード例 #28
0
        public void ValidDetailsSaved()
        {
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            // Contract
            var cd = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails {
                Name = "Test"
            };
            var nexus = new EnergyTrading.Mdm.Contracts.SystemData {
                StartDate = new DateTime(2012, 1, 1)
            };
            var identifier = new EnergyTrading.Mdm.Contracts.MdmId {
                SystemName = "Test", Identifier = "A"
            };
            var contract = new EnergyTrading.MDM.Contracts.Sample.Broker {
                Details = cd, MdmSystemData = nexus
            };

            contract.Identifiers.Add(identifier);

            // Domain
            var system = new SourceSystem {
                Name = "Test"
            };
            var mapping = new PartyRoleMapping {
                System = system, MappingValue = "A"
            };
            var d1 = new BrokerDetails {
                Id = 1, Name = "Test", Timestamp = 74UL.GetVersionByteArray()
            };
            var entity = new Broker()
            {
                Party = new Party()
                {
                    Id = 999
                }
            };

            entity.AddDetails(d1);

            var d2 = new BrokerDetails {
                Name = "Test"
            };
            var range = new DateRange(new DateTime(2012, 1, 1), DateTime.MaxValue);

            validatorFactory.Setup(x => x.IsValid(It.IsAny <CreateMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);
            validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.MDM.Contracts.Sample.Broker>(), It.IsAny <IList <IRule> >())).Returns(true);

            repository.Setup(x => x.FindOne <Broker>(1)).Returns(entity);

            mappingEngine.Setup(x => x.Map <EnergyTrading.MDM.Contracts.Sample.BrokerDetails, BrokerDetails>(cd)).Returns(d2);
            mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.SystemData, DateRange>(nexus)).Returns(range);
            mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, PartyRoleMapping>(identifier)).Returns(mapping);

            var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            // Act
            service.Update(1, 74, contract);

            // Assert
            Assert.AreEqual(2, entity.Details.Count, "Details count differs");
            Assert.AreEqual(1, entity.Mappings.Count, "Mapping count differs");
            repository.Verify(x => x.Save(entity));
            repository.Verify(x => x.Flush());
        }
コード例 #29
0
        public void ValidDetailsSaved()
        {
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            // Contract
            var cd = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails { Name = "Test" };
            var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) };
            var identifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "A" };
            var contract = new EnergyTrading.MDM.Contracts.Sample.Broker { Details = cd, MdmSystemData = nexus };
            contract.Identifiers.Add(identifier);

            // Domain
            var system = new SourceSystem { Name = "Test" };
            var mapping = new PartyRoleMapping { System = system, MappingValue = "A" };
            var d1 = new BrokerDetails { Id = 1, Name = "Test", Timestamp = 74UL.GetVersionByteArray() };
            var entity = new Broker() { Party = new Party() { Id = 999 } };
            entity.AddDetails(d1);

            var d2 = new BrokerDetails { Name = "Test" };
            var range = new DateRange(new DateTime(2012, 1, 1), DateTime.MaxValue);

            validatorFactory.Setup(x => x.IsValid(It.IsAny<CreateMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);
            validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Broker>(), It.IsAny<IList<IRule>>())).Returns(true);

            repository.Setup(x => x.FindOne<Broker>(1)).Returns(entity);

            mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.BrokerDetails, BrokerDetails>(cd)).Returns(d2);
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.SystemData, DateRange>(nexus)).Returns(range);
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, PartyRoleMapping>(identifier)).Returns(mapping);

            var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            // Act
            service.Update(1, 74, contract);

            // Assert
            Assert.AreEqual(2, entity.Details.Count, "Details count differs");
            Assert.AreEqual(1, entity.Mappings.Count, "Mapping count differs");
            repository.Verify(x => x.Save(entity));
            repository.Verify(x => x.Flush());
        }