Example #1
0
        public async Task SaveRestoreState_OneTorrentFile_NoContainingDirectory()
        {
            var pieceLength = Constants.BlockSize * 4;

            using var tmpDir = TempDir.Create();

            TestRig.CreateMultiFileTorrent(TorrentFile.Create(pieceLength, Constants.BlockSize, Constants.BlockSize * 2, Constants.BlockSize * 3), pieceLength, out BEncoding.BEncodedDictionary metadata);
            var metadataFile = Path.Combine(tmpDir.Path, "test.torrent");

            File.WriteAllBytes(metadataFile, metadata.Encode());

            var engine = new ClientEngine(EngineSettingsBuilder.CreateForTests(cacheDirectory: tmpDir.Path));
            await engine.AddStreamingAsync(metadataFile, "mySaveDirectory", new TorrentSettingsBuilder { CreateContainingDirectory = false }.ToSettings());

            var restoredEngine = await ClientEngine.RestoreStateAsync(await engine.SaveStateAsync());

            Assert.AreEqual(engine.Settings, restoredEngine.Settings);
            Assert.AreEqual(engine.Torrents[0].Torrent.Name, restoredEngine.Torrents[0].Torrent.Name);
            Assert.AreEqual(engine.Torrents[0].SavePath, restoredEngine.Torrents[0].SavePath);
            Assert.AreEqual(engine.Torrents[0].Settings, restoredEngine.Torrents[0].Settings);
            Assert.AreEqual(engine.Torrents[0].InfoHash, restoredEngine.Torrents[0].InfoHash);
            Assert.AreEqual(engine.Torrents[0].MagnetLink.ToV1String(), restoredEngine.Torrents[0].MagnetLink.ToV1String());

            Assert.AreEqual(engine.Torrents[0].Files.Count, restoredEngine.Torrents[0].Files.Count);
            for (int i = 0; i < engine.Torrents.Count; i++)
            {
                Assert.AreEqual(engine.Torrents[0].Files[i].FullPath, restoredEngine.Torrents[0].Files[i].FullPath);
                Assert.AreEqual(engine.Torrents[0].Files[i].Priority, restoredEngine.Torrents[0].Files[i].Priority);
            }
        }
Example #2
0
        public void Equals()
        {
            using var tempDir = TempDir.Create();
            var dataProvider = new DataProvider();

            var dataSource1 = new DataSource(dataProvider, tempDir, Model.DataSourceType.Custom);
            var dataSource2 = new DataSource(dataProvider, tempDir, Model.DataSourceType.Custom);
            var dataSource3 = new DataSource(dataProvider, tempDir, Model.DataSourceType.Default);
            var dataSource4 = new DataSource(dataProvider, tempDir, Model.DataSourceType.Online);

            // o == o for all data sources
            Assert.That(dataSource1.Equals(dataSource1));
            Assert.That(dataSource2.Equals(dataSource2));
            Assert.That(dataSource3.Equals(dataSource3));
            Assert.That(dataSource4.Equals(dataSource4));

            // o1 == o2 for all pairs of data sources
            Assert.That(dataSource1.Equals(dataSource2));
            Assert.That(dataSource2.Equals(dataSource1));
            Assert.That(dataSource1.Equals(dataSource3));
            Assert.That(dataSource3.Equals(dataSource1));
            Assert.That(dataSource1.Equals(dataSource4));
            Assert.That(dataSource4.Equals(dataSource1));
            Assert.That(dataSource2.Equals(dataSource3));
            Assert.That(dataSource3.Equals(dataSource2));
            Assert.That(dataSource2.Equals(dataSource4));
            Assert.That(dataSource4.Equals(dataSource2));
            Assert.That(dataSource3.Equals(dataSource4));
            Assert.That(dataSource4.Equals(dataSource3));

            Assert.That(dataSource1.GetHashCode(), Is.EqualTo(dataSource1.GetHashCode()));
            Assert.That(dataSource1.GetHashCode(), Is.EqualTo(dataSource2.GetHashCode()));
            Assert.That(dataSource1.GetHashCode(), Is.EqualTo(dataSource3.GetHashCode()));
            Assert.That(dataSource1.GetHashCode(), Is.EqualTo(dataSource4.GetHashCode()));
        }
