Guest User

Untitled

a guest
Jun 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. [TestInitialize]
  2. public void Setup()
  3. {
  4. var unityContainer = A.Fake<IUnityContainer>();
  5.  
  6. var addTagAction = A.Fake<IAddTagAction>();
  7.  
  8. A.CallTo(() => unityContainer.Resolve(typeof(IAddTagAction), null, A<ResolverOverride[]>._)).Returns(addTagAction);
  9.  
  10. this.testee = new ActionFactory(unityContainer);
  11. }
  12.  
  13. public interface IAddTagAction : IBaseAction
  14. {
  15. }
  16.  
  17. public interface IBaseAction
  18. {
  19. void Execute(IList<long> artikelIds, int? id, RegelModel regelModel);
  20. string GetWertbezeichnung(int? wert);
  21. string GetWertbezeichnung(IList<int> werte);
  22. }
  23.  
  24. public class AddTagAction : BaseAction, IAddTagAction
  25. {
  26. public AddTagAction(
  27. IEfContextFactory efContextFactory,
  28. IRepositoryFactory repositoryFactory,
  29. IDateTimeProvider dateTimeProvider)
  30. : base(efContextFactory, repositoryFactory, dateTimeProvider)
  31. {
  32. }
  33.  
  34. public override void Execute(IList<long> artikelIds, int? tagId, RegelModel regelModel)
  35. {
  36. // ...
  37. }
  38.  
  39. /// <inheritdoc />
  40. public override string GetWertbezeichnung(IList<int> werte)
  41. {
  42. using (var context = this.EfContextFactory.Create(RequestInfo))
  43. {
  44. var tagRepository = this.RepositoryFactory.Create<ITagRepository>(context, RequestInfo);
  45. var tags = tagRepository.GetTagNames(werte.ToList()).FirstOrDefault();
  46. return tags.Value;
  47. }
  48. }
  49.  
  50. public abstract class BaseAction : IBaseAction
  51. {
  52. protected BaseAction(IEfContextFactory efContextFactory, IRepositoryFactory repositoryFactory, IDateTimeProvider dateTimeProvider)
  53. {
  54. this.EfContextFactory = efContextFactory;
  55. this.RepositoryFactory = repositoryFactory;
  56. this.DateTimeProvider = dateTimeProvider;
  57. }
  58.  
  59. protected IRepositoryFactory RepositoryFactory { get; }
  60.  
  61. protected IEfContextFactory EfContextFactory { get; }
  62.  
  63. protected IDateTimeProvider DateTimeProvider { get; }
  64.  
  65. public virtual void Execute(IList<long> artikelIds, int? id, RegelModel regelModel)
  66. {
  67. // ...
  68. }
  69.  
  70. public string GetWertbezeichnung(int? wert)
  71. {
  72. if (!wert.HasValue) {
  73. return string.Empty;
  74. }
  75. var werte = new List<int> { wert.Value };
  76. return GetWertbezeichnung(werte);
  77. }
  78.  
  79. public abstract string GetWertbezeichnung(IList<int> werte);
  80. }
Add Comment
Please, Sign In to add comment