Exemple #1
0
        public void CompareContractWithSavedEntity(EnergyTrading.Mdm.Contracts.SourceSystem contract)
        {
            int id          = int.Parse(contract.Identifiers.Where(x => x.IsMdmId).First().Identifier);
            var savedEntity = new DbSetRepository(new DbContextProvider(() => new SampleMappingContext())).FindOne <MDM.SourceSystem>(id);

            this.CompareContractWithEntityDetails(contract, savedEntity);
        }
        public void CreateEntity(MdmRequestInfo requestInfo)
        {
            var requester = new Mock<IMessageRequester>();
            var service = new MdmEntityService<SourceSystem>("sourcesystem", requester.Object);
            var sourcesystem = new SourceSystem();
            var response = new WebResponse<SourceSystem>() { Code = HttpStatusCode.OK, IsValid = true };

            requester.Setup(x => x.Create("sourcesystem", sourcesystem, requestInfo ?? It.IsAny<MdmRequestInfo>()))
                .Returns(response);

            requester.Setup(x => x.Request<SourceSystem>(It.IsAny<string>()))
                .Returns(new WebResponse<SourceSystem>
                             {
                                 IsValid = true,
                                 Code = HttpStatusCode.OK,
                                 Message = sourcesystem,
                             });

            // Act

            var result = (requestInfo == null) ? service.Create(sourcesystem) : service.Create(sourcesystem, requestInfo);

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, result.Code, "Status code differ");
            Assert.AreEqual(true, result.IsValid, "IsValid differ");
        }
        public void ReturnNullForZeroIdentifiers()
        {
            var entity = new SourceSystem();

            var candidate = entity.ToMdmId();

            Assert.IsNull(candidate);
        }
        public void ReturnZeroForZeroIdentifiers()
        {
            var entity = new SourceSystem();

            var candidate = entity.ToMdmKey();

            Assert.AreEqual(0, candidate);
        }
        protected override void OnSetup()
        {
            ConfigurationManager.AppSettings["MdmCaching"] = false.ToString();

            base.OnSetup();

            this.sourcesystem = SourceSystemData.PostBasicEntity();
        }
        public void ReturnNexusIdentifier()
        {
            var expected = new MdmId { Identifier = "1", IsMdmId = true };
            var entity = new SourceSystem { Identifiers = new MdmIdList { new MdmId(), expected } };

            var candidate = entity.ToMdmKey();

            Assert.AreEqual(1, candidate);
        }
        public void ShouldReturnFalseOnNullIdentifier()
        {
            var entity = new SourceSystem();
            entity.Identifiers.Add(new MdmId { SystemName = "A", Identifier = "A" });

            MdmId value = null;

            Assert.IsFalse(entity.HasIdentifier(value));
        }
        public void ReturnNexusIdentifier()
        {
            var expected = new MdmId { Identifier = "1", SystemName = SystemName };
            var entity = new SourceSystem { Identifiers = new MdmIdList { new MdmId(), expected } };

            var candidate = entity.ToSystemId(SystemName);

            Assert.AreEqual(expected, candidate);
        }
        public void ReturnZeroForNoNexusIdentifier()
        {
            var entity = new SourceSystem();
            entity.Identifiers.Add(new MdmId());

            var candidate = entity.ToMdmKey();

            Assert.AreEqual(0, candidate);
        }
        public void ReturnNullForNoNexusIdentifier()
        {
            var entity = new SourceSystem();
            entity.Identifiers.Add(new MdmId());

            var candidate = entity.ToMdmId();

            Assert.IsNull(candidate);
        }
        public void ShouldReturnFalseIfNotPresent()
        {
            var entity = new SourceSystem();
            entity.Identifiers.Add(new MdmId { SystemName = "A", Identifier = "A" });

            var value = new MdmId { SystemName = "B", Identifier = "B" };

            Assert.IsFalse(entity.HasIdentifier(value));
        }
        public void ReturnValueForEntityIfSystemFound()
        {
            var expected = new MdmId { SystemName = "A", Identifier = "A" };
            var entity = new SourceSystem();
            entity.Identifiers.Add(new MdmId());
            entity.Identifiers.Add(expected);

            var candidate = entity.SystemId("A");
            Assert.AreSame(expected, candidate);
        }
        public void ReturnOriginatingIdentifierForEntityIfPresent()
        {
            var expected = new MdmId { SourceSystemOriginated = true };

            var entity = new SourceSystem();
            entity.Identifiers.Add(new MdmId());
            entity.Identifiers.Add(expected);

            var candidate = entity.PrimaryIdentifier();
            Assert.AreSame(expected, candidate);
        }
Exemple #14
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");
        }
