Beispiel #1
0
 private void EnsureMockPresent(IDiscriminator <TToken> discriminator)
 {
     if (!_pack.ContainsKey(discriminator))
     {
         _pack.Add(discriminator, _mockFactory.CreateMock <TMock>());
     }
 }
Beispiel #2
0
 public ResponseCacheMiddleware(ICache cache, IDiscriminator <ResponseCacheMiddleware> discriminator, RequestDelegate next, Options.CacheResponseOptions options)
 {
     _next          = next;
     _cache         = cache;
     _discriminator = discriminator;
     _options       = options;
 }
Beispiel #3
0
        public Winner GetWinner(IList <Card> firstHand, IList <Card> secondHand)
        {
            if (firstHand == null)
            {
                throw new ArgumentNullException("firstHand");
            }
            if (secondHand == null)
            {
                throw new ArgumentNullException("secondHand");
            }

            if (firstHand.Count != 5 || secondHand.Count != 5)
            {
                throw new NotAPokerHandException();
            }
            HandType firstHandType  = GetHandType(firstHand);
            HandType secondHandType = GetHandType(secondHand);

            if ((int)firstHandType > (int)secondHandType)
            {
                return(Winner.First);
            }
            if ((int)firstHandType < (int)secondHandType)
            {
                return(Winner.Second);
            }

            IDiscriminator discriminator = DiscriminatorFactory.CreateDiscriminator(firstHandType);

            return(discriminator.GetWinnerForHandsWithSameType(firstHand, secondHand));
        }
Beispiel #4
0
 public static bool IsValid(this IDiscriminator me)
 {
     return
         (!Comparer.AreEquals(me.Id, me.Id?.GetType().GetDefaultValue()) &&
          !string.IsNullOrWhiteSpace(me.Name) &&
          !Comparer.AreEquals(me.TypeId, me.TypeId?.GetType().GetDefaultValue()) &&
          !string.IsNullOrWhiteSpace(me.TypeName));
 }
Beispiel #5
0
        public IMokkit <TToken> Customize <TMock>(IDiscriminator <TToken> discriminator, Action <TMock> customizeFn)
            where TMock : class
        {
            EnsureMockPresent <TMock>();
            var mock = _pack[discriminator] as TMock;

            customizeFn(mock);

            return(this);
        }
Beispiel #6
0
        public TMocked Resolve <TMocked>(IDiscriminator <TToken> discriminator)
            where TMocked : class
        {
            EnsureMockPresent(discriminator);
            var mock = _pack[discriminator];

            if (mock == null)
            {
                throw new InvalidOperationException("No mock created, fatal error.");
            }

            var mocked = _mockFactory.ResolveMocked <TMocked>(mock);

            return(mocked);
        }
Beispiel #7
0
        public static IEnumerable <IDiscriminator> GetAllRelated(this IDiscriminator me, ScopePropagation propagation)
        {
            var res = new List <IDiscriminator>();

            if (propagation.HasFlag(ScopePropagation.ToMe))
            {
                res.Add(me);
            }
            if (propagation.HasFlag(ScopePropagation.ToInclusions))
            {
                res.AddRange(me.GetAllInclusions());
            }
            if (propagation.HasFlag(ScopePropagation.ToExclusions))
            {
                res.AddRange(me.GetAllExclusions());
            }
            return(res);
        }
 private void LoadDiscriminator(IDiscriminator discriminator)
 {
     if (discriminator is Test.Dao.CountryDao)
     {
         var statesRef = Entry((Test.Dao.CountryDao)discriminator).Collection(c => c.States);
         if (!statesRef.IsLoaded)
         {
             statesRef.Load();
             foreach (var sta in ((Test.Dao.CountryDao)discriminator).States)
             {
                 LoadDiscriminator(sta);
             }
         }
     }
     else if (discriminator is StateDao)
     {
         var citiesRef = Entry((StateDao)discriminator).Collection(s => s.Cities);
         if (!citiesRef.IsLoaded)
         {
             citiesRef.Load();
             foreach (var cit in ((StateDao)discriminator).Cities)
             {
                 LoadDiscriminator(cit);
             }
         }
         var countryRef = Entry((StateDao)discriminator).Reference(s => s.Country);
         if (!countryRef.IsLoaded)
         {
             countryRef.Load();
             LoadDiscriminator(((StateDao)discriminator).Country);
         }
     }
     else if (discriminator is Test.Dao.CityDao)
     {
         var stateRef = Entry((Test.Dao.CityDao)discriminator).Reference(c => c.State);
         if (!stateRef.IsLoaded)
         {
             stateRef.Load();
             LoadDiscriminator(((Test.Dao.CityDao)discriminator).State);
         }
     }
 }
Beispiel #9
0
 public static bool IsValid(this IDiscriminator me) => !Comparer.AreEquals(me.TypeKey, me.TypeKey?.GetType().GetDefaultValue()) &&
 !string.IsNullOrWhiteSpace(me.TypeName);
Beispiel #10
0
 public static string ToOneLineString(this IDiscriminator me) => $"{me.TypeName} ({(string.IsNullOrWhiteSpace(me.Name?.ToString()) ? "null" : me.Name)})";
Beispiel #11
0
 public static string ToOneLineString(this IDiscriminator me)
 {
     return($"{me.TypeId} - {me.Id}");
 }
 internal void SetDiscriminator(IDiscriminator discriminator)
 {
     _discriminator = discriminator != null ?
         discriminator : NonDiscriminator.DefaultInstance;
 }
 public virtual int IndexOf(IDiscriminator discriminator)
 {
     return InnerList.IndexOf(discriminator);
 }
 public virtual bool Contains(IDiscriminator discriminator)
 {
     return InnerList.Contains(discriminator);
 }