public void EarlierVersionRaisesVersionConflict()
        {
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.Mdm.Contracts.SourceSystem>(), It.IsAny<IList<IRule>>())).Returns(true);

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

            var cd = new EnergyTrading.Mdm.Contracts.SourceSystemDetails();
            var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) };
            var contract = new EnergyTrading.Mdm.Contracts.SourceSystem { Details = cd, MdmSystemData = nexus };

            var details = ObjectMother.Create<SourceSystem>();
            details.Id = 1;
            var entity = ObjectMother.Create<SourceSystem>();
            entity.Id = 2;
            entity.AddDetails(details);

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

            // Act
            service.Update(1, 1, contract);
        }
 protected static void Establish_context()
 {
     entity = Script.SourceSystemData.CreateBasicEntity();
     var notAMapping = new EnergyTrading.Mdm.Contracts.SourceSystem();
     content = HttpContentExtensions.CreateDataContract(notAMapping);
     client = new HttpClient();
 }
        protected static void Establish_context()
        {
            sourcesystem = Script.SourceSystemData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(sourcesystem);
            client  = new HttpClient();
        }
        protected static void Establish_context()
        {
            client = new HttpClient();
            var sourcesystem = new EnergyTrading.Mdm.Contracts.SourceSystem();

            content = HttpContentExtensions.CreateDataContract(sourcesystem);
        }
        public void Map()
        {
            // Arrange
            var start = new DateTime(2010, 1, 1);
            var end = DateUtility.MaxDate;
            var range = new DateRange(start, end);

            var id = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "A" };
            var contractDetails = new EnergyTrading.Mdm.Contracts.SourceSystemDetails();
            var contract = new EnergyTrading.Mdm.Contracts.SourceSystem
            {
                Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { id },
                Details = contractDetails,
                MdmSystemData = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = start, EndDate = end }
            };

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

            var mapping = new SourceSystemMapping();

            var mappingEngine = new Mock<IMappingEngine>();
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, SourceSystemMapping>(id)).Returns(mapping);
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.SourceSystemDetails, SourceSystem>(contractDetails)).Returns(details);

            var mapper = new SourceSystemMapper(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");
        }
        public void EntityNotFound()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

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

            var cd    = new EnergyTrading.Mdm.Contracts.SourceSystemDetails();
            var nexus = new EnergyTrading.Mdm.Contracts.SystemData {
                StartDate = new DateTime(2012, 1, 1)
            };
            var contract = new EnergyTrading.Mdm.Contracts.SourceSystem {
                Details = cd, MdmSystemData = nexus
            };

            validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.Mdm.Contracts.SourceSystem>(), It.IsAny <IList <IRule> >())).Returns(true);

            // Act
            var response = service.Update(1, 1, contract);

            // Assert
            Assert.IsNotNull(response, "Response is null");
            Assert.IsFalse(response.IsValid, "Response is valid");
            Assert.AreEqual(ErrorType.NotFound, response.Error.Type, "ErrorType differs");
        }
Пример #7
0
        protected override void Because_of()
        {
            var bobSmith = new EnergyTrading.Mdm.Contracts.SourceSystem()
            {
                Details = new EnergyTrading.Mdm.Contracts.SourceSystemDetails()
                {
                    Name = "Bob"
                }
            };

            var fredJones = new EnergyTrading.Mdm.Contracts.SourceSystem()
            {
                Details = new EnergyTrading.Mdm.Contracts.SourceSystemDetails()
                {
                    Name = "Fred"
                }
            };

            var personList = new List <EnergyTrading.Mdm.Contracts.SourceSystem>()
            {
                bobSmith, fredJones
            };

            var cacheSearchResultPage = new CacheSearchResultPage(new List <int>()
            {
                1, 2
            }, DateTime.Now, null, this.currentSearch.ToString());
            var searchResultPage = new SearchResultPage <EnergyTrading.Mdm.Contracts.SourceSystem>(cacheSearchResultPage, personList);

            this.response = this.Sut.WithEntityName("SourceSystem").WithItems(searchResultPage.Contracts).Build();
        }
        public void EarlierVersionRaisesVersionConflict()
        {
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.Mdm.Contracts.SourceSystem>(), It.IsAny <IList <IRule> >())).Returns(true);

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

            var cd    = new EnergyTrading.Mdm.Contracts.SourceSystemDetails();
            var nexus = new EnergyTrading.Mdm.Contracts.SystemData {
                StartDate = new DateTime(2012, 1, 1)
            };
            var contract = new EnergyTrading.Mdm.Contracts.SourceSystem {
                Details = cd, MdmSystemData = nexus
            };

            var details = ObjectMother.Create <SourceSystem>();

            details.Id = 1;
            var entity = ObjectMother.Create <SourceSystem>();

            entity.Id = 2;
            entity.AddDetails(details);

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

            // Act
            service.Update(1, 1, contract);
        }
