Exemple #1
0
        /// <summary>
        /// Instantiates a new Location Test object
        /// </summary>
        public PathEdge()
        {
            //Set up the Data Connection
            var    config    = new ConfigurationBuilder().AddJsonFile("xunit.config.json").Build();
            string SQLServer = config["gfSqlServer"];
            string DBName    = config["gfDbName"];

            this._SQLConnection = new GFSqlConnector("testappAPIKEY", "testadminuserAPIKEY", SQLServer, DBName, true); //Need to log in as admin

            //Create a Test Simulation and save to DB

            this._TestSimulation = new Core.SimSig.Simulation("Test PathEdge Sim Name", "Test PathEdge Sim Desc", null, "TestPESimCode", this._SQLConnection);
            this._TestSimulation.SaveToSQLDB();
            this._TestVersion = new Core.SimSig.Version("Test PathEdge Version", "Test LocCode Version", 4.15M, this._SQLConnection);
            this._TestVersion.SaveToSQLDB();
            this._TestLocation1 = new Core.SimSig.Location(this._TestSimulation, "Test PathEdge Loc Name 1", null, "TestPECode1", false, Core.SimSig.SimSigLocationType.Station, this._SQLConnection);
            this._TestLocation1.SaveToSQLDB();
            this._TestLocationNode1 = new Core.SimSig.LocationNode(this._TestSimulation.ID, this._TestLocation1.SimSigCode, this._TestSimulation.GetSimulationEras().Find(x => x.Type == EraType.Template).ID, this._TestVersion, null, new Core.Electrification(0), SimSigLocationType.Station, null, false, null, null, this._SQLConnection);
            this._TestLocationNode1.SaveToSQLDB();
            this._TestLocation2 = new Core.SimSig.Location(this._TestSimulation, "Test PathEdge Loc Name 2", null, "TestPECode2", false, Core.SimSig.SimSigLocationType.Station, this._SQLConnection);
            this._TestLocation2.SaveToSQLDB();
            this._TestLocationNode2 = new Core.SimSig.LocationNode(this._TestSimulation.ID, this._TestLocation2.SimSigCode, this._TestSimulation.GetSimulationEras().Find(x => x.Type == EraType.Template).ID, this._TestVersion, null, new Core.Electrification(0), SimSigLocationType.Station, null, false, null, null, this._SQLConnection);
            this._TestLocationNode2.SaveToSQLDB();
            this._TestSimulationExt = new SimulationExtension(this._TestSimulation.ID, this._SQLConnection);
            this._TestSimulationExt.Locations.Add(this._TestLocation1);
            this._TestSimulationExt.Locations.Add(this._TestLocation2);
            this._TestSimulationExt.LocationNodes.Add(this._TestLocationNode1);
            this._TestSimulationExt.LocationNodes.Add(this._TestLocationNode2);
        }
Exemple #2
0
        public void Simulation_Method_SaveToSQLDB_WithDateTime(string Name, string Description, string SimSigWikiLink, string SimSigCode)
        {
            Core.SimSig.Simulation TestSim = new Core.SimSig.Simulation(Name, Description, SimSigWikiLink, SimSigCode, this._SQLConnection);

            DateTimeOffset TestDateTime = new DateTimeOffset(new DateTime(2019, 1, 1), TimeSpan.FromHours(-8));

            TestSim.SaveToSQLDB(TestDateTime);
            Assert.Equal(Name, TestSim.Name);
            Assert.Equal(Description, TestSim.Description);
            Assert.Equal(SimSigWikiLink, TestSim.SimSigWikiLink);
            Assert.Equal(SimSigCode, TestSim.SimSigCode);
            Assert.NotEqual(0, TestSim.ID);

            this._SQLConnection.Open();
            SqlCommand Cmd = this._SQLConnection.SQLCommand("SELECT createdon, modifiedon FROM [simsig].[TSIM] WHERE [id] = @id", System.Data.CommandType.Text);

            Cmd.Parameters.Add(new SqlParameter("@id", TestSim.ID));
            SqlDataReader DataReader = Cmd.ExecuteReader();

            DateTimeOffset TestCreatedOnDateTime  = DateTimeOffset.UtcNow;
            DateTimeOffset TestModifiedOnDateTime = DateTimeOffset.UtcNow;

            while (DataReader.Read())
            {
                TestCreatedOnDateTime  = DataReader.GetDateTimeOffset(0);
                TestModifiedOnDateTime = DataReader.GetDateTimeOffset(1);
            }

            this._SQLConnection.Close();

            Assert.Equal(TestDateTime, TestCreatedOnDateTime);
            Assert.Equal(TestDateTime, TestModifiedOnDateTime);
        }
