public void SaveLoad_Test()
        {
            var fromClassifiers = new ClassifierDictionary(String);
            var toClassifiers = new ClassifierDictionary();
            var fromDiagram = new Diagram(fromClassifiers);
            var toDiagram = new Diagram(toClassifiers);
           
            var serializer = new JsonSerializer();

            // store the classifiers as json
            var json = serializer.Save(fromDiagram);
            // read them from json to another dictionary
            serializer.Load(json, toDiagram);

            // Ensure that both have the same classifiers
            Assert.IsTrue(toClassifiers.Count(x => x.Name == String.Name) == 1);
        }
        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);
        }
        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]);
        }
        public void Save()
        {
            if (_fileName == null)
            {
                var saveFileDialog = new SaveFileDialog
                {
                    Filter = EditorStrings.UmlJsonFileFilter,
                    InitialDirectory = GetFolderPath(SpecialFolder.MyDocuments)
                };

                if (saveFileDialog.ShowDialog() == true)
                {
                    _fileName = new FileName(saveFileDialog.FileName);
                    StoreProjectFileName();
                }
            }

            // user has not choosen any file, so skip here
            if (_fileName == null)
                return;

            var jsonContent = new JsonSerializer().Save(_diagram);
            try
            {
                System.IO.File.WriteAllText(
                    _fileName.ToString(),
                    jsonContent.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    string.Format(EditorStrings.SaveFileError, ex.Message),
                    EditorStrings.Save,
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }
        }