Skip to content
This repository has been archived by the owner on Aug 7, 2022. It is now read-only.

Commit

Permalink
Created EndToEnd test
Browse files Browse the repository at this point in the history
  • Loading branch information
erri120 committed Nov 28, 2019
1 parent 21aee4a commit afa5711
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 0 deletions.
144 changes: 144 additions & 0 deletions OMODFramework.Test/EndToEndTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Directory = Alphaleonis.Win32.Filesystem.Directory;
using File = Alphaleonis.Win32.Filesystem.File;
using Path = Alphaleonis.Win32.Filesystem.Path;

namespace OMODFramework.Test
{
[TestClass]
public class EndToEndTest
{
public string OMODFile;
public List<string> ModFiles;
public List<string> FolderStructure;
public string Readme;
public string Script;

[TestInitialize]
public void Setup()
{
Framework.TempDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestTempDir");

if (!Directory.Exists(Framework.TempDir))
Directory.CreateDirectory(Framework.TempDir);
else
Framework.CleanTempDir();

OMODFile = Path.Combine(Framework.TempDir, "ILoveTesting.omod");
ModFiles = new List<string>();
FolderStructure = new List<string>();

if (File.Exists("readme.txt"))
Readme = File.ReadAllText("readme.txt");

if (File.Exists("script.txt"))
Script = File.ReadAllText("script.txt");

Directory.GetFiles("files", "*", SearchOption.AllDirectories).Do(f =>
{
ModFiles.Add(f);
FolderStructure.Add(f.Substring("files\\".Length));
});
}

[TestMethod]
public void EndToEnd()
{
// Creation

var ops = new OMODCreationOptions
{
Name = "I love, love... moist towelettes",
Author = "erri120",
Email = "[email protected]",
Website = "https://github.com/erri120",
Description = "The best OMOD you can find on the internet!",
Image = "",
MajorVersion = 6,
MinorVersion = 6,
BuildVersion = 6,
CompressionType = CompressionType.SevenZip,
DataFileCompressionLevel = CompressionLevel.High,
OMODCompressionLevel = CompressionLevel.Medium,
ESPs = new List<string>(0),
ESPPaths = new List<string>(0),
DataFiles = ModFiles,
DataFilePaths = FolderStructure,
Readme = Readme,
Script = Script
};

OMOD.CreateOMOD(ops, OMODFile);

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

// Test parsing

var omod = new OMOD(OMODFile);

Assert.IsNotNull(omod);
Assert.IsTrue(CompareCreationToFile(ref ops, ref omod));

// Test extraction

var data = omod.GetDataFiles();

var fList1 = new List<FileInfo>();
var fList2 = new List<FileInfo>();

Directory.GetFiles("files", "*", SearchOption.AllDirectories).Do(f =>
{
fList1.Add(new FileInfo(f));
});

Directory.GetFiles(data, "*", SearchOption.AllDirectories).Do(f =>
{
fList2.Add(new FileInfo(f));
});

Assert.IsTrue(fList1.Count == fList2.Count);

for (var i = 0; i < fList1.Count; i++)
{
var f1 = fList1[i];
var f2 = fList2[i];

Assert.IsTrue(Equals(f1, f2, Path.GetFullPath("files"), data));
}

// Test scripting

var scriptFunctions = new ScriptFunctions();

var srd = omod.RunScript(scriptFunctions);

Assert.IsNotNull(srd);
Assert.IsTrue(!srd.CancelInstall);
Assert.IsTrue(srd.CopyDataFiles.Count == 1 && srd.CopyDataFiles.TryGetValue(new ScriptCopyDataFile("A\\A.txt", "meshes\\a.txt"), out _));
Assert.IsTrue(srd.InstallData.Contains("something.txt"));
}

private static bool CompareCreationToFile(ref OMODCreationOptions ops, ref OMOD omod)
{
if (ops.Name != omod.ModName) return false;
if (ops.Author != omod.Author) return false;
if (ops.Email != omod.Email) return false;
if (ops.Website != omod.Website) return false;
if (ops.Description != omod.Description) return false;
if (ops.MajorVersion != omod.MajorVersion) return false;
if (ops.MinorVersion != omod.MinorVersion) return false;
if (ops.BuildVersion != omod.BuildVersion) return false;
if (ops.CompressionType != omod.Compression) return false;
return true;
}

private static bool Equals(FileInfo f1, FileInfo f2, string path1, string path2)
{
return f1.Name == f2.Name && f1.Length == f2.Length &&
f1.DirectoryName?.Replace(path1, path2) == f2.DirectoryName?.Replace(path1, path2);
}
}
}
1 change: 1 addition & 0 deletions OMODFramework.Test/omod_files/files/A/A.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
1 change: 1 addition & 0 deletions OMODFramework.Test/omod_files/files/B/B.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
B
1 change: 1 addition & 0 deletions OMODFramework.Test/omod_files/files/something.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root
15 changes: 15 additions & 0 deletions OMODFramework.Test/omod_files/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam egestas, purus ut viverra lobortis, lectus dolor euismod turpis, non hendrerit sem nulla eu ex. Vivamus accumsan tellus sed venenatis venenatis. Etiam dui lacus, malesuada sed metus ut, mattis cursus tellus. Nulla at nulla vel nulla malesuada accumsan eleifend in nisl. Morbi sodales ultrices lectus vel rhoncus. Duis quis sapien euismod, mollis ligula bibendum, fringilla urna. Curabitur eu vehicula eros. Maecenas pellentesque tristique tortor, a posuere mi lacinia sed. Donec quis lacus suscipit, sollicitudin urna in, scelerisque ligula. In in posuere purus, vel blandit velit. Integer faucibus maximus maximus. Morbi pulvinar commodo tellus, ac elementum ex porta vitae. Praesent sit amet rhoncus nisl.

