Ejemplo n.º 1
0
        public async Task Kvit_Push_ShouldCreate_Keys_and_Folders_on_Consul(bool runWithBaseDir)
        {
            // Arrange
            await ConsulTestHelper.DeleteAllKeys();

            var baseDir = ProcessTestHelper.CreateRandomBaseDir();

            FileTestHelper.WriteAllText(Path.Combine(baseDir, "file0"), "555");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "folder1", "file1"), "true");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "folder1", "file2"), @"{""myNameIsFile2"": ""yes""}");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "folder1", "folder1.1", "file3"), @"{""iaminasubfolder"": ""absolutely""}");

            // Act
            var(stdout, stderr, exitCode) = ProcessTestHelper.RunKvit(runWithBaseDir, baseDir, "push");

            // Assert
            stdout.ShouldContain("key(s) pushed");
            stderr.ShouldBeEmpty();
            exitCode.ShouldBe(0);

            // Assert keys
            var file0Content = await ConsulTestHelper.GetValueFromConsulAsync("file0");

            var file1Content = await ConsulTestHelper.GetValueFromConsulAsync("folder1/file1");

            var file2Content = await ConsulTestHelper.GetValueFromConsulAsync("folder1/file2");

            var file3Content = await ConsulTestHelper.GetValueFromConsulAsync("folder1/folder1.1/file3");

            file0Content.ShouldBe("555");
            file1Content.ShouldBe("true");
            file2Content.ShouldBe(@"{""myNameIsFile2"": ""yes""}");
            file3Content.ShouldBe(@"{""iaminasubfolder"": ""absolutely""}");
        }
Ejemplo n.º 2
0
        public void SaveAllTest()
        {
            FileTestHelper.CreateDummyFile(centreFileBase.ResourceType, "test2.txt");
            centreFileBase.LoadAll();
            var results = centreFileBase.GetAll();

            if (results.Count == 0)
            {
                throw new Exception("Assert Fails");
            }

            var    bytes = new byte[] { 1, 3, 2, 2, 3, 2 };
            string key   = results.Keys.FirstOrDefault();

            results[key].LoadBytes(bytes);

            centreFileBase.SaveAll();
            centreFileBase.LoadAll();

            var results2 = centreFileBase.GetAll();

            if (results2.Count == 0)
            {
                throw new Exception("Assert Fails");
            }

            var bytes2 = results2[key].GetBytes();

            Assert.Equal(bytes2, bytes);
        }
Ejemplo n.º 3
0
        public void SaveTest()
        {
            FileTestHelper.CreateDummyFile(centreFileBase.ResourceType, "test3.txt");
            StaticHub.ResourceManager.LoadAllResources();
            centreFileBase.LoadAll();
            var results = centreFileBase.GetAll();

            if (results.Count == 0)
            {
                throw new Exception("Assert Fails");
            }

            var    bytes = new byte[] { 1, 3, 2, 2, 3, 2 };
            string key   = "test3.txt";

            //results[key].LoadBytes(bytes);

            centreFileBase.Save(key, bytes);
            centreFileBase.LoadAll();

            var results2 = centreFileBase.GetAll();

            if (results2.Count == 0)
            {
                throw new Exception("Assert Fails");
            }

            var bytes2 = results2[key].GetBytes();

            Assert.Equal(bytes2, bytes);
        }
Ejemplo n.º 4
0
        public void LoadAllTest()
        {
            FileTestHelper.CreateDummyFile(centreFileBase.ResourceType, "test1.txt");
            centreFileBase.LoadAll();
            var results = centreFileBase.GetAll();

            if (results.Count == 0)
            {
                throw new Exception("Assert Fails");
            }
        }