Example #3
0
        public void Empty()
        {
            using var tempDir = TempDir.Create();
            var dataProvider = new DataProvider();
            var dataSource   = new DataSource(dataProvider, tempDir, Model.DataSourceType.Custom);

            var context = new Context(dataSource,
                                      new System.Collections.Generic.List <Class>(),
                                      new System.Collections.Generic.List <Property>());

            Assert.That(context.DataSource, Is.EqualTo(dataSource));
            Assert.That(context.Classes, Is.Empty);
            Assert.That(context.UnknownReferences, Is.Empty);
            Assert.That(context.LoadSubmodels(), Is.Empty);
            Assert.That(context.LoadSubmodelElements(), Is.Empty);

            Assert.That(context.GetElement <Class>(""), Is.Null);
            Assert.That(context.UnknownReferences, Is.Empty);

            Assert.That(context.GetElement <Class>("test"), Is.Null);
            Assert.That(context.UnknownReferences, Is.EquivalentTo(new[] {
                new Model.UnknownReference("test", "Class")
            }));

            Assert.That(context.GetElement <Property>("test123"), Is.Null);
            Assert.That(context.UnknownReferences, Is.EquivalentTo(new[] {
                new Model.UnknownReference("test", "Class"),
                new Model.UnknownReference("test123", "Property")
            }));
        }
Example #4
0
        public void ExtendedCopyTest()
        {
            // First try it with a real file
            using (ITempDir tmp = TempDir.Create())
            {
                Raster          rTempl          = new Raster(new FileInfo(DirHelpers.GetTestRasterPath("Slopey950-980.tif")));
                ExtentRectangle newExtReal      = rTempl.Extent.Buffer(15);
                Raster          rTemplateOutput = RasterOperators.ExtendedCopy(rTempl, new FileInfo(Path.Combine(tmp.Name, "ExtendedCopyRasterTestBuffer.tif")), newExtReal);

                ExtentRectangle newExtReal2 = rTempl.Extent.Buffer(5);
                newExtReal2.Rows = (int)newExtReal2.Rows / 2;
                newExtReal2.Cols = (int)newExtReal2.Cols / 3;
                Raster rTemplateOutput2 = RasterOperators.ExtendedCopy(rTempl, new FileInfo(Path.Combine(tmp.Name, "ExtendedCopyRasterTestSlice.tif")), newExtReal2);
            }

            Raster Raster1 = new FakeRaster <int>(10, 20, -1, 1, new int[, ] {
                { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }
            });

            int[,] outgrid = new int[7, 8];
            outgrid.Fill(-999);
            Raster rOutput = new FakeRaster <int>(10, 20, -1, 1, outgrid);

            ExtentRectangle newExt = Raster1.Extent.Buffer(2);

            Internal.Operators.ExtendedCopy <int> copyOp = new Internal.Operators.ExtendedCopy <int>(Raster1, rOutput, new ExtentRectangle(newExt));
            copyOp.RunWithOutput();
        }
Example #5
0
        public void LinearExtractorTest()
        {
            Raster rDetrended = new Raster(new FileInfo(DirHelpers.GetTestRootPath(@"ExtractorTest\Detrended.tif")));
            Raster rWSEDEM    = new Raster(new FileInfo(DirHelpers.GetTestRootPath(@"ExtractorTest\WSEDEM.tif")));

            Vector centerline = new Vector(new FileInfo(DirHelpers.GetTestRootPath(@"ExtractorTest\BCenterline.shp")));
            Vector xs         = new Vector(new FileInfo(DirHelpers.GetTestRootPath(@"ExtractorTest\BCrossSections.shp")));

            using (ITempDir tmp = TempDir.Create())
            {
                //FileInfo centerlinecsv = new FileInfo(Path.Combine(tmp.Name, "centerline.csv"));
                //FileInfo xscsv = new FileInfo(Path.Combine(tmp.Name, "xs.csv"));

                //FileInfo centerlinecsv = new FileInfo(@"c:\dev\CSV\centerline.csv");
                //FileInfo xscsv = new FileInfo(@"c:\dev\CSV\xs.csv");

                //RasterOperators.LinearExtractor(xs, new List<Raster> { rDetrended, rWSEDEM }, xscsv);
                //RasterOperators.LinearExtractor(centerline, new List<Raster> { rDetrended, rWSEDEM }, centerlinecsv);

                FileInfo centerlinecsv1mFIELD = new FileInfo(Path.Combine(tmp.Name, "centerline1mFIELD.csv"));
                FileInfo xscsv1mFIELD         = new FileInfo(Path.Combine(tmp.Name, "xs1mFIELD.csv"));
                FileInfo xscsv1mNoFIELD       = new FileInfo(Path.Combine(tmp.Name, "xs1mNoField.csv"));

                RasterOperators.LinearExtractor(xs, new List <Raster> {
                    rDetrended, rWSEDEM
                }, xscsv1mFIELD, 1.0m, "IsValid");
                RasterOperators.LinearExtractor(xs, new List <Raster> {
                    rDetrended, rWSEDEM
                }, xscsv1mNoFIELD, 1.0m);
                RasterOperators.LinearExtractor(centerline, new List <Raster> {
                    rDetrended, rWSEDEM
                }, centerlinecsv1mFIELD, 1.0m, "CLID");
            }
        }