Fusce sed eleifend ex. Phasellus luctus vel augue et vehicula. Proin gravida risus odio, et semper augue vulputate at. Duis feugiat pellentesque mi, nec ornare est suscipit in. Maecenas nec interdum nisi. Vestibulum sed tempus augue, eu fermentum tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer in nisi sit amet lectus congue consectetur. Aenean at lorem molestie, pharetra urna vel, ultrices sem. Suspendisse ultrices facilisis nisi, sit amet mattis odio rhoncus nec. Sed sagittis leo id interdum placerat. Nunc ut erat rhoncus, tincidunt justo id, sodales ex. Praesent cursus massa non elementum posuere. Donec nec placerat metus, sed eleifend urna. Vivamus in nisi et risus rhoncus elementum.

Sed ipsum nunc, volutpat nec est sit amet, euismod accumsan purus. Sed rutrum fringilla pretium. In a tincidunt purus, tincidunt ullamcorper metus. Donec placerat felis ac justo dictum tincidunt. Etiam at dignissim nisl, non ultricies diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse nec augue tellus. Vestibulum ac convallis nibh, sit amet condimentum massa. Etiam finibus, mauris non consequat tincidunt, tellus leo convallis nisl, sit amet dignissim diam ligula quis justo. Sed in sem quis tellus blandit venenatis. Duis nec sodales augue, in porta magna. Fusce consequat lacinia libero, rhoncus convallis velit ornare et. Suspendisse potenti. Phasellus mollis eros id rutrum malesuada. Phasellus auctor sodales vehicula. Sed convallis id magna sit amet interdum.

Sed quis metus in est suscipit eleifend id ac elit. Cras et maximus ex. Fusce et lacinia urna. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Duis hendrerit, justo vitae euismod egestas, enim lacus blandit augue, sed pretium nibh risus quis neque. Mauris congue lectus dui, id fermentum justo aliquam a. Suspendisse sit amet efficitur tortor, vel ullamcorper tellus.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum orci nulla, facilisis eget convallis accumsan, venenatis eu tortor. Donec maximus egestas felis, at tempor lectus varius id. Praesent varius ultricies quam, a lacinia magna pellentesque vitae. Mauris malesuada massa id tincidunt finibus. Sed vulputate elementum porttitor. Nullam blandit lectus at dui feugiat facilisis. Sed pulvinar rhoncus lorem id mattis. Aliquam sollicitudin ligula eros, at euismod sem efficitur sed. Nam ultricies, mi id placerat semper, quam magna viverra sapien, eget scelerisque orci enim id diam. Nulla facilisi.

Suspendisse maximus consectetur neque, eget sodales tellus volutpat sed. Nulla sollicitudin lectus ut vehicula porttitor. Vestibulum ornare velit libero, auctor efficitur est efficitur sit amet. Praesent eget odio quis nisl suscipit porta. Vestibulum aliquam tempus eros, nec volutpat dolor porttitor vitae. Aenean bibendum vulputate dui, sit amet mattis mauris vestibulum sit amet. Sed ornare, sapien vitae suscipit pretium, odio velit lobortis nisi, feugiat efficitur tortor quam vitae dolor.

Nam pulvinar quam sit amet justo vulputate ultricies. Praesent ac dolor ut leo malesuada porta. In ornare ac eros ut varius. Phasellus non pulvinar tellus. Nam eu nisi diam. Praesent porttitor arcu vel risus hendrerit, vitae varius ante faucibus. In a ex risus. Proin egestas, nibh sed tempor sollicitudin, sapien justo tincidunt leo, ut imperdiet enim lectus in eros. Nam lacinia ante id arcu scelerisque, vel euismod est porttitor. Nulla faucibus tempus nisi et vulputate. Proin placerat sem vitae luctus facilisis. Nam blandit accumsan leo, ac blandit libero congue a. Ut ornare purus non suscipit aliquam. Sed viverra lacus quis ex ullamcorper, vel porttitor lorem porta. Mauris vel justo euismod, congue neque id, viverra nunc. Curabitur eget erat et metus molestie luctus.

Proin eget euismod velit, sit amet rhoncus lectus. Praesent malesuada malesuada cursus. Quisque elementum nulla augue, ultricies facilisis orci pretium eu. Donec tempus et magna ac imperdiet. Morbi efficitur turpis nec dolor fermentum, nec lobortis mi interdum. Nulla eu tellus quis ligula cursus imperdiet in a sapien. Vivamus ac diam feugiat, venenatis arcu at, commodo nisi. Aenean non amet.
17 changes: 17 additions & 0 deletions OMODFramework.Test/omod_files/script.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
If VersionLessThan 0.9.3
Message "This mod must be installed by OBMM version 0.9.3 or later to prevent script errors."
FatalError
EndIf

DontInstallAnyDataFiles

InstallDataFile "something.txt"

Select "A or B?" "A" "B"
Case A
CopyDataFolder "A" "Meshes" True
Break
Case B
CopyDataFolder "B" "Meshes" True
Break
EndSelect

0 comments on commit afa5711

Please sign in to comment.