//[TestCase(GSATargetLayer.Analysis, "S5pNxjmUH.json")] public void ReceiverTestForDebug(GSATargetLayer layer, string fileName) { var json = Helper.ReadFile(fileName, TestDataDirectory); var mockGsaCom = SetupMockGsaCom(); Initialiser.AppResources.Proxy.OpenFile("", false, mockGsaCom.Object); var receiverProcessor = new ReceiverProcessor(TestDataDirectory, Initialiser.AppResources); //Run conversion to GWA keywords receiverProcessor.JsonSpeckleStreamsToGwaRecords(new[] { fileName }, out var actualGwaRecords, layer); Assert.IsNotNull(actualGwaRecords); Assert.IsNotEmpty(actualGwaRecords); var keywords = Helper.GetTypeCastPriority(ioDirection.Receive, layer, false).Select(i => i.Key.GetGSAKeyword()).Distinct().ToList(); //Log outcome to file foreach (var keyword in keywords) { var actualGwaRecordsForKeyword = new List <GwaRecord>(); for (var i = 0; i < actualGwaRecords.Count(); i++) { Initialiser.AppResources.Proxy.ParseGeneralGwa(actualGwaRecords[i].GwaCommand, out var recordKeyword, out var foundIndex, out var foundStreamId, out string foundApplicationId, out var gwaWithoutSet, out var gwaSetCommandType); if (recordKeyword.Equals(keyword, StringComparison.InvariantCultureIgnoreCase)) { actualGwaRecordsForKeyword.Add(actualGwaRecords[i]); } } var actualUniqueApplicationIds = actualGwaRecordsForKeyword.Where(r => !string.IsNullOrEmpty(r.ApplicationId)).Select(r => r.ApplicationId).Distinct(); } }
public void ReceiverTestLoadRelated(GSATargetLayer layer, string fileName, int expectedNum0DLoads, int expectedNum2DBeamLoads, int expectedNum2dFaceLoads, int expectedNumLoadTasks, int expectedLoadCombos) { var json = Helper.ReadFile(fileName, TestDataDirectory); var mockGsaCom = SetupMockGsaCom(); Initialiser.AppResources.Proxy.OpenFile("", false, mockGsaCom.Object); var receiverProcessor = new ReceiverProcessor(TestDataDirectory); //Run conversion to GWA keywords Assert.IsTrue(receiverProcessor.JsonSpeckleStreamsToGwaRecords(new[] { fileName }, out var actualGwaRecords, layer)); Assert.IsNotNull(actualGwaRecords); Assert.IsNotEmpty(actualGwaRecords); var TypePrerequisites = Initialiser.GsaKit.RxTypeDependencies; var keywords = TypePrerequisites.Select(i => i.Key.GetGSAKeyword()).Distinct().ToList(); //Log outcome to file var actualGwaRecordsForKeyword = new Dictionary <string, List <string> >(); for (var i = 0; i < actualGwaRecords.Count(); i++) { GSAProxy.ParseGeneralGwa(actualGwaRecords[i].GwaCommand, out var recordKeyword, out var foundIndex, out var foundStreamId, out string foundApplicationId, out var gwaWithoutSet, out var gwaSetCommandType); if (!actualGwaRecordsForKeyword.ContainsKey(recordKeyword)) { actualGwaRecordsForKeyword.Add(recordKeyword, new List <string>()); } actualGwaRecordsForKeyword[recordKeyword].Add(actualGwaRecords[i].GwaCommand); } Assert.AreEqual(expectedNum0DLoads, actualGwaRecords.Where(r => r.GwaCommand.Contains("LOAD_NODE")).Count()); Assert.AreEqual(expectedNum2DBeamLoads, actualGwaRecords.Where(r => r.GwaCommand.Contains("LOAD_BEAM_UDL")).Count()); Assert.AreEqual(expectedNum2dFaceLoads, actualGwaRecords.Where(r => r.GwaCommand.Contains("LOAD_2D_FACE")).Count()); Assert.AreEqual(expectedNumLoadTasks, actualGwaRecords.Where(r => r.GwaCommand.Contains("TASK")).Count()); Assert.AreEqual(expectedLoadCombos, actualGwaRecords.Where(r => r.GwaCommand.Contains("COMBINATION")).Count()); /* * Assert.AreEqual(expectedNum2DBeamLoads, actualGwaRecordsForKeyword["LOAD_BEAM_UDL.2"].Distinct().Count()); * Assert.AreEqual(expectedNum2dFaceLoads, actualGwaRecordsForKeyword["LOAD_2D_FACE.2"].Distinct().Count()); * Assert.AreEqual(expectedNumLoadTasks, actualGwaRecordsForKeyword["TASK.1"].Distinct().Count()); * Assert.AreEqual(expectedLoadCombos, actualGwaRecordsForKeyword["COMBINATION.1"].Distinct().Count()); */ }
private void ReceiverGsaValidation(string subdir, string[] jsonFiles, GSATargetLayer layer) { // Takes a saved Speckle stream with structural objects // converts to GWA and sends to GSA // then reads the data back out of GSA // and compares the two sets of GWA // if successful then there will be the same number // of each of the keywords in as out SpeckleInitializer.Initialize(); Initialiser.AppResources = new MockGSAApp(proxy: new GSAProxy()); Initialiser.GsaKit.Clear(); Initialiser.AppResources.Settings.TargetLayer = layer; Initialiser.AppResources.Proxy.NewFile(true); var dir = TestDataDirectory; if (subdir != String.Empty) { dir = Path.Combine(TestDataDirectory, subdir); dir = dir + @"\"; // TestDataDirectory setup unconvetionally with trailing seperator - follow suit } var receiverProcessor = new ReceiverProcessor(dir, Initialiser.AppResources); // Run conversion to GWA keywords // Note that it can be one model split over several json files receiverProcessor.JsonSpeckleStreamsToGwaRecords(jsonFiles, out var gwaRecordsFromFile, layer); //Run conversion to GWA keywords Assert.IsNotNull(gwaRecordsFromFile); Assert.IsNotEmpty(gwaRecordsFromFile); var designTypeHierarchy = Helper.GetTypeCastPriority(ioDirection.Receive, GSATargetLayer.Design, false); var analysisTypeHierarchy = Helper.GetTypeCastPriority(ioDirection.Receive, GSATargetLayer.Analysis, false); var keywords = designTypeHierarchy.Select(i => i.Key.GetGSAKeyword()).ToList(); keywords.AddRange(designTypeHierarchy.SelectMany(i => i.Key.GetSubGSAKeyword())); keywords.AddRange(analysisTypeHierarchy.Select(i => i.Key.GetGSAKeyword())); keywords.AddRange(analysisTypeHierarchy.SelectMany(i => i.Key.GetSubGSAKeyword())); keywords = keywords.Where(k => k.Length > 0).Select(k => Helper.RemoveVersionFromKeyword(k)).Distinct().ToList(); Initialiser.AppResources.Proxy.Sync(); // send GWA to GSA var retrievedGwa = Initialiser.AppResources.Proxy.GetGwaData(keywords, true); // read GWA from GSA var retrievedDict = new Dictionary <string, List <string> >(); foreach (var gwa in retrievedGwa) { Initialiser.AppResources.Proxy.ParseGeneralGwa(gwa.GwaWithoutSet, out string keyword, out _, out _, out _, out _, out _); if (!retrievedDict.ContainsKey(keyword)) { retrievedDict.Add(keyword, new List <string>()); } retrievedDict[keyword].Add(gwa.GwaWithoutSet); } var fromFileDict = new Dictionary <string, List <string> >(); foreach (var r in gwaRecordsFromFile) { Initialiser.AppResources.Proxy.ParseGeneralGwa(r.GwaCommand, out string keyword, out _, out _, out _, out string gwaWithoutSet, out _); if (!fromFileDict.ContainsKey(keyword)) { fromFileDict.Add(keyword, new List <string>()); } fromFileDict[keyword].Add(gwaWithoutSet); } Initialiser.AppResources.Proxy.Close(); var unmatching = new Dictionary <string, UnmatchedData>(); foreach (var keyword in fromFileDict.Keys) { if (!retrievedDict.ContainsKey(keyword)) { unmatching[keyword] = new UnmatchedData(); unmatching[keyword].FromFile = fromFileDict[keyword]; } else if (retrievedDict[keyword].Count != fromFileDict[keyword].Count) { unmatching[keyword] = new UnmatchedData(); unmatching[keyword].Retrieved = (retrievedDict.ContainsKey(keyword)) ? retrievedDict[keyword] : null; unmatching[keyword].FromFile = fromFileDict[keyword]; } } Assert.AreEqual(0, unmatching.Count()); // GSA sometimes forgets the SID - should check that this has passed through correctly here }
private void RunReceiverTest(string[] savedJsonFileNames, string expectedGwaPerIdsFile, GSATargetLayer layer) { var expectedJson = Helper.ReadFile(expectedGwaPerIdsFile, TestDataDirectory); var expectedGwaRecords = Helper.DeserialiseJson <List <GwaRecord> >(expectedJson); var mockGsaCom = SetupMockGsaCom(); gsaInterfacer.OpenFile("", false, mockGsaCom.Object); var receiverProcessor = new ReceiverProcessor(TestDataDirectory, gsaInterfacer, gsaCache); //Run conversion to GWA keywords receiverProcessor.JsonSpeckleStreamsToGwaRecords(savedJsonFileNames, out var actualGwaRecords); Assert.IsNotNull(actualGwaRecords); Assert.IsNotEmpty(actualGwaRecords); var keywords = Helper.GetTypeCastPriority(ioDirection.Receive, GSATargetLayer.Design, false).Select(i => i.Key.GetGSAKeyword()).Distinct().ToList(); //Log outcome to file foreach (var keyword in keywords) { var expectedGwaRecordsForKeyword = new List <GwaRecord>(); for (var i = 0; i < expectedGwaRecords.Count(); i++) { Initialiser.Interface.ParseGeneralGwa(expectedGwaRecords[i].GwaCommand, out var recordKeyword, out var foundIndex, out var foundStreamId, out string foundApplicationId, out var gwaWithoutSet, out var gwaSetCommandType); if (recordKeyword.Equals(keyword, StringComparison.InvariantCultureIgnoreCase)) { expectedGwaRecordsForKeyword.Add(expectedGwaRecords[i]); } } var actualGwaRecordsForKeyword = new List <GwaRecord>(); for (var i = 0; i < actualGwaRecords.Count(); i++) { Initialiser.Interface.ParseGeneralGwa(actualGwaRecords[i].GwaCommand, out var recordKeyword, out var foundIndex, out var foundStreamId, out string foundApplicationId, out var gwaWithoutSet, out var gwaSetCommandType); if (recordKeyword.Equals(keyword, StringComparison.InvariantCultureIgnoreCase)) { actualGwaRecordsForKeyword.Add(actualGwaRecords[i]); } } if (expectedGwaRecordsForKeyword.Count() == 0) { continue; } Assert.GreaterOrEqual(actualGwaRecordsForKeyword.Count(), expectedGwaRecordsForKeyword.Count(), "Number of GWA records don't match"); var actualUniqueApplicationIds = actualGwaRecordsForKeyword.Where(r => !string.IsNullOrEmpty(r.ApplicationId)).Select(r => r.ApplicationId).Distinct(); var expectedUniqueApplicationIds = expectedGwaRecordsForKeyword.Where(r => !string.IsNullOrEmpty(r.ApplicationId)).Select(r => r.ApplicationId).Distinct(); Assert.AreEqual(expectedUniqueApplicationIds.Count(), actualUniqueApplicationIds.Count()); //Check for any actual records missing from expected Assert.IsTrue(actualUniqueApplicationIds.All(a => expectedUniqueApplicationIds.Contains(a))); //Check any expected records missing in actual Assert.IsTrue(expectedUniqueApplicationIds.All(a => actualUniqueApplicationIds.Contains(a))); //Check each actual record has match in expected foreach (var actualGwaRecord in actualGwaRecordsForKeyword) { Assert.GreaterOrEqual(1, expectedGwaRecordsForKeyword.Count(er => er.ApplicationId == actualGwaRecord.ApplicationId && er.GwaCommand.Equals(actualGwaRecord.GwaCommand, StringComparison.InvariantCultureIgnoreCase)), "Expected record not found in actual records"); } } }