protected static void Establish_context() { entity = Script.LocationData.CreateBasicEntity(); var notAMapping = new EnergyTrading.MDM.Contracts.Sample.Location(); content = HttpContentExtensions.CreateDataContract(notAMapping); client = new HttpClient(); }
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.Sample.LocationDetails(); var contract = new EnergyTrading.MDM.Contracts.Sample.Location { 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 Location(); var mapping = new LocationMapping(); var mappingEngine = new Mock<IMappingEngine>(); mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, LocationMapping>(id)).Returns(mapping); mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.LocationDetails, Location>(contractDetails)).Returns(details); var mapper = new LocationMapper(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 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.Sample.Location>(), It.IsAny <IList <IRule> >())).Returns(true); var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.MDM.Contracts.Sample.LocationDetails(); var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.MDM.Contracts.Sample.Location { Details = cd, MdmSystemData = nexus }; var details = ObjectMother.Create <Location>(); details.Id = 1; var entity = ObjectMother.Create <Location>(); entity.Id = 2; entity.AddDetails(details); repository.Setup(x => x.FindOne <Location>(1)).Returns(entity); // Act service.Update(1, 1, contract); }
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 LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.MDM.Contracts.Sample.LocationDetails(); var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.MDM.Contracts.Sample.Location { Details = cd, MdmSystemData = nexus }; validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.MDM.Contracts.Sample.Location>(), 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"); }
public EnergyTrading.MDM.Contracts.Sample.Location CreateContractForEntityCreation() { var contract = new EnergyTrading.MDM.Contracts.Sample.Location(); this.AddDetailsToContract(contract); return(contract); }
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.Sample.Location>(), It.IsAny<IList<IRule>>())).Returns(true); var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.MDM.Contracts.Sample.LocationDetails(); var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.MDM.Contracts.Sample.Location { Details = cd, MdmSystemData = nexus }; var details = ObjectMother.Create<Location>(); details.Id = 1; var entity = ObjectMother.Create<Location>(); entity.Id = 2; entity.AddDetails(details); repository.Setup(x => x.FindOne<Location>(1)).Returns(entity); // Act service.Update(1, 1, contract); }
protected static void Establish_context() { client = new HttpClient(); var location = new EnergyTrading.MDM.Contracts.Sample.Location(); content = HttpContentExtensions.CreateDataContract(location); }
protected static void Establish_context() { location = Script.LocationData.CreateContractForEntityCreation(); content = HttpContentExtensions.CreateDataContract(location); client = new HttpClient(); }
protected static void Establish_context() { client = new HttpClient(); entity = Script.LocationData.CreateBasicEntity(); var getResponse = client.Get(ServiceUrl["Location"] + entity.Id); updatedContract = getResponse.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Location>(); content = HttpContentExtensions.CreateDataContract(Script.LocationData.MakeChangeToContract(updatedContract)); }
protected static void Establish_context() { client = new HttpClient(); entity = Script.LocationData.CreateBasicEntity(); var getResponse = client.Get(ServiceUrl["Location"] + entity.Id); updatedContract = getResponse.Content.ReadAsDataContract <EnergyTrading.MDM.Contracts.Sample.Location>(); content = HttpContentExtensions.CreateDataContract(Script.LocationData.MakeChangeToContract(updatedContract)); }
protected static void Because_of() { using (var client = new HttpClient(ServiceUrl["Location"] + location.Id)) { using (HttpResponseMessage response = client.Get()) { returnedLocation = response.Content.ReadAsDataContract <EnergyTrading.MDM.Contracts.Sample.Location>(); } } }
protected static void Because_of() { asof = Script.baseDate.AddSeconds(1); client = new HttpClient(ServiceUrl["Location"] + string.Format("{0}?as-of={1}", location.Id.ToString(), asof.ToString(DateFormatString))); HttpResponseMessage response = client.Get(); returnedLocation = response.Content.ReadAsDataContract <EnergyTrading.MDM.Contracts.Sample.Location>(); }
protected static void Because_of() { using (var client = new HttpClient(ServiceUrl["Location"] + location.Id)) { using (HttpResponseMessage response = client.Get()) { returnedLocation = response.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Location>(); } } }
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 LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var contract = new EnergyTrading.MDM.Contracts.Sample.Location(); 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 LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var contract = new EnergyTrading.MDM.Contracts.Sample.Location(); validatorFactory.Setup(x => x.IsValid(It.IsAny<object>(), It.IsAny<IList<IRule>>())).Returns(false); // Act service.Create(contract); }
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 LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var location = new Location(); var contract = new EnergyTrading.MDM.Contracts.Sample.Location(); validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Location>(), It.IsAny<IList<IRule>>())).Returns(true); mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.Location, Location>(contract)).Returns(location); // Act var expected = service.Create(contract); // Assert Assert.AreSame(expected, location, "Location differs"); repository.Verify(x => x.Add(location)); 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 LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var location = new Location(); var contract = new EnergyTrading.MDM.Contracts.Sample.Location(); validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.MDM.Contracts.Sample.Location>(), It.IsAny <IList <IRule> >())).Returns(true); mappingEngine.Setup(x => x.Map <EnergyTrading.MDM.Contracts.Sample.Location, Location>(contract)).Returns(location); // Act var expected = service.Create(contract); // Assert Assert.AreSame(expected, location, "Location differs"); repository.Verify(x => x.Add(location)); 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 LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.MDM.Contracts.Sample.LocationDetails(); var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.MDM.Contracts.Sample.Location { Details = cd, MdmSystemData = nexus }; validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Location>(), 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"); }
protected static void Because_of() { asof = Script.baseDate.AddSeconds(1); client = new HttpClient(ServiceUrl["Location"] + string.Format("{0}?as-of={1}", location.Id.ToString(), asof.ToString(DateFormatString))); HttpResponseMessage response = client.Get(); returnedLocation = response.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Location>(); }
public static void Compare(EnergyTrading.MDM.Contracts.Sample.Location contract, Location entity) { Assert.AreEqual(contract.Details.Name, entity.Name); Assert.AreEqual(contract.Details.Type, entity.Type); }
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.Sample.LocationDetails(); 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.Sample.Location { Details = cd, MdmSystemData = nexus }; contract.Identifiers.Add(identifier); // Domain var system = new SourceSystem { Name = "Test" }; var mapping = new LocationMapping { System = system, MappingValue = "A" }; var d1 = ObjectMother.Create<Location>(); d1.Id = 1; d1.Timestamp = 74UL.GetVersionByteArray(); var entity = ObjectMother.Create<Location>(); entity.Timestamp = 74UL.GetVersionByteArray(); entity.AddDetails(d1); var d2 = ObjectMother.Create<Location>(); 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.Sample.Location>(), It.IsAny<IList<IRule>>())).Returns(true); repository.Setup(x => x.FindOne<Location>(1)).Returns(entity); mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.LocationDetails, Location>(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, LocationMapping>(identifier)).Returns(mapping); var service = new LocationService(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); }
public EnergyTrading.MDM.Contracts.Sample.Location CreateContractForEntityCreation() { var contract = new EnergyTrading.MDM.Contracts.Sample.Location(); this.AddDetailsToContract(contract); return contract; }
public EnergyTrading.MDM.Contracts.Sample.Location MakeChangeToContract(EnergyTrading.MDM.Contracts.Sample.Location currentContract) { this.AddDetailsToContract(currentContract); currentContract.MdmSystemData.StartDate = currentContract.MdmSystemData.StartDate.Value.AddDays(2); return(currentContract); }
partial void AddDetailsToContract(EnergyTrading.MDM.Contracts.Sample.Location 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.Sample.LocationDetails(); 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.Sample.Location { Details = cd, MdmSystemData = nexus }; contract.Identifiers.Add(identifier); // Domain var system = new SourceSystem { Name = "Test" }; var mapping = new LocationMapping { System = system, MappingValue = "A" }; var d1 = ObjectMother.Create <Location>(); d1.Id = 1; d1.Timestamp = 74UL.GetVersionByteArray(); var entity = ObjectMother.Create <Location>(); entity.Timestamp = 74UL.GetVersionByteArray(); entity.AddDetails(d1); var d2 = ObjectMother.Create <Location>(); 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.Sample.Location>(), It.IsAny <IList <IRule> >())).Returns(true); repository.Setup(x => x.FindOne <Location>(1)).Returns(entity); mappingEngine.Setup(x => x.Map <EnergyTrading.MDM.Contracts.Sample.LocationDetails, Location>(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, LocationMapping>(identifier)).Returns(mapping); var service = new LocationService(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); }