fork download
  1. using BVC.SpotBuyCenter.Core.Case;
  2. using BVC.SpotBuyCenter.Core.Case.Cache;
  3. using BVC.SpotBuyCenter.Core.Crm.Client;
  4. using BVC.SpotBuyCenter.Core.Incoming;
  5. using BVC.SpotBuyCenter.Core.Infrastructure;
  6. using BVC.SpotBuyCenter.Core.Infrastructure.Database;
  7. using BVC.SpotBuyCenter.Services.Account;
  8. using Funq;
  9. using NLog;
  10. using NLog.Config;
  11. using NLog.Targets;
  12. using NUnit.Framework;
  13. using Raven.Abstractions.Data;
  14. using Raven.Client;
  15. using Raven.Client.Embedded;
  16. using Raven.Client.Indexes;
  17. using Raven.Client.Listeners;
  18. using ServiceStack.CacheAccess;
  19. using ServiceStack.CacheAccess.Providers;
  20. using ServiceStack.ServiceClient.Web;
  21. using ServiceStack.ServiceInterface;
  22. using ServiceStack.ServiceInterface.Auth;
  23. using ServiceStack.WebHost.Endpoints;
  24. using ServiceStack.WebHost.Endpoints.Support;
  25.  
  26. namespace BVC.SpotBuyCenter.Tests.Integration
  27. {
  28. [SetUpFixture]
  29. public class GlobalSetupFixture
  30. {
  31. public const string HostUrl = "http://localhost:9987/";
  32. public static HttpListenerBase Host;
  33. public static JsonServiceClient Client;
  34.  
  35. public static IDocumentStore Store
  36. {
  37. get { return Host.Container.Resolve<IDocumentStore>(); }
  38. }
  39.  
  40. public static IUserAuthRepository AuthRepository
  41. {
  42. get { return Host.Container.Resolve<IUserAuthRepository>(); }
  43. }
  44.  
  45. public static ICacheClient CacheClient
  46. {
  47. get { return Host.Container.Resolve<ICacheClient>(); }
  48. }
  49.  
  50. [SetUp]
  51. public void GlobalSetup()
  52. {
  53. Host = new SelfAppHost();
  54. Host.Init();
  55. Host.Start(HostUrl);
  56.  
  57. Client = new JsonServiceClient(HostUrl);
  58. }
  59.  
  60. [TearDown]
  61. public void GlobalTearDown()
  62. {
  63. Host.Dispose();
  64. Host = null;
  65. }
  66. }
  67.  
  68. public class SelfAppHost : AppHostHttpListenerBase
  69. {
  70. public SelfAppHost() : base("BVC Web Services Test Host", typeof(AccountService).Assembly) { }
  71.  
  72. public override void Configure(Container container)
  73. {
  74. container.RegisterAs<TestStorageConfig, IStorageConfig>().ReusedWithin(ReuseScope.Container);
  75.  
  76. container.Resolve<IStorageConfig>().Init(container);
  77.  
  78. MainAppHostConfiguration.Apply(this, container);
  79.  
  80. ConfigureLogging();
  81.  
  82. Plugins.Add(new AuthFeature(() => new AuthUserSession(), new[] { new CredentialsAuthProvider() }));
  83. }
  84.  
  85. private static void ConfigureLogging()
  86. {
  87. var config = new LoggingConfiguration();
  88. ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget();
  89. config.AddTarget("console", consoleTarget);
  90. consoleTarget.Layout = @"${date:format=HH\:MM\:ss} ${logger} ${message}";
  91. config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget));
  92. LogManager.Configuration = config;
  93. }
  94. }
  95.  
  96. public class TestStorageConfig : IStorageConfig
  97. {
  98. public IDocumentStore Store { get; set; }
  99.  
  100. private static readonly Logger logger = LogManager.GetCurrentClassLogger();
  101.  
  102. public void Init(Container container)
  103. {
  104. var store = new EmbeddableDocumentStore { RunInMemory = true };
  105.  
  106. logger.Debug("Initializing in-memory document store...");
  107.  
  108. store.Initialize();
  109. store.RegisterListener(new NoStaleQueriesListener());
  110. Store = store;
  111.  
  112. logger.Debug("Document store created.");
  113.  
  114. IndexCreation.CreateIndexes(typeof(ClientsByDivisionId).Assembly, Store);
  115.  
  116. container.Register(Store);
  117.  
  118. container.Register(c => c.Resolve<IDocumentStore>().OpenSession()).ReusedWithin(ReuseScope.Request);
  119.  
  120. container.RegisterAs<CaseCacheManager, ICaseCacheManager>().ReusedWithin(ReuseScope.Request);
  121. container.RegisterAs<CreateCaseFromIncomingRfpHandler, ICreateCaseFromIncomingRfpHandler>().ReusedWithin(ReuseScope.Request);
  122. container.RegisterAs<CreateCaseFromIncomingPoHandler, ICreateCaseFromIncomingPoHandler>().ReusedWithin(ReuseScope.Request);
  123. container.RegisterAs<CaseFactory, ICaseFactory>().ReusedWithin(ReuseScope.Request);
  124.  
  125. container.Register<ICacheClient>(new MemoryCacheClient());
  126. container.Register<IUserAuthRepository>(new RavenUserAuthRepository(Store));
  127. }
  128.  
  129. public DatabaseStatistics GetDbStats()
  130. {
  131. return null;
  132. }
  133. }
  134.  
  135. public class NoStaleQueriesListener : IDocumentQueryListener
  136. {
  137. public void BeforeQueryExecuted(IDocumentQueryCustomization queryCustomization)
  138. {
  139. queryCustomization.WaitForNonStaleResults();
  140. }
  141. }
  142. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty