Esempio n. 1
0
        public void SaveData_inFile()
        {
            //arrange
            string pathfile = @"C:\Users\Artemman\documents\visual studio 2013\Projects\ToolBar\ToolBar.Tests\TestContent\DataXml.xml",
                   path = @"C:\Users\Artemman\Desktop\ЛР 2.rar", image = "ЛР 2.rar.ico", name = "ЛР 2", result1 = path + image + name;
            string epath, eimage, ename;

            //act
            model.SaveData(pathfile, path, image, name);
            XDocument doc = XDocument.Load(pathfile);

            if (File.Exists(pathfile))
            {
                epath  = doc.Root.Elements("Item").Select(x => x.Attribute("Path").Value).First();
                eimage = doc.Root.Elements("Item").Select(x => x.Attribute("Image").Value).First();
                ename  = doc.Root.Elements("Item").Select(x => x.Attribute("Name").Value).First();
                string result = epath + eimage + ename;
                TestContext.WriteLine(result);
                Assert.AreEqual(result, result1);
            }
            else
            {
                Assert.Fail();
            }
        }
Esempio n. 2
0
        private void Execute(object parametr)
        {
            IDataObject idata = parametr as IDataObject;

            if (idata != null)
            {
                string[] path = (string[])idata.GetData(DataFormats.FileDrop, true);
                if (path != null)
                {
                    string directoryfile = @".\Icons\";
                    if (File.Exists(path[0]))
                    {
                        string filename = Path.GetFileName(path[0]);

                        directoryfile += filename + ".ico";
                        _modelList.SaveIcon(path[0], directoryfile);
                        ItemsCollection.Add(new Item {
                            Path = path[0], Image = _modelList.GetBitmap(filename + ".ico"), Name = Path.GetFileNameWithoutExtension(path[0])
                        });
                        _xamlscriptgenerator.SaveData(datafile, path[0], filename + ".ico", Path.GetFileNameWithoutExtension(path[0]));
                    }
                    else if (Directory.Exists(path[0]))
                    {
                        string filename = new DirectoryInfo(path[0]).Name;
                        directoryfile += filename + ".ico";
                        _modelList.SaveIcon(directoryfile, Properties.Resources.folder);
                        ItemsCollection.Add(new Item {
                            Path = path[0], Image = _modelList.GetBitmap(filename + ".ico"), Name = filename
                        });
                        _xamlscriptgenerator.SaveData(datafile, path[0], filename + ".ico", filename);
                    }
                }
                else
                {
                    MessageBox.Show("Invalid operaiton. You can't add to the ToolBar: Desktop or Basket.", "Error!");
                }
            }
        }