Example #6
0
        public void MathTest()
        {
            using (ITempDir tmp = TempDir.Create())
            {
                Raster rTempl = new Raster(new FileInfo(DirHelpers.GetTestRasterPath("const900.tif")));
                Raster rTemp2 = new Raster(new FileInfo(DirHelpers.GetTestRasterPath("const950.tif")));

                Raster rOld = new Raster(new FileInfo(DirHelpers.GetTestRootPath(@"VerificationProject\inputs\2005DecDEM\2005DecDEM.tif")));
                Raster rNew = new Raster(new FileInfo(DirHelpers.GetTestRootPath(@"VerificationProject\inputs\2006FebDEM\2006FebDEM.tif")));

                Raster rAdd1 = RasterOperators.Add(rTempl, 2.1m, new FileInfo(Path.Combine(tmp.Name, "RasterAddOperand.tif")));
                Raster rAdd2 = RasterOperators.Add(rTempl, rTemp2, new FileInfo(Path.Combine(tmp.Name, "RasterAddRaster.tif")));

                Raster rSub1 = RasterOperators.Subtract(rTempl, 2.1m, new FileInfo(Path.Combine(tmp.Name, "RasterSubtractOperand.tif")));
                Raster rSub2 = RasterOperators.Subtract(rTempl, rTemp2, new FileInfo(Path.Combine(tmp.Name, "RasterSubtractRaster.tif")));

                // Do another real DoD for luck
                Raster rSub3 = RasterOperators.Subtract(rNew, rOld, new FileInfo(Path.Combine(tmp.Name, "RasterSubtractRasterDoD.tif")));

                Raster rMult1 = RasterOperators.Multiply(rTempl, 2.1m, new FileInfo(Path.Combine(tmp.Name, "RasterMultiplyOperand.tif")));
                Raster rMult2 = RasterOperators.Multiply(rTempl, rTemp2, new FileInfo(Path.Combine(tmp.Name, "RasterMultiplyRaster.tif")));

                Raster rDiv1 = RasterOperators.Divide(rTempl, 2.1m, new FileInfo(Path.Combine(tmp.Name, "RasterDivideOperand.tif")));
                Raster rDiv2 = RasterOperators.Divide(rTempl, rTemp2, new FileInfo(Path.Combine(tmp.Name, "RasterDivideRaster.tif")));
            }
        }
Example #7
0
        public void PosteriorProbabilityTest()
        {
            using (ITempDir tmp = TempDir.Create())
            {
                Raster rTemp2005 = new Raster(new FileInfo(DirHelpers.GetTestRootPath(@"BudgetSeg\SulphurCreek\2005Dec_DEM\2005Dec_DEM.img")));
                Raster rTemp2006 = new Raster(new FileInfo(DirHelpers.GetTestRootPath(@"BudgetSeg\SulphurCreek\2006Feb_DEM\2006Feb_DEM.img")));
                Raster rDoD      = RasterOperators.Subtract(rTemp2006, rTemp2005, new FileInfo(Path.Combine(tmp.Name, "rDoD.tif")));

                Raster GCDErosion1    = RasterOperators.NeighbourCount(rDoD, RasterOperators.GCDWindowType.Erosion, 1, new FileInfo(Path.Combine(tmp.Name, "Erosion1.tif")));
                Raster GCDDeposition1 = RasterOperators.NeighbourCount(rDoD, RasterOperators.GCDWindowType.Deposition, 1, new FileInfo(Path.Combine(tmp.Name, "Deposition1.tif")));
                Raster GCDAll1        = RasterOperators.NeighbourCount(rDoD, RasterOperators.GCDWindowType.All, 1, new FileInfo(Path.Combine(tmp.Name, "All1.tif")));

                ErrorRasterProperties props02 = new ErrorRasterProperties(0.2m);
                ErrorRasterProperties props01 = new ErrorRasterProperties(0.1m);
                // min 60% => 5 // max 100% => 9

                // 0.1 2006
                // 0.2 2005
                Raster r2005Error = RasterOperators.CreateErrorRaster(rTemp2005, props02, new FileInfo(Path.Combine(tmp.Name, "2005Dec_DEM_CONSTERR02.tif")));
                Raster r2006Error = RasterOperators.CreateErrorRaster(rTemp2006, props01, new FileInfo(Path.Combine(tmp.Name, "2006Feb_DEM_CONSTERR01.tif")));

                Raster propError = RasterOperators.RootSumSquares(r2006Error, r2005Error, new FileInfo(Path.Combine(tmp.Name, "properror.tif")));
                Raster postProb  = RasterOperators.CreatePriorProbabilityRaster(rDoD, propError, new FileInfo(Path.Combine(tmp.Name, "priorprob.tif")));

                Raster PostProb = RasterOperators.PosteriorProbability(rDoD, postProb, GCDErosion1, GCDDeposition1, new FileInfo(Path.Combine(tmp.Name, "postprob.tif")), new FileInfo(Path.Combine(tmp.Name, "cond.tif")), 5, 9);
            }
        }