Ejemplo n.º 5
0
        public async Task Kvit_Compare_ShouldShow_File_Contents_are_Equal_between_FileSystem_and_Consul(bool runWithBaseDir)
        {
            // Arrange
            await ConsulTestHelper.DeleteAllKeys();

            var baseDir = ProcessTestHelper.CreateRandomBaseDir();

            var testObj = new
            {
                key1 = "value1",
                key2 = new
                {
                    key3 = "value3",
                    key4 = new
                    {
                        key5 = "value5"
                    }
                }
            };

            // ReSharper disable once MethodHasAsyncOverload
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "file1"), JsonConvert.SerializeObject(testObj, Formatting.Indented));

            await ConsulTestHelper.AddDataToConsulAsync("file1", testObj);

            // Act
            var(stdout, stderr, exitCode) = ProcessTestHelper.RunKvit(runWithBaseDir, baseDir, "compare file1");

            // Assert
            var stdoutLines = stdout
                              .Split(Environment.NewLine)
                              .Select(ProcessTestHelper.StripAnsiEscapeCodes)
                              .ToArray();

            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[2].ShouldContain("Consul"),
                () => stdoutLines[2].ShouldContain("Local")
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[5].ShouldContain(@"""key1"": ""value1"""),
                () => stdoutLines[5].ShouldContain(@"""key1"": ""value1""")
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[7].ShouldContain(@"""key3"": ""value3"""),
                () => stdoutLines[7].ShouldContain(@"""key3"": ""value3""")
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[9].ShouldContain(@"""key5"": ""value5"""),
                () => stdoutLines[9].ShouldContain(@"""key5"": ""value5""")
                );

            exitCode.ShouldBe(0);
            stderr.ShouldBeEmpty();
        }
Ejemplo n.º 6
0
        public void GetFilesFromFolderTest()
        {
            FileTestHelper.CreateDummyFile("Shapes", "whatever");

            var files = fileAssistant.GetFilesFromFolder(@"Data\Resources\Shapes");

            if (files == null || files.Count == 0)
            {
                throw new Exception("Assert Fails");
            }
        }
Ejemplo n.º 7
0
        public void GetResourceTest(string type, string name)
        {
            FileTestHelper.CreateDummyFile(type, name);
            manager.LoadAllResources();

            byte[] bytes = manager.GetResource(type, name);
            if (bytes == null || bytes.Length == 0)
            {
                throw new Exception("Assert Fails");
            }
        }
Ejemplo n.º 8
0
        public void GetAllResourcesTest()
        {
            FileTestHelper.CreateDummyFile("Test\\Test232", "Test.txt");
            manager.LoadAllResources();
            var results = manager.GetAllResources("Test\\Test232");

            if (results.Count != 1)
            {
                throw new Exception("Assert Fails");
            }
        }
Ejemplo n.º 9
0
        public void GetTest()
        {
            FileTestHelper.CreateDummyFile(centreFileBase.ResourceType, "test3.txt");
            centreFileBase.LoadAll();
            var results = centreFileBase.Get("test3.txt");//TO NIE ZADZIALA (samo: test3)

            if (results == null)
            {
                throw new Exception("Assert Fails");
            }
        }
        public void GetTest()
        {
            FileTestHelper.CreateDummyFile(centreSerializationBase.ResourceType, "test1.json", "{\"Shape\":{\"TypeName\":\"IdkYet32\",\"Placement\":null,\"GraphicName\":null},\"Route\":null,\"InitPlacement\":null,\"Prediction\":false,\"ElementName\":null}");
            StaticHub.ResourceManager.LoadAllResources();
            centreSerializationBase.LoadAll();
            var results = centreSerializationBase.Get("test1.json");

            if (results == null)
            {
                throw new Exception("Assert Fails");
            }
        }
Ejemplo n.º 11
0
 public void SetUp()
 {
     fileTestHelper = new FileTestHelper();
     codeInfoUtils  = new CodeInfoUtils();
     task           = new NuspecGenerator
     {
         PackageDir    = string.Empty,
         ProjectDir    = ProjectDir,
         OutputPath    = Path.GetFullPath(Assembly),
         Language      = codeInfoUtils.GetCodeLanguage(CodeLanguage.CSharp),
         Configuration = Configuration
     };
 }
Ejemplo n.º 12
0
        public void SaveAllTest(string type, string name)
        {
            FileTestHelper.CreateDummyFile(type, name);
            manager.LoadAllResources();
            var resource = manager.GetAllResources(type).FirstOrDefault();

            byte[] bytes = new byte[] { 1, 1, 1, 1, 1, 1 };

            //resource.Value = bytes;
            manager.AddOrUpdateResource(type, name, bytes);

            manager.SaveAll();
            manager.LoadAllResources();

            var resource2 = manager.GetResource(type, name);

            Assert.Equal(bytes, resource2);
        }
