public void GetByLocation_CoordinatesValid_ExpectedResult_WithCallSaveToDb_OneRecord() { IList <HotelResult> list = new List <HotelResult> { new HotelResult() }; Dto.Result res = new Dto.Result { Results = list }; MessangerMock.Setup(m => m.GetHotelsByLocation(It.IsAny <string>())).Returns(Task.FromResult(res)) .Verifiable(); RepoMock.Setup(m => m.AddRangeHotels(It.IsAny <IEnumerable <Hotel> >())).Returns(Task.CompletedTask) .Verifiable(); var response = sut.GetByLocation("19.22,189.33").GetAwaiter().GetResult(); var hotelsDbo = Mapper.Map <IEnumerable <Hotel> >(list); var expected = Mapper.Map <List <HotelDto> >(hotelsDbo); MessangerMock.Verify(); RepoMock.Verify(x => x.AddRangeHotels(It.IsAny <IEnumerable <Hotel> >()), Times.Once); Assert.IsNotNull(response); Assert.IsInstanceOfType(response, typeof(List <HotelDto>)); Assert.AreEqual(expected.Count, response.Count); }
public void ResetTurnedOff() { SetupSettings(0, 0, 0); Resetter = new UserRequestLimitResetter(JobMock.Object, RepoMock.Object, SettingsMock.Object); Resetter.Execute(ContextMock.Object); RepoMock.Verify(x => x.Delete(It.IsAny <RequestLimit>()), Times.Never); }
// generates .dll files// public bool load_builder_files(List <String> fbuild, String child_folder, List <String> test_names) { Console.WriteLine(); Console.WriteLine("****************************"); Console.WriteLine("-------Build Started------ "); Console.WriteLine("****************************"); Process pr = new Process(); pr.StartInfo.FileName = "cmd.exe"; pr.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; String errors = ""; String output = ""; String output_build_log = ""; String file_build = ""; foreach (String t_name in test_names) { foreach (String d_file in fbuild) { Console.WriteLine(); pr.StartInfo.Arguments = "/Ccsc /target:library /out:" + t_name + ".dll " + d_file; // provide file to be built pr.StartInfo.WorkingDirectory = child_folder; pr.StartInfo.RedirectStandardError = true; pr.StartInfo.RedirectStandardOutput = true; pr.StartInfo.UseShellExecute = false; pr.Start(); pr.WaitForExit(); errors = pr.StandardError.ReadToEnd(); output = pr.StandardOutput.ReadToEnd(); output_build_log = output_build_log + " " + output; file_build = "" + "/Ccsc /target:library " + d_file; Console.WriteLine("Build Command : {0} ", file_build); file_build = ""; } using (StreamWriter wr = new StreamWriter(@"../../../Repo_Files/Build_log_" + t_name + ".txt")) { wr.WriteLine(output_build_log); } } RepoMock rm = new RepoMock(); String path = Path.GetFullPath(rm.storagePath); Console.WriteLine("*********************************************************************"); Console.WriteLine("----------Build Logs stored in :\"{0}\"---------------", path); Console.WriteLine("**********************************************************************"); if (output_build_log.Contains("error")) { return(false); } else { Console.WriteLine("*********************************************************************"); Console.WriteLine("----------------DLL Files Stored In:{0}---------------------------", System.IO.Path.GetFullPath(child_folder)); Console.WriteLine("**********************************************************************"); return(true); } }
public void Get_ReadsList() { RepoMock.Setup(r => r.ReadListAsync()).Returns(Task.FromResult(Articles)); var result = Controller.Get().Result; RepoMock.Verify(r => r.ReadListAsync(), Times.Once); var resultArticles = GetResultAndAssert(result); Assert.That(resultArticles.SequenceEqual(Articles)); }
public void Put_Updates() { var article = Articles[0]; RepoMock.Setup(r => r.UpdateAsync(article)).Returns(Task.CompletedTask); var result = Controller.Put(article.Id, article).Result; Assert.That(result is OkResult); RepoMock.Verify(r => r.UpdateAsync(article), Times.Once); }
public void Reset(int movie, int tv, int album, RequestType type) { SetupSettings(movie, tv, album); RepoMock.Setup(x => x.GetAll()) .Returns(F.Build <RequestLimit>().With(x => x.FirstRequestDate, DateTime.Now.AddDays(-8)).With(x => x.RequestType, type).CreateMany()); Resetter = new UserRequestLimitResetter(JobMock.Object, RepoMock.Object, SettingsMock.Object); Resetter.Execute(ContextMock.Object); RepoMock.Verify(x => x.Delete(It.IsAny <RequestLimit>()), Times.Exactly(3)); }
public void DoNotReset(int days, RequestType type) { SetupSettings(1, 1, 1); RepoMock.Setup(x => x.GetAll()) .Returns(F.Build <RequestLimit>().With(x => x.FirstRequestDate, DateTime.Now.AddDays(days)).With(x => x.RequestType, type).CreateMany()); Resetter = new UserRequestLimitResetter(JobMock.Object, RepoMock.Object, SettingsMock.Object); Resetter.Execute(ContextMock.Object); RepoMock.Verify(x => x.Delete(It.IsAny <RequestLimit>()), Times.Never); }
public void Get_Reads(long id) { var article = Articles.Single(a => a.Id == id); RepoMock.Setup(r => r.ReadAsync(id)).Returns(Task.FromResult(article)); var result = Controller.Get(id).Result; RepoMock.Verify(r => r.ReadAsync(id), Times.Once); var resultArticle = GetResultAndAssert(result); Assert.That(resultArticle == article); }
//<-----------------------------------------Driver Logic-------------------------------------------> static void Main(string[] args) { RepoMock repomock = new RepoMock(); Buildserver buildserver = new Buildserver(); repomock.storagePath = "../../../RepoMock/RepoStorage"; repomock.receivePath = "../../../BuildServer/BuilderStorage"; repomock.getFiles("*.*"); Dictionary <string, string> dict = buildserver.processbuildrequest("../../../BuildServer/BuilderStorage/BuildRequest.xml", repomock); List <string> files = buildserver.getbuilderfiles(); files = buildserver.processdircontents(files); List <string> outputlist = buildserver.generatedllfiles(files, dict, "../../../BuildServer/BuilderStorage"); buildserver.generatetestrequest("../../../BuildServer/BuilderStorage/BuildRequest.xml", outputlist); }
public void CreateBookings_BookingIsValid_ExpectedResult_WithoutCallSaveToDb_NullResult() { BookingDto bookingDto = new BookingDto { From = DateTime.Today, To = DateTime.Today.AddDays(1), HotelId = 1 }; Hotel hotel = new Hotel(); RepoMock.Setup(m => m.GetHotelById(It.IsAny <int>())).Returns(Task.FromResult(hotel)) .Verifiable(); var response = sut.CreateBookings(bookingDto).GetAwaiter().GetResult(); RepoMock.Verify(x => x.GetHotelById(It.IsAny <int>()), Times.Once); Assert.IsNotNull(response); Assert.IsInstanceOfType(response, typeof(string)); }
public void GetBookings_HotelIdIsValid_ExpectedResult_WithCallSaveToDb_ReturnResult() { int hotelId = 1; List <Booking> bookings = new List <Booking> { new Booking() }; RepoMock.Setup(m => m.GetBookingsByHotelId(It.IsAny <int>())).Returns(Task.FromResult(bookings)) .Verifiable(); var response = sut.GetBookings(hotelId).GetAwaiter().GetResult(); var expected = Mapper.Map <List <BookingDto> >(bookings); RepoMock.Verify(x => x.GetBookingsByHotelId(It.IsAny <int>()), Times.Once); Assert.IsNotNull(response); Assert.IsInstanceOfType(response, typeof(List <BookingDto>)); Assert.AreEqual(expected.Count, response.Count); }
//<-------------------driver logic--------------------------------> static void Main(string[] args) { printrequirementsdemo(); Executive exe = new Executive(); Client client = new Client(); BuildRequest request = client.makerequest(); RepoMock repomock = new RepoMock(); Buildserver buildserver = new Buildserver(); TestMockHarness harness = new TestMockHarness(); string xmlcontent = client.getXmlRequest(); repomock.storagePath = "../../../RepoMock/RepoStorage"; repomock.receivePath = "../../../BuildServer/BuilderStorage"; repomock.getFiles("*.*"); Console.WriteLine("\n"); Console.WriteLine("Client sent build request to MOCK REPOSITORY"); Boolean validation = repomock.parsebuildmessage(request, repomock.files); string buildrequestlocation = "../../../RepoMock/RepoStorage/BuildRequests/BuildRequest.xml"; if (validation == true) { repomock.savecontent(xmlcontent, buildrequestlocation); } Console.WriteLine("-------------------------------------------------------------------------------------------------------------"); Console.WriteLine("Demonstration of Requirement 4 command sent to mock repo"); Console.WriteLine("-------------------------------------------------------------------------------------------------------------"); repomock.processcommand("buildrequesttobuildsever", buildrequestlocation, repomock.receivePath); Dictionary <string, string> dict = buildserver.processbuildrequest("../../../BuildServer/BuilderStorage/BuildRequest.xml", repomock); List <string> files = exe.getbuilderfiles(); files = exe.processdircontents(files); List <string> outputfilelist = buildserver.generatedllfiles(files, dict, "../../../BuildServer/BuilderStorage"); buildserver.generatetestrequest("../../../BuildServer/BuilderStorage/BuildRequest.xml", outputfilelist); harness.processtestrequest("../../../MockTestHarness/DLLRepository/TestRequest.xml", buildserver); TestMockHarness.testersLocation = "../../../MockTestHarness/DLLRepository"; TestMockHarness.testersLocation = Path.GetFullPath(TestMockHarness.testersLocation); string result = harness.loadAndExerciseTesters(); Console.Write("\n\n {0}", result); Console.Write("\n\n"); }
public void CreateBookings_BookingIsValid_ExpectedResult_WithCallSaveToDb_OneRecord() { BookingDto bookingDto = new BookingDto { From = DateTime.Today, To = DateTime.Today.AddDays(1), HotelId = 1 }; Booking booking = Mapper.Map <Booking>(bookingDto); Hotel hotel = new Hotel { Id = 1, Title = "Test", Distance = 0 }; RepoMock.Setup(m => m.GetHotelById(It.IsAny <int>())).Returns(Task.FromResult(hotel)) .Verifiable(); RepoMock.Setup(m => m.AddBooking(It.IsAny <Booking>())).Returns(Task.CompletedTask) .Verifiable(); var response = sut.CreateBookings(bookingDto).GetAwaiter().GetResult(); RepoMock.Verify(x => x.GetHotelById(It.IsAny <int>()), Times.Once); RepoMock.Verify(x => x.AddBooking(It.IsAny <Booking>()), Times.Once); Assert.IsNotNull(response); Assert.IsInstanceOfType(response, typeof(string)); }
//<------------------ Contains core logic to process build request-----------------------------------> public Dictionary <string, string> processbuildrequest(string path, RepoMock mockobj) { Console.WriteLine("---------------------------------Build Server processing build request-----------------------------------"); Console.WriteLine("\n"); string xmlstring = File.ReadAllText(path); BuildRequest newRequest = xmlstring.FromXml <BuildRequest>(); repomock = mockobj; foreach (BuildItem item in newRequest.Builds) { string child = ""; List <string> parent = new List <string>(); foreach (file f in item.driver) { parent.Add(f.name); Console.WriteLine("requesting " + f.name); Console.WriteLine("\n"); repomock.processfilerequest(f.name); } foreach (file f in item.sourcefiles) { child = child + f.name + " "; Console.WriteLine("requesting " + f.name); Console.WriteLine("\n"); repomock.processfilerequest(f.name); } foreach (string str in parent) { dict.Add(str, child); } } return(dict); }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.DarkBlue; Console.BackgroundColor = ConsoleColor.White; Console.Write("\n Demonstration of Mock Repo"); Console.Write("\n ============================\n"); Console.ResetColor(); //fetch the to be built files in the repo to buildstorage RepoMock repo = new RepoMock(); repo.CopyDirectory(repo.storagePath, repo.receivePath); Console.ForegroundColor = ConsoleColor.Blue; Console.BackgroundColor = ConsoleColor.White; Console.Write("\nRepo Send build projects to build server"); Console.ResetColor(); Console.Write("\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.BackgroundColor = ConsoleColor.White; Console.Write("\n Building .csproj files "); Console.Write("\n =========================\n\n"); Console.ResetColor(); //starting building process and catch build exception BuilderDemo builder = new BuilderDemo(); try { builder.BuildCsproj(); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.BackgroundColor = ConsoleColor.White; Console.Write("\n\n An error occured while trying to build the csproj file.\n Details: {0}\n\n", ex.Message); Console.ResetColor(); } Console.Write("\n The TestHarness asked the BuildServer for the Dll files"); DllLoaderExec testharness = new DllLoaderExec(); //fetch the alreay built dll files to the testers testharness.getFiles("*.dll"); foreach (string file in testharness.files) { Console.Write("\n \"{0}\"", file); } foreach (string file in testharness.files) { string fileName = Path.GetFileName(file); Console.Write("\n sending \"{0}\" to \"{1}\"", fileName, testharness.TestreceivePath); testharness.sendFile(file); } Console.Write("\n\n"); Console.Write("\n Demonstrating Robust Test Loader"); Console.Write("\n ==================================\n"); DllLoaderExec.testersLocation = Path.GetFullPath(DllLoaderExec.testersLocation); Console.Write("\n Loading Test Modules from:\n {0}\n", DllLoaderExec.testersLocation); // run load and tests string result = testharness.loadAndExerciseTesters(); Console.Write("\n\n {0}", result); Console.Write("\n\n"); }
static void Main(string[] args) { TestExecutive testExecutive = new TestExecutive(); Client.Client client = new Client.Client(); buildRequest.buildRequest buildRequest = new buildRequest.buildRequest(); RepoMock repoMock = new RepoMock(); buildServer buildServer = new buildServer(); List <string> list; TestRequest TestRequest = new TestRequest(); TestHarness TestHarness = new TestHarness(); Dictionary <string, string> dictionary; Console.WriteLine("\n\n-------------------------Project 2: Demosntrating a Build Server------------------------------------- \n\n"); Console.WriteLine("***********************************************************************************************************\n\n"); //-------------------------------------------<Requirment 1>--------------------------------------------------------------------------------- Console.WriteLine("\n\tRequirment 1: \n\n"); Console.WriteLine("=========================================================================\n"); Console.WriteLine("\t\tProject Prepared using C# .Net Framework and Visual Studio 2017" + Environment.Version.ToString() + "\n\n"); Console.WriteLine("-----------------------------------------------------------------------------------\n\n"); //----------------------------------------------<Requirment 2>------------------------------------------------------------------------------ Console.WriteLine("\n\t Requirment 2: \n\n"); Console.WriteLine("=========================================================================\n"); Console.WriteLine("\t\tInclude a package for\n" + nameof(buildRequest) + "\n\n" + nameof(client) + "\n\n" + nameof(repoMock) + "\n\n" + nameof(buildServer) + "\n\n" + nameof(TestRequest) + "\n\n" + nameof(TestHarness) + "\n\n" + nameof(testExecutive) + "\n\n"); Console.WriteLine("------------------------------------------------------------------------------------------------------------------------\n\n\n"); //------------------------------------------------<Requirment 3>---------------------------------------------------------------------------------- Console.WriteLine("\n\n\t Requirment 3: \n"); Console.WriteLine("=========================================================================\n"); Console.WriteLine("\t\tConstructed a fixed sequence of operations of the mock repository, mock test harness, and core builder\n\n"); Console.WriteLine("------------------------------------------------------------------------------------------------------------------------\n\n\n"); Console.WriteLine("The BuiltRequest Data structure generated by the client is \n"); buildRequest = client.buildrequest(); string sendXml = client.Xml; repoMock.getFiles("*.*"); repoMock.parseRequest(buildRequest, repoMock.files); Console.WriteLine("\nBuiltRequest Sent to MockRepository"); string buildrequestLocation = "../../../repoMock/repoStorage/buildRequest/buildRequest.xml"; repoMock.savecontent(buildrequestLocation, sendXml); Console.WriteLine("\n\n Demonstrated the requirment of the builddriver xmlfile being saved in the repository\n\n"); Console.WriteLine("------------------------------------------------------------------------------------------------------------------------\n\n\n"); //----------------------------------------------<Requirment 4>------------------------------------------------------------------------------------------ Console.WriteLine("\n\n\t Requirmrnt 4: \n"); Console.WriteLine("=========================================================================\n"); Console.WriteLine("\t\tRepopsitory on demand copies a set of test source files, test drivers and test request with a test for each test driver\n\n"); Console.WriteLine("Enter command for copying a set of test source files, test drivers and test request( Enter :send)"); string command = Console.ReadLine(); repoMock.sendFile(command, buildrequestLocation, "../../../buildServer/builderStorage"); Console.WriteLine("\n\nThe Demonstrated the requirment of sending the builtRequest on command to the buildserver build storage \n"); Console.WriteLine("-----------------------------------------------------------------------------"); dictionary = buildServer.processBuild("../../../buildServer/builderStorage/buildRequest.xml", repoMock); Console.WriteLine("------------------------------------------------------------------------------------------------------------------------\n\n\n"); //--------------------------------------------<Requirment 5>-------------------------------------------------------------------------------------------- Console.WriteLine("\n\n\t Requirment 5:\n"); Console.WriteLine("=========================================================================\n"); Console.WriteLine("\t\t The build server builds each visual studio project delivered by the mock repository\n\n"); list = buildServer.getBuilderFiles(); list = buildServer.processdirectory(list); buildServer.buildFile(list, dictionary); Console.WriteLine("\n\nDemonstarted the requirment of successfully building the test files which have been sent to the build server repository\n\n"); Console.WriteLine("-----------------------------------------------------------------------------------------------------------------------------\n\n"); Console.WriteLine("------------------------------------------------------------------------------------------------------------------------\n\n\n"); //----------------------------------------------<Requirment 6>----------------------------------------------------------------------------------------- Console.WriteLine("\n\n\t Requirment 6: \n"); Console.WriteLine("=========================================================================\n"); Console.WriteLine("\t\t The builder reported to the console the success or the failure of the build, and any warning emitted\n\n"); Console.WriteLine("------------------------------------------------------------------------------------------------------------------------\n\n\n"); //----------------------------------------------<Requirment 7>------------------------------------------------------------------------------------------ Console.WriteLine("\n\n\t Requirment 7: \n"); Console.WriteLine("=========================================================================\n"); Console.WriteLine("\t\t The Builder on success delivered the built library path known by mock test harness \n\n "); TestRequest = buildServer.generateTestRequest(); string xml = buildServer.xml; repoMock.getFiles("*.*"); // buildServer.parseTestRequest(TestRequest,buildServer.files); //buildServer.parseTestRequest(TestRequest, buildServer.files); string testRequestLocation = "../../../BuildServer/BuilderStorage/TestRequest.xml"; repoMock.sendFile("send", testRequestLocation, "../../../DllLoaderDemo/testHarnessStorage"); Console.WriteLine("Demonstarted the requirment of saving the testRequest in the build server"); Console.WriteLine("------------------------------------------------------------------------------------------------------------------------\n\n\n"); //-----------------------------------------------<Requirment 8>------------------------------------------------------------------------------------------- Console.WriteLine("\n\n\t Requirment 8: \n"); Console.WriteLine("=========================================================================\n"); Console.WriteLine("\t\t The test harness attempt to load and execute each test library \n\n"); repoMock.savecontent(testRequestLocation, xml); // repoMock.sendFile("sendFile", testRequestLocation, "../../../DllLoaderDemo/testHarnessStorage"); Console.WriteLine("Demonstrated the requirment of sending the testDriver to the testHarness"); TestHarness.processTestRequest("../../../DllLoaderDemo/testHarnessStorage/TestRequest.xml", buildServer); Console.WriteLine("------------------------------------------------------------------------------------------------------------------------\n\n\n"); Console.Write("\n\n The test driver and the test file dll have been successfully sent to the test harness\n\n"); Console.WriteLine("-----------------------------------------------------------------------------------------\n"); //string loadandexecute = TestHarness.loadAndExerciseTesters(); //------------------------<For loading and executing the test libraries absolute path is required>------------------------------ TestHarness.testersLocation = Path.GetFullPath("../../../DllLoaderDemo/testHarnessStorage"); Console.Write("\n Loading Test Modules from:\n {0}\n", TestHarness.testersLocation); // run load and tests string result = TestHarness.loadAndExerciseTesters(); Console.Write("\n\n {0}", result); Console.Write("\n\n"); Console.WriteLine("\n\nDemonstrated the requirment of Simulated testing\n\n "); Console.WriteLine("--------------------------------------------------------------------------------------------------------\n\n"); Console.WriteLine("\n\n=======================================================================================================================\n\n"); }
public void call_client() { TestElement te1 = new TestElement(); te1.testName = "test1"; te1.addDriver("td1.cs"); te1.addCode("tc1.cs"); te1.addCode("tc2.cs"); //te1.addCode("tc3.cs"); TestElement te2 = new TestElement(); te2.testName = "test2"; te2.addDriver("td2.cs"); te2.addCode("tc3.cs"); te2.addCode("tc4.cs"); TestElement te3 = new TestElement(); te3.testName = "test3"; te3.addDriver("td3.cs"); te3.addCode("tc5.cs"); te3.addCode("tc6.cs"); //te1.addCode("tc3.cs"); TestElement te4 = new TestElement(); te4.testName = "test4"; te4.addDriver("td4.cs"); te4.addCode("tc7.cs"); te4.addCode("tc8.cs"); TestElement te5 = new TestElement(); te5.testName = "test5"; te5.addDriver("td5.cs"); te5.addCode("tc9.cs"); te5.addCode("tc10.cs"); TestRequest tr = new TestRequest(); tr.author = "Salim Zhulkhrni"; tr.tests.Add(te1); tr.tests.Add(te2); tr.tests.Add(te3); tr.tests.Add(te4); tr.tests.Add(te5); // creating test request // string trXml = tr.ToXml(); Console.WriteLine("************************************************"); Console.WriteLine("-----------------Test Request------------------"); Console.WriteLine("************************************************"); Console.Write(trXml); Console.WriteLine(); //sending files to the repository // RepoMock rm = new RepoMock(); rm.send_files_to_mock_repo(); Console.WriteLine(); Console.WriteLine("*********************************************************************"); Console.WriteLine("-----------------Sending Test Request to Repository------------------"); Console.WriteLine("*********************************************************************"); string repo_path = @"..\..\..\MockRepo\RepoStorage\Files\XMLDocument.xml"; File.WriteAllText(repo_path, trXml); Build_Server.Build_Server bs = new Build_Server.Build_Server(); //bs.receive_string_from_client(trXml); }