Example #8
0
        public void ReadWriteFileSpecialCaseTest()
        {
            // Write to a file then read it to see if we get the same thing
            Histogram rTest1 = new Histogram(1, decimal.MaxValue);

            //Add some fake values into the mix
            rTest1.AddBinVal(-5);
            rTest1.AddBinVal(7.123);

            // First try it with a real file
            using (ITempDir tmp = TempDir.Create())
            {
                UnitGroup ug       = new UnitGroup(VolumeUnit.CubicMeter, AreaUnit.SquareMeter, LengthUnit.Meter, LengthUnit.Meter);
                Area      cellArea = Area.From(0.2 * 0.3, ug.ArUnit);
                FileInfo  fPath    = new FileInfo(Path.Combine(tmp.Name, "myHistogram.csv"));
                rTest1.WriteFile(fPath, cellArea, ug);
                Histogram rTestRead = new Histogram(fPath);

                // Make sure the two histograms have the same edges and width
                Assert.AreEqual(rTest1.Count, rTest1.Count);
                Assert.AreEqual(rTest1.HistogramLower(ug).Meters, rTest1.HistogramLower(ug).Meters);
                Assert.AreEqual(rTest1.HistogramUpper(ug).Meters, rTest1.HistogramUpper(ug).Meters);
                Assert.AreEqual(rTest1._binWidth, rTest1._binWidth);

                // Now go bin-by-bin to make sure we end up with the same numbers everywhere
                for (int bid = 0; bid < rTestRead.Count; bid++)
                {
                    Assert.AreEqual(rTest1.BinCounts[bid], rTestRead.BinCounts[bid]);
                    Assert.AreEqual(rTest1.BinArea(bid, cellArea).SquareMeters, rTestRead.BinArea(bid, cellArea).SquareMeters);
                    Assert.AreEqual(rTest1.BinLower(bid, ug).Meters, rTestRead.BinLower(bid, ug).Meters);
                }
            }
        }
Example #9
0
            public void MissingDirectory()
            {
                using var tempDir = TempDir.Create();
                var dataProvider = new DataProvider();

                Assert.That(dataProvider.FindDefaultDataSources(tempDir), Is.Empty);
            }
Example #10
0
    public static TestSetup Create()
    {
        var tempDir    = TempDir.Create();
        var repository = TempRepository.Create(tempDir);

        return(new TestSetup(repository, tempDir));
    }
Example #11
0
        public void VectorCopyTest()
        {
            using (ITempDir tmp = TempDir.Create())
            {
                Vector   rVector1 = new Vector(new FileInfo(DirHelpers.GetTestRootPath("SulphurGCDMASK/Sulphur_ComplexGCDMask.shp")));
                FileInfo rV1Copy  = new FileInfo(Path.Combine(tmp.Name, "COPYSulphur_ComplexGCDMask.shp"));
                rVector1.Copy(rV1Copy);

                // Now verify that everything got created correctly
                Vector rVector1Copy = new Vector(rV1Copy);

                Assert.IsFalse(rVector1.Fields.ContainsKey(Vector.CGDMASKFIELD));
                Assert.IsTrue(rVector1Copy.Fields.ContainsKey(Vector.CGDMASKFIELD));

                // Make sure our GCDFID is getting set properly
                foreach (KeyValuePair <long, VectorFeature> kvp in rVector1Copy.Features)
                {
                    int fieldID = rVector1Copy.Fields[Vector.CGDMASKFIELD].FieldID;
                    Assert.AreEqual(kvp.Value.Feat.GetFieldAsInteger(fieldID), kvp.Key);
                }

                Vector rVector = new Vector(new FileInfo(DirHelpers.GetTestVectorPath("StressTest.shp")));
                rVector.Copy(new FileInfo(Path.Combine(tmp.Name, "CopyShapefile.shp")));

                // Make sure we're good.
                Assert.IsTrue(File.Exists(Path.Combine(tmp.Name, "CopyShapefile.shp")));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.Name, "CopyShapefile.dbf")));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.Name, "CopyShapefile.prj")));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.Name, "CopyShapefile.shx")));
            }
        }