Ejemplo n.º 13
0
        public void ExportLocationCalculationsForTargetProbabilities_ValidData_ReturnsTrueAndWritesCorrectData(HydraulicBoundaryLocationCalculationsType calculationsType,
                                                                                                               string expectedExportFileName)
        {
            // Setup
            const double targetProbability = 0.05;

            string directoryPath = TestHelper.GetScratchPadPath(nameof(ExportLocationCalculationsForTargetProbabilities_ValidData_ReturnsTrueAndWritesCorrectData));

            Directory.CreateDirectory(directoryPath);

            string shapeFileName = GetExpectedShapeFileName(calculationsType, targetProbability);

            // Precondition
            FileTestHelper.AssertEssentialShapefilesExist(directoryPath, $"{shapeFileName}.shp", false);

            try
            {
                // Call
                bool isExported = HydraulicBoundaryLocationCalculationsExportHelper.ExportLocationCalculationsForTargetProbabilities(
                    new[]
                {
                    new Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double>(new[]
                    {
                        new HydraulicBoundaryLocationCalculation(new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2))
                    }, targetProbability)
                }, calculationsType, directoryPath);

                // Assert
                Assert.IsTrue(isExported);

                FileTestHelper.AssertEssentialShapefilesExist(directoryPath, shapeFileName, true);
                FileTestHelper.AssertEssentialShapefileMd5Hashes(
                    directoryPath, shapeFileName,
                    Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Riskeer.Integration.IO),
                                 nameof(HydraulicBoundaryLocationCalculationsExportHelper)),
                    expectedExportFileName, 28, 8, 628);
            }
            finally
            {
                DirectoryHelper.TryDelete(directoryPath);
            }
        }
        public void SaveTest()
        {
            FileTestHelper.CreateDummyFile(centreSerializationBase.ResourceType, "test3.json", "{\"Shape\":{\"TypeName\":\"IdkYet32\",\"Placement\":null,\"GraphicName\":null},\"Route\":null,\"InitPlacement\":null,\"Prediction\":false,\"ElementName\":null}");
            StaticHub.ResourceManager.LoadAllResources();
            centreSerializationBase.LoadAll();
            var element = centreSerializationBase.Get("test3.json");

            element.Prediction = true;
            element.Name       = "test3";
            centreSerializationBase.Save(element);

            StaticHub.ResourceManager.LoadAllResources();
            centreSerializationBase.LoadAll();
            var element2 = centreSerializationBase.Get("test3.json");

            if (!element2.Prediction)
            {
                throw new Exception("Assert Fails");
            }
        }
        public void Export_ValidData_ReturnsTrueAndWritesCorrectData(HydraulicBoundaryLocationCalculationsType calculationsType,
                                                                     string expectedExportFileName)
        {
            // Setup
            const string fileName = "test";

            string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_ValidData_ReturnsTrueAndWritesCorrectData));

            Directory.CreateDirectory(directoryPath);
            string filePath = Path.Combine(directoryPath, $"{fileName}.shp");

            var exporter = new HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter(new[]
            {
                new HydraulicBoundaryLocationCalculation(new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2))
            }, filePath, calculationsType);

            // Precondition
            FileTestHelper.AssertEssentialShapefilesExist(directoryPath, fileName, false);

            try
            {
                // Call
                bool isExported = exporter.Export();

                // Assert
                FileTestHelper.AssertEssentialShapefilesExist(directoryPath, fileName, true);
                FileTestHelper.AssertEssentialShapefileMd5Hashes(
                    directoryPath, fileName,
                    Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Riskeer.Integration.IO),
                                 nameof(HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter)),
                    expectedExportFileName, 28, 8, 628);
                Assert.IsTrue(isExported);
            }
            finally
            {
                DirectoryHelper.TryDelete(directoryPath);
            }
        }
Ejemplo n.º 16
0
        public async Task Kvit_Push_ShouldIgnore_OperatingSystemSpecific_Files(bool runWithBaseDir)
        {
            // Arrange
            await ConsulTestHelper.DeleteAllKeys();

            var baseDir = ProcessTestHelper.CreateRandomBaseDir();

            FileTestHelper.WriteAllText(Path.Combine(baseDir, "file0"), "555");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, ".DS_Store"), "bla bla for mac");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "desktop.ini"), "bla bla for windows");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "subfolder", ".DS_Store"), "bla bla for mac in sub folder");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "subfolder", "desktop.ini"), "bla bla for windows in sub folder");

            // Act
            var(stdout, stderr, exitCode) = ProcessTestHelper.RunKvit(runWithBaseDir, baseDir, "push");

            // Assert
            stdout.ShouldContain("key(s) pushed");
            stderr.ShouldBeEmpty();
            exitCode.ShouldBe(0);

            // Assert keys
            var file0Content = await ConsulTestHelper.GetValueFromConsulAsync("file0");

            var dsStoreContent = await ConsulTestHelper.GetValueFromConsulAsync(".DS_Store");

            var desktopIniContent = await ConsulTestHelper.GetValueFromConsulAsync("desktop.ini");

            var dsStoreInSubFolderContent = await ConsulTestHelper.GetValueFromConsulAsync("subfolder/.DS_Store");

            var desktopIniInSubFolderContent = await ConsulTestHelper.GetValueFromConsulAsync("subfolder/desktop.ini");

            file0Content.ShouldBe("555");
            dsStoreContent.ShouldBeNullOrEmpty();
            desktopIniContent.ShouldBeNullOrEmpty();
            dsStoreInSubFolderContent.ShouldBeNullOrEmpty();
            desktopIniInSubFolderContent.ShouldBeNullOrEmpty();
        }
