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 CurveService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);
            var identifier = new NexusId { SystemName = "Test", Identifier = "A" };
            var message = new CreateMappingRequest
            {
                EntityId = 12,
                Mapping = identifier
            };

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

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

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

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

            // Assert
            Assert.AreSame(mapping, candidate);
            repository.Verify(x => x.Save(curve));
            repository.Verify(x => x.Flush());
        }
コード例 #2
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 MDM.Contracts.NexusId { SystemName = "Test", Identifier = "A" };
            var contractDetails = new MDM.Contracts.CurveDetails();
            var contract = new MDM.Contracts.Curve
            {
                Identifiers = new MDM.Contracts.NexusIdList { id },
                Details = contractDetails,
                Nexus = new MDM.Contracts.SystemData { StartDate = start, EndDate = end }
            };

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

            var mapping = new CurveMapping();

            var mappingEngine = new Mock<IMappingEngine>();
            mappingEngine.Setup(x => x.Map<MDM.Contracts.NexusId, CurveMapping>(id)).Returns(mapping);
            mappingEngine.Setup(x => x.Map<MDM.Contracts.CurveDetails, Curve>(contractDetails)).Returns(details);

            var mapper = new CurveMapper(mappingEngine.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");
            Check(range, details.Validity, "Validity differs");
        }
コード例 #3
0
        protected static void Because_of()
        {
            entity  = CurveData.CreateBasicEntityWithOneMapping();
            mapping = entity.Mappings[0];
            client  = new HttpClient(ServiceUrl["Curve"] + string.Format("{0}/mapping/{1}", entity.Id, mapping.Id));

            response        = client.Get();
            mappingResponse = response.Content.ReadAsDataContract <Contracts.MappingResponse>();
        }
コード例 #4
0
        protected static void Because_of()
        {
            entity = CurveData.CreateBasicEntityWithOneMapping();
            mapping = entity.Mappings[0];
            client = new HttpClient(ServiceUrl["Curve"] + string.Format("{0}/mapping/{1}", entity.Id, mapping.Id));

            response = client.Get();
            mappingResponse = response.Content.ReadAsDataContract<Contracts.MappingResponse>();
        }
コード例 #5
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 curveMapping = new CurveMapping {
                System = system, MappingValue = "1", Validity = validity
            };

            var list = new List <CurveMapping> {
                curveMapping
            };
            var repository = new Mock <IRepository>();

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

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

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

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

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

            validatorEngine.Setup(x => x.IsValid(It.IsAny <MDM.Contracts.NexusId>(), It.IsAny <IList <IRule> >()))
            .Returns((MDM.Contracts.NexusId x, IList <IRule> y) => identifierValidator.IsValid(x, y));
            var validator = new CurveValidator(validatorEngine.Object, repository.Object);

            var curve = new Curve {
                Identifiers = new MDM.Contracts.NexusIdList {
                    overlapsRangeIdentifier
                }
            };

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

            // Assert
            Assert.IsFalse(result, "Validator succeeded");
        }