Example #12
0
        public void Test_GetBuildFileName()
        {
            try {
                ConsoleDriver.GetBuildFileName(null, null, false);
                Assert.Fail("Exception not thrown.");
            } catch {
            }

            string baseDirectory  = TempDir.Create(Path.Combine(TempDirName, "GetBuildFileName"));
            string build1FileName = Path.Combine(baseDirectory, "file1.build");
            string build2FileName = Path.Combine(baseDirectory, "file2.build");

            try {
                ConsoleDriver.GetBuildFileName(baseDirectory, null, false);
                Assert.Fail("ApplicationException not thrown.");
            } catch (ApplicationException) {
            }

            TempFile.Create(build1FileName);

            Assert.AreEqual(build1FileName, ConsoleDriver.GetBuildFileName(Path.GetDirectoryName(build1FileName), null, false));

            // create a second build file in same directory
            TempFile.Create(build2FileName);
            Assert.AreEqual(Path.GetDirectoryName(build1FileName), Path.GetDirectoryName(build2FileName));

            try {
                ConsoleDriver.GetBuildFileName(Path.GetDirectoryName(build1FileName), null, false);
                Assert.Fail("ApplicationException not thrown.");
            } catch (ApplicationException) {
            }
        }
Example #13
0
        public void Test_BuildFileOption()
        {
            string filename       = "file1.ha";
            string baseDirectory  = TempDir.Create(Path.Combine(TempDirName, "foo"));
            string build1FileName = TempFile.CreateWithContents("<project/>", Path.Combine(baseDirectory, filename));

            string oldCurrDir = Environment.CurrentDirectory;

            Environment.CurrentDirectory = baseDirectory;
            using (ConsoleCapture c = new ConsoleCapture()) {
                bool errors = false;
                try {
                    //check filename only, should be resolvable via currentdirectory
                    Assert.IsTrue(0 == ConsoleDriver.Main(new string[] { "-buildfile:" + filename }), "Using filepath failed");
                    //check absolute
                    Assert.IsTrue(0 == ConsoleDriver.Main(new string[] { @"-buildfile:" + build1FileName }), "Using absolute filepath failed");
                    //check relative path, should be resolvable via currentdirectory
                    Assert.IsTrue(0 == ConsoleDriver.Main(new string[] { string.Format("-buildfile:.{0}{1}", Path.DirectorySeparatorChar, filename) }), "Using relative filepath failed #1");
                    //check relative path, should be resolvable via currentdirectory
                    Assert.IsTrue(0 == ConsoleDriver.Main(new string[] { string.Format("-buildfile:..{0}foo{0}{1}", Path.DirectorySeparatorChar, filename) }), "Using relative filepath failed #2");
                } catch (Exception e) {
                    e.ToString();
                    errors = true;
                    throw;
                }
                finally {
                    string results = c.Close();
                    if (errors)
                    {
                        System.Console.Write(results);
                    }
                }
            }
            Environment.CurrentDirectory = oldCurrDir;
        }
Example #14
0
        public void DownloadSingleArtifact()
        {
            foreach (var job in JobNames)
            {
                if (job.Key == JobType.MatrixProject)
                {
                    // Matrix not supported
                    continue;
                }

                using (var cts = new CancellationTokenSource(new TimeSpan(0, 0, 30)))
                    using (var tmp = TempDir.Create())
                    {
                        var zipFileName = tmp.GetPath("archive.zip");
                        Assert.IsFalse(File.Exists(zipFileName), $"Archive.zip should not exist prior to download for {job.Key} job {job.Value}");

                        var client = CreateClient();

                        var artifactTask = Task.Run <List <JenkinsBuildArtifact> >(async() => await client.GetBuildArtifactsAsync(job.Value, GetTestBranchName(job.Key), "lastSuccessfulBuild").ConfigureAwait(false));
                        var artifacts    = artifactTask.Result;

                        var task = Task.Run(async() => await client.DownloadSingleArtifactAsync(job.Value, GetTestBranchName(job.Key), "lastSuccessfulBuild", zipFileName, artifacts[0]).ConfigureAwait(false));
                        task.GetAwaiter().GetResult();

                        Assert.IsTrue(File.Exists(zipFileName), $"Archive.zip should be downloaded for {job.Key} job {job.Value}");
                    }
            }
        }
Example #15
0
        public void DuplicateElements()
        {
            using var tempDir = TempDir.Create();
            var dataProvider = new DataProvider();
            var dataSource   = new DataSource(dataProvider, tempDir, Model.DataSourceType.Custom);

            var clsId   = "clsid";
            var clsDict = CreateClassDictionary();

            clsDict["MDC_P001_5"] = clsId;
            var cls = new Class(clsDict);

            var propertyId   = "propertyid";
            var propertyDict = CreatePropertyDictionary();

            propertyDict["MDC_P001_6"] = propertyId;
            var property = new Property(propertyDict);

            var context1 = new Context(dataSource, new[] { cls }.ToList(), new[] { property }.ToList());
            var context2 = new Context(dataSource,
                                       new[] { cls, cls, cls }.ToList(),
                                       new[] { property, property, property, property, property }.ToList());

            // TODO (krahlro-sick, 2020-07-31): make sure that there are no duplicates
            Assert.That(context1.GetElement <Class>(clsId), Is.EqualTo(cls));
            Assert.That(context1.GetElement <Property>(propertyId), Is.EqualTo(property));
            Assert.That(context2.GetElement <Class>(clsId), Is.EqualTo(cls));
            Assert.That(context2.GetElement <Property>(propertyId), Is.EqualTo(property));
        }