Exemple #15
0
        public void ConfirmEntitySaved(int id, EnergyTrading.Mdm.Contracts.SourceSystem contract)
        {
            var savedEntity =
                new DbSetRepository(new DbContextProvider(() => new SampleMappingContext())).FindOne <MDM.SourceSystem>(id);

            contract.Identifiers.Add(new MdmId()
            {
                IsMdmId = true, Identifier = id.ToString()
            });

            this.CompareContractWithEntityDetails(contract, savedEntity);
        }
Exemple #16
0
        private SourceSystem NewSourceSystem(string name, int parentId)
        {
            var sourceSystem = new SourceSystem();

            sourceSystem.Details.Name   = name;
            sourceSystem.Details.Parent = new EntityId
            {
                Identifier = new MdmId
                {
                    SystemName = "Nexus", Identifier = parentId.ToString(), IsMdmId = true
                }
            };
            return(sourceSystem);
        }
Exemple #17
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");
        }
Exemple #18
0
        private SourceSystem NewSourceSystem(string name, int parentId)
        {
            var sourceSystem = new SourceSystem
            {
                Details =
                {
                    Name   = name,
                    Parent = new EntityId
                    {
                        Identifier     = new MdmId
                        {
                            SystemName = "Nexus",
                            Identifier = parentId.ToString(CultureInfo.InvariantCulture),
                            IsMdmId    = true
                        }
                    }
                }
            };

            return(sourceSystem);
        }
        public void ShouldRetrieveFromCacheIfClientRequestByNexusIdMapping()
        {
            const string CacheKey = "MDM.SourceSystem";

            // Given
            var mockMdmEntityService = new Mock<IMdmEntityService<SourceSystem>>();
            var mockConfigManager = new Mock<IConfigurationManager>();
            var inmemoryCacheRepo = new DefaultMdmClientCacheRepository(new InMemoryCacheRepository());
            mockConfigManager.Setup(x => x.AppSettings).Returns(new NameValueCollection { { "CacheItemPolicy.Expiration." + CacheKey, "3500" } });
            var cachePolicyFactory = new AbsoluteCacheItemPolicyFactory(CacheKey, mockConfigManager.Object);
            var locationEntityService = new CachePolicyMdmEntityService<SourceSystem>(mockMdmEntityService.Object, cachePolicyFactory,inmemoryCacheRepo);
            var nexusId = new MdmId { SystemName = "Nexus", Identifier = "1", IsMdmId = true };
            var location = new SourceSystem
            {
                Identifiers = new MdmIdList { nexusId },
                Details = new SourceSystemDetails { Name = "Blah" }
            };

            //Setup a context, i.e. calling once to retrieve location should cache an entity..
            mockMdmEntityService.Setup(x => x.Get(1, It.IsAny<DateTime?>())).Returns(
                new WebResponse<SourceSystem> { Code = HttpStatusCode.OK, IsValid = true, Message = location });

            var response = locationEntityService.Get(nexusId);

            response.Code.Should().Be(HttpStatusCode.OK);
            response.Message.ToMdmId().Identifier.Should().Be(nexusId.Identifier);

            // When , we call second time..
            response = locationEntityService.Get(nexusId);

            // Then
            // It should not call mdm service again... should retrive form cache, so that verify...
            mockMdmEntityService.Verify(x => x.Get(1, It.IsAny<DateTime?>()), Times.Once());
            mockMdmEntityService.Verify(x => x.Get(It.IsAny<MdmId>(), It.IsAny<DateTime?>()), Times.Never());
            response.Code.Should().Be(HttpStatusCode.OK);
            response.Message.ToMdmId().Identifier.Should().Be(nexusId.Identifier);
        }
        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");
        }
partial         void AddRelatedEntities(SourceSystem contract);
        private SourceSystem NewSourceSystem(string name, int parentId)
        {
            var sourceSystem = new SourceSystem
            {
                Details =
                {
                    Name = name,
                    Parent = new EntityId
                    {
                        Identifier = new MdmId
                        {
                            SystemName = "Nexus",
                            Identifier = parentId.ToString(CultureInfo.InvariantCulture),
                            IsMdmId = true
                        }
                    }
                }
            };

            return sourceSystem;
        }
 private SourceSystem NewSourceSystem(string name, int parentId)
 {
     var sourceSystem = new SourceSystem();
     sourceSystem.Details.Name = name;
     sourceSystem.Details.Parent = new EntityId
         {Identifier = new MdmId
             {
                 SystemName = "Nexus", Identifier = parentId.ToString(), IsMdmId = true
             }};
     return sourceSystem;
 }
        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");
        }
        public void GetByMapping()
        {
            var requester = new Mock<IMessageRequester>();
            var service = new MdmEntityService<SourceSystem>("sourcesystem", requester.Object);

            var entity = new SourceSystem
            {
                Details = new SourceSystemDetails
                {
                    Name = "Gas"
                },
                Identifiers = new MdmIdList
                {
                    new MdmId { SystemName = "Nexus", Identifier = "1", IsMdmId = true},
                    new MdmId { SystemName = "Trayport", Identifier = "A"},
                    new MdmId { SystemName = "Endur", Identifier = "B"},
                }
            };
            var expected = new WebResponse<SourceSystem>
            {
                Code = HttpStatusCode.OK,
                Message = entity,
                Tag = "1"
            };
            requester.Setup(x => x.Request<SourceSystem>(It.IsAny<string>())).Returns(expected);

            var identifier = new Mapping { SystemName = "Trayport", Identifier = "A" };

            // Act
            var candidate = service.Get(identifier);

            // Assert
            Assert.AreSame(expected, candidate, "Entities differ");
        }