コード例 #6
0
        public void ValidDetailsSaved()
        {
            const int mappingId = 12;

            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

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

            // NB Don't put mappingId here - service assigns it
            var identifier = new NexusId {
                SystemName = "Test", Identifier = "A"
            };
            var message = new AmendMappingRequest {
                MappingId = mappingId, Mapping = identifier, Version = 34
            };

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

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

            m1.Curve = entity;
            entity.Mappings.Add(m1);

            validatorFactory.Setup(x => x.IsValid(It.IsAny <AmendMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);
            repository.Setup(x => x.FindOne <CurveMapping>(mappingId)).Returns(m1);
            mappingEngine.Setup(x => x.Map <NexusId, CurveMapping>(identifier)).Returns(m2);

            // Act
            service.UpdateMapping(message);

            // Assert
            Assert.AreEqual(mappingId, identifier.MappingId, "Mapping identifier differs");
            // Proves we have an update not an add
            Assert.AreEqual(1, entity.Mappings.Count, "Mapping count differs");
            // NB Don't verify result of Update - already covered by CurveMappingFixture
            repository.Verify(x => x.Save(entity));
            repository.Verify(x => x.Flush());
        }
コード例 #7
0
        public static void Run()
        {
            // ExStart:AddAnimationPropertyToDocument
            // Initialize scene object
            Scene scene = new Scene();

            // Call Common class create mesh using polygon builder method to set mesh instance
            Mesh mesh = Common.CreateMeshUsingPolygonBuilder();

            // Each cube node has their own translation
            Node cube1 = scene.RootNode.CreateChildNode("cube1", mesh);

            // Find translation property on node's transform object
            Property translation = cube1.Transform.FindProperty("Translation");

            // Create a curve mapping based on translation property
            CurveMapping mapping = new CurveMapping(scene, translation);

            // Create the animation curve on X component of the scale
            mapping.BindCurve("X", new Curve()
            {
                // Move node's translation to (10, 0, 10) at 0 sec using bezier interpolation
                { 0, 10.0f, Interpolation.Bezier },
                // Move node's translation to (20, 0, -10) at 3 sec
                { 3, 20.0f, Interpolation.Bezier },
                // Move node's translation to (30, 0, 0) at 5 sec
                { 5, 30.0f, Interpolation.Linear },
            });

            // Create the animation curve on Z component of the scale
            mapping.BindCurve("Z", new Curve()
            {
                // Move node's translation to (10, 0, 10) at 0 sec using bezier interpolation
                { 0, 10.0f, Interpolation.Bezier },
                // Move node's translation to (20, 0, -10) at 3 sec
                { 3, -10.0f, Interpolation.Bezier },
                // Move node's translation to (30, 0, 0) at 5 sec
                { 5, 0.0f, Interpolation.Linear },
            });

            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir();

            MyDir = MyDir + RunExamples.GetOutputFilePath("PropertyToDocument.fbx");

            // Save 3D scene in the supported file formats
            scene.Save(MyDir, FileFormat.FBX7500ASCII);
            // ExEnd:AddAnimationPropertyToDocument

            Console.WriteLine("\nAnimation property added successfully to document.\nFile saved at " + MyDir);
        }
コード例 #8
0
        protected static void Establish_context()
        {
            entity = CurveData.CreateBasicEntityWithOneMapping();
            currentTrayportMapping = entity.Mappings[0];

            mapping = new Mapping {
                SystemName             = currentTrayportMapping.System.Name,
                Identifier             = currentTrayportMapping.MappingValue,
                SourceSystemOriginated = currentTrayportMapping.IsMaster,
                DefaultReverseInd      = currentTrayportMapping.IsDefault,
                StartDate = currentTrayportMapping.Validity.Start,
                EndDate   = currentTrayportMapping.Validity.Finish.AddDays(2)
            };

            content = HttpContentExtensions.CreateDataContract(mapping);
            client  = new HttpClient();
        }
コード例 #9
0
        public static void Run()
        {
            // ExStart:AddAnimationPropertyToDocument
            // Initialize scene object
            Scene scene = new Scene();

            // Call Common class create mesh using polygon builder method to set mesh instance 
            Mesh mesh = Common.CreateMeshUsingPolygonBuilder();             

            // Each cube node has their own translation
            Node cube1 = scene.RootNode.CreateChildNode("cube1", mesh);

            // Find translation property on node's transform object
            Property translation = cube1.Transform.FindProperty("Translation");
            
            // Create a curve mapping based on translation property
            CurveMapping mapping = new CurveMapping(scene, translation);
            
            // Create curve on channel X and Z
            Curve curveX = mapping.CreateCurve("X");
            Curve curveZ = mapping.CreateCurve("Z");
            
            // Move node's translation to (10, 0, 10) at 0 sec using bezier interpolation
            curveX.CreateKeyFrame(0, 10.0f, Interpolation.Bezier);
            curveZ.CreateKeyFrame(0, 10.0f, Interpolation.Bezier);
            
            // Move node's translation to (20, 0, -10) at 3 sec
            curveX.CreateKeyFrame(3, 20.0f, Interpolation.Bezier);
            curveZ.CreateKeyFrame(3, -10.0f, Interpolation.Bezier);
            
            // Move node's translation to (30, 0, 0) at 5 sec
            curveX.CreateKeyFrame(5, 30.0f, Interpolation.Linear);
            curveZ.CreateKeyFrame(5, 0.0f, Interpolation.Bezier);            

            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir();
            MyDir = MyDir + RunExamples.GetOutputFilePath("PropertyToDocument.fbx");            

            // Save 3D scene in the supported file formats
            scene.Save(MyDir, FileFormat.FBX7500ASCII);
            // ExEnd:AddAnimationPropertyToDocument

            Console.WriteLine("\nAnimation property added successfully to document.\nFile saved at " + MyDir);
            
        }
コード例 #10
0
        protected static void Establish_context()
        {
            entity = CurveData.CreateBasicEntityWithOneMapping();
            currentTrayportMapping = entity.Mappings[0];

            mapping = new Mapping {

                    SystemName = currentTrayportMapping.System.Name,
                    Identifier = currentTrayportMapping.MappingValue,
                    SourceSystemOriginated = currentTrayportMapping.IsMaster,
                    DefaultReverseInd = currentTrayportMapping.IsDefault,
                    StartDate = currentTrayportMapping.Validity.Start,
                    EndDate = currentTrayportMapping.Validity.Finish.AddDays(2)
                };

            content = HttpContentExtensions.CreateDataContract(mapping);
            client = new HttpClient();
        }
コード例 #11
0
        public static void Run()
        {
            // Initialize scene object
            Scene scene = new Scene();

            // Call Common class create mesh method to set mesh instance
            Mesh mesh = Common.CreateMesh();

            // Each cube node has their own translation
            Node cube1 = scene.RootNode.CreateChildNode("cube1", mesh);

            // Find translation property on node's transform object
            Property translation = cube1.Transform.FindProperty("Translation");

            // Create a curve mapping based on translation property
            CurveMapping mapping = new CurveMapping(scene, translation);

            // Create curve on channel X and Z
            Curve curveX = mapping.CreateCurve("X");
            Curve curveZ = mapping.CreateCurve("Z");

            // Move node's translation to (10, 0, 10) at 0 sec using bezier interpolation
            curveX.CreateKeyFrame(0, 10.0f, Interpolation.Bezier);
            curveZ.CreateKeyFrame(0, 10.0f, Interpolation.Bezier);

            // Move node's translation to (20, 0, -10) at 3 sec
            curveX.CreateKeyFrame(3, 20.0f, Interpolation.Bezier);
            curveZ.CreateKeyFrame(3, -10.0f, Interpolation.Bezier);

            // Move node's translation to (30, 0, 0) at 5 sec
            curveX.CreateKeyFrame(5, 30.0f, Interpolation.Linear);
            curveZ.CreateKeyFrame(5, 0.0f, Interpolation.Bezier);

            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir_Animation();

            MyDir = MyDir + "PropertyToDocument.fbx";

            // Save 3D scene in the supported file formats
            scene.Save(MyDir, FileFormat.FBX7400ASCII);

            Console.WriteLine("\nAnimation property added successfully to document.\nFile saved at " + MyDir);
        }
コード例 #12
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 MDM.Contracts.NexusId {
                SystemName = "Test", Identifier = "A"
            };
            var contractDetails = new MDM.Contracts.CurveDetails();
            var contract        = new MDM.Contracts.Curve
            {
                Identifiers = new MDM.Contracts.NexusIdList {
                    id
                },
                Details = contractDetails,
                Nexus   = new MDM.Contracts.SystemData {
                    StartDate = start, EndDate = end
                }
            };

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

            var mapping = new CurveMapping();

            var mappingEngine = new Mock <IMappingEngine>();

            mappingEngine.Setup(x => x.Map <MDM.Contracts.NexusId, CurveMapping>(id)).Returns(mapping);
            mappingEngine.Setup(x => x.Map <MDM.Contracts.CurveDetails, Curve>(contractDetails)).Returns(details);

            var mapper = new CurveMapper(mappingEngine.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");
            Check(range, details.Validity, "Validity differs");
        }
コード例 #13
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 CurveService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);
            var identifier = new NexusId {
                SystemName = "Test", Identifier = "A"
            };
            var message = new CreateMappingRequest
            {
                EntityId = 12,
                Mapping  = identifier
            };

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

            validatorFactory.Setup(x => x.IsValid(It.IsAny <CreateMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);
            mappingEngine.Setup(x => x.Map <NexusId, CurveMapping>(identifier)).Returns(mapping);

            var curve = new MDM.Curve();

            repository.Setup(x => x.FindOne <MDM.Curve>(12)).Returns(curve);

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

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

            // Assert
            Assert.AreSame(mapping, candidate);
            repository.Verify(x => x.Save(curve));
            repository.Verify(x => x.Flush());
        }
