Example #1
0
 /// <summary>
 /// Creates an <see cref="EntityId" /> from a <see cref="MdmId" />
 /// </summary>
 /// <param name="value">MdmId to use</param>
 /// <param name="name">Optional name to use</param>
 /// <returns>A new <see cref="EntityId" /> wrapping the original MdmId</returns>
 public static EntityId ToEntityId(this MdmId value, string name = null)
 {
     return(new EntityId
     {
         Name = name,
         Identifier = value
     });
 }
Example #2
0
        /// <summary>
        /// Check whether an MDM entity has an identifier.
        /// </summary>
        /// <param name="entity">Entity to check</param>
        /// <param name="value">Identifier to use</param>
        /// <returns>true if the identifier is equal to any of the entities identifiers, otherwise false.</returns>
        public static bool HasIdentifier(this IMdmEntity entity, MdmId value)
        {
            if (entity == null || value == null)
            {
                return(false);
            }

            return(entity.Identifiers.Any(id => id.Equals(value)));
        }
Example #3
0
        /// <summary>
        /// Convert the identifier to a numeric key.
        /// </summary>
        /// <param name="identifier">Identifier to use.</param>
        /// <param name="defaultKey">Value if not found, defaults to zero</param>
        /// <returns>Numeric value of the identifier or the default if the identifier is null or does not convert.</returns>
        public static int ToKey(this MdmId identifier, int defaultKey = 0)
        {
            if (identifier == null)
            {
                return(defaultKey);
            }
            int key;

            return(int.TryParse(identifier.Identifier, out key) ? key : defaultKey);
        }
Example #4
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 sourcesystemMapping = new SourceSystemMapping {
                System = system, MappingValue = "1", Validity = validity
            };

            var list = new List <SourceSystemMapping> {
                sourcesystemMapping
            };
            var repository = new Mock <IRepository>();

            repository.Setup(x => x.Queryable <SourceSystemMapping>()).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 <SourceSystemMapping>(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 SourceSystemValidator(validatorEngine.Object, repository.Object);

            var sourcesystem = new SourceSystem {
                Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList {
                    overlapsRangeIdentifier
                }
            };

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

            // Assert
            Assert.IsFalse(result, "Validator succeeded");
        }
Example #5
0
        public void ValidSourceSystemPasses()
        {
            // 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 SourceSystemValidator(validatorEngine.Object, repository);

            var sourcesystem = new SourceSystem {
                Details = new EnergyTrading.Mdm.Contracts.SourceSystemDetails {
                    Name = "Test"
                }, Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList {
                    identifier
                }
            };

            this.AddRelatedEntities(sourcesystem);

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

            // Assert
            Assert.IsTrue(result, "Validator failed");
            Assert.AreEqual(0, violations.Count, "Violation count differs");
        }
Example #6
0
        /// <summary>
        /// Converts an <see cref="MdmId" /> into a <see cref="Mapping" />
        /// </summary>
        /// <param name="value">MdmId to convert.</param>
        /// <returns>Converted mapping if not null, otherwise null</returns>
        public static Mapping ToMapping(this MdmId value)
        {
            if (value == null)
            {
                return(null);
            }

            // TODO: Do we want all the bits or just system/id, different overload?
            return(new Mapping
            {
                MappingId = value.MappingId,
                SystemName = value.SystemName,
                Identifier = value.Identifier,
                IsMdmId = value.IsMdmId,
                DefaultReverseInd = value.DefaultReverseInd,
                SourceSystemOriginated = value.SourceSystemOriginated,
                StartDate = value.StartDate,
                EndDate = value.EndDate
            });
        }
        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 sourcesystemMapping = new SourceSystemMapping { System = system, MappingValue = "1", Validity = validity };

            var list = new List<SourceSystemMapping> { sourcesystemMapping };
            var repository = new Mock<IRepository>();
            repository.Setup(x => x.Queryable<SourceSystemMapping>()).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<SourceSystemMapping>(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 SourceSystemValidator(validatorEngine.Object, repository.Object);

            var sourcesystem = new SourceSystem { Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { badSystemIdentifier } };

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

            // Assert
            Assert.IsFalse(result, "Validator succeeded");
        }
        public void ValidSourceSystemPasses()
        {
            // 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 SourceSystemValidator(validatorEngine.Object, repository);

            var sourcesystem = new SourceSystem { Details = new EnergyTrading.Mdm.Contracts.SourceSystemDetails{Name = "Test"}, Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { identifier } };
            this.AddRelatedEntities(sourcesystem);

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

            // Assert
            Assert.IsTrue(result, "Validator failed");
            Assert.AreEqual(0, violations.Count, "Violation count differs");
        }
Example #9
0
 /// <summary>
 /// Convert a <see cref="MdmId" /> to a string identifier.
 /// </summary>
 /// <param name="value">MdmId to use.</param>
 /// <returns>Null if the identifier is null, value.Identifier otherwise.</returns>
 public static string ToIdentifier(this MdmId value)
 {
     return(value == null ? null : value.Identifier);
 }