Пример #9
0
        public EnergyTrading.Mdm.Contracts.SourceSystem CreateContractForEntityCreation()
        {
            var contract = new EnergyTrading.Mdm.Contracts.SourceSystem();

            this.AddDetailsToContract(contract);
            return(contract);
        }
        protected static void Establish_context()
        {
            sourcesystem = Script.SourceSystemData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(sourcesystem);
            client = new HttpClient();
        }
        protected static void Establish_context()
        {
            entity = Script.SourceSystemData.CreateBasicEntity();
            var notAMapping = new EnergyTrading.Mdm.Contracts.SourceSystem();

            content = HttpContentExtensions.CreateDataContract(notAMapping);
            client  = new HttpClient();
        }
        protected static void Establish_context()
        {
            client = new HttpClient();
            entity = Script.SourceSystemData.CreateBasicEntity();
            var getResponse = client.Get(ServiceUrl["SourceSystem"] + entity.Id);

            updatedContract = getResponse.Content.ReadAsDataContract<EnergyTrading.Mdm.Contracts.SourceSystem>();
            content = HttpContentExtensions.CreateDataContract(Script.SourceSystemData.MakeChangeToContract(updatedContract));
        }
Пример #13
0
        protected static void Establish_context()
        {
            client = new HttpClient();
            entity = Script.SourceSystemData.CreateBasicEntity();
            var getResponse = client.Get(ServiceUrl["SourceSystem"] + entity.Id);

            updatedContract = getResponse.Content.ReadAsDataContract <EnergyTrading.Mdm.Contracts.SourceSystem>();
            content         = HttpContentExtensions.CreateDataContract(Script.SourceSystemData.MakeChangeToContract(updatedContract));
        }
Пример #14
0
 protected static void Because_of()
 {
     using (var client = new HttpClient(ServiceUrl["SourceSystem"] +
                                        sourcesystem.Id))
     {
         using (HttpResponseMessage response = client.Get())
         {
             returnedSourceSystem = response.Content.ReadAsDataContract <EnergyTrading.Mdm.Contracts.SourceSystem>();
         }
     }
 }
 protected static void Because_of()
 {
     using (var client = new HttpClient(ServiceUrl["SourceSystem"] +
         sourcesystem.Id))
     {
         using (HttpResponseMessage response = client.Get())
         {
             returnedSourceSystem = response.Content.ReadAsDataContract<EnergyTrading.Mdm.Contracts.SourceSystem>();
         }
     }
 }