コード例 #14
0
        public static Curve CreateBasicEntityWithOneMapping()
        {
            SourceSystem endur = repository.Queryable <SourceSystem>().Where(system => system.Name == "Endur").First();

            var entity = ObjectMother.Create <Curve>();

            var endurMapping = new CurveMapping
            {
                MappingValue = Guid.NewGuid().ToString(),
                System       = endur,
                IsDefault    = true,
                Validity     = new DateRange(DateTime.MinValue, DateTime.MaxValue.Subtract(new TimeSpan(72, 0, 0)))
            };

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

            return(entity);
        }
コード例 #15
0
        public static Curve CreateBasicEntityWithOneMapping()
        {
            SourceSystem endur = repository.Queryable<SourceSystem>().Where(system => system.Name == "Endur").First();

            var entity = ObjectMother.Create<Curve>();

            var endurMapping = new CurveMapping
                {
                    MappingValue = Guid.NewGuid().ToString(),
                    System = endur,
                    IsDefault = true,
                    Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue.Subtract(new TimeSpan(72, 0, 0)))
                };

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

            return entity;
        }
コード例 #16
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 curveMapping = new CurveMapping { System = system, MappingValue = "1", Validity = validity };

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

            var systemList = new List<MDM.SourceSystem>();
            var systemRepository = new Mock<IRepository<MDM.SourceSystem>>();
            systemRepository.Setup(x => x.Queryable()).Returns(systemList.AsQueryable());

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

            var identifierValidator = new NexusIdValidator<CurveMapping>(repository.Object);
            var validatorEngine = new Mock<IValidatorEngine>();
            validatorEngine.Setup(x => x.IsValid(It.IsAny<MDM.Contracts.NexusId>(), It.IsAny<IList<IRule>>()))
                          .Returns((MDM.Contracts.NexusId x, IList<IRule> y) => identifierValidator.IsValid(x, y));
            var validator = new CurveValidator(validatorEngine.Object, repository.Object);

            var curve = new Curve { Identifiers = new MDM.Contracts.NexusIdList { overlapsRangeIdentifier } };

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

            // Assert
            Assert.IsFalse(result, "Validator succeeded");
        }
