protected static void Establish_context()
 {
     entity = CurveData.CreateBasicEntity();
     var notAMapping = new Contracts.Curve();
     content = HttpContentExtensions.CreateDataContract(notAMapping);
     client = new HttpClient();
 }
        public void Map()
        {
            // Arrange
            var source = new MDM.Curve()
            {
                Name = "curve name",
                Type = "Forward",
                Currency = "GBP",
                Commodity = new Commodity() { Id = 1 },
                CommodityUnit = "ton",
                Location = new Location() { Id = 1 },
                DefaultSpread = .005m
            };

            var mapper = new MDM.Mappers.CurveDetailsMapper();

            // Act
            var result = mapper.Map(source);

            // Assert
            // TODO_UnitTestGeneration_Curve
            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(source.Name, result.Name);
            Assert.AreEqual(source.Type, result.CurveType);
            Assert.AreEqual(source.Currency, result.Currency);
            Assert.AreEqual(source.Commodity.Id.ToString(), result.Commodity.Identifier.Identifier);
            Assert.AreEqual(source.CommodityUnit, result.CommodityUnit);
            Assert.AreEqual(source.Location.Id.ToString(), result.Location.Identifier.Identifier);
            Assert.AreEqual(source.DefaultSpread, result.DefaultSpread);
        }
        protected static void Establish_context()
        {
            client = new HttpClient();
            entity = CurveData.CreateBasicEntity();

            content = HttpContentExtensions.CreateDataContract(new MDM.Contracts.Curve());
            startVersion = CurrentEntityVersion();
        }
        protected static void Establish_context()
        {
            client = new HttpClient();
            entity = CurveData.CreateBasicEntity();

            content      = HttpContentExtensions.CreateDataContract(new MDM.Contracts.Curve());
            startVersion = CurrentEntityVersion();
        }
        protected static void Establish_context()
        {
            entity = CurveData.CreateBasicEntity();
            var notAMapping = new Contracts.Curve();

            content = HttpContentExtensions.CreateDataContract(notAMapping);
            client  = new HttpClient();
        }
Exemple #6
0
        protected static void Establish_context()
        {
            entity = CurveData.CreateBasicEntityWithOneMapping();
            client = new HttpClient();
            var notAMapping = new MDM.Curve();

            content      = HttpContentExtensions.CreateDataContract(notAMapping);
            startVersion = CurrentEntityVersion();
        }
Exemple #7
0
 public static void Compare(Contracts.Curve contract, MDM.Curve entity)
 {
     Assert.AreEqual(contract.Details.Name, entity.Name);
     Assert.AreEqual(contract.Details.Commodity.NexusId().Value, entity.Commodity.Id);
     Assert.AreEqual(contract.Details.Originator.NexusId().Value, entity.Originator.Id);
     Assert.AreEqual(contract.Details.Location.NexusId().Value, entity.Location.Id);
     Assert.AreEqual(contract.Details.CommodityUnit, entity.CommodityUnit);
     Assert.AreEqual(contract.Details.CurveType, entity.Type);
     Assert.AreEqual(contract.Details.DefaultSpread, entity.DefaultSpread);
     Assert.AreEqual(contract.Details.Currency, entity.Currency);
 }
        protected static void Because_of()
        {
            entity = CurveData.CreateEntityWithTwoDetailsAndTwoMappings();

            client = new HttpClient(ServiceUrl["Curve"] +
                "crossmap?source-system=trayport&destination-system=endur&mapping-string=" + entity.Mappings[0].MappingValue
                + "&as-of=" + entity.Mappings[0].Validity.Start.ToString(DateFormatString));

            response = client.Get();
            mappingResponse = response.Content.ReadAsDataContract<Contracts.MappingResponse>();
        }
        protected static void Because_of()
        {
            entity = CurveData.CreateEntityWithTwoDetailsAndTwoMappings();

            client = new HttpClient(ServiceUrl["Curve"] +
                                    "crossmap?source-system=trayport&destination-system=endur&mapping-string=" + entity.Mappings[0].MappingValue
                                    + "&as-of=" + entity.Mappings[0].Validity.Start.ToString(DateFormatString));

            response        = client.Get();
            mappingResponse = response.Content.ReadAsDataContract <Contracts.MappingResponse>();
        }
        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());
        }
        protected static void Establish_context()
        {
            entity1 = CurveData.CreateBasicEntity();
            entity2 = CurveData.CreateBasicEntity();

            client = new HttpClient();

            var search = new Search();
            CurveData.CreateSearch(search, entity1, entity2);

            content = HttpContentExtensions.CreateDataContract(search);
        }
        protected static void Establish_context()
        {
            entity1 = CurveData.CreateBasicEntity();
            entity2 = CurveData.CreateBasicEntity();

            client = new HttpClient();

            var search = new Search().IsMutliPage().MaxPageSize(1);

            CurveData.CreateSearch(search, entity1, entity2);

            content = HttpContentExtensions.CreateDataContract(search);
        }
        protected static void Establish_context()
        {
            entity1 = CurveData.CreateBasicEntityWithOneMapping();

            client = new HttpClient();

            Search search = SearchBuilder.CreateSearch(IsMappingSearch: true);

            search.AddSearchCriteria(SearchCombinator.And).AddCriteria(
                "MappingValue", SearchCondition.Equals, entity1.Mappings[0].MappingValue).AddCriteria(
                "System.Name", SearchCondition.Equals, "Endur");

            content = HttpContentExtensions.CreateDataContract(search);
        }
        protected static void Establish_context()
        {
            entity = CurveData.CreateBasicEntity();
            mapping = new Mapping {
                    SystemName = "Endur",
                    Identifier = Guid.NewGuid().ToString(),
                    SourceSystemOriginated = false,
                    DefaultReverseInd = false,
                    StartDate = Script.baseDate,
                    EndDate = Script.baseDate.AddDays(2)
                };

            content = HttpContentExtensions.CreateDataContract(mapping);
            client = new HttpClient();
        }