Example #16
0
        public void RasterDeleteTest()
        {
            using (ITempDir tmp = TempDir.Create())
            {
                FileInfo sSourceRater = new FileInfo(DirHelpers.GetTestRasterPath("const990.tif"));
                FileInfo sDeletePath  = new FileInfo(Path.Combine(tmp.Name, "DeleteRasterTest.tif"));

                Raster rRaster = new Raster(sSourceRater);
                rRaster.Copy(sDeletePath);
                // Make sure our setup worked
                Assert.IsTrue(sDeletePath.Exists);

                Raster rDeleteRaster = new Raster(sDeletePath);
                rDeleteRaster.Delete();

                // Make sure we're good.
                sDeletePath.Refresh();
                Assert.IsFalse(sDeletePath.Exists);
                Assert.IsFalse(File.Exists(Path.Combine(tmp.Name, "DeleteRasterTest.tif.aux.xml")));
                Assert.IsFalse(File.Exists(Path.Combine(tmp.Name, "DeleteRasterTest.tif.ovr")));
                rRaster.UnloadDS();
                rDeleteRaster.UnloadDS();
                rDeleteRaster = null;
                rRaster       = null;
            }
        }
Example #17
0
        public void Empty()
        {
            using var tempDir = TempDir.Create();
            var dataProvider = new DataProvider();
            var dataSource   = new DataSource(dataProvider, tempDir, Model.DataSourceType.Custom);

            var cls     = new Class(CreateClassDictionary());
            var context = new Context(dataSource, new[] { cls }.ToList(),
                                      new System.Collections.Generic.List <Property>());
            var submodels = context.LoadSubmodels();

            Assert.That(submodels, Has.Count.EqualTo(1));
            var submodel = submodels.First();

            Assert.That(submodel, Is.InstanceOf <ClassWrapper>());
            var wrapper = submodel as ClassWrapper;

            Assert.That(wrapper, Is.Not.Null);

            if (wrapper == null)
            {
                return;
            }

            Assert.That(wrapper.DataSource, Is.EqualTo(dataSource));
            Assert.That(wrapper.Id, Is.Empty);
            Assert.That(wrapper.Name, Is.Empty);
            Assert.That(wrapper.Parent, Is.Null);
            Assert.That(wrapper.Children, Is.Empty);
        }
Example #18
0
        public void Start_Stop_Verify_No_MessageBox_Is_Shown_If_Too_Old_Files_Created_In_Directory()
        {
            using (var tmp = TempDir.Create())
            {
                using (var model = Create(tmp.Name, bUseTraceDirStopVariable: true))
                {
                    using (File.Create(Path.Combine(tmp.Name, "test1.etl"))) { };

                    Thread.Sleep(2000); // create etl file too old ot match trace start

                    model.Commands["StartTracing"].Execute(null);

                    WaitUntilLocalTargetState(model, TraceStates.Running);

                    model.Commands["StopTracing"].Execute(null);

                    WaitUntilLocalTargetState(model, TraceStates.Stopped);

                    ContainsMessage("hi trace start");
                    ContainsMessage($"trace stop performed {tmp.Name}");

                    MessageBoxShown($"Error: No new etl files were created in directory {tmp.Name}");
                }
            }
        }
Example #19
0
        public void Name_German()
        {
            using var tempDir = TempDir.Create();
            var dataProvider = new DataProvider();
            var dataSource   = new DataSource(dataProvider, tempDir, Model.DataSourceType.Custom);

            var clsId   = "clsid";
            var clsName = "German Name";
            var clsDict = CreateClassDictionary();

            clsDict["MDC_P001_5"]    = clsId;
            clsDict["MDC_P004_1.de"] = clsName;
            var cls = new Class(clsDict);

            var context = new Context(dataSource, new[] { cls }.ToList(),
                                      new System.Collections.Generic.List <Property>());
            var wrapper = context.LoadSubmodels().First() as ClassWrapper;

            Assert.That(wrapper, Is.Not.Null);
            if (wrapper == null)
            {
                return;
            }

            Assert.That(wrapper.DataSource, Is.EqualTo(dataSource));
            Assert.That(wrapper.Id, Is.EqualTo(clsId));
            Assert.That(wrapper.Name, Is.EqualTo(clsName));
            Assert.That(wrapper.Parent, Is.Null);
            Assert.That(wrapper.Children, Is.Empty);
        }
