Guest User

Untitled

a guest
Jun 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.81 KB | None | 0 0
  1. using NUnit.Framework;
  2. using RelevantCodes.ExtentReports;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace GettingStartedWithLoadTesting
  10. {
  11. [TestFixture]
  12. public class BasicReport
  13. {
  14. public ExtentReports extent;
  15. public ExtentTest test;
  16.  
  17. [OneTimeSetUp]
  18. public void StartReport()
  19. {
  20. string pth =
  21. System.Reflection.Assembly.GetCallingAssembly().CodeBase;
  22. string actualPath = pth.Substring(0, pth.LastIndexOf("bin"));
  23. string projectPath = new Uri(actualPath).LocalPath;
  24.  
  25. string reportPath = projectPath + "Reports\MyOwnReport.html";
  26.  
  27. extent = new ExtentReports(reportPath, true);
  28.  
  29. extent.AddSystemInfo("Host Name", "MININT-F36S5EH")
  30. .AddSystemInfo("Environment", "QA")
  31. .AddSystemInfo("User Name", "Mohamed Amine");
  32.  
  33. extent.LoadConfig(projectPath + "extent-config.xml");
  34.  
  35. }
  36.  
  37. [Test]
  38. public void DemoReportPass()
  39. {
  40. test = extent.StartTest("DemoReportPass");
  41. Assert.IsTrue(true);
  42. test.Log(LogStatus.Pass, "Assert Pass as condition is True");
  43. }
  44.  
  45. [Test]
  46. public void DemoReportFail()
  47. {
  48. test = extent.StartTest("DemoReportFail");
  49. Assert.IsTrue(false);
  50. test.Log(LogStatus.Pass, "Assert Pass as condition is Fail");
  51.  
  52. }
  53.  
  54. [TearDown]
  55. public void GetResult()
  56. {
  57. var status = TestContext.CurrentContext.Result.Outcome.Status;
  58. var stackTrace = "<pre>" +
  59. TestContext.CurrentContext.Result.StackTrace + "</pre>";
  60. var errorMessage = TestContext.CurrentContext.Result.Message;
  61.  
  62. if (status == NUnit.Framework.Interfaces.TestStatus.Failed)
  63.  
  64. {
  65. test.Log(LogStatus.Fail, stackTrace + errorMessage);
  66. }
  67. extent.EndTest(test);
  68. }
  69.  
  70. [OneTimeTearDown]
  71. public void EndReport()
  72. {
  73. extent.Flush();
  74. extent.Close();
  75. }
  76.  
  77.  
  78. }
  79. }
  80.  
  81. using System;
  82. using GettingStartedWithLoadTesting;
  83. using Microsoft.VisualStudio.TestTools.UnitTesting;
  84. using System.Collections.ObjectModel;
  85. using MS.Dynamics.TestTools.CloudCommonTestUtilities.Authentication;
  86. using MS.Dynamics.TestTools.CloudCommonTestUtilities.Enums;
  87. using Microsoft.Dynamics.TestTools.Dispatcher.Client;
  88. using MS.Dynamics.TestTools.DispatcherProxyLibrary.ApplicationForms;
  89. using MS.Dynamics.Performance.Framework.TaskRecorder;
  90. using MS.Dynamics.TestTools.CloudCommonTestUtilities;
  91. using System.Text;
  92. using System.IO;
  93. using RelevantCodes.ExtentReports;
  94.  
  95. namespace TatAutomationFramework.Web
  96.  
  97. {
  98. [TestClass]
  99. public sealed class TestFullScenarioBase
  100. {
  101. StringBuilder sb;
  102.  
  103.  
  104. /// <summary>
  105. /// Gets the test context. Use the property for setting test transactions
  106. in the performance tests.
  107. /// </summary>
  108. public TestContext TestContext
  109. {
  110. get;
  111. set;
  112. }
  113.  
  114. [TestCleanup]
  115. public void TestCleanup()
  116. {
  117. Client.Close();
  118. Client.Dispose();
  119. _userContext.Dispose();
  120. }
  121.  
  122. private DispatchedClient Client;
  123. private UserContext _userContext;
  124. private TimerProvider timerProvider;
  125. [TestInitialize​]
  126. public void TestSetup()
  127. {
  128.  
  129.  
  130.  
  131. // For multi-user uncomment following lines
  132. //if (this.TestContext != null)
  133. //{
  134. // timerProvider = new TimerProvider(this.TestContext);
  135. //}
  136. SetupData();
  137. _userContext = new UserContext(UserManagement.AdminUser);
  138. // For multi-user testing use this line
  139. // Client = new DispatchedClientHelper().GetClient();
  140. Client = DispatchedClient.DefaultInstance;
  141. Client.ForceEditMode = false;
  142. Client.Company = WellKnownCompanyID.USMF.ToString();
  143. Client.Open();
  144. }
  145.  
  146. private ClientContext CreateClientContext()
  147. {
  148. if (timerProvider != null)
  149. {
  150. return ClientContext.Create(Client, timerProvider.OnBeginTimer,
  151. timerProvider.OnEndTimer);
  152. }
  153.  
  154. return ClientContext.Create(Client);
  155. }
  156.  
  157. private PurchTable PurchTableForm;
  158. private PurchCreateOrder PurchCreateOrderForm;
  159. private string PurchCreateOrder_PurchTable_OrderAccount;
  160. private string PurchTable_PurchLine_ItemId;
  161. private string PurchTable_InventoryDimensionsGrid_InventSiteId;
  162. private decimal PurchTable_PurchLine_PurchQtyGrid;
  163. private decimal PurchTable_PurchLine_PurchPriceGrid;
  164. private PurchEditLines PurchEditLinesForm;
  165. private string PurchEditLines_PurchParmTable_Num;
  166. private void SetupData()
  167. {
  168. PurchCreateOrder_PurchTable_OrderAccount = "US_TX_008";
  169. PurchTable_PurchLine_ItemId = "A0002";
  170. PurchTable_InventoryDimensionsGrid_InventSiteId = "2";
  171. PurchTable_PurchLine_PurchQtyGrid = 3m;
  172. PurchTable_PurchLine_PurchPriceGrid = 20m;
  173. PurchEditLines_PurchParmTable_Num = "3";
  174. }
  175.  
  176. [TestMethod]
  177. public void TestFullScenario()
  178. {
  179.  
  180.  
  181.  
  182. using (var c = this.CreateClientContext())
  183. {
  184. using (var c1 = c.Navigate<PurchTable>("purchtablelistpage",
  185. Microsoft.Dynamics.TestTools.Dispatcher.MenuItemType.Display))
  186. {
  187. PurchTableForm = c1.Form<PurchTable>();
  188. using (var c2 = c1.Action("SystemDefinedNewButton_Click"))
  189. {
  190.  
  191.  
  192. Microsoft.Dynamics.TestTools.Dispatcher
  193. .Client.Controls
  194. .CommandButtonControl.Attach(PurchTableForm,"SystemDefinedNewButton")
  195. .Click();
  196. using (var c3 = c2.Attach<PurchCreateOrder>())
  197. {
  198. PurchCreateOrderForm = c3.Form<PurchCreateOrder>();
  199.  
  200. PurchCreateOrderForm.PurchTable_OrderAccount
  201. .SetValue(PurchCreateOrder_PurchTable_OrderAccount);
  202. PurchCreateOrderForm.OK.Click();
  203. }
  204. }
  205.  
  206. PurchTableForm.LineSpec.MarkActiveRow();
  207.  
  208. PurchTableForm.PurchLine_ItemId.SetValue(PurchTable_PurchLine_ItemId);
  209.  
  210. PurchTableForm
  211. .InventoryDimensionsGrid_InventSiteId
  212. .SetValue(PurchTable_InventoryDimensionsGrid_InventSiteId);
  213. PurchTableForm.PurchLine_PurchQtyGrid
  214. .SetValue(PurchTable_PurchLine_PurchQtyGrid);
  215. PurchTableForm.PurchLine_PurchPriceGrid
  216. .SetValue(PurchTable_PurchLine_PurchPriceGrid);
  217. Microsoft.Dynamics.TestTools.Dispatcher.Client
  218. .Controls.CommandButtonControl
  219. .Attach(PurchTableForm,"SystemDefinedSaveButton").Click();
  220. PurchTableForm.Purchase.Activate();
  221. PurchTableForm.ButtonConfirm.Click();
  222. PurchTableForm.Receive.Activate();
  223. using (var c4 = c1.Action("buttonUpdatePackingSlip_Click"))
  224. {
  225. PurchTableForm.ButtonUpdatePackingSlip.Click();
  226. using (var c5 = c4.Attach<PurchEditLines>())
  227. {
  228. PurchEditLinesForm = c5.Form<PurchEditLines>();
  229. PurchEditLinesForm.GridParmTable.MarkActiveRow();
  230. PurchEditLinesForm.PurchParmTable_Num
  231. .SetValue(PurchEditLines_PurchParmTable_Num);
  232. PurchEditLinesForm.OK.Click();
  233. }
  234. }
  235. }
  236.  
  237. BasicReport BsRep = new BasicReport();
  238. BsRep.StartReport();
  239. BsRep.DemoReportPass();
  240. BsRep.DemoReportFail();
  241. BsRep.GetResult();
  242. BsRep.EndReport();
  243. }
  244. }
  245.  
  246.  
  247. }
Add Comment
Please, Sign In to add comment