public void Read_WithCollector_NewPointAndEntityRegistered() { // Setup const string name = "testName"; var points = new[] { new Point2D(0, 0) }; string pointXml = new Point2DCollectionXmlSerializer().ToXml(points); var entity = new FailureMechanismSectionEntity { Name = name, FailureMechanismSectionPointXml = pointXml }; var collector = new ReadConversionCollector(); // Call FailureMechanismSection section = entity.Read(collector); // Assert Assert.IsNotNull(section); Assert.AreEqual(name, section.Name); Assert.AreEqual(section, collector.Get(entity)); Assert.IsTrue(collector.Contains(entity)); }
private static void AddEntitiesForPipingScenarioConfigurationPerFailureMechanismSection( IEnumerable <PipingScenarioConfigurationPerFailureMechanismSection> scenarioConfigurations, PersistenceRegistry registry) { foreach (PipingScenarioConfigurationPerFailureMechanismSection configuration in scenarioConfigurations) { PipingScenarioConfigurationPerFailureMechanismSectionEntity configurationPerFailureMechanismSectionEntity = configuration.Create(); FailureMechanismSectionEntity section = registry.Get(configuration.Section); section.PipingScenarioConfigurationPerFailureMechanismSectionEntities.Add(configurationPerFailureMechanismSectionEntity); } }
private static void AddEntitiesForSectionResults( IEnumerable <AdoptableWithProfileProbabilityFailureMechanismSectionResult> sectionResults, PersistenceRegistry registry) { foreach (AdoptableWithProfileProbabilityFailureMechanismSectionResult pipingFailureMechanismSectionResult in sectionResults) { AdoptableWithProfileProbabilityFailureMechanismSectionResultEntity sectionResultEntity = pipingFailureMechanismSectionResult.Create(); FailureMechanismSectionEntity section = registry.Get(pipingFailureMechanismSectionResult.Section); section.AdoptableWithProfileProbabilityFailureMechanismSectionResultEntities.Add(sectionResultEntity); } }
private static void AddEntitiesForSectionResults( IEnumerable <NonAdoptableFailureMechanismSectionResult> sectionResults, PersistenceRegistry registry) { foreach (NonAdoptableFailureMechanismSectionResult failureMechanismSectionResult in sectionResults) { NonAdoptableFailureMechanismSectionResultEntity sectionResultEntity = failureMechanismSectionResult.Create(); FailureMechanismSectionEntity section = registry.Get(failureMechanismSectionResult.Section); section.NonAdoptableFailureMechanismSectionResultEntities.Add(sectionResultEntity); } }
/// <summary> /// Read the <see cref="FailureMechanismSectionEntity"/> and use the information to construct a <see cref="FailureMechanismSection"/>. /// </summary> /// <param name="entity">The <see cref="FailureMechanismSectionEntity"/> to create <see cref="FailureMechanismSection"/> for.</param> /// <param name="collector">The object keeping track of read operations.</param> /// <returns>A new <see cref="FailureMechanismSection"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="collector"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when <see cref="FailureMechanismSectionEntity.FailureMechanismSectionPointXml"/> /// of <paramref name="entity"/> is <c>null</c> or empty.</exception> internal static FailureMechanismSection Read(this FailureMechanismSectionEntity entity, ReadConversionCollector collector) { if (collector == null) { throw new ArgumentNullException(nameof(collector)); } Point2D[] points = new Point2DCollectionXmlSerializer().FromXml(entity.FailureMechanismSectionPointXml); var mechanismSection = new FailureMechanismSection(entity.Name, points); collector.Read(entity, mechanismSection); return(mechanismSection); }
private static FailureMechanismSectionEntity CreateSimpleFailureMechanismSectionEntity() { var dummyPoints = new[] { new Point2D(0, 0) }; string dummyPointXml = new Point2DCollectionXmlSerializer().ToXml(dummyPoints); var failureMechanismSectionEntity = new FailureMechanismSectionEntity { Name = "section", FailureMechanismSectionPointXml = dummyPointXml }; return(failureMechanismSectionEntity); }
public void Read_FailureMechanismSectionPointXmlNullOrEmpty_ThrowsArgumentException(string xml) { // Setup var entity = new FailureMechanismSectionEntity { FailureMechanismSectionPointXml = xml }; // Call TestDelegate test = () => entity.Read(new ReadConversionCollector()); // Assert string paramName = Assert.Throws <ArgumentException>(test).ParamName; Assert.AreEqual("xml", paramName); }
/// <summary> /// Creates a <see cref="FailureMechanismSectionEntity"/> based on the information of the <see cref="FailureMechanismSection"/>. /// </summary> /// <param name="section">The section to create a database entity for.</param> /// <param name="registry">The object keeping track of create operations.</param> /// <returns>A new <see cref="FailureMechanismSectionEntity"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="registry"/> is <c>null</c>.</exception> internal static FailureMechanismSectionEntity Create(this FailureMechanismSection section, PersistenceRegistry registry) { if (registry == null) { throw new ArgumentNullException(nameof(registry)); } var failureMechanismSectionEntity = new FailureMechanismSectionEntity { Name = section.Name.DeepClone(), FailureMechanismSectionPointXml = new Point2DCollectionXmlSerializer().ToXml(section.Points) }; registry.Register(failureMechanismSectionEntity, section); return(failureMechanismSectionEntity); }
public void Read_ValidEntityWithSections_ReturnSpecificFailureMechanism() { // Setup const string filePath = "sections/File/Path"; FailureMechanismSectionEntity failureMechanismSectionEntity = CreateSimpleFailureMechanismSectionEntity(); var sectionResultEntity = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResultEntity { FailureMechanismSectionEntity = failureMechanismSectionEntity }; SectionResultTestHelper.SetSectionResult(sectionResultEntity); failureMechanismSectionEntity.NonAdoptableWithProfileProbabilityFailureMechanismSectionResultEntities = new List <NonAdoptableWithProfileProbabilityFailureMechanismSectionResultEntity> { sectionResultEntity }; var entity = new SpecificFailureMechanismEntity { N = 1.1, FailureMechanismSectionEntities = new List <FailureMechanismSectionEntity> { failureMechanismSectionEntity }, FailureMechanismSectionCollectionSourcePath = filePath }; var collector = new ReadConversionCollector(); // Call SpecificFailureMechanism specificFailureMechanism = entity.Read(collector); // Assert Assert.AreEqual(filePath, specificFailureMechanism.FailureMechanismSectionSourcePath); Assert.AreEqual(entity.FailureMechanismSectionEntities.Count, specificFailureMechanism.Sections.Count()); SectionResultTestHelper.AssertSectionResult(entity.FailureMechanismSectionEntities .SelectMany(fms => fms.NonAdoptableWithProfileProbabilityFailureMechanismSectionResultEntities) .Single(), specificFailureMechanism.SectionResults.Single()); }
public void Create_StringPropertiesDoNotShareReference() { // Setup const string testName = "original name"; var geometryPoints = new[] { new Point2D(0, 0), new Point2D(0, 0) }; var failureMechanismSection = new FailureMechanismSection(testName, geometryPoints); var registry = new PersistenceRegistry(); // Call FailureMechanismSectionEntity entity = failureMechanismSection.Create(registry); // Assert Assert.AreNotSame(testName, entity.Name, "To create stable binary representations/fingerprints, it's really important that strings are not shared."); Assert.AreEqual(testName, entity.Name); }
public void Create_WithCollectorAndGeometry_ReturnsFailureMechanismSectionWithGeometryStringSet() { // Setup const string testName = "testName"; var geometryPoints = new[] { new Point2D(0, 0), new Point2D(0, 0) }; var failureMechanismSection = new FailureMechanismSection(testName, geometryPoints); var registry = new PersistenceRegistry(); // Call FailureMechanismSectionEntity entity = failureMechanismSection.Create(registry); // Assert Assert.IsNotNull(entity); Assert.AreEqual(testName, entity.Name); string expectedXml = new Point2DCollectionXmlSerializer().ToXml(geometryPoints); Assert.AreEqual(expectedXml, entity.FailureMechanismSectionPointXml); }
/// <summary> /// Registers a create operation for <paramref name="model"/> and the <paramref name="entity"/> /// that was constructed with the information. /// </summary> /// <param name="entity">The <see cref="FailureMechanismSectionEntity"/> to be registered.</param> /// <param name="model">The <see cref="FailureMechanismSection"/> to be registered.</param> /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception> internal void Register(FailureMechanismSectionEntity entity, FailureMechanismSection model) { Register(failureMechanismSections, entity, model); }