Exemplo n.º 1
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.PartyRole>(), It.IsAny <IList <IRule> >())).Returns(true);

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

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

            var details = new PartyRoleDetails {
                Id = 2, Name = "PartyRole 1"
            };
            var entity = new PartyRole();

            entity.AddDetails(details);

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

            // Act
            service.Update(1, 1, contract);
        }
Exemplo n.º 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 PartyRoleService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

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

            validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.MDM.Contracts.Sample.PartyRole>(), 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");
        }
        public void ValidContractAdded()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyRoleService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);
            var identifier = new MdmId { SystemName = "Test", Identifier = "A" };
            var message = new CreateMappingRequest
            {
                EntityId = 12,
                Mapping = identifier
            };

            var system = new MDM.SourceSystem { Name = "Test" };
            var mapping = new PartyRoleMapping { System = system, MappingValue = "A" };
            validatorFactory.Setup(x => x.IsValid(It.IsAny<CreateMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, PartyRoleMapping>(identifier)).Returns(mapping);

            var partyrole = new MDM.PartyRole();
            repository.Setup(x => x.FindOne<MDM.PartyRole>(12)).Returns(partyrole);

            // Act
            var candidate = (PartyRoleMapping)service.CreateMapping(message);

            // Assert
            Assert.AreSame(mapping, candidate);
            repository.Verify(x => x.Save(partyrole));
            repository.Verify(x => x.Flush());
        }
Exemplo n.º 4
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 PartyRoleService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var message = new CreateMappingRequest
            {
                EntityId = 12,
                Mapping  = new MdmId {
                    SystemName = "Test", Identifier = "A"
                }
            };

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

            // Act
            var candidate = service.CreateMapping(message);

            // Assert
            Assert.IsNull(candidate);
        }
        public void UnsuccessfulMatchReturnsNotFound()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

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

            var list = new List <PartyRoleMapping>();

            repository.Setup(x => x.Queryable <PartyRoleMapping>()).Returns(list.AsQueryable());
            validatorFactory.Setup(x => x.IsValid(It.IsAny <MappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);

            var request = new MappingRequest {
                SystemName = "Endur", Identifier = "A", ValidAt = SystemTime.UtcNow()
            };

            // Act
            var contract = service.Map(request);

            // Assert
            repository.Verify(x => x.Queryable <PartyRoleMapping>());
            Assert.IsNotNull(contract, "Contract null");
            Assert.IsFalse(contract.IsValid, "Contract valid");
            Assert.AreEqual(ErrorType.NotFound, contract.Error.Type, "ErrorType difers");
        }
        public void VersionConflict()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

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

            var message = new AmendMappingRequest
            {
                MappingId = 12,
                Mapping   = new MdmId {
                    SystemName = "Test", Identifier = "A"
                },
                Version = 34
            };

            var party = new MDM.PartyRole();

            party.AddDetails(new PartyRoleDetails()
            {
                Timestamp = BitConverter.GetBytes(25L)
            });
            var mapping = new PartyRoleMapping {
                PartyRole = party
            };

            validatorFactory.Setup(x => x.IsValid(It.IsAny <AmendMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);
            repository.Setup(x => x.FindOne <PartyRoleMapping>(12)).Returns(mapping);

            // Act
            service.UpdateMapping(message);
        }
        public void NullRequestErrors()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

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

            // Act
            service.Map(null);
        }
        public void NullRequestErrors()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

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

            // Act
            service.CrossMap(null);
        }
        public void NullContractInvalid()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

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

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

            // Act
            service.Create(null);
        }