Exemple #15
0
        protected static void Establish_context()
        {
            entity  = CurveData.CreateBasicEntity();
            mapping = new Mapping {
                SystemName             = "Endur",
                Identifier             = Guid.NewGuid().ToString(),
                SourceSystemOriginated = false,
                DefaultReverseInd      = false,
                StartDate = Script.baseDate,
                EndDate   = Script.baseDate.AddDays(2)
            };

            content = HttpContentExtensions.CreateDataContract(mapping);
            client  = new HttpClient();
        }
Exemple #16
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();
        }
        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();
        }
        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());
        }
        public void Map()
        {
            // Arrange
            var source = new MDM.Curve()
            {
                Name      = "curve name",
                Type      = "Forward",
                Currency  = "GBP",
                Commodity = new Commodity()
                {
                    Id = 1
                },
                CommodityUnit = "ton",
                Location      = new Location()
                {
                    Id = 1
                },
                DefaultSpread = .005m
            };

            var mapper = new MDM.Mappers.CurveDetailsMapper();

            // Act
            var result = mapper.Map(source);

            // Assert
            // TODO_UnitTestGeneration_Curve
            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(source.Name, result.Name);
            Assert.AreEqual(source.Type, result.CurveType);
            Assert.AreEqual(source.Currency, result.Currency);
            Assert.AreEqual(source.Commodity.Id.ToString(), result.Commodity.Identifier.Identifier);
            Assert.AreEqual(source.CommodityUnit, result.CommodityUnit);
            Assert.AreEqual(source.Location.Id.ToString(), result.Location.Identifier.Identifier);
            Assert.AreEqual(source.DefaultSpread, result.DefaultSpread);
        }
 public static void CompareContractWithEntityDetails(Contracts.Curve contract, MDM.Curve entity)
 {
     CurveComparer.Compare(contract, entity);
 }
Exemple #21
0
 protected static void Establish_context()
 {
     curve = CurveData.CreateEntityWithTwoDetailsAndTwoMappings();
 }
        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());
        }
 protected static void Establish_context()
 {
     curve = CurveData.CreateEntityWithTwoDetailsAndTwoMappings();
 }
        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");
        }
 protected static void Because_of()
 {
     entity = CurveData.CreateBasicEntity();
     client.DefaultHeaders.Add("If-Match", entity.Version.ToString());
     response = client.Post(ServiceUrl["Curve"] + entity.Id, content);
 }
        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");
        }
        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());
        }
 protected static void Establish_context()
 {
     curve = CurveData.CreateBasicEntity();
 }
 protected static void Establish_context()
 {
     curve = CurveData.CreateBasicEntity();
 }
Exemple #30
0
 protected static void Because_of()
 {
     entity = CurveData.CreateBasicEntity();
     client.DefaultHeaders.Add("If-Match", entity.Version.ToString());
     response = client.Post(ServiceUrl["Curve"] + entity.Id, content);
 }