public static void CreateSandbox(TestContext testContext) { var site = Node.Load<Site>("/Root/TestSiteForAppModelTest"); if (site == null) { site = new Site(Repository.Root); site.Name = "TestSiteForAppModelTest"; var urlList = new Dictionary<string, string>(); urlList.Add("testhost", "Windows"); site.UrlList = urlList; site.Save(); } var homePage = EnsureSiteStartPage(site); var webContent = Node.Load<GenericContent>("/Root/TestSiteForAppModelTest/Home/WebContent1"); if (webContent == null) { webContent = new GenericContent(homePage, "WebContent"); webContent.Name = "WebContent1"; webContent.Save(); } var file = Node.Load<File>("/Root/TestSiteForAppModelTest/Home/File1"); if (file == null) { file = new File(homePage); file.Name = "File1"; file.GetBinary("Binary").SetStream(Tools.GetStreamFromString("File1 content")); file.Save(); } //---- Appmodel var siteAppsFolder = Node.Load<SystemFolder>("/Root/TestSiteForAppModelTest/(apps)"); if (siteAppsFolder == null) { siteAppsFolder = new SystemFolder(site); siteAppsFolder.Name = "(apps)"; siteAppsFolder.Save(); } var siteAppsPageFolder = Node.Load<Folder>("/Root/TestSiteForAppModelTest/(apps)/Page"); if (siteAppsPageFolder == null) { siteAppsPageFolder = new SystemFolder(siteAppsFolder); siteAppsPageFolder.Name = "Page"; siteAppsPageFolder.Save(); } var siteAppsPageBrowsePage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/Page/Browse"); if (siteAppsPageBrowsePage == null) { siteAppsPageBrowsePage = new Page(siteAppsPageFolder); siteAppsPageBrowsePage.Name = "Browse"; siteAppsPageBrowsePage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>Page Browse App</h1></body></html>")); siteAppsPageBrowsePage.Save(); } var siteAppsPageEditPage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/Page/Edit"); if (siteAppsPageEditPage == null) { siteAppsPageEditPage = new Page(siteAppsPageFolder); siteAppsPageEditPage.Name = "Edit"; siteAppsPageEditPage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>Page EditPage</h1></body></html>")); siteAppsPageEditPage.Save(); } var siteAppsGenericContentFolder = Node.Load<Folder>("/Root/TestSiteForAppModelTest/(apps)/GenericContent"); if (siteAppsGenericContentFolder == null) { siteAppsGenericContentFolder = new SystemFolder(siteAppsFolder); siteAppsGenericContentFolder.Name = "GenericContent"; siteAppsGenericContentFolder.Save(); } var siteAppsGenericContentBrowsePage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/GenericContent/Browse"); if (siteAppsGenericContentBrowsePage == null) { siteAppsGenericContentBrowsePage = new Page(siteAppsGenericContentFolder); siteAppsGenericContentBrowsePage.Name = "Browse"; siteAppsGenericContentBrowsePage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>GenericContent Browse App</h1></body></html>")); siteAppsGenericContentBrowsePage.Save(); } var siteAppsGenericContentEditPage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/GenericContent/Edit"); if (siteAppsGenericContentEditPage == null) { siteAppsGenericContentEditPage = new Page(siteAppsGenericContentFolder); siteAppsGenericContentEditPage.Name = "Edit"; siteAppsGenericContentEditPage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>GenericContent EditPage</h1></body></html>")); siteAppsGenericContentEditPage.Save(); } //---- SelfDispatcher node var selfDispatcherContent = Node.Load<GenericContent>("/Root/TestSiteForAppModelTest/Home/SelfDispatcherContent1"); if (selfDispatcherContent == null) { selfDispatcherContent = new GenericContent(homePage, "WebContent"); selfDispatcherContent.Name = "SelfDispatcherContent1"; selfDispatcherContent.BrowseApplication = Node.LoadNode("/Root/TestSiteForAppModelTest/(apps)/GenericContent/Edit"); selfDispatcherContent.Save(); } }
public void BinaryData_RenameFileNode() { string rootName = "BinaryTestFolder"; string rootPath = RepositoryPath.Combine(this.TestRoot.Path, rootName); if (Node.Exists(rootPath)) Node.ForceDelete(rootPath); Folder folder = new Folder(this.TestRoot); folder.Name = rootName; folder.Save(); Stream stream; const int TESTBINARY_SIZE = 512 * 1024; // 512k byte[] testBinaryArray = new byte[TESTBINARY_SIZE]; int i; for (i=0; i < TESTBINARY_SIZE; i++) testBinaryArray[i] = Convert.ToByte(i % 256); BinaryData testBinary = new BinaryData(); testBinary.FileName = "test.txt"; testBinary.SetStream(new MemoryStream(testBinaryArray)); File file = new File(folder); file.Name = "OriginalName"; file.Binary = testBinary; file.Save(); stream = file.Binary.GetStream(); file = null; int readByte; i = 0; while ((readByte = stream.ReadByte()) != -1) { Assert.IsTrue(readByte == i % 256); i++; } Assert.IsTrue(i == TESTBINARY_SIZE); file = (File)File.LoadNode(RepositoryPath.Combine(rootPath, "OriginalName")); file.Name = "NewName"; file.Save(); file = (File)File.LoadNode(RepositoryPath.Combine(rootPath, "NewName")); stream = file.Binary.GetStream(); file = null; i = 0; while ((readByte = stream.ReadByte()) != -1) { Assert.IsTrue(readByte == i % 256); i++; } if (Node.Exists(rootPath)) Node.ForceDelete(rootPath); Assert.IsTrue(i == TESTBINARY_SIZE); }
public void BinaryData_FileStreamChanged() { var s0 = "qwer"; var s1 = "qwert"; var s2 = "Qwert"; var s3 = "QWERT"; var ch0 = BinaryData.CalculateChecksum(Tools.GetStreamFromString(s0)); var ch1 = BinaryData.CalculateChecksum(Tools.GetStreamFromString(s1)); var ch2 = BinaryData.CalculateChecksum(Tools.GetStreamFromString(s2)); var ch3 = BinaryData.CalculateChecksum(Tools.GetStreamFromString(s3)); var file = new File(TestRoot); file.Binary.SetStream(Tools.GetStreamFromString(s0)); file.Save(); var fileId = file.Id; var ch01 = file.Binary.Checksum; var ss01 = Tools.GetStreamString(file.Binary.GetStream()); file = Node.Load<File>(fileId); var ch10 = file.Binary.Checksum; var ss10 = Tools.GetStreamString(file.Binary.GetStream()); file.Binary.SetStream(Tools.GetStreamFromString(s1)); file.Save(); var ch11 = file.Binary.Checksum; var ss11 = Tools.GetStreamString(file.Binary.GetStream()); file = Node.Load<File>(fileId); var ch20 = file.Binary.Checksum; var ss20 = Tools.GetStreamString(file.Binary.GetStream()); file.Binary.SetStream(Tools.GetStreamFromString(s2)); file.Save(); var ch21 = file.Binary.Checksum; var ss21 = Tools.GetStreamString(file.Binary.GetStream()); file = Node.Load<File>(fileId); var ch30 = file.Binary.Checksum; var ss30 = Tools.GetStreamString(file.Binary.GetStream()); file.Binary.SetStream(Tools.GetStreamFromString(s3)); file.Save(); var ch31 = file.Binary.Checksum; var ss31 = Tools.GetStreamString(file.Binary.GetStream()); Assert.IsTrue(ss01 == s0, "#1"); Assert.IsTrue(ss10 == s0, "#2"); Assert.IsTrue(ss11 == s1, "#3"); Assert.IsTrue(ss20 == s1, "#4"); Assert.IsTrue(ss21 == s2, "#5"); Assert.IsTrue(ss30 == s2, "#6"); Assert.IsTrue(ss31 == s3, "#7"); Assert.IsTrue(ch01 == ch0, "#11"); Assert.IsTrue(ch10 == ch0, "#12"); Assert.IsTrue(ch11 == ch1, "#13"); Assert.IsTrue(ch20 == ch1, "#14"); Assert.IsTrue(ch21 == ch2, "#15"); Assert.IsTrue(ch30 == ch2, "#16"); Assert.IsTrue(ch31 == ch3, "#17"); }
public void BinaryData_InsertUpdateDelete() { File file = new File(this.TestRoot); file.Save(); file = Node.Load<File>(file.Id); var x = file.Binary.Id; // Insert file.Binary = new BinaryData(); file.Binary.SetStream(TestTools.GetTestStream()); file.Save(); int id = file.Id; int binaryId = file.Binary.Id; Assert.AreNotEqual(0, file.Binary.Id); // Load back file = (File)Node.LoadNode(id); Assert.AreEqual(binaryId, file.Binary.Id); Assert.AreEqual(TestTools.TestStreamLength, file.Binary.GetStream().Length); Assert.AreEqual(TestTools.TestStreamLength, file.Binary.Size); // Update file.Binary.SetStream (null); file.Save(); // Load back file = (File)Node.LoadNode(id); Assert.AreEqual(binaryId, file.Binary.Id); Assert.AreEqual((long)-1, file.Binary.Size); // Delete file.Binary = null; file.Save(); // Load back file = (File)Node.LoadNode(id); Assert.IsTrue(file.Binary.IsEmpty); }
public void BinaryData_Rollback() { string text = "Lorem ipsum..."; File file = new File(this.TestRoot); var bin = new BinaryData(); bin.FileName = "1.txt"; bin.SetStream(Tools.GetStreamFromString(text)); file.Binary = bin; file.Save(); int id = file.Id; file = Node.Load<File>(id); TransactionScope.Begin(); try { // Save binary file.Binary = null; file.Save(); } finally { // Rollback TransactionScope.Rollback(); } file = Node.Load<File>(id); Assert.IsNotNull(file.Binary, "#1"); Assert.IsTrue(file.Binary.Size > 0, "#2"); Assert.IsTrue(Tools.GetStreamString(file.Binary.GetStream()) == text, "#3"); }
public void BinaryData_SampleStream() { File file = new File(this.TestRoot); // Save binary BinaryData data = new BinaryData(); data.SetStream(TestTools.GetTestStream()); data.FileName = "....bin"; file.Binary = data; file.Save(); int id = file.Id; // Load binary back file = (File)Node.LoadNode(id); Assert.AreNotEqual(0, file.Binary.Id); Assert.AreEqual("application/octet-stream", file.Binary.ContentType); Assert.AreEqual("....bin", file.Binary.FileName.FullFileName); Assert.AreEqual(TestTools.TestStreamLength, file.Binary.Size); Assert.AreNotEqual(null, file.Binary.GetStream()); }
public void BinaryData_EmptyWrite() { // Save binary File file = new File(this.TestRoot); BinaryData target = new BinaryData(); file.Binary = target; file.Save(); int id = file.Id; // Load binary back file = (File)Node.LoadNode(id); Assert.IsTrue(file.GetBinary("Binary").IsEmpty); //Assert.AreNotEqual(0, file.Binary.Id); //Assert.AreEqual(string.Empty, file.Binary.ContentType); //Assert.AreEqual(string.Empty, file.Binary.FileName.FullFileName); //Assert.AreEqual((long)-1, file.Binary.Size); //Assert.AreEqual(null, file.Binary.GetStream()); }
public void CrossDomain_RenameSubtree() { DistributedApplication.ClusterChannel.Purge(); var fileContent = "File text"; var folder = new Folder(TestRoot); folder.Save(); var folderId = folder.Id; var folderPath = folder.Path; var folderName = folder.Name; var file = new File(folder); file.Binary.SetStream(Tools.GetStreamFromString(fileContent)); file.Save(); var fileId = file.Id; var filePath = file.Path; var fileName = file.Name; var foldersAfterCreate = AllEngine_LoadNode(folderPath); var filesAfterCreate = AllEngine_LoadNode(filePath); var cacheKeysAfterCreate = AllEngine_GetCacheKeys(); folder = Node.Load<Folder>(folderId); folder.Name = "Renamed"; folder.Save(); var newFolderPath = RepositoryPath.Combine(TestRoot.Path, folder.Name); var newFilePath = RepositoryPath.Combine(newFolderPath, file.Name); var foldersAfterRenameOld = AllEngine_LoadNode(folderPath); var filesAfterRenameOld = AllEngine_LoadNode(filePath); var foldersAfterRenameNew = AllEngine_LoadNode(newFolderPath); var filesAfterRenameNew = AllEngine_LoadNode(newFilePath); var cacheKeysAfterRename = AllEngine_GetCacheKeys(); var filecontents = AllEngine_GetFileContents(newFilePath); Node.ForceDelete(folderId); var foldersAfterDeleteOld = AllEngine_LoadNode(folderPath); var filesAfterDeleteOld = AllEngine_LoadNode(filePath); var foldersAfterDeleteNew = AllEngine_LoadNode(folderPath); var filesAfterDeleteNew = AllEngine_LoadNode(filePath); var cacheKeysAfterDelete = AllEngine_GetCacheKeys(); DistributedApplication.ClusterChannel.Purge(); Assert.IsTrue(foldersAfterCreate.Distinct().Count() == 1, "#equality1 foldersAfterCreate"); Assert.IsTrue(foldersAfterCreate.Distinct().First() == folderId, "#value1 foldersAfterCreate"); Assert.IsTrue(filesAfterCreate.Distinct().Count() == 1, "#equality2 filesAfterCreate"); Assert.IsTrue(filesAfterCreate.Distinct().First() == fileId, "#value2 filesAfterCreate"); Assert.IsTrue(foldersAfterRenameOld.Distinct().Count() == 1, "#equality3 foldersAfterRenameOld"); Assert.IsTrue(foldersAfterRenameOld.Distinct().First() == 0, "#value3 foldersAfterRenameOld"); Assert.IsTrue(filesAfterRenameOld.Distinct().Count() == 1, "#equality4 filesAfterRenameOld"); Assert.IsTrue(filesAfterRenameOld.Distinct().First() == 0, "#value4 filesAfterRenameOld"); Assert.IsTrue(foldersAfterRenameNew.Distinct().Count() == 1, "#equality5 foldersAfterRenameNew"); Assert.IsTrue(foldersAfterRenameNew.Distinct().First() == folderId, "#value5 foldersAfterRenameNew"); Assert.IsTrue(filesAfterRenameNew.Distinct().Count() == 1, "#equality6 filesAfterRenameNew"); Assert.IsTrue(filesAfterRenameNew.Distinct().First() == fileId, "#value6 filesAfterRenameNew"); Assert.IsTrue(filecontents.Distinct().Count() == 1, "#equality7 filecontents"); Assert.IsTrue(filecontents.Distinct().First() == fileContent, "#value7 filecontents"); Assert.IsTrue(foldersAfterDeleteOld.Distinct().Count() == 1, "#equality8 foldersAfterDeleteOld"); Assert.IsTrue(foldersAfterDeleteOld.Distinct().First() == 0, "#value8 foldersAfterDeleteOld"); Assert.IsTrue(filesAfterDeleteOld.Distinct().Count() == 1, "#equality9 filesAfterDeleteOld"); Assert.IsTrue(filesAfterDeleteOld.Distinct().First() == 0, "#value9 filesAfterDeleteOld"); Assert.IsTrue(foldersAfterDeleteNew.Distinct().Count() == 1, "#equality10 foldersAfterDeleteNew"); Assert.IsTrue(foldersAfterDeleteNew.Distinct().First() == 0, "#value10 foldersAfterDeleteNew"); Assert.IsTrue(filesAfterDeleteNew.Distinct().Count() == 1, "#equality11 filesAfterDeleteNew"); Assert.IsTrue(filesAfterDeleteNew.Distinct().First() == 0, "#value11 filesAfterDeleteNew"); }