Exemplo n.º 10
0
        public void NullContractInvalid()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

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

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

            // Act
            service.CreateMapping(null);
        }
        public void ValidDetailsSaved()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

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

            var identifier = new MdmId {
                SystemName = "Test", Identifier = "A"
            };
            var message = new AmendMappingRequest {
                MappingId = 12, Mapping = identifier, Version = 34
            };

            var start  = new DateTime(2000, 12, 31);
            var finish = DateUtility.Round(SystemTime.UtcNow().AddDays(5));
            var s1     = new MDM.SourceSystem {
                Name = "Test"
            };
            var m1 = new PartyRoleMapping {
                Id = 12, System = s1, MappingValue = "1", Version = 34UL.GetVersionByteArray(), Validity = new DateRange(start, DateUtility.MaxDate)
            };
            var m2 = new PartyRoleMapping {
                Id = 12, System = s1, MappingValue = "1", Validity = new DateRange(start, finish)
            };

            // NB We deliberately bypasses the business logic
            var party = new MDM.PartyRole();

            m1.PartyRole = party;
            party.Mappings.Add(m1);

            validatorFactory.Setup(x => x.IsValid(It.IsAny <AmendMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);
            repository.Setup(x => x.FindOne <PartyRoleMapping>(12)).Returns(m1);
            mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, PartyRoleMapping>(identifier)).Returns(m2);

            // Act
            service.UpdateMapping(message);

            // Assert
            // NB Don't verify result of Update - already covered by PartyRoleMappingFixture
            repository.Verify(x => x.Save(party));
            repository.Verify(x => x.Flush());
        }
        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 PartyRoleService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

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

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

            // Act
            service.Create(contract);
        }
        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 PartyRoleService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

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

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

            // Act
            service.Create(contract);
        }
