fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using BVC.SpotBuyCenter.Core.Infrastructure.Database;
  5. using Raven.Abstractions.Data;
  6. using Raven.Client;
  7. using Raven.Client.Indexes;
  8. using ServiceStack.CacheAccess.Providers;
  9. using ServiceStack.ServiceClient.Web;
  10. using ServiceStack.ServiceInterface.Auth;
  11. using ServiceStack.WebHost.Endpoints.Support;
  12.  
  13. namespace BVC.SpotBuyCenter.Tests.Integration
  14. {
  15. public abstract class IntegrationBaseTest
  16. {
  17. protected string HostUrl
  18. {
  19. get { return GlobalSetupFixture.HostUrl; }
  20. }
  21.  
  22. protected HttpListenerBase Host
  23. {
  24. get { return GlobalSetupFixture.Host; }
  25. }
  26.  
  27. protected IDocumentStore Store
  28. {
  29. get { return GlobalSetupFixture.Store; }
  30. }
  31.  
  32. protected JsonServiceClient Client
  33. {
  34. get { return GlobalSetupFixture.Client; }
  35. }
  36.  
  37. protected IUserAuthRepository AuthRepository
  38. {
  39. get { return GlobalSetupFixture.AuthRepository; }
  40. }
  41.  
  42. protected void Seed(Action<IDocumentSession> seedAction)
  43. {
  44. using (var session = Store.OpenSession())
  45. {
  46. seedAction.Invoke(session);
  47.  
  48. session.SaveChanges();
  49. }
  50. Store.ClearStaleIndexes();
  51. }
  52.  
  53. protected void ClearDb()
  54. {
  55. new RavenDocumentsByEntityName().Execute(Store);
  56. Store.ClearStaleIndexes();
  57. Store.DatabaseCommands.DeleteByIndex("Raven/DocumentsByEntityName", new IndexQuery { Query = "Tag: *" });
  58.  
  59. GlobalSetupFixture.CacheClient.ClearCaches();
  60. }
  61.  
  62. protected UserAuth Login(string role = null, string email = "testuser@example.com", string password = "testpass")
  63. {
  64. var roles = new List<string>();
  65.  
  66. if (role != null)
  67. {
  68. roles.Add(role);
  69. }
  70.  
  71. return Login(roles, email, password);
  72. }
  73.  
  74. protected UserAuth Login(IEnumerable<string> roles = null, string email = "testuser@example.com", string password = "testpass")
  75. {
  76. var user = new UserAuth
  77. {
  78. Email = email,
  79. Roles = (roles ?? new string[] { }).ToList()
  80. };
  81.  
  82. AuthRepository.CreateUserAuth(user, password);
  83.  
  84. Client.Post(new Auth {
  85. provider = CredentialsAuthProvider.Name,
  86. UserName = email,
  87. Password = password
  88. });
  89.  
  90. return user;
  91. }
  92. }
  93. }
  94.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty