Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [TestInitialize]
- public void Setup()
- {
- var unityContainer = A.Fake<IUnityContainer>();
- var addTagAction = A.Fake<IAddTagAction>();
- A.CallTo(() => unityContainer.Resolve(typeof(IAddTagAction), null, A<ResolverOverride[]>._)).Returns(addTagAction);
- this.testee = new ActionFactory(unityContainer);
- }
- public interface IAddTagAction : IBaseAction
- {
- }
- public interface IBaseAction
- {
- void Execute(IList<long> artikelIds, int? id, RegelModel regelModel);
- string GetWertbezeichnung(int? wert);
- string GetWertbezeichnung(IList<int> werte);
- }
- public class AddTagAction : BaseAction, IAddTagAction
- {
- public AddTagAction(
- IEfContextFactory efContextFactory,
- IRepositoryFactory repositoryFactory,
- IDateTimeProvider dateTimeProvider)
- : base(efContextFactory, repositoryFactory, dateTimeProvider)
- {
- }
- public override void Execute(IList<long> artikelIds, int? tagId, RegelModel regelModel)
- {
- // ...
- }
- /// <inheritdoc />
- public override string GetWertbezeichnung(IList<int> werte)
- {
- using (var context = this.EfContextFactory.Create(RequestInfo))
- {
- var tagRepository = this.RepositoryFactory.Create<ITagRepository>(context, RequestInfo);
- var tags = tagRepository.GetTagNames(werte.ToList()).FirstOrDefault();
- return tags.Value;
- }
- }
- public abstract class BaseAction : IBaseAction
- {
- protected BaseAction(IEfContextFactory efContextFactory, IRepositoryFactory repositoryFactory, IDateTimeProvider dateTimeProvider)
- {
- this.EfContextFactory = efContextFactory;
- this.RepositoryFactory = repositoryFactory;
- this.DateTimeProvider = dateTimeProvider;
- }
- protected IRepositoryFactory RepositoryFactory { get; }
- protected IEfContextFactory EfContextFactory { get; }
- protected IDateTimeProvider DateTimeProvider { get; }
- public virtual void Execute(IList<long> artikelIds, int? id, RegelModel regelModel)
- {
- // ...
- }
- public string GetWertbezeichnung(int? wert)
- {
- if (!wert.HasValue) {
- return string.Empty;
- }
- var werte = new List<int> { wert.Value };
- return GetWertbezeichnung(werte);
- }
- public abstract string GetWertbezeichnung(IList<int> werte);
- }
Add Comment
Please, Sign In to add comment