From d9976ff5209db1f77e652a13b4ed9f18610846cb Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 28 Aug 2024 12:01:03 +0200 Subject: [PATCH] BotUser registriert und eingeloggt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Methoden zum Bot User registrieren und einloggen hinzugefügt aber auskommentiert, weil dies nur zu Debug bzw. Test gründen benutzt wurde --- .../Properties/AssemblyInfo.cs | 20 +++++ bibtalk/UnitTestProject1/UnitTest1.cs | 14 ++++ .../UnitTestProject1/UnitTestProject1.csproj | 68 ++++++++++++++++ bibtalk/UnitTestProject1/packages.config | 5 ++ .../Properties/AssemblyInfo.cs | 20 +++++ bibtalk/UnitTestProject2/UnitTest1.cs | 15 ++++ .../UnitTestProject2/UnitTestProject2.csproj | 74 ++++++++++++++++++ bibtalk/UnitTestProject2/packages.config | 5 ++ bibtalk/UserTest/GlobalUsings.cs | 1 + bibtalk/UserTest/UnitTest1.cs | 11 +++ bibtalk/UserTest/UserTest.csproj | 23 ++++++ bibtalk/UserTests/Fakes/bib-talk.fakes | Bin 0 -> 196 bytes bibtalk/UserTests/GlobalUsings.cs | 1 + bibtalk/UserTests/UnitTest1.cs | 12 +++ bibtalk/UserTests/UserTests.csproj | 34 ++++++++ bibtalk/bib-talk.sln | 2 +- bibtalk/bib-talk/Business/LoginManager.cs | 29 +++++++ bibtalk/bib-talk/Business/RegisterManager.cs | 25 ++++++ bibtalk/bib-talk/UI/Login.xaml | 2 +- bibtalk/bib-talk/UI/Login.xaml.cs | 17 +++- bibtalk/bib-talk/UI/RegisterWindow.xaml.cs | 18 ++++- 21 files changed, 391 insertions(+), 5 deletions(-) create mode 100644 bibtalk/UnitTestProject1/Properties/AssemblyInfo.cs create mode 100644 bibtalk/UnitTestProject1/UnitTest1.cs create mode 100644 bibtalk/UnitTestProject1/UnitTestProject1.csproj create mode 100644 bibtalk/UnitTestProject1/packages.config create mode 100644 bibtalk/UnitTestProject2/Properties/AssemblyInfo.cs create mode 100644 bibtalk/UnitTestProject2/UnitTest1.cs create mode 100644 bibtalk/UnitTestProject2/UnitTestProject2.csproj create mode 100644 bibtalk/UnitTestProject2/packages.config create mode 100644 bibtalk/UserTest/GlobalUsings.cs create mode 100644 bibtalk/UserTest/UnitTest1.cs create mode 100644 bibtalk/UserTest/UserTest.csproj create mode 100644 bibtalk/UserTests/Fakes/bib-talk.fakes create mode 100644 bibtalk/UserTests/GlobalUsings.cs create mode 100644 bibtalk/UserTests/UnitTest1.cs create mode 100644 bibtalk/UserTests/UserTests.csproj diff --git a/bibtalk/UnitTestProject1/Properties/AssemblyInfo.cs b/bibtalk/UnitTestProject1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..92c2db2 --- /dev/null +++ b/bibtalk/UnitTestProject1/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("UnitTestProject1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("UnitTestProject1")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("5ab576d6-0fab-4721-acc8-e94e9cdba4bc")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/bibtalk/UnitTestProject1/UnitTest1.cs b/bibtalk/UnitTestProject1/UnitTest1.cs new file mode 100644 index 0000000..cb81000 --- /dev/null +++ b/bibtalk/UnitTestProject1/UnitTest1.cs @@ -0,0 +1,14 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; + +namespace UnitTestProject1 +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestMethod1() + { + } + } +} diff --git a/bibtalk/UnitTestProject1/UnitTestProject1.csproj b/bibtalk/UnitTestProject1/UnitTestProject1.csproj new file mode 100644 index 0000000..5f3c603 --- /dev/null +++ b/bibtalk/UnitTestProject1/UnitTestProject1.csproj @@ -0,0 +1,68 @@ + + + + + + Debug + AnyCPU + {5AB576D6-0FAB-4721-ACC8-E94E9CDBA4BC} + Library + Properties + UnitTestProject1 + UnitTestProject1 + 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.2.10\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.2.2.10\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + + + 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/bibtalk/UnitTestProject1/packages.config b/bibtalk/UnitTestProject1/packages.config new file mode 100644 index 0000000..36cbc3e --- /dev/null +++ b/bibtalk/UnitTestProject1/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/bibtalk/UnitTestProject2/Properties/AssemblyInfo.cs b/bibtalk/UnitTestProject2/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8380438 --- /dev/null +++ b/bibtalk/UnitTestProject2/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("UnitTestProject2")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("UnitTestProject2")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("2206e204-1087-4204-b79d-1880c23798eb")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/bibtalk/UnitTestProject2/UnitTest1.cs b/bibtalk/UnitTestProject2/UnitTest1.cs new file mode 100644 index 0000000..525abc8 --- /dev/null +++ b/bibtalk/UnitTestProject2/UnitTest1.cs @@ -0,0 +1,15 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; + +namespace UnitTestProject2 +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestMethod1() + { + + } + } +} diff --git a/bibtalk/UnitTestProject2/UnitTestProject2.csproj b/bibtalk/UnitTestProject2/UnitTestProject2.csproj new file mode 100644 index 0000000..2f8ba2a --- /dev/null +++ b/bibtalk/UnitTestProject2/UnitTestProject2.csproj @@ -0,0 +1,74 @@ + + + + + + Debug + AnyCPU + {2206E204-1087-4204-B79D-1880C23798EB} + Library + Properties + UnitTestProject2 + UnitTestProject2 + 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.2.10\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.2.2.10\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + {92b3214e-6fb1-4d94-b93f-6f1a9d9f2224} + bib-talk + + + + + + + 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/bibtalk/UnitTestProject2/packages.config b/bibtalk/UnitTestProject2/packages.config new file mode 100644 index 0000000..36cbc3e --- /dev/null +++ b/bibtalk/UnitTestProject2/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/bibtalk/UserTest/GlobalUsings.cs b/bibtalk/UserTest/GlobalUsings.cs new file mode 100644 index 0000000..ab67c7e --- /dev/null +++ b/bibtalk/UserTest/GlobalUsings.cs @@ -0,0 +1 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file diff --git a/bibtalk/UserTest/UnitTest1.cs b/bibtalk/UserTest/UnitTest1.cs new file mode 100644 index 0000000..b38dd64 --- /dev/null +++ b/bibtalk/UserTest/UnitTest1.cs @@ -0,0 +1,11 @@ +namespace UserTest +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestMethod1() + { + } + } +} \ No newline at end of file diff --git a/bibtalk/UserTest/UserTest.csproj b/bibtalk/UserTest/UserTest.csproj new file mode 100644 index 0000000..06daf38 --- /dev/null +++ b/bibtalk/UserTest/UserTest.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + diff --git a/bibtalk/UserTests/Fakes/bib-talk.fakes b/bibtalk/UserTests/Fakes/bib-talk.fakes new file mode 100644 index 0000000000000000000000000000000000000000..ea38044b1ff4466a557ea1f7a0d2301e13c17ac1 GIT binary patch literal 196 zcmYL@!4APd7=*vG#5*+Zx;RQTadGqxyHX)lm97IXkB<=f4?8pa&&>aPRBVW}G-L{H zbeuSgS4=o?buKIkPG+alxDmyr?@?u-m-X!3Eakm=ko__P3uernU}DXfkv# + + + net6.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bibtalk/bib-talk.sln b/bibtalk/bib-talk.sln index 42d0166..a82996c 100644 --- a/bibtalk/bib-talk.sln +++ b/bibtalk/bib-talk.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33213.308 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bib-talk", "bib-talk\bib-talk.csproj", "{92B3214E-6FB1-4D94-B93F-6F1A9D9F2224}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bib-talk", "bib-talk\bib-talk.csproj", "{92B3214E-6FB1-4D94-B93F-6F1A9D9F2224}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/bibtalk/bib-talk/Business/LoginManager.cs b/bibtalk/bib-talk/Business/LoginManager.cs index e711d6a..95eaa54 100644 --- a/bibtalk/bib-talk/Business/LoginManager.cs +++ b/bibtalk/bib-talk/Business/LoginManager.cs @@ -1,4 +1,9 @@ using bib_talk.Repository; +using Newtonsoft.Json; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using System.Windows; namespace bib_talk.Business { @@ -15,5 +20,29 @@ namespace bib_talk.Business { await loginDatabase.LoginServer(); } + + public async Task LoginBots(string username, string password) + { + var loginData = new { Username = username, Password = password, Email = "", Birthday = "", IsOnline = "" }; + string json = JsonConvert.SerializeObject(loginData); + + using (var client = new HttpClient()) + { + var content = new StringContent(json, Encoding.UTF8, "application/json"); + var response = await client.PostAsync("http://daddypig.dns.navy:5114/api/users/login", content); + + if (response.IsSuccessStatusCode) + { + var responseContent = await response.Content.ReadAsStringAsync(); + var responseData = JsonConvert.DeserializeObject(responseContent); + + } + else + { + var responseContent = await response.Content.ReadAsStringAsync(); + MessageBox.Show($"Login failed: {responseContent}"); + } + } + } } } diff --git a/bibtalk/bib-talk/Business/RegisterManager.cs b/bibtalk/bib-talk/Business/RegisterManager.cs index 893a25a..c370c27 100644 --- a/bibtalk/bib-talk/Business/RegisterManager.cs +++ b/bibtalk/bib-talk/Business/RegisterManager.cs @@ -1,4 +1,8 @@ using bib_talk.Repository; +using Newtonsoft.Json; +using System.Net.Http; +using System.Text; +using System.Windows; namespace bib_talk.Business { @@ -15,5 +19,26 @@ namespace bib_talk.Business { await registerDatabase.RegisterServer(); } + + public async void RegisterBots(string username, string password, string email, string birthday) + { + var newUser = new { Username = username, Password = password, Email = email, Birthday = birthday, IsOnline = "" }; + string json = JsonConvert.SerializeObject(newUser); + + using (var client = new HttpClient()) + { + var content = new StringContent(json, Encoding.UTF8, "application/json"); + var response = await client.PostAsync("http://daddypig.dns.navy:5114/api/users/register", content); + + if (response.IsSuccessStatusCode) + { + MessageBox.Show("Registrierung erfolgreich."); + } + else + { + MessageBox.Show("Registrierung fehlgeschlagen. " + response); + } + } + } } } diff --git a/bibtalk/bib-talk/UI/Login.xaml b/bibtalk/bib-talk/UI/Login.xaml index a4d6c58..afe36d0 100644 --- a/bibtalk/bib-talk/UI/Login.xaml +++ b/bibtalk/bib-talk/UI/Login.xaml @@ -134,6 +134,6 @@ - + diff --git a/bibtalk/bib-talk/UI/Login.xaml.cs b/bibtalk/bib-talk/UI/Login.xaml.cs index 3f1dfb8..d5d83b2 100644 --- a/bibtalk/bib-talk/UI/Login.xaml.cs +++ b/bibtalk/bib-talk/UI/Login.xaml.cs @@ -3,6 +3,7 @@ using System.Windows.Media; using System.Windows; using bib_talk.Business; using System.Windows.Controls; +using System.Threading; namespace bib_talk { @@ -88,5 +89,19 @@ namespace bib_talk } } } - } + + private void LoginBotUser(object sender, RoutedEventArgs e) + { + // for (int i = 1; i <= 100; i++) + // { + // string name = "Bot"; + // string password = "Bot123"; + // loginManager.LoginBots(name + i, password); + // Thread.Sleep(1000); + //} + + + + } + } } diff --git a/bibtalk/bib-talk/UI/RegisterWindow.xaml.cs b/bibtalk/bib-talk/UI/RegisterWindow.xaml.cs index 21de0aa..eb4bfcd 100644 --- a/bibtalk/bib-talk/UI/RegisterWindow.xaml.cs +++ b/bibtalk/bib-talk/UI/RegisterWindow.xaml.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Text.RegularExpressions; +using System.Threading; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -159,6 +160,19 @@ namespace bib_talk } } - - } + + // Benutzt um 100 User accounts zu erstellen + //private void RegisterNewBots(object sender, RoutedEventArgs e) + //{ + // for (int i = 10; i <= 100; i++) + // { + // string name = "Bot"; + // string password = "Bot123"; + // string email = "bot@edu.bib.de"; + // string birthday = "12.12.2000"; + // registerManager.RegisterBots(name + i, password, i + email, birthday); + // Thread.Sleep(1000); + // } + //} + } }