Пример #16
0
        protected static void Because_of()
        {
            asof   = Script.baseDate.AddSeconds(1);
            client =
                new HttpClient(ServiceUrl["SourceSystem"] + string.Format("{0}?as-of={1}",
                                                                          sourcesystem.Id.ToString(), asof.ToString(DateFormatString)));

            HttpResponseMessage response = client.Get();

            returnedSourceSystem = response.Content.ReadAsDataContract <EnergyTrading.Mdm.Contracts.SourceSystem>();
        }
        public void InvalidContractNotSaved()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

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

            var contract = new EnergyTrading.Mdm.Contracts.SourceSystem();

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

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

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

            var contract = new EnergyTrading.Mdm.Contracts.SourceSystem();

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

            // Act
            service.Create(contract);
        }
        public void Map()
        {
            // Arrange
            var start = new DateTime(2010, 1, 1);
            var end   = DateUtility.MaxDate;
            var range = new DateRange(start, end);

            var id = new EnergyTrading.Mdm.Contracts.MdmId {
                SystemName = "Test", Identifier = "A"
            };
            var contractDetails = new EnergyTrading.Mdm.Contracts.SourceSystemDetails();
            var contract        = new EnergyTrading.Mdm.Contracts.SourceSystem
            {
                Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList {
                    id
                },
                Details       = contractDetails,
                MdmSystemData = new EnergyTrading.Mdm.Contracts.SystemData {
                    StartDate = start, EndDate = end
                }
            };

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

            var mapping = new SourceSystemMapping();

            var mappingEngine = new Mock <IMappingEngine>();

            mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, SourceSystemMapping>(id)).Returns(mapping);
            mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.SourceSystemDetails, SourceSystem>(contractDetails)).Returns(details);

            var mapper = new SourceSystemMapper(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");
        }
        public void ValidContractIsSaved()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

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

            var sourcesystem = new SourceSystem();
            var contract     = new EnergyTrading.Mdm.Contracts.SourceSystem();

            validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.Mdm.Contracts.SourceSystem>(), It.IsAny <IList <IRule> >())).Returns(true);
            mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.SourceSystem, SourceSystem>(contract)).Returns(sourcesystem);

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

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

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

            var sourcesystem = new SourceSystem();
            var contract = new EnergyTrading.Mdm.Contracts.SourceSystem();

            validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.Mdm.Contracts.SourceSystem>(), It.IsAny<IList<IRule>>())).Returns(true);
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.SourceSystem, SourceSystem>(contract)).Returns(sourcesystem);

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

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

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

            var cd = new EnergyTrading.Mdm.Contracts.SourceSystemDetails();
            var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) };
            var contract = new EnergyTrading.Mdm.Contracts.SourceSystem { Details = cd, MdmSystemData = nexus };

            validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.Mdm.Contracts.SourceSystem>(), It.IsAny<IList<IRule>>())).Returns(true);

            // Act
            var response = service.Update(1, 1, contract);

            // Assert
            Assert.IsNotNull(response, "Response is null");
            Assert.IsFalse(response.IsValid, "Response is valid");
            Assert.AreEqual(ErrorType.NotFound, response.Error.Type, "ErrorType differs");
        }
 partial void AddDetailsToContract(EnergyTrading.Mdm.Contracts.SourceSystem contract)
 {
     contract.Details.Name = Guid.NewGuid().ToString();
 }
 public EnergyTrading.Mdm.Contracts.SourceSystem CreateContractForEntityCreation()
 {
     var contract = new EnergyTrading.Mdm.Contracts.SourceSystem();
     this.AddDetailsToContract(contract);
     return contract;
 }
        public void ValidDetailsSaved()
        {
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            // Contract
            var cd    = new EnergyTrading.Mdm.Contracts.SourceSystemDetails();
            var nexus = new EnergyTrading.Mdm.Contracts.SystemData {
                StartDate = new DateTime(2012, 1, 1)
            };
            var identifier = new EnergyTrading.Mdm.Contracts.MdmId {
                SystemName = "Test", Identifier = "A"
            };
            var contract = new EnergyTrading.Mdm.Contracts.SourceSystem {
                Details = cd, MdmSystemData = nexus
            };

            contract.Identifiers.Add(identifier);

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

            d1.Id        = 1;
            d1.Timestamp = 74UL.GetVersionByteArray();
            var entity = ObjectMother.Create <SourceSystem>();

            entity.Timestamp = 74UL.GetVersionByteArray();
            entity.AddDetails(d1);

            var d2    = ObjectMother.Create <SourceSystem>();
            var range = new DateRange(new DateTime(2012, 1, 1), DateTime.MaxValue);

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

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

            mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.SourceSystemDetails, SourceSystem>(cd)).Returns(d2);
            mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.SystemData, DateRange>(nexus)).Returns(range);
            mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, SourceSystemMapping>(identifier)).Returns(mapping);

            var service = new SourceSystemService(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);
        }
 protected static void Establish_context()
 {
     client = new HttpClient();
     var sourcesystem = new EnergyTrading.Mdm.Contracts.SourceSystem();
     content = HttpContentExtensions.CreateDataContract(sourcesystem);
 }
Пример #27
0
 partial void AddDetailsToContract(EnergyTrading.Mdm.Contracts.SourceSystem contract);
Пример #28
0
 public EnergyTrading.Mdm.Contracts.SourceSystem MakeChangeToContract(EnergyTrading.Mdm.Contracts.SourceSystem currentContract)
 {
     this.AddDetailsToContract(currentContract);
     currentContract.MdmSystemData.StartDate = currentContract.MdmSystemData.StartDate.Value.AddDays(2);
     return(currentContract);
 }
        public void ValidDetailsSaved()
        {
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            // Contract
            var cd = new EnergyTrading.Mdm.Contracts.SourceSystemDetails();
            var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) };
            var identifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "A" };
            var contract = new EnergyTrading.Mdm.Contracts.SourceSystem { Details = cd, MdmSystemData = nexus };
            contract.Identifiers.Add(identifier);

            // Domain
            var system = new SourceSystem { Name = "Test" };
            var mapping = new SourceSystemMapping { System = system, MappingValue = "A" };
            var d1 = ObjectMother.Create<SourceSystem>();
            d1.Id = 1;
            d1.Timestamp = 74UL.GetVersionByteArray();
            var entity = ObjectMother.Create<SourceSystem>();
            entity.Timestamp = 74UL.GetVersionByteArray();
            entity.AddDetails(d1);

            var d2 = ObjectMother.Create<SourceSystem>();
            var range = new DateRange(new DateTime(2012, 1, 1), DateTime.MaxValue);

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

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

            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.SourceSystemDetails, SourceSystem>(cd)).Returns(d2);
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.SystemData, DateRange>(nexus)).Returns(range);
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, SourceSystemMapping>(identifier)).Returns(mapping);

            var service = new SourceSystemService(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);
        }
        protected static void Because_of()
        {
            asof = Script.baseDate.AddSeconds(1);
            client =
                new HttpClient(ServiceUrl["SourceSystem"] + string.Format("{0}?as-of={1}",
                    sourcesystem.Id.ToString(), asof.ToString(DateFormatString)));

            HttpResponseMessage response = client.Get();
            returnedSourceSystem = response.Content.ReadAsDataContract<EnergyTrading.Mdm.Contracts.SourceSystem>();
        }