Exemple #26
0
 public void CompareContractWithEntityDetails(EnergyTrading.Mdm.Contracts.SourceSystem contract, MDM.SourceSystem entity)
 {
     SourceSystemComparer.Compare(contract, entity);
 }
 private static int Transform(SourceSystem broker)
 {
     return 1;
 }
        public void GetByIdValidAt()
        {
            var requester = new Mock<IMessageRequester>();
            var service = new MdmEntityService<SourceSystem>("sourcesystem", requester.Object);

            var entity = new SourceSystem
            {
                Details = new SourceSystemDetails
                {
                    Name = "Gas"
                },
                Identifiers = new MdmIdList
                {
                    new MdmId { SystemName = "Nexus", Identifier = "1", IsMdmId = true},
                    new MdmId { SystemName = "Trayport", Identifier = "A"},
                    new MdmId { SystemName = "Endur", Identifier = "B"},
                }
            };
            var expected = new WebResponse<SourceSystem>
            {
                Code = HttpStatusCode.OK,
                Message = entity,
                Tag = "1"
            };

            requester.Setup(x => x.Request<SourceSystem>(It.IsAny<string>())).Returns(expected);

            var now = DateTime.Now;
            string dateFormatString = "yyyy-MM-dd'T'HH:mm:ss.fffffffZ";

            // Act
            service.Get(1, now);

            // Assert
            requester.Verify(x => x.Request<SourceSystem>(It.Is<string>(s => s.Split('?')[1].Contains("as-of=" + now.ToString(dateFormatString)))), Times.Once());
        }
Exemple #29
0
 partial void AddRelatedEntities(SourceSystem contract);
        public void GetMappingMissingSystemId()
        {
            var requester = new Mock<IMessageRequester>();
            var service = new MdmEntityService<SourceSystem>("sourcesystem", requester.Object);

            var tpIdentifier = new MdmId { SystemName = "Trayport", Identifier = "A" };
            var entity = new SourceSystem
            {
                Details = new SourceSystemDetails
                {
                    Name = "Gas"
                },
                Identifiers = new MdmIdList
                {
                    new MdmId { SystemName = "Nexus", Identifier = "1", IsMdmId = true},
                    tpIdentifier,
                    new MdmId { SystemName = "Endur", Identifier = "B"},
                }
            };

            var response = new WebResponse<SourceSystem>
            {
                Code = HttpStatusCode.OK,
                Message = entity,
                Tag = "1"
            };

            requester.Setup(x => x.Request<SourceSystem>(It.IsAny<string>())).Returns(response);

            // Act
            var candidate = service.Map(1, "Fred");

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, candidate.Code, "Code differs");
            Assert.AreEqual(false, candidate.IsValid, "IsValid differs");
        }
 protected static void SetAdditionalData(SourceSystem entity)
 {
 }
Exemple #32
0
 public void should_not_return_a_sourcesystem()
 {
     EnergyTrading.Mdm.Contracts.SourceSystem returnedSourceSystem = null;
     try { returnedSourceSystem = response.Content.ReadAsDataContract <EnergyTrading.Mdm.Contracts.SourceSystem>(); } catch { }
     Assert.IsNull(returnedSourceSystem);
 }
        public void GetByMappingUrlEncodesCorrectly()
        {
            var requester = new Mock<IMessageRequester>();
            var service = new MdmEntityService<SourceSystem>("sourcesystem", requester.Object);

            var entity = new SourceSystem
            {
                Details = new SourceSystemDetails
                {
                    Name = "Gas"
                },
                Identifiers = new MdmIdList
                {
                    new MdmId { SystemName = "Trayport", Identifier = "1&1"},
                }
            };
            var expected = new WebResponse<SourceSystem>
            {
                Code = HttpStatusCode.OK,
                Message = entity,
                Tag = "1"
            };
            requester.Setup(x => x.Request<SourceSystem>(It.IsAny<string>())).Returns(expected);

            var identifier = new Mapping { SystemName = "S&P", Identifier = "1&1" };

            // Act
            var candidate = service.Get(identifier);

            // Assert
            requester.Verify(x => x.Request<SourceSystem>("sourcesystem/map?source-system=S%26P&mapping-string=1%261"));
        }