From 4a4bcc81e04948a8e9baf6f7c01bd2925b163a98 Mon Sep 17 00:00:00 2001 From: Matthew Burke Date: Mon, 14 Aug 2023 17:10:38 -0400 Subject: [PATCH] Created Unit Test Project --- PWAPPv2.sln | 6 ++ PWAPPv2/MainWindow.xaml | 2 +- PWAPPv2/MainWindow.xaml.cs | 38 ++++++---- PWAPPv2/Source/API/APIConfig.cs | 2 +- PWAPPv2/Source/API/APIConnection.cs | 35 +-------- PWAPPv2/Source/DataObjects/APICredentials.cs | 7 +- UnitTests/Properties/AssemblyInfo.cs | 20 ++++++ UnitTests/UnitTest1.cs | 29 ++++++++ UnitTests/UnitTests.csproj | 74 ++++++++++++++++++++ UnitTests/packages.config | 5 ++ 10 files changed, 167 insertions(+), 51 deletions(-) create mode 100644 UnitTests/Properties/AssemblyInfo.cs create mode 100644 UnitTests/UnitTest1.cs create mode 100644 UnitTests/UnitTests.csproj create mode 100644 UnitTests/packages.config diff --git a/PWAPPv2.sln b/PWAPPv2.sln index 9ee99ea..5b08ebc 100644 --- a/PWAPPv2.sln +++ b/PWAPPv2.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.33529.622 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PWAPPv2", "PWAPPv2\PWAPPv2.csproj", "{45E26AF8-41D7-4308-A2C8-D55A0350DB47}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "UnitTests\UnitTests.csproj", "{164B9220-F337-4E88-B619-0C52C502B9C4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {45E26AF8-41D7-4308-A2C8-D55A0350DB47}.Debug|Any CPU.Build.0 = Debug|Any CPU {45E26AF8-41D7-4308-A2C8-D55A0350DB47}.Release|Any CPU.ActiveCfg = Release|Any CPU {45E26AF8-41D7-4308-A2C8-D55A0350DB47}.Release|Any CPU.Build.0 = Release|Any CPU + {164B9220-F337-4E88-B619-0C52C502B9C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {164B9220-F337-4E88-B619-0C52C502B9C4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {164B9220-F337-4E88-B619-0C52C502B9C4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {164B9220-F337-4E88-B619-0C52C502B9C4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PWAPPv2/MainWindow.xaml b/PWAPPv2/MainWindow.xaml index 57a5183..920b7a5 100644 --- a/PWAPPv2/MainWindow.xaml +++ b/PWAPPv2/MainWindow.xaml @@ -69,7 +69,7 @@ - + diff --git a/PWAPPv2/MainWindow.xaml.cs b/PWAPPv2/MainWindow.xaml.cs index 6b8c9e0..3242c7b 100644 --- a/PWAPPv2/MainWindow.xaml.cs +++ b/PWAPPv2/MainWindow.xaml.cs @@ -33,6 +33,8 @@ namespace PWAPPv2 List images; + string ConfigPath = "C:\\PWAPP\\Config\\Config.xml"; + public MainWindow() { try @@ -41,28 +43,37 @@ namespace PWAPPv2 } catch (Exception) { } + try + { + images = new List(); - images = new List(); + apiconfig.LoadConfig(ConfigPath); + DataConfig = new Source.Database.DatabaseConfig(ConfigPath); + Source.Database.DatabaseConnection dbcon = new Source.Database.DatabaseConnection(DataConfig); - apiconfig.LoadConfig("./Config/Config.xml"); - DataConfig = new Source.Database.DatabaseConfig("./Config/Config.xml"); - Source.Database.DatabaseConnection dbcon = new Source.Database.DatabaseConnection(DataConfig); + apiCreds = new Source.DataObjects.APICredentials(apiconfig); - apiCreds = new Source.DataObjects.APICredentials(apiconfig); + apiConnection = new Source.API.APIConnection("http://apipatientweb.azurewebsites.net/", + apiCreds); - apiConnection = new Source.API.APIConnection("http://apipatientweb.azurewebsites.net/", - apiCreds); + InitializeComponent(); - InitializeComponent(); + PopulateComboBoxes(); - PopulateComboBoxes(); + patient = new Source.Patient(); - patient = new Source.Patient(); + patient.BuildFromDatabase(dbcon, args[0]); - patient.BuildFromDatabase(dbcon, args[0]); - - this.DataContext = new Source.PatientGUIAdapter(patient); + this.DataContext = new Source.PatientGUIAdapter(patient); + } + catch(NullReferenceException) + { + } + catch(Exception e) + { + MessageBox.Show(e.Message); + } } private void PopulateComboBoxes() @@ -244,7 +255,6 @@ namespace PWAPPv2 imageGrid.HorizontalAlignment = HorizontalAlignment.Left; imageGrid.VerticalAlignment = VerticalAlignment.Top; imageGrid.ShowGridLines = true; - imageGrid.Background = new SolidColorBrush(Colors.LightSteelBlue); ColumnDefinition imageColumn = new ColumnDefinition(); imageColumn.Width = new GridLength(50); diff --git a/PWAPPv2/Source/API/APIConfig.cs b/PWAPPv2/Source/API/APIConfig.cs index 6c11bce..3a88069 100644 --- a/PWAPPv2/Source/API/APIConfig.cs +++ b/PWAPPv2/Source/API/APIConfig.cs @@ -3,7 +3,7 @@ using System.Xml; namespace PWAPPv2.Source { - class APIConfig + public class APIConfig { public string PWUserID; public string PWPassword; diff --git a/PWAPPv2/Source/API/APIConnection.cs b/PWAPPv2/Source/API/APIConnection.cs index fe6038c..6847714 100644 --- a/PWAPPv2/Source/API/APIConnection.cs +++ b/PWAPPv2/Source/API/APIConnection.cs @@ -7,7 +7,7 @@ using System.Text; namespace PWAPPv2.Source.API { - class APIConnection + public class APIConnection { private static string BaseURL; @@ -52,39 +52,6 @@ namespace PWAPPv2.Source.API } } - public string APIPost() - { - string text; - try - { - HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://apipatientweb.azurewebsites.net/api/PWReferralTypes"); - request.Method = "POST"; - request.ContentType = "application/json; charset=\"utf-8\""; - request.Accept = "application/json"; - - string postData = Source.API.APIRequestBuilder.BuildJsonBodyRequest(Credentials); - - ASCIIEncoding encoding = new ASCIIEncoding(); - byte[] data = encoding.GetBytes(postData); - request.ContentLength = data.Length; - Stream newStream = request.GetRequestStream(); - newStream.Write(data, 0, data.Length); - newStream.Close(); - - var response = (HttpWebResponse)request.GetResponse(); - - using (var sr = new StreamReader(response.GetResponseStream())) - { - text = sr.ReadToEnd(); - } - } - catch (WebException wex) - { - text = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd(); - } - return text; - } - public string SendPostRequestAsync(string apiUri) { HttpClient client = new HttpClient(); diff --git a/PWAPPv2/Source/DataObjects/APICredentials.cs b/PWAPPv2/Source/DataObjects/APICredentials.cs index 5df1277..77e513c 100644 --- a/PWAPPv2/Source/DataObjects/APICredentials.cs +++ b/PWAPPv2/Source/DataObjects/APICredentials.cs @@ -1,12 +1,17 @@ namespace PWAPPv2.Source.DataObjects { - class APICredentials + public class APICredentials { public string UserID; public string Password; public string PracticeId; public string APIid; + public APICredentials() + { + + } + public APICredentials(Source.APIConfig config) { UserID = config.PWUserID; diff --git a/UnitTests/Properties/AssemblyInfo.cs b/UnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..806675f --- /dev/null +++ b/UnitTests/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("UnitTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("UnitTests")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("164b9220-f337-4e88-b619-0c52c502b9c4")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/UnitTests/UnitTest1.cs b/UnitTests/UnitTest1.cs new file mode 100644 index 0000000..3de928a --- /dev/null +++ b/UnitTests/UnitTest1.cs @@ -0,0 +1,29 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using PWAPPv2.Source.API; +using PWAPPv2.Source.DataObjects; + +// System.Threading.Tasks.Task.Result.get returned "\"1|Endo|2|Implant|3|Oral Surgery|4|Ortho|5|Pedo|6|Perio|7|Restore|8|Other \\n\"" string + +namespace UnitTests +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestV1Get() + { + APICredentials creds = new APICredentials(); + creds.UserID = "testdoctor"; + creds.Password = "testdoctor"; + creds.PracticeId = "210"; + creds.APIid = "12345678"; + + APIConnection conn = new APIConnection("http://apipatientweb.azurewebsites.net/", creds); + + string res = conn.SendPostRequestAsync("api/PWReferralTypes"); + Assert.AreEqual("\"1|Endo|2|Implant|3|Oral Surgery|4|Ortho|5|Pedo|6|Perio|7|Restore|8|Other \\n\"", res); + + } + } +} diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj new file mode 100644 index 0000000..720bce6 --- /dev/null +++ b/UnitTests/UnitTests.csproj @@ -0,0 +1,74 @@ + + + + + + Debug + AnyCPU + {164B9220-F337-4E88-B619-0C52C502B9C4} + Library + Properties + UnitTests + UnitTests + v4.7.2 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + {45e26af8-41d7-4308-a2c8-d55a0350db47} + PWAPPv2 + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/UnitTests/packages.config b/UnitTests/packages.config new file mode 100644 index 0000000..f84cb10 --- /dev/null +++ b/UnitTests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file