コード例 #17
0
        public static Curve CreateEntityWithTwoDetailsAndTwoMappings()
        {
            SourceSystem endur    = repository.Queryable <SourceSystem>().Where(system => system.Name == "Endur").First();
            SourceSystem trayport =
                repository.Queryable <SourceSystem>().Where(system => system.Name == "Trayport").First();

            var entity = new Curve();

            baseDate          = DateTime.Today.Subtract(new TimeSpan(72, 0, 0));
            SystemTime.UtcNow = () => new DateTime(DateTime.Today.Subtract(new TimeSpan(73, 0, 0)).Ticks);

            AddDetailsToEntity(entity, DateTime.MinValue, baseDate);
            AddDetailsToEntity(entity, baseDate, DateTime.MaxValue);

            SystemTime.UtcNow = () => DateTime.Now;

            var trayportMapping = new CurveMapping
            {
                MappingValue = Guid.NewGuid().ToString(),
                System       = trayport,
                Validity     = new DateRange(DateTime.MinValue, DateTime.MaxValue)
            };

            var endurMapping = new CurveMapping
            {
                MappingValue = Guid.NewGuid().ToString(),
                System       = endur,
                IsDefault    = true,
                Validity     = new DateRange(DateTime.MinValue, DateTime.MaxValue)
            };

            entity.ProcessMapping(trayportMapping);
            entity.ProcessMapping(endurMapping);

            repository.Add(entity);
            repository.Flush();
            return(entity);
        }
