Guest User

Untitled

a guest
Jun 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. static int instCount = 0;
  2.  
  3. public FakeAutocompleteRepository()
  4. {
  5. instCount++;
  6. ...
  7. }
  8.  
  9. [PartCreationPolicy(CreationPolicy.Shared)]
  10. [Export(typeof(IAutocompleteRepository))]
  11. [ExportMetadata("IsTesting", "True")]
  12. class FakeAutocompleteRepository : IAutocompleteRepository
  13. { ... }
  14.  
  15. var catalog = new AggregateCatalog();
  16. catalog.Catalogs.Add(new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly()));
  17. catalog.Catalogs.Add(new DirectoryCatalog("."));
  18. var container = new CompositionContainer(catalog);
  19. var batch = new CompositionBatch();
  20. batch.AddPart(this);
  21. container.Compose(batch);
  22.  
  23.  
  24. if (null != ConfigurationSettings.AppSettings["IsTesting"] && bool.Parse(ConfigurationSettings.AppSettings["IsTesting"]))
  25. repository = container.GetExports<IAutocompleteRepository>().Where(expDef => expDef.Metadata.Keys.Contains("IsTesting")).Single().GetExportedObject();
  26.  
  27. [Export("/MyViewModel")]
  28. public class MyViewModel
  29. {
  30. [ImportingConstructor]
  31. public MyViewModel(
  32. [Import("/Services/LoggingService")] ILoggingService l)
  33. {
  34. logger = l;
  35. }
  36.  
  37. private ILoggingService logger { get; set; }
  38.  
  39. /* ... */
  40. }
  41.  
  42. MyViewModel target = new MyViewModel(new MockLoggingService());
Add Comment
Please, Sign In to add comment