Exemplo n.º 14
0
        public void ValidContractAdded()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            var service    = new PartyRoleService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);
            var identifier = new MdmId {
                SystemName = "Test", Identifier = "A"
            };
            var message = new CreateMappingRequest
            {
                EntityId = 12,
                Mapping  = identifier
            };

            var system = new MDM.SourceSystem {
                Name = "Test"
            };
            var mapping = new PartyRoleMapping {
                System = system, MappingValue = "A"
            };

            validatorFactory.Setup(x => x.IsValid(It.IsAny <CreateMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);
            mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, PartyRoleMapping>(identifier)).Returns(mapping);

            var partyrole = new MDM.PartyRole();

            repository.Setup(x => x.FindOne <MDM.PartyRole>(12)).Returns(partyrole);

            // Act
            var candidate = (PartyRoleMapping)service.CreateMapping(message);

            // Assert
            Assert.AreSame(mapping, candidate);
            repository.Verify(x => x.Save(partyrole));
            repository.Verify(x => x.Flush());
        }
        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 PartyRoleService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var message = new CreateMappingRequest
                {
                    EntityId = 12,
                    Mapping = new MdmId { SystemName = "Test", Identifier = "A" }
                };

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

            // Act
            var candidate = service.CreateMapping(message);

            // Assert
            Assert.IsNull(candidate);
        }
        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.PartyRole>(), It.IsAny<IList<IRule>>())).Returns(true);

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

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

            var details = new PartyRoleDetails { Id = 2, Name = "PartyRole 1" };
            var entity = new PartyRole();
            entity.AddDetails(details);

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

            // Act
            service.Update(1, 1, contract);
        }
        public void ValidDetailsSaved()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

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

            var identifier = new MdmId { SystemName = "Test", Identifier = "A" };
            var message = new AmendMappingRequest { MappingId = 12, Mapping = identifier, Version = 34 };

            var start = new DateTime(2000, 12, 31);
            var finish = DateUtility.Round(SystemTime.UtcNow().AddDays(5));
            var s1 = new MDM.SourceSystem { Name = "Test" };
            var m1 = new PartyRoleMapping { Id = 12, System = s1, MappingValue = "1", Version = 34UL.GetVersionByteArray(), Validity = new DateRange(start, DateUtility.MaxDate) };
            var m2 = new PartyRoleMapping { Id = 12, System = s1, MappingValue = "1", Validity = new DateRange(start, finish) };

            // NB We deliberately bypasses the business logic
            var party = new MDM.PartyRole();
            m1.PartyRole = party;
            party.Mappings.Add(m1);

            validatorFactory.Setup(x => x.IsValid(It.IsAny<AmendMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);
            repository.Setup(x => x.FindOne<PartyRoleMapping>(12)).Returns(m1);
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, PartyRoleMapping>(identifier)).Returns(m2);

            // Act
            service.UpdateMapping(message);

            // Assert
            // NB Don't verify result of Update - already covered by PartyRoleMappingFixture
            repository.Verify(x => x.Save(party));
            repository.Verify(x => x.Flush());
        }
        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 PartyRoleService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

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

            validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.PartyRole>(), 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");
        }
        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 PartyRoleService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

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

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

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

            // Assert
            Assert.AreSame(expected, partyrole, "PartyRole differs");
            repository.Verify(x => x.Add(partyrole));
            repository.Verify(x => x.Flush());
        }
        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 PartyRoleService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

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

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

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

            // Assert
            Assert.AreSame(expected, partyrole, "PartyRole differs");
            repository.Verify(x => x.Add(partyrole));
            repository.Verify(x => x.Flush());
        }
        public void SuccessMatch()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

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

            // Domain details
            var system = new MDM.SourceSystem {
                Name = "Endur"
            };
            var mapping = new PartyRoleMapping
            {
                System       = system,
                MappingValue = "A",
            };
            var targetSystem = new MDM.SourceSystem {
                Name = "Trayport"
            };
            var targetMapping = new PartyRoleMapping
            {
                System       = targetSystem,
                MappingValue = "B",
                IsDefault    = true
            };
            var details = new MDM.PartyRoleDetails
            {
                Name = "PartyRole 1"
            };
            var party = new MDM.PartyRole
            {
                Id = 1
            };

            party.AddDetails(details);
            party.ProcessMapping(mapping);
            party.ProcessMapping(targetMapping);

            // Contract details
            var targetIdentifier = new MdmId
            {
                SystemName = "Trayport",
                Identifier = "B"
            };

            mappingEngine.Setup(x => x.Map <PartyRoleMapping, MdmId>(targetMapping)).Returns(targetIdentifier);

            var list = new List <PartyRoleMapping> {
                mapping
            };

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

            var request = new CrossMappingRequest
            {
                SystemName       = "Endur",
                Identifier       = "A",
                TargetSystemName = "trayport",
                ValidAt          = SystemTime.UtcNow(),
                Version          = 1
            };

            // Act
            var response  = service.CrossMap(request);
            var candidate = response.Contract;

            // Assert
            Assert.IsNotNull(response, "Contract null");
            Assert.IsNotNull(candidate, "Mapping null");
            Assert.AreEqual(1, candidate.Mappings.Count, "Identifier count incorrect");
            Assert.AreSame(targetIdentifier, candidate.Mappings[0], "Different identifier assigned");
        }
        public void SuccessMatch()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

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

            // Domain details
            var start  = new DateTime(1999, 12, 31);
            var finish = new DateTime(2020, 1, 1);
            var system = new SourceSystem {
                Name = "Endur"
            };
            var mapping = new PartyRoleMapping
            {
                System       = system,
                MappingValue = "A"
            };
            var details = new PartyRoleDetails
            {
                Name     = "PartyRole 1",
                Validity = new DateRange(start, finish)
            };
            var party = new PartyRole
            {
                Id    = 1,
                Party = new Party {
                    Id = 999
                }
            };

            party.AddDetails(details);
            party.ProcessMapping(mapping);

            // Contract details
            var identifier = new EnergyTrading.Mdm.Contracts.MdmId
            {
                SystemName = "Endur",
                Identifier = "A"
            };
            var cDetails = new EnergyTrading.MDM.Contracts.Sample.PartyRoleDetails
            {
                Name = "PartyRole 1"
            };

            mappingEngine.Setup(x => x.Map <PartyRoleMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping)).Returns(identifier);
            mappingEngine.Setup(x => x.Map <PartyRoleDetails, EnergyTrading.MDM.Contracts.Sample.PartyRoleDetails>(details)).Returns(cDetails);
            validatorFactory.Setup(x => x.IsValid(It.IsAny <MappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);

            var list = new List <PartyRoleMapping> {
                mapping
            };

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

            var request = new MappingRequest
            {
                SystemName = "Endur",
                Identifier = "A",
                ValidAt    = SystemTime.UtcNow(),
                Version    = 1
            };

            // Act
            var response  = service.Map(request);
            var candidate = response.Contract;

            // Assert
            repository.Verify(x => x.Queryable <PartyRoleMapping>());

            Assert.IsTrue(response.IsValid);
            Assert.IsNotNull(candidate, "Contract null");

            mappingEngine.Verify(x => x.Map <PartyRoleMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping));
            mappingEngine.Verify(x => x.Map <PartyRoleDetails, EnergyTrading.MDM.Contracts.Sample.PartyRoleDetails>(details));

            Assert.AreEqual(2, candidate.Identifiers.Count, "Identifier count incorrect");
            // NB This is order dependent
            Assert.AreSame(identifier, candidate.Identifiers[1], "Different identifier assigned");
            Assert.AreSame(cDetails, candidate.Details, "Different details assigned");
            Assert.AreEqual(start, candidate.MdmSystemData.StartDate, "Start date differs");
            Assert.AreEqual(finish, candidate.MdmSystemData.EndDate, "End date differs");
        }
        public void VersionConflict()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

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

            var message = new AmendMappingRequest
            {
                MappingId = 12,
                Mapping = new MdmId { SystemName = "Test", Identifier = "A" },
                Version = 34
            };

            var party = new MDM.PartyRole();
            party.AddDetails(new PartyRoleDetails() { Timestamp = BitConverter.GetBytes(25L) });
            var mapping = new PartyRoleMapping { PartyRole =  party };

            validatorFactory.Setup(x => x.IsValid(It.IsAny<AmendMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);
            repository.Setup(x => x.FindOne<PartyRoleMapping>(12)).Returns(mapping);

            // Act
            service.UpdateMapping(message);
        }
        public void SuccessMatch()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

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

            // Domain details
            var start = new DateTime(1999, 12, 31);
            var finish = new DateTime(2020, 1, 1);
            var system = new SourceSystem { Name = "Endur" };
            var mapping = new PartyRoleMapping
                {
                    System = system,
                    MappingValue = "A"
                };
            var details = new PartyRoleDetails
                {
                    Name = "PartyRole 1",
                    Validity = new DateRange(start, finish)
                };
            var party = new PartyRole
                {
                    Id = 1,
                    Party = new Party {  Id = 999 }
                };
            party.AddDetails(details);
            party.ProcessMapping(mapping);

            // Contract details
            var identifier = new EnergyTrading.Mdm.Contracts.MdmId
                {
                    SystemName = "Endur",
                    Identifier = "A"
                };
            var cDetails = new EnergyTrading.MDM.Contracts.Sample.PartyRoleDetails
                {
                    Name = "PartyRole 1"
                };

            mappingEngine.Setup(x => x.Map<PartyRoleMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping)).Returns(identifier);
            mappingEngine.Setup(x => x.Map<PartyRoleDetails, EnergyTrading.MDM.Contracts.Sample.PartyRoleDetails>(details)).Returns(cDetails);
            validatorFactory.Setup(x => x.IsValid(It.IsAny<MappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);

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

            var request = new MappingRequest
            {
                SystemName = "Endur",
                Identifier = "A",
                ValidAt = SystemTime.UtcNow(),
                Version = 1
            };

            // Act
            var response = service.Map(request);
            var candidate = response.Contract;

            // Assert
            repository.Verify(x => x.Queryable<PartyRoleMapping>());

            Assert.IsTrue(response.IsValid);
            Assert.IsNotNull(candidate, "Contract null");

            mappingEngine.Verify(x => x.Map<PartyRoleMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping));
            mappingEngine.Verify(x => x.Map<PartyRoleDetails, EnergyTrading.MDM.Contracts.Sample.PartyRoleDetails>(details));

            Assert.AreEqual(2, candidate.Identifiers.Count, "Identifier count incorrect");
            // NB This is order dependent
            Assert.AreSame(identifier, candidate.Identifiers[1], "Different identifier assigned");
            Assert.AreSame(cDetails, candidate.Details, "Different details assigned");
            Assert.AreEqual(start, candidate.MdmSystemData.StartDate, "Start date differs");
            Assert.AreEqual(finish, candidate.MdmSystemData.EndDate, "End date differs");
        }
        public void SuccessMatchCurrentVersion()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

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

            // Domain details
            var start = new DateTime(1999, 12, 31);
            var finish = new DateTime(2020, 1, 1);
            var system = new SourceSystem { Name = "Endur" };
            var mapping = new PartyRoleMapping
            {
                System = system,
                MappingValue = "A"
            };
            var details = new PartyRoleDetails
            {
                Name = "PartyRole 1",
                Validity = new DateRange(start, finish)
            };
            var party = new PartyRole
            {
                Id = 1
            };
            party.AddDetails(details);
            party.ProcessMapping(mapping);

            // Contract details
            var identifier = new EnergyTrading.Mdm.Contracts.MdmId
            {
                SystemName = "Endur",
                Identifier = "A"
            };
            var cDetails = new EnergyTrading.MDM.Contracts.Sample.PartyRoleDetails
            {
                Name = "PartyRole 1"
            };

            mappingEngine.Setup(x => x.Map<PartyRoleMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping)).Returns(identifier);
            mappingEngine.Setup(x => x.Map<PartyRoleDetails, EnergyTrading.MDM.Contracts.Sample.PartyRoleDetails>(details)).Returns(cDetails);
            validatorFactory.Setup(x => x.IsValid(It.IsAny<MappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);

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

            var request = new MappingRequest
            {
                SystemName = "Endur",
                Identifier = "A",
                ValidAt = SystemTime.UtcNow(),
                Version = 0
            };

            // Act
            var response = service.Map(request);

            // Assert
            repository.Verify(x => x.Queryable<PartyRoleMapping>());

            Assert.IsNull(response.Contract, "Contract not null");
            Assert.IsTrue(response.IsValid);
            Assert.AreEqual(0UL, response.Version);
        }
        public void SuccessMatch()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

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

            // Domain details
            var system = new MDM.SourceSystem { Name = "Endur" };
            var mapping = new PartyRoleMapping
                {
                    System = system,
                    MappingValue = "A",
                };
            var targetSystem = new MDM.SourceSystem { Name = "Trayport" };
            var targetMapping = new PartyRoleMapping
                {
                    System = targetSystem,
                    MappingValue = "B",
                    IsDefault = true
                };
            var details = new MDM.PartyRoleDetails
                {
                    Name = "PartyRole 1"
                };
            var party = new MDM.PartyRole
                {
                    Id = 1
                };
            party.AddDetails(details);
            party.ProcessMapping(mapping);
            party.ProcessMapping(targetMapping);

            // Contract details
            var targetIdentifier = new MdmId
                {
                    SystemName = "Trayport",
                    Identifier = "B"
                };

            mappingEngine.Setup(x => x.Map<PartyRoleMapping, MdmId>(targetMapping)).Returns(targetIdentifier);

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

            var request = new CrossMappingRequest
            {
                SystemName = "Endur",
                Identifier = "A",
                TargetSystemName = "trayport",
                ValidAt = SystemTime.UtcNow(),
                Version = 1
            };

            // Act
            var response = service.CrossMap(request);
            var candidate = response.Contract;

            // Assert
            Assert.IsNotNull(response, "Contract null");
            Assert.IsNotNull(candidate, "Mapping null");
            Assert.AreEqual(1, candidate.Mappings.Count, "Identifier count incorrect");
            Assert.AreSame(targetIdentifier, candidate.Mappings[0], "Different identifier assigned");
        }
        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.PartyRoleDetails { Name = "PartyRole 1" };
            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.PartyRole { 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 PartyRoleDetails { Id = 1, Name = "PartyRole 1", Timestamp = 74UL.GetVersionByteArray() };
            var entity = new PartyRole {Party = new Party {Id = 999}};
            entity.AddDetails(d1);

            var d2 = new PartyRoleDetails { Name = "PartyRole 1" };
            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.PartyRole>(), It.IsAny<IList<IRule>>())).Returns(true);

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

            mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.PartyRoleDetails, PartyRoleDetails>(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 PartyRoleService(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());
        }
        public void UnsuccessfulMatchReturnsNotFound()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

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

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

            var request = new CrossMappingRequest { SystemName = "Endur", Identifier = "A", ValidAt = SystemTime.UtcNow(), TargetSystemName = "Trayport" };

            // Act
            var contract = service.CrossMap(request);

            // Assert
            Assert.IsNotNull(contract, "Contract null");
            Assert.IsFalse(contract.IsValid, "Contract valid");
            Assert.AreEqual(ErrorType.NotFound, contract.Error.Type, "ErrorType difers"); ;
        }