コード例 #18
0
        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 CurveService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

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

            var mapping = new CurveMapping {
                Curve = new MDM.Curve()
                {
                    Timestamp = BitConverter.GetBytes(25L)
                }
            };

            // var <%= EntityName.ToLower() %> = new MDM.<%= EntityName %>();
            // <%= EntityName.ToLower() %>.AddDetails(new <%= EntityName %>Details() { Timestamp = BitConverter.GetBytes(25L) });
            // var mapping = new <%= EntityName %>Mapping { <%= EntityName %> =  <%= EntityName.ToLower() %> };

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

            // Act
            service.UpdateMapping(message);
        }
コード例 #19
0
        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 CurveService(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 CurveMapping
            {
                System       = system,
                MappingValue = "A"
            };
            var curve = new Curve
            {
                Id       = 1,
                Validity = new DateRange(start, finish)
            };

            //Curve.AddDetails(details);
            curve.ProcessMapping(mapping);

            // Contract details
            var identifier = new MDM.Contracts.NexusId
            {
                SystemName = "Endur",
                Identifier = "A"
            };
            var cdetails = new MDM.Contracts.CurveDetails();

            mappingEngine.Setup(x => x.Map <CurveMapping, MDM.Contracts.NexusId>(mapping)).Returns(identifier);
            mappingEngine.Setup(x => x.Map <Curve, MDM.Contracts.CurveDetails>(curve)).Returns(cdetails);
            validatorFactory.Setup(x => x.IsValid(It.IsAny <MappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);


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

            repository.Setup(x => x.Queryable <CurveMapping>()).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
            mappingEngine.Verify(x => x.Map <CurveMapping, MDM.Contracts.NexusId>(mapping));
            mappingEngine.Verify(x => x.Map <Curve, MDM.Contracts.CurveDetails>(curve));
            repository.Verify(x => x.Queryable <CurveMapping>());
            Assert.IsNotNull(candidate, "Contract null");
            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.Nexus.StartDate, "Start date differs");
            Assert.AreEqual(finish, candidate.Nexus.EndDate, "End date differs");
        }
