Beispiel #1
0
 /// <summary>
 ///     Internal constructor with all dependencies.
 /// </summary>
 internal InjectionDetector(
     IInjectionAlerter alerter,
     ITypeIdGenerator typeIdGenerator,
     IStamper <object> stateStamper,
     IStamper <Type> codeStamper,
     bool scanCode, bool scanState,
     InjectionAlertChannel alertChannel)
 {
     if (alerter == null)
     {
         throw new ArgumentNullException(nameof(alerter));
     }
     if (stateStamper == null)
     {
         throw new ArgumentNullException(nameof(stateStamper));
     }
     if (codeStamper == null)
     {
         throw new ArgumentNullException(nameof(codeStamper));
     }
     _alerter         = alerter;
     _typeIdGenerator = typeIdGenerator;
     _stateStamper    = stateStamper;
     _codeStamper     = codeStamper;
     _alertChannel    = alertChannel;
     ScanCode         = scanCode;
     ScanState        = scanState;
 }
        private static IInjectionDetector GetSut(bool protectCode              = true, bool protectState = true,
                                                 bool isStateValid             = true, bool isCodeValid  = true, IStamper <object> stateStamper = null,
                                                 IStamper <Type> codeStamper   = null, IInjectionAlerter alerter = null,
                                                 InjectionAlertChannel channel = Defaults.AlertChannel)
        {
            var codeStampMock = new Mock <IStamp>();

            codeStampMock.Setup(m => m.Equals(It.IsAny <IStamp <int> >())).Returns(isCodeValid);
            var stateStampMock = new Mock <IStamp>();

            stateStampMock.Setup(m => m.Equals(It.IsAny <IStamp <int> >())).Returns(isStateValid);
            var stateStamperMock = new Mock <IStamper <object> >();

            stateStamperMock.Setup(m => m.GetStamp(It.IsAny <object>())).Returns(stateStampMock.Object);
            var codeStamperMock = new Mock <IStamper <Type> >();

            codeStamperMock.Setup(m => m.GetStamp(It.IsAny <Type>())).Returns(codeStampMock.Object);
            return(new InjectionDetector(alerter ?? Mock.Of <IInjectionAlerter>(), Stubs.Get <ITypeIdGenerator>(),
                                         stateStamper ?? stateStamperMock.Object, codeStamper ?? codeStamperMock.Object, protectCode,
                                         protectState, channel));
        }