Example #20
0
        public void Empty()
        {
            using var tempDir = TempDir.Create();
            var dataProvider = new DataProvider();
            var dataSource   = new DataSource(dataProvider, tempDir, Model.DataSourceType.Custom);

            var property = new Property(CreatePropertyDictionary());
            var context  = new Context(dataSource, new List <Class>(), new[] { property }.ToList());

            Assert.That(context.LoadSubmodels(), Is.Empty);
            var submodelElements = context.LoadSubmodelElements();

            Assert.That(submodelElements, Has.Count.EqualTo(1));
            var submodelElement = submodelElements.First();

            Assert.That(submodelElement, Is.InstanceOf <PropertyWrapper>());
            var wrapper = submodelElement as PropertyWrapper;

            Assert.That(wrapper, Is.Not.Null);

            if (wrapper == null)
            {
                return;
            }

            Assert.That(wrapper.DataSource, Is.EqualTo(dataSource));
            Assert.That(wrapper.Id, Is.Empty);
            Assert.That(wrapper.Name, Is.Empty);
            Assert.That(wrapper.Parent, Is.Null);
            Assert.That(wrapper.Children, Is.Empty);
        }
Example #21
0
        public void Properties_UnknownReference()
        {
            using var tempDir = TempDir.Create();
            var dataProvider = new DataProvider();
            var dataSource   = new DataSource(dataProvider, tempDir, Model.DataSourceType.Custom);

            var propertyId = "propertyid";
            var clsId      = "clsid";
            var clsDict    = CreateClassDictionary();

            clsDict["MDC_P001_5"] = clsId;
            clsDict["MDC_P014"]   = propertyId;
            var cls = new Class(clsDict);

            var context = new Context(dataSource, new[] { cls }.ToList(), new List <Property>());
            var wrapper = context.LoadSubmodels().First() as ClassWrapper;

            Assert.That(wrapper, Is.Not.Null);
            if (wrapper == null)
            {
                return;
            }

            Assert.That(wrapper.Children.Cast <PropertyWrapper>().Select(p => p.Element), Is.Empty);
            Assert.That(context.UnknownReferences, Is.EquivalentTo(new[]
            {
                UnknownReference.Create <Property>(propertyId),
            }));
        }
Example #22
0
        public void Id()
        {
            using var tempDir = TempDir.Create();
            var dataProvider = new DataProvider();
            var dataSource   = new DataSource(dataProvider, tempDir, Model.DataSourceType.Custom);

            var propertyId   = "0112/2///62683#ACE101";
            var propertyDict = CreatePropertyDictionary();

            propertyDict["MDC_P001_6"] = propertyId;
            var property = new Property(propertyDict);

            var context = new Context(dataSource, new List <Class>(), new[] { property }.ToList());
            var wrapper = context.LoadSubmodelElements().First() as PropertyWrapper;

            if (wrapper == null)
            {
                return;
            }

            Assert.That(wrapper.DataSource, Is.EqualTo(dataSource));
            Assert.That(wrapper.Id, Is.EqualTo(propertyId));
            Assert.That(wrapper.ToString(), Is.EqualTo(propertyId));
            Assert.That(wrapper.Name, Is.Empty);
            Assert.That(wrapper.Parent, Is.Null);
            Assert.That(wrapper.Children, Is.Empty);
            Assert.That(wrapper.GetDetailsUrl(), Is.EqualTo(new Uri(
                                                                "https://cdd.iec.ch/cdd/iec62683/iec62683.nsf/PropertiesAllVersions/0112-2---62683%23ACE101")));
        }
Example #23
0
        public void CreateErrorRasterFis()
        {
            Raster   rOld    = new Raster(new FileInfo(DirHelpers.GetTestRootPath(@"VerificationProject\inputs\2005DecDEM\2005DecDEM.tif")));
            Raster   rNew    = new Raster(new FileInfo(DirHelpers.GetTestRootPath(@"VerificationProject\inputs\2006FebDEM\2006FebDEM.tif")));
            FileInfo fisFile = new FileInfo(DirHelpers.GetTestRootPath(@"FIS\FuzzyChinookJuvenile_03.fis"));

            // And now the budget seg case
            Vector vPolyMask = new Vector(new FileInfo(DirHelpers.GetTestRootPath(@"SulphurGCDMASK\Sulphur_SimpleGCDMask.shp")));

            using (ITempDir tmp = TempDir.Create())
            {
                FileInfo fiPolyMaskCopy = new FileInfo(Path.Combine(tmp.Name, "Sulphur_SimpleGCDMask.shp"));
                vPolyMask.Copy(fiPolyMaskCopy);
                Vector vPolyMaskCopy = new Vector(fiPolyMaskCopy);

                Dictionary <string, Raster> fisinputs = new Dictionary <string, Raster>()
                {
                    { "Depth", rOld },
                    { "Velocity", rNew },
                    { "GrainSize_mm", rOld }
                };

                Dictionary <string, ErrorRasterProperties> props = new Dictionary <string, ErrorRasterProperties>
                {
                    { "LiDAR", new ErrorRasterProperties(0.1m) },
                    { "Total Station", new ErrorRasterProperties(0.2m) },
                    { "Unknown", new ErrorRasterProperties(fisFile, fisinputs) }
                };


                Raster r2006Error = RasterOperators.CreateErrorRaster(rOld, vPolyMaskCopy, "Method", props, new FileInfo(Path.Combine(tmp.Name, "2006Feb_DEM_CONSTERR01.tif")));
            }
        }