コード例 #20
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 MDM.Contracts.CurveDetails();
            var nexus = new MDM.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) };
            var identifier = new MDM.Contracts.NexusId { SystemName = "Test", Identifier = "A" };
            var contract = new MDM.Contracts.Curve { Details = cd, Nexus = nexus };
            contract.Identifiers.Add(identifier);

            // Domain
            var system = new SourceSystem { Name = "Test" };
            var mapping = new CurveMapping { System = system, MappingValue = "A" };
            var d1 = ObjectMother.Create<Curve>();
            d1.Id = 1;
            d1.Timestamp = new byte[] { 74, 0, 0, 0, 0, 0, 0, 0 };
            var entity = ObjectMother.Create<Curve>();
            entity.Timestamp = new byte[] { 74, 0, 0, 0, 0, 0, 0, 0 };
            entity.AddDetails(d1);

            var d2 = ObjectMother.Create<Curve>();
            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<MDM.Contracts.Curve>(), It.IsAny<IList<IRule>>())).Returns(true);

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

            mappingEngine.Setup(x => x.Map<MDM.Contracts.CurveDetails, Curve>(cd)).Returns(d2);
            mappingEngine.Setup(x => x.Map<MDM.Contracts.SystemData, DateRange>(nexus)).Returns(range);
            mappingEngine.Setup(x => x.Map<MDM.Contracts.NexusId, CurveMapping>(identifier)).Returns(mapping);

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

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

            // Assert
            Assert.AreEqual(0, d2.Mappings.Count, "Created entity mappings count differs");
            Assert.AreEqual(0, d2.Id, "Created entity id differs");

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

            // Ok, hack the created one to align it
            d2.Id = entity.Id;
            foreach (var m in entity.Mappings)
            {
                d2.Mappings.Add(m);
            }

            // Should now be the same - avoid exposing what properties we have here
            Check(d2, entity);
        }
コード例 #21
0
        public static Curve CreateEntityWithTwoDetailsAndTwoMappings()
        {
            SourceSystem endur = repository.Queryable<SourceSystem>().Where(system => system.Name == "Endur").First();
            SourceSystem trayport =
                repository.Queryable<SourceSystem>().Where(system => system.Name == "Trayport").First();

            var entity = new Curve();
            baseDate = DateTime.Today.Subtract(new TimeSpan(72, 0, 0));
            SystemTime.UtcNow = () => new DateTime(DateTime.Today.Subtract(new TimeSpan(73, 0, 0)).Ticks);

            AddDetailsToEntity(entity, DateTime.MinValue, baseDate);
            AddDetailsToEntity(entity, baseDate, DateTime.MaxValue);

            SystemTime.UtcNow = () => DateTime.Now;

            var trayportMapping = new CurveMapping
                {
                    MappingValue = Guid.NewGuid().ToString(),
                    System = trayport,
                    Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue)
                };

            var endurMapping = new CurveMapping
                {
                    MappingValue = Guid.NewGuid().ToString(),
                    System = endur,
                    IsDefault = true,
                    Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue)
                };

            entity.ProcessMapping(trayportMapping);
            entity.ProcessMapping(endurMapping);

            repository.Add(entity);
            repository.Flush();
            return entity;
        }
コード例 #22
0
        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 CurveService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            // Domain details
            var system = new MDM.SourceSystem { Name = "Endur" };
            var mapping = new CurveMapping
            {
                System = system,
                MappingValue = "A"
            };
            var targetSystem = new MDM.SourceSystem { Name = "Trayport" };
            var targetMapping = new CurveMapping
            {
                System = targetSystem,
                MappingValue = "B",
                IsDefault = true
            };
            var curve = new MDM.Curve
            {
                Id = 1,
                Timestamp = new byte[] { 1, 0, 0, 0, 0, 0, 0, 0 }
            };
            //Curve.AddDetails(details);
            curve.ProcessMapping(mapping);
            curve.ProcessMapping(targetMapping);

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

            mappingEngine.Setup(x => x.Map<CurveMapping, NexusId>(targetMapping)).Returns(targetIdentifier);

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

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

            // 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");
        }
コード例 #23
0
        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 CurveService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            // Domain details
            var system = new MDM.SourceSystem {
                Name = "Endur"
            };
            var mapping = new CurveMapping
            {
                System       = system,
                MappingValue = "A"
            };
            var targetSystem = new MDM.SourceSystem {
                Name = "Trayport"
            };
            var targetMapping = new CurveMapping
            {
                System       = targetSystem,
                MappingValue = "B",
                IsDefault    = true
            };
            var curve = new MDM.Curve
            {
                Id        = 1,
                Timestamp = new byte[] { 1, 0, 0, 0, 0, 0, 0, 0 }
            };

            //Curve.AddDetails(details);
            curve.ProcessMapping(mapping);
            curve.ProcessMapping(targetMapping);

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

            mappingEngine.Setup(x => x.Map <CurveMapping, NexusId>(targetMapping)).Returns(targetIdentifier);

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

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

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

            // 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");
        }