Exemple #3
0
 public void Simulation_Constructor_FromValues_CheckProperties(string Name, string Description, string SimSigWikiLink, string SimSigCode)
 {
     Core.SimSig.Simulation TestSim = new Core.SimSig.Simulation(Name, Description, SimSigWikiLink, SimSigCode, this._SQLConnection);
     Assert.Equal(Name, TestSim.Name);
     Assert.Equal(Description, TestSim.Description);
     Assert.Equal(SimSigWikiLink, TestSim.SimSigWikiLink);
     Assert.Equal(SimSigCode, TestSim.SimSigCode);
 }
Exemple #4
0
 public void Simulation_Constructor_Check_CreateEra_On_UnsavedSim(string Name, string Description, string SimSigWikiLink, string SimSigCode)
 {
     Core.SimSig.Simulation TestSim = new Core.SimSig.Simulation(Name, Description, SimSigWikiLink, SimSigCode, this._SQLConnection);
     Assert.Equal(Name, TestSim.Name);
     Assert.Equal(Description, TestSim.Description);
     Assert.Equal(SimSigWikiLink, TestSim.SimSigWikiLink);
     Assert.Equal(SimSigCode, TestSim.SimSigCode);
 }
Exemple #5
0
 public void Simulation_Method_Exists(string Name, string Description, string SimSigWikiLink, string SimSigCode)
 {
     Core.SimSig.Simulation TestSim = new Core.SimSig.Simulation(Name, Description, SimSigWikiLink, SimSigCode, this._SQLConnection);
     Assert.False(TestSim.Exists());
     TestSim.SaveToSQLDB();
     //Now create a new Simulation object with the same arguments and see if it exists.
     Core.SimSig.Simulation TestSimExists = new Core.SimSig.Simulation(Name, Description, SimSigWikiLink, SimSigCode, this._SQLConnection);
     Assert.True(TestSimExists.Exists());
 }
Exemple #6
0
 public void Simulation_Method_SaveToSQLDB_NoDateTime(string Name, string Description, string SimSigWikiLink, string SimSigCode)
 {
     Core.SimSig.Simulation TestSim = new Core.SimSig.Simulation(Name, Description, SimSigWikiLink, SimSigCode, this._SQLConnection);
     TestSim.SaveToSQLDB();
     Assert.Equal(Name, TestSim.Name);
     Assert.Equal(Description, TestSim.Description);
     Assert.Equal(SimSigWikiLink, TestSim.SimSigWikiLink);
     Assert.Equal(SimSigCode, TestSim.SimSigCode);
     Assert.NotEqual(0, TestSim.ID);
 }
Exemple #7
0
        public void Simulation_Method_SaveToSQLDB_NoDateTime_CheckDuplicateUpdatesExistingRecord(string Name, string Description, string SimSigWikiLink, string SimSigCode)
        {
            Core.SimSig.Simulation TestSim = new Core.SimSig.Simulation(Name, Description, SimSigWikiLink, SimSigCode, this._SQLConnection);
            TestSim.SaveToSQLDB();
            int TestID = TestSim.ID;

            //Create a new object with same properties. The ID returned when saving should be the same as the first record saved
            Core.SimSig.Simulation DupeTestSim = new Core.SimSig.Simulation(Name, Description, SimSigWikiLink, SimSigCode, this._SQLConnection);
            DupeTestSim.SaveToSQLDB();
            Assert.Equal(TestID, DupeTestSim.ID);
        }
 public IActionResult GetSimLocations(int id)
 {
     try
     {
         Core.SimSig.Simulation Sim = new Core.SimSig.Simulation(id, this._SQLConnection);
         return(Ok(new Core.SimSig.LocationCollection(Sim, this._SQLConnection)));
     }
     catch (Exception Ex)
     {
         _logger.LogError($"An error has occurred: {Ex}");
         return(StatusCode(500, Ex.Message));
     }
 }