Ejemplo n.º 17
0
        public void WriteReferenceLine_ValidData_WritesShapeFile()
        {
            // Setup
            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(new[]
            {
                new Point2D(1.1, 2.2),
                new Point2D(11.11, 22.22)
            });

            string directoryPath = TestHelper.GetScratchPadPath(nameof(WriteReferenceLine_ValidData_WritesShapeFile));

            using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(WriteReferenceLine_ValidData_WritesShapeFile)))
            {
                Directory.CreateDirectory(directoryPath);
                string       filePath = Path.Combine(directoryPath, "test.shp");
                const string baseName = "test";

                var writer = new ReferenceLineWriter();

                // Precondition
                FileTestHelper.AssertEssentialShapefilesExist(directoryPath, baseName, false);

                // Call
                writer.WriteReferenceLine(referenceLine, "anId", filePath);

                // Assert
                FileTestHelper.AssertEssentialShapefilesExist(directoryPath, baseName, true);
                FileTestHelper.AssertEssentialShapefileMd5Hashes(directoryPath,
                                                                 baseName,
                                                                 TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO),
                                                                 "LineShapefileMd5",
                                                                 88,
                                                                 8,
                                                                 289);
            }
        }
Ejemplo n.º 18
0
        public void ExportLocationCalculationsForTargetProbabilities_DuplicateTargetProbability_ReturnsTrueAndWritesExpectedFiles(HydraulicBoundaryLocationCalculationsType calculationsType)
        {
            // Setup
            const double targetProbability = 0.00005;

            string directoryPath = TestHelper.GetScratchPadPath(nameof(ExportLocationCalculationsForTargetProbabilities_DuplicateTargetProbability_ReturnsTrueAndWritesExpectedFiles));

            Directory.CreateDirectory(directoryPath);

            string shapeFileName = GetExpectedShapeFileName(calculationsType, targetProbability);

            // Precondition
            FileTestHelper.AssertEssentialShapefilesExist(directoryPath, $"{shapeFileName}.shp", false);

            try
            {
                // Call
                bool isExported = HydraulicBoundaryLocationCalculationsExportHelper.ExportLocationCalculationsForTargetProbabilities(
                    new[]
                {
                    new Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double>(
                        Enumerable.Empty <HydraulicBoundaryLocationCalculation>(), targetProbability),
                    new Tuple <IEnumerable <HydraulicBoundaryLocationCalculation>, double>(
                        Enumerable.Empty <HydraulicBoundaryLocationCalculation>(), targetProbability)
                }, calculationsType, directoryPath);

                // Assert
                Assert.IsTrue(isExported);

                FileTestHelper.AssertEssentialShapefilesExist(directoryPath, shapeFileName, true);
                FileTestHelper.AssertEssentialShapefilesExist(directoryPath, $"{shapeFileName} (1)", true);
            }
            finally
            {
                DirectoryHelper.TryDelete(directoryPath);
            }
        }
        public void WriteHydraulicBoundaryLocationCalculations_ValidData_WritesShapeFile(HydraulicBoundaryLocationCalculationsType calculationsType,
                                                                                         string expectedExportFileName)
        {
            // Setup
            const string fileName      = "test";
            string       directoryPath = TestHelper.GetScratchPadPath(nameof(WriteHydraulicBoundaryLocationCalculations_ValidData_WritesShapeFile));
            string       filePath      = Path.Combine(directoryPath, $"{fileName}.shp");

            // Precondition
            FileTestHelper.AssertEssentialShapefilesExist(directoryPath, fileName, false);

            var calculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation("location 1"))
            {
                Output = new TestHydraulicBoundaryLocationCalculationOutput(0.1)
            };

            try
            {
                // Call
                HydraulicBoundaryLocationCalculationsForTargetProbabilityWriter.WriteHydraulicBoundaryLocationCalculations(new[]
                {
                    calculation
                }, filePath, calculationsType);

                // Assert
                FileTestHelper.AssertEssentialShapefilesExist(directoryPath, fileName, true);
                FileTestHelper.AssertEssentialShapefileMd5Hashes(
                    directoryPath, fileName,
                    Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Riskeer.Integration.IO),
                                 nameof(HydraulicBoundaryLocationCalculationsForTargetProbabilityWriter)),
                    expectedExportFileName, 28, 8, 628);
            }
            finally
            {
                DirectoryHelper.TryDelete(directoryPath);
            }
        }
