Exemple #1
0
        public void TestPackWhenEditorStateIsDeleted(string appName)
        {
            var root = Path.Combine(Environment.CurrentDirectory, "Apps", appName);

            Assert.IsTrue(File.Exists(root));

            (var msapp, var errors) = CanvasDocument.LoadFromMsapp(root);
            errors.ThrowOnErrors();

            using (var tempDir = new TempDir())
            {
                string outSrcDir = tempDir.Dir;

                // Save to sources
                msapp.SaveToSources(outSrcDir);

                // Delete Entropy directory
                var editorStatePath = Path.Combine(outSrcDir, "Src", "EditorState");
                if (Directory.Exists(editorStatePath))
                {
                    Directory.Delete(editorStatePath, true);
                }

                // Load app from the sources after deleting the entropy
                var app = SourceSerializer.LoadFromSource(outSrcDir, new ErrorContainer());

                using (var tempFile = new TempFile())
                {
                    // Repack the app
                    MsAppSerializer.SaveAsMsApp(app, tempFile.FullPath, new ErrorContainer());
                }
            }
        }
        public void TestTableDefinitionsAreLastEntriesWhenEntropyDeleted(string appName)
        {
            var root = Path.Combine(Environment.CurrentDirectory, "Apps", appName);

            Assert.IsTrue(File.Exists(root));

            (var msapp, var errors) = CanvasDocument.LoadFromMsapp(root);
            errors.ThrowOnErrors();

            using (var tempDir = new TempDir())
            {
                string outSrcDir = tempDir.Dir;

                // Save to sources
                msapp.SaveToSources(outSrcDir);

                // Delete Entropy directory
                var entropyPath = Path.Combine(outSrcDir, "Entropy");
                if (Directory.Exists(entropyPath))
                {
                    Directory.Delete(entropyPath, true);
                }

                // Load app from the sources after deleting the entropy
                var app = SourceSerializer.LoadFromSource(outSrcDir, new ErrorContainer());

                using (var tempFile = new TempFile())
                {
                    // Repack the app
                    MsAppSerializer.SaveAsMsApp(app, tempFile.FullPath, new ErrorContainer());

                    using (var stream = new FileStream(tempFile.FullPath, FileMode.Open))
                    {
                        // Read the msapp file
                        ZipArchive zipOpen = new ZipArchive(stream, ZipArchiveMode.Read);

                        foreach (var entry in zipOpen.Entries)
                        {
                            var kind = FileEntry.TriageKind(FilePath.FromMsAppPath(entry.FullName));

                            switch (kind)
                            {
                            // Validate that the last entry in the DataSources.json is TableDefinition entry.
                            case FileKind.DataSources:
                            {
                                var dataSourcesFromMsapp = ToObject <DataSourcesJson>(entry);
                                var last = dataSourcesFromMsapp.DataSources.LastOrDefault();
                                Assert.AreEqual(last.TableDefinition != null, true);
                                return;
                            }

                            default:
                                break;
                            }
                        }
                    }
                }
            }
        }