コード例 #24
0
        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 CurveService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

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

            var mapping = new CurveMapping { Curve = new MDM.Curve() { Timestamp = BitConverter.GetBytes(25L) } };

            // var <%= EntityName.ToLower() %> = new MDM.<%= EntityName %>();
            // <%= EntityName.ToLower() %>.AddDetails(new <%= EntityName %>Details() { Timestamp = BitConverter.GetBytes(25L) });
            // var mapping = new <%= EntityName %>Mapping { <%= EntityName %> =  <%= EntityName.ToLower() %> };

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

            // Act
            service.UpdateMapping(message);
        }
コード例 #25
0
        public void ValidDetailsSaved()
        {
            const int mappingId = 12;

            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

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

            // NB Don't put mappingId here - service assigns it
            var identifier = new NexusId { SystemName = "Test", Identifier = "A" };
            var message = new AmendMappingRequest { MappingId = mappingId, Mapping = identifier, Version = 34 };

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

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

            validatorFactory.Setup(x => x.IsValid(It.IsAny<AmendMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);
            repository.Setup(x => x.FindOne<CurveMapping>(mappingId)).Returns(m1);
            mappingEngine.Setup(x => x.Map<NexusId, CurveMapping>(identifier)).Returns(m2);

            // Act
            service.UpdateMapping(message);

            // Assert
            Assert.AreEqual(mappingId, identifier.MappingId, "Mapping identifier differs");
            // Proves we have an update not an add
            Assert.AreEqual(1, entity.Mappings.Count, "Mapping count differs");
            // NB Don't verify result of Update - already covered by CurveMappingFixture
            repository.Verify(x => x.Save(entity));
            repository.Verify(x => x.Flush());
        }
コード例 #26
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 MDM.Contracts.CurveDetails();
            var nexus = new MDM.Contracts.SystemData {
                StartDate = new DateTime(2012, 1, 1)
            };
            var identifier = new MDM.Contracts.NexusId {
                SystemName = "Test", Identifier = "A"
            };
            var contract = new MDM.Contracts.Curve {
                Details = cd, Nexus = nexus
            };

            contract.Identifiers.Add(identifier);

            // Domain
            var system = new SourceSystem {
                Name = "Test"
            };
            var mapping = new CurveMapping {
                System = system, MappingValue = "A"
            };
            var d1 = ObjectMother.Create <Curve>();

            d1.Id        = 1;
            d1.Timestamp = new byte[] { 74, 0, 0, 0, 0, 0, 0, 0 };
            var entity = ObjectMother.Create <Curve>();

            entity.Timestamp = new byte[] { 74, 0, 0, 0, 0, 0, 0, 0 };
            entity.AddDetails(d1);

            var d2    = ObjectMother.Create <Curve>();
            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 <MDM.Contracts.Curve>(), It.IsAny <IList <IRule> >())).Returns(true);

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

            mappingEngine.Setup(x => x.Map <MDM.Contracts.CurveDetails, Curve>(cd)).Returns(d2);
            mappingEngine.Setup(x => x.Map <MDM.Contracts.SystemData, DateRange>(nexus)).Returns(range);
            mappingEngine.Setup(x => x.Map <MDM.Contracts.NexusId, CurveMapping>(identifier)).Returns(mapping);

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

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

            // Assert
            Assert.AreEqual(0, d2.Mappings.Count, "Created entity mappings count differs");
            Assert.AreEqual(0, d2.Id, "Created entity id differs");

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

            // Ok, hack the created one to align it
            d2.Id = entity.Id;
            foreach (var m in entity.Mappings)
            {
                d2.Mappings.Add(m);
            }

            // Should now be the same - avoid exposing what properties we have here
            Check(d2, entity);
        }