public void PBToDTOSemanticVersion() { SemanticVersionDTO dtoStart = Misc.CreateSemanticVersionDTO; PBSemanticVersion pb = dtoStart.ToPBSemanticVersion(); SemanticVersionDTO dtoEnd = pb.ToSemanticVersion(); Assert.True(dtoStart.CompareTo(dtoEnd) == 0); }
public void SemanticVersionDTOFieldsTest() { SemanticVersionDTO dtoStart = Misc.CreateSemanticVersionDTO; Misc.Compare(dtoStart.PublicId, Misc.g1, Misc.g2, Misc.g3, Misc.g4); Assert.True(dtoStart.StampDTO.CompareTo(Misc.CreateStampDTO) == 0); FieldCompare.Same(dtoStart.Fields, new Object[] { 1, "abcdef", 0.3F }); }
public static PBSemanticVersion ToPBSemanticVersion(this SemanticVersionDTO c) { //# Tested PBSemanticVersion retVal = new PBSemanticVersion { PublicId = c.PublicId.ToPBPublicId(), Stamp = c.Stamp.ToPBStamp(), }; retVal.FieldValues.AddRange(c.Fields.ToPBFields()); return(retVal); }
/// <summary> /// Read an array or SemanticVersionDTO items. /// </summary> /// <param name="publicId">Public id (component ids).</param> /// <returns>SemanticVersionDTO[].</returns> public SemanticVersionDTO[] ReadSemanticVersionList( IPublicId publicId) { Int32 length = this.GetInt32(); SemanticVersionDTO[] retVal = new SemanticVersionDTO[length]; for (Int32 i = 0; i < length; i++) { retVal[i] = SemanticVersionDTO.Make( this, publicId); } return(retVal); }
public void SemanticChronologyDTOCompareToTest() { { SemanticChronologyDTO a = Misc.CreateSemanticChronologyDTO; SemanticChronologyDTO b = Misc.CreateSemanticChronologyDTO; Assert.True(a.CompareTo(b) == 0); } { SemanticChronologyDTO a = Misc.CreateSemanticChronologyDTO; SemanticChronologyDTO b = Misc.CreateSemanticChronologyDTO with { PublicId = new PublicId(Misc.g2, Misc.g2, Misc.g3, Misc.g4) }; Assert.False(a.CompareTo(b) == 0); } { SemanticChronologyDTO a = Misc.CreateSemanticChronologyDTO; SemanticChronologyDTO b = Misc.CreateSemanticChronologyDTO with { PatternForSemantic = new PublicId(Misc.g2, Misc.g2, Misc.g3, Misc.g4) }; Assert.False(a.CompareTo(b) == 0); } { SemanticChronologyDTO a = Misc.CreateSemanticChronologyDTO; SemanticChronologyDTO b = Misc.CreateSemanticChronologyDTO with { ReferencedComponentPublicId = new PublicId(Misc.g2, Misc.g2, Misc.g3, Misc.g4) }; Assert.False(a.CompareTo(b) == 0); } { SemanticChronologyDTO a = Misc.CreateSemanticChronologyDTO; SemanticChronologyDTO b = Misc.CreateSemanticChronologyDTO with { SemanticVersions = new SemanticVersionDTO[] { Misc.CreateSemanticVersionDTO, Misc.CreateSemanticVersionDTO }.ToImmutableArray() }; Assert.False(a.CompareTo(b) == 0); } }
public static SemanticChronologyDTO ToSemanticChronology(this PBSemanticChronology c) { //# Tested SemanticVersionDTO[] versions = new SemanticVersionDTO[c.Versions.Count]; for (Int32 i = 0; i < c.Versions.Count; i++) { versions[i] = c.Versions[i].ToSemanticVersion(); } SemanticChronologyDTO retVal = new SemanticChronologyDTO( c.PublicId.ToPublicId(), c.PatternForSemantic.ToPublicId(), c.ReferencedComponent.ToPublicId(), versions.ToImmutableArray()); return(retVal); }
/// <summary> /// Read SemanticVersionDTO values from the named child property. /// </summary> /// <param name="jObj">JSON parent container.</param> /// <param name = "publicId" > Public id(component ids).</param> /// <param name = "fieldName" > Json child field name.</param> /// <param name="definitionForSemanticPublicId">Externally defined definition for semantic uuids.</param> /// <param name="referencedComponentPublicId">Externally defined referenced component uuids.</param> /// <returns>Semantic version values.</returns> public static IEnumerable <SemanticVersionDTO> ReadSemanticVersionList( this JObject jObj, String fieldName, IPublicId publicId, IPublicId definitionForSemanticPublicId, IPublicId referencedComponentPublicId) { List <SemanticVersionDTO> retVal = new List <SemanticVersionDTO>(); JArray items = jObj.ReadToken <JArray>(fieldName); foreach (JObject item in items.Values <JObject>()) { retVal.Add(SemanticVersionDTO.Make(item, publicId)); } return(retVal); }
public void SemanticVersionDTOMarshalTest() { SemanticVersionDTO dtoStart = Misc.CreateSemanticVersionDTO; MemoryStream ms = new MemoryStream(); using (TinkarOutput output = new TinkarOutput(ms)) { dtoStart.Marshal(output); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { SemanticVersionDTO dtoRead = SemanticVersionDTO.Make(input, dtoStart.PublicId); Assert.True(dtoStart.CompareTo(dtoRead) == 0); } }
public void SemanticVersionDTOJsonMarshal() { SemanticVersionDTO dtoStart = Misc.CreateSemanticVersionDTO; MemoryStream ms = new MemoryStream(); using (TinkarJsonOutput output = new TinkarJsonOutput(ms, true)) { dtoStart.Marshal(output); } ms.Dump(); ms.Position = 0; using (TinkarJsonInput input = new TinkarJsonInput(ms)) { SemanticVersionDTO dtoEnd = SemanticVersionDTO.Make( input.ReadJsonObject(), dtoStart.PublicId ); Assert.True(dtoStart.CompareTo(dtoEnd) == 0); } }
public void SemanticVersionDTOCompareToTest() { { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO; Assert.True(a.CompareTo(b) == 0); } { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO with { PublicId = new PublicId(Misc.g2, Misc.g2, Misc.g3, Misc.g4) }; Assert.False(a.CompareTo(b) == 0); } { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO with { StampDTO = Misc.CreateStampDTO with { StatusPublicId = new PublicId(Misc.g2) } }; Assert.False(a.CompareTo(b) == 0); } { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO with { Fields = new Object[] { 1, "abcdef" }.ToImmutableArray() }; Assert.False(a.CompareTo(b) == 0); } }
public void SemanticVersionDTOIsEquivalentTest() { { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO; Assert.True(a.IsEquivalent(b)); } { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO with { PublicId = new PublicId(Misc.other) }; Assert.False(a.IsEquivalent(b)); } { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO with { StampDTO = Misc.CreateStampDTO with { StatusPublicId = new PublicId(Misc.g2) } }; Assert.False(a.IsEquivalent(b)); } { SemanticVersionDTO a = Misc.CreateSemanticVersionDTO; SemanticVersionDTO b = Misc.CreateSemanticVersionDTO with { Fields = new Object[] { 1, "abcdef" }.ToImmutableArray() }; Assert.False(a.IsEquivalent(b)); } }
/// <summary> /// Create serialized output test cases. /// These can be read into java side to compare java and c# implementations. /// </summary> public List <ComponentDTO> CreateComponents() { List <ComponentDTO> retVal = new List <ComponentDTO>(); { IPublicId pid = NextPublicId(1); // Write ConceptChronologyDTO. ConceptChronologyDTO dto = new ConceptChronologyDTO( pid, new ConceptVersionDTO[] { new ConceptVersionDTO(pid, NextStamp()), new ConceptVersionDTO(pid, NextStamp()) }.ToImmutableArray() ); retVal.Add(dto); } { ConceptDTO dto = new ConceptDTO(NextPublicId(4)); retVal.Add(dto); } { IPublicId pid = NextPublicId(1); PatternChronologyDTO dto = new PatternChronologyDTO( pid, new PatternVersionDTO[] { new PatternVersionDTO( pid, NextStamp(), NextPublicId(4), NextPublicId(5), new FieldDefinitionDTO[] { new FieldDefinitionDTO( NextPublicId(4), NextPublicId(3), NextPublicId(2) ), new FieldDefinitionDTO( NextPublicId(1), NextPublicId(2), NextPublicId(3) ) }.ToImmutableArray() ) }.ToImmutableArray() ); retVal.Add(dto); } { PatternDTO dto = new PatternDTO(NextPublicId(2)); retVal.Add(dto); } { IPublicId componentPublicId = NextPublicId(4); IPublicId patternForSemanticPublicId = NextPublicId(3); IPublicId referencedComponentPublicId = NextPublicId(2); SemanticChronologyDTO dto = new SemanticChronologyDTO( componentPublicId, patternForSemanticPublicId, referencedComponentPublicId, new SemanticVersionDTO[] { new SemanticVersionDTO( componentPublicId, NextStamp(), new Object[] { true, false, new byte[] { }, new byte[] { 1, 2, 3 }, 0.3F, -1, 0, 1, "abcdef", new DateTime(2020, 1, 2), new SpatialPointDTO(1, 2, 3), new PlanarPointDTO(-1, -2) }.ToImmutableArray() ) }.ToImmutableArray() ); retVal.Add(dto); } { SemanticDTO dto = new SemanticDTO(NextPublicId(4)); retVal.Add(dto); } { SemanticVersionDTO dto = new SemanticVersionDTO( NextPublicId(3), NextStamp(), new Object[] { true, false, new byte[] { }, new byte[] { 1, 2, 3 }, 0.3F, -1, 0, 1, "abcdef", new DateTime(2020, 1, 2), new SpatialPointDTO(1, 2, 3), new PlanarPointDTO(-1, -2) }.ToImmutableArray() ); } return(retVal); }