Exemple #9
0
        /// <summary>
        /// Instantiates a new Location Test object
        /// </summary>
        public Location()
        {
            //Set up the Data Connection
            var    config    = new ConfigurationBuilder().AddJsonFile("xunit.config.json").Build();
            string SQLServer = config["gfSqlServer"];
            string DBName    = config["gfDbName"];

            this._SQLConnection = new GFSqlConnector("testappAPIKEY", "testadminuserAPIKEY", SQLServer, DBName, true); //Need to log in as admin

            //Create a Test Simulation and save to DB

            this._TestSimulation = new Core.SimSig.Simulation("Test Location Sim Name", "Test Location Sim Desc", null, "Test Location Sim Code", this._SQLConnection);
            this._TestSimulation.SaveToSQLDB();
        }
Exemple #10
0
        public void Simulation_Method_SaveToSQLDB_NoDateTime_CheckGetFromSQLDatabase(string Name, string Description, string SimSigWikiLink, string SimSigCode)
        {
            Core.SimSig.Simulation SetUpSim = new Core.SimSig.Simulation(Name, Description, SimSigWikiLink, SimSigCode, this._SQLConnection);
            SetUpSim.SaveToSQLDB();
            int SetupSimID = SetUpSim.ID;

            //Retrieve the simulation record from the Groundframe.SQL database
            Core.SimSig.Simulation TestSim = new Core.SimSig.Simulation(SetupSimID, this._SQLConnection);
            Assert.Equal(Name, TestSim.Name);
            Assert.Equal(Description, TestSim.Description);
            Assert.Equal(SimSigWikiLink, TestSim.SimSigWikiLink);
            Assert.Equal(SimSigCode.ToLower(), TestSim.SimSigCode);
            Assert.Equal(SetupSimID, TestSim.ID);
        }
Exemple #11
0
        public void LocationCollection_Constructor_Default()
        {
            //Populate some data
            Core.SimSig.Simulation TestSim = new Core.SimSig.Simulation("LocColl Sim Name", "LocColl Sim Desc", null, "LocCollCode", this._SQLConnection);
            TestSim.SaveToSQLDB();
            Core.SimSig.Location TestLocation1 = new Core.SimSig.Location(TestSim, "LocColl Loc Name", null, "LocCollLocCode1", true, Core.SimSig.SimSigLocationType.Station, this._SQLConnection);
            TestLocation1.SaveToSQLDB();
            Core.SimSig.Location TestLocation2 = new Core.SimSig.Location(TestSim, "LocCol2 Loc Name", "LocCollTIPLOC2", "LocCollLocCode2", false, Core.SimSig.SimSigLocationType.Station, this._SQLConnection);
            TestLocation2.SaveToSQLDB();

            //Get Collection
            Core.SimSig.LocationCollection TestLocCollection = new Core.SimSig.LocationCollection(TestSim, this._SQLConnection);
            //Check 5 records are returned
            Assert.Equal(2, TestLocCollection.Count);
        }
Exemple #12
0
        /// <summary>
        /// Instantiates a new Location Test object
        /// </summary>
        public LocationNode()
        {
            //Set up the Data Connection
            var    config    = new ConfigurationBuilder().AddJsonFile("xunit.config.json").Build();
            string SQLServer = config["gfSqlServer"];
            string DBName    = config["gfDbName"];

            this._SQLConnection = new GFSqlConnector("testappAPIKEY", "testadminuserAPIKEY", SQLServer, DBName, true); //Need to log in as admin

            //Create a Test Simulation and save to DB

            this._TestSimulation = new Core.SimSig.Simulation("Test LocationNode Sim Name", "Test LocationNode Sim Desc", null, "TestLocationNodeSimCode", this._SQLConnection);
            this._TestSimulation.SaveToSQLDB();
            this._TestLocation = new Core.SimSig.Location(this._TestSimulation, "Test LocNode Loc Name", null, "TestLocNodeCode", false, Core.SimSig.SimSigLocationType.Station, this._SQLConnection);
            this._TestLocation.SaveToSQLDB();
            this._TestSimulationExt = new SimulationExtension(this._TestLocation.ID, this._SQLConnection);
            this._TestSimulationExt.Locations.Add(this._TestLocation);
            this._TestVersion = new Core.SimSig.Version("Test LocNode Version", "Test LocCode Version", 4.15M, this._SQLConnection);
            this._TestVersion.SaveToSQLDB();
        }