예제 #1
0
 internal JsonContent SaveDto(DiagramDataDto completeDiagramData)
 {
     var jsonString = JsonConvert.SerializeObject(
         completeDiagramData,
         Formatting.Indented,
         new JsonSerializerSettings
         {
             PreserveReferencesHandling = PreserveReferencesHandling.Objects,
             DefaultValueHandling = DefaultValueHandling.Ignore
         });
     return new JsonContent(jsonString);
 }
예제 #2
0
        public void SaveLoad_ReleationsDto()
        {
            var diagramDto = new DiagramDataDto
            {
                Classifiers = new List<ClassifierDto> { CarDto, TireDto },
            };

            var serializer = new JsonSerializer();
            var json = serializer.SaveDto(diagramDto);

            var newDiagramDto = serializer.LoadDto(json);
            var loadedCar = newDiagramDto.Classifiers[0];
            var loadedTire = newDiagramDto.Classifiers[1];
            var relation = loadedCar.Associations.Single();

            Assert.AreSame(loadedCar, relation.Start);
            Assert.AreSame(loadedTire, relation.End);
            Assert.AreEqual("has", relation.Name);
            Assert.AreEqual(RelationType.Aggregation, relation.RelationType);
            Assert.AreEqual(Multiplicity.ZeroToMany, relation.EndMultiplicity);
        }
예제 #3
0
        public void SaveLoad_MethodDtos()
        {
            var diagramDto = new DiagramDataDto
            {
                Classifiers = new List<ClassifierDto>
                {
                    StringDto,IntegerDto,ServiceDto
                }
            };

            var serializer = new JsonSerializer();
            var content = serializer.SaveDto(diagramDto);
            var restoredDtos = serializer
                .LoadDto(content)
                .Classifiers
                .ToList();

            var service = restoredDtos.Single(x => x.Name == "Service");
            // ensure that classifiers references are reused
            Assert.AreSame(restoredDtos[0], service.Methods[0].Parameters[0].Type);
            // ensure that all method data was read correctly
            Assert.AreEqual(service.Methods[0],ServiceDto.Methods[0]);
        }
예제 #4
0
 /// <summary>
 /// converts the list of classifier DTOs back to a classifier dictionary
 /// </summary>
 public void ToDomain(Diagram diagram, DiagramDataDto diagramDto)
 {
     // remove all existing classifiers before adding new ones
     diagram.Classifiers.Clear();
     _mapper.Map(diagramDto,diagram);
 }