Example #24
0
        public void EnsureOldestFilesAreCleared()
        {
            using (var tmp = TempDir.Create())
            {
                for (int i = 0; i < 20; i++)
                {
                    FileInfo fi = new FileInfo(Path.Combine(tmp.Name, $"{i}.jpg"));
                    using (fi.Create())
                    {
                    }
                    fi.CreationTime = DateTime.Now + TimeSpan.FromMinutes(i);
                }

                Assert.AreEqual(20, Directory.GetFiles(tmp.Name, "*.jpg").Length);

                ScreenshotRecorder.ClearFiles(tmp.Name, 10);

                HashSet <string> expectedFiles = new HashSet <string>(Enumerable.Range(10, 10).Select(x => $"{x}.jpg"));

                var afterDeletion = Directory.GetFiles(tmp.Name, "*.jpg");
                Assert.AreEqual(10, afterDeletion.Length);

                foreach (var file in afterDeletion)
                {
                    string jpg = Path.GetFileName(file);
                    Assert.IsTrue(expectedFiles.Contains(jpg), $"File {file} was not exepcted to exist after deletion of 10 oldest files.");
                }
            }
        }
Example #25
0
 public void UniformTest()
 {
     using (ITempDir tmp = TempDir.Create())
     {
         Raster rTempl           = new Raster(new FileInfo(DirHelpers.GetTestRasterPath("AngledSlopey950-980E.tif")));
         Raster rTemplateOutput1 = RasterOperators.Uniform <int>(rTempl, new FileInfo(Path.Combine(tmp.Name, "UniformTest.tif")), 7);
     }
 }
Example #26
0
            public void EmptyDirectory()
            {
                using var tempDir = TempDir.Create();
                var dataProvider = new DataProvider();

                Assert.That(!dataProvider.IsValidPath(tempDir));
                Assert.That(() => dataProvider.OpenPath(tempDir).Load(), Throws.InstanceOf <Model.ImportException>());
            }
Example #27
0
 public void RootSumSquaresTest()
 {
     using (ITempDir tmp = TempDir.Create())
     {
         Raster rTempl           = new Raster(new FileInfo(DirHelpers.GetTestRasterPath("const900.tif")));
         Raster rTemp2           = new Raster(new FileInfo(DirHelpers.GetTestRasterPath("const950.tif")));
         Raster rTemplateOutput2 = RasterOperators.RootSumSquares(rTempl, rTemp2, new FileInfo(Path.Combine(tmp.Name, "FISTest.tif")));
     }
 }
Example #28
0
 public void BuildPyramidsInterfaceTest()
 {
     using (ITempDir tmp = TempDir.Create())
     {
         Raster          rTempl          = new Raster(new FileInfo(DirHelpers.GetTestRasterPath("AngledSlopey950-980E.tif")));
         ExtentRectangle newExtReal      = rTempl.Extent.Buffer(15);
         Raster          rTemplateOutput = RasterOperators.ExtendedCopy(rTempl, new FileInfo(Path.Combine(tmp.Name, "PyramidTest.tif")), newExtReal);
         RasterOperators.BuildPyramids(new FileInfo(Path.Combine(tmp.Name, "PyramidTest.tif")));
     }
 }
Example #29
0
            public void ValidDirectory()
            {
                using var tempDir = TempDir.Create();
                var dataProvider = new DataProvider();

                CreateEmptyXls(tempDir, GetExportFileName("class", "12345"));
                CreateEmptyXls(tempDir, GetExportFileName("property", "12345"));
                Assert.That(dataProvider.IsValidPath(tempDir));
                Assert.That(() => dataProvider.OpenPath(tempDir).Load(), Throws.Nothing);
            }
Example #30
0
            public void MissingRequiredFiles()
            {
                using var tempDir = TempDir.Create();
                var dataProvider = new DataProvider();

                CreateEmptyXls(tempDir, GetExportFileName("CLASS", "12345"));
                Assert.That(!dataProvider.IsValidPath(tempDir));
                Assert.That(() => dataProvider.OpenPath(tempDir).Load(),
                            Throws.TypeOf <MissingExportFilesException>());
            }