Exemplo n.º 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.PartyRoleDetails {
                Name = "PartyRole 1"
            };
            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.PartyRole {
                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 PartyRoleDetails {
                Id = 1, Name = "PartyRole 1", Timestamp = 74UL.GetVersionByteArray()
            };
            var entity = new PartyRole {
                Party = new Party {
                    Id = 999
                }
            };

            entity.AddDetails(d1);

            var d2 = new PartyRoleDetails {
                Name = "PartyRole 1"
            };
            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.PartyRole>(), It.IsAny <IList <IRule> >())).Returns(true);

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

            mappingEngine.Setup(x => x.Map <EnergyTrading.MDM.Contracts.Sample.PartyRoleDetails, PartyRoleDetails>(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 PartyRoleService(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());
        }
        public void SuccessMatchCurrentVersion()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

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

            // Domain details
            var start  = new DateTime(1999, 12, 31);
            var finish = new DateTime(2020, 1, 1);
            var system = new SourceSystem {
                Name = "Endur"
            };
            var mapping = new PartyRoleMapping
            {
                System       = system,
                MappingValue = "A"
            };
            var details = new PartyRoleDetails
            {
                Name     = "PartyRole 1",
                Validity = new DateRange(start, finish)
            };
            var party = new PartyRole
            {
                Id = 1
            };

            party.AddDetails(details);
            party.ProcessMapping(mapping);

            // Contract details
            var identifier = new EnergyTrading.Mdm.Contracts.MdmId
            {
                SystemName = "Endur",
                Identifier = "A"
            };
            var cDetails = new EnergyTrading.MDM.Contracts.Sample.PartyRoleDetails
            {
                Name = "PartyRole 1"
            };

            mappingEngine.Setup(x => x.Map <PartyRoleMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping)).Returns(identifier);
            mappingEngine.Setup(x => x.Map <PartyRoleDetails, EnergyTrading.MDM.Contracts.Sample.PartyRoleDetails>(details)).Returns(cDetails);
            validatorFactory.Setup(x => x.IsValid(It.IsAny <MappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);

            var list = new List <PartyRoleMapping> {
                mapping
            };

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

            var request = new MappingRequest
            {
                SystemName = "Endur",
                Identifier = "A",
                ValidAt    = SystemTime.UtcNow(),
                Version    = 0
            };

            // Act
            var response = service.Map(request);

            // Assert
            repository.Verify(x => x.Queryable <PartyRoleMapping>());

            Assert.IsNull(response.Contract, "Contract not null");
            Assert.IsTrue(response.IsValid);
            Assert.AreEqual(0UL, response.Version);
        }