Ejemplo n.º 20
0
 public ResourceManagerTests()
 {
     FileTestHelper.Init();
     manager.LoadAllResources();
 }
Ejemplo n.º 21
0
        public async Task Kvit_Diff_ShouldShow_Missing_Files_between_FileSystem_and_Consul(bool runWithBaseDir)
        {
            // Arrange
            await ConsulTestHelper.DeleteAllKeys();

            var baseDir = ProcessTestHelper.CreateRandomBaseDir();

            // missingFilesOnConsul
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "file"), @"""text""");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "folder1", "file2"), @"{""myNameIsFile2"": ""yes""}");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "folder1", "folder1.1", "file3"), @"{""iaminasubfolder"": ""absolutely""}");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "file0"), @"""555""");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "key1"), @"""value""");
            FileTestHelper.WriteAllText(Path.Combine(baseDir, "folder1", "file1"), "true");

            // missingFilesOnFileSystem
            await ConsulTestHelper.AddDirectoryToConsulAsync("dir1");

            await ConsulTestHelper.AddDataToConsulAsync("file0", "555");

            await ConsulTestHelper.AddDataToConsulAsync("key1", "value1");

            await ConsulTestHelper.AddDataToConsulAsync("folder1/file1", "true");

            await ConsulTestHelper.AddDataToConsulAsync("key", "value");

            await ConsulTestHelper.AddDataToConsulAsync("dir1/key1_in_dir1", "value2");

            await ConsulTestHelper.AddDataToConsulAsync("dir2/dir3/dir4/key_in_subfolder", "value3");

            // Act
            var(stdout, stderr, exitCode) = ProcessTestHelper.RunKvit(runWithBaseDir, baseDir, "diff --all");

            // Assert
            var stdoutLines = stdout.Split(Environment.NewLine).ToArray();

            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[2].ShouldContain("Files"),
                () => stdoutLines[2].ShouldContain("Consul - Local")
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[4].ShouldContain("file0"),
                () => stdoutLines[4].ShouldContain(DiffCommand.FileContentsAreEqualSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[5].ShouldContain("folder1/file1"),
                () => stdoutLines[5].ShouldContain(DiffCommand.FileContentsAreDifferentSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[6].ShouldContain("key1"),
                () => stdoutLines[6].ShouldContain(DiffCommand.FileContentsAreDifferentSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[7].ShouldContain("file"),
                () => stdoutLines[7].ShouldContain(DiffCommand.OnlyInConsulSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[8].ShouldContain("folder1/file2"),
                () => stdoutLines[8].ShouldContain(DiffCommand.OnlyInConsulSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[9].ShouldContain("folder1/folder1.1/file3"),
                () => stdoutLines[9].ShouldContain(DiffCommand.OnlyInConsulSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[10].ShouldContain("dir1/key1_in_dir1"),
                () => stdoutLines[10].ShouldContain(DiffCommand.OnlyInFileSystemSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[11].ShouldContain("dir2/dir3/dir4/key_in_subfolder"),
                () => stdoutLines[11].ShouldContain(DiffCommand.OnlyInFileSystemSign)
                );
            stdoutLines.ShouldSatisfyAllConditions(
                () => stdoutLines[11].ShouldContain("key"),
                () => stdoutLines[11].ShouldContain(DiffCommand.OnlyInFileSystemSign)
                );

            exitCode.ShouldBe(2);
            stderr.ShouldBeEmpty();
        }
Ejemplo n.º 22
0
 public FileAssistantTests()
 {
     FileTestHelper.Init();
 }
Ejemplo n.º 23
0
 public CentreFileBaseTests()
 {
     //centreFileBase.ResourceType = "FileCentreTest";
     FileTestHelper.CreateFolder("Data\\Resources\\" + centreFileBase.ResourceType);
     StaticHub.ResourceManager.LoadAllResources();
 }