Example #1
0
        public void CastingCollectionOfClassToAnotherThroughtInterfaceShouldWork()
        {
            var t = new GenericTestsClassT() { Id = 1, Name = "T", CustomT = "CustomT", UnexpectedCommonName = "Common" };

            var collection = new HashSet<GenericTestsClassT>() { t };

            var result = collection.Cast<GenericTestsClassT, GenericTestsClassU, GenericTestsInterfaceI>().SingleOrDefault();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Id);
            Assert.AreEqual("T", result.Name);
            Assert.IsNull(result.CustomU);
            Assert.IsNull(result.UnexpectedCommonName);
        }
 static DisjunctiveExamplesSpec WitnessK(GrammarRule rule, int parameter, DisjunctiveExamplesSpec spec)
 {
     var result = new Dictionary<State, IEnumerable<object>>();
     foreach (var example in spec.DisjunctiveExamples)
     {
         State inputState = example.Key;
         var ks = new HashSet<int?>();
         var inp = (string)inputState[rule.Body[0]];
         foreach (int? pos in example.Value)
         {
             ks.Add(pos);
             ks.Add(pos - inp.Length - 1);
         }
         if (ks.Count == 0) return null;
         result[inputState] = ks.Cast<object>();
     }
     return new DisjunctiveExamplesSpec(result);
 }
Example #3
0
        public void PersistentActor_should_support_a_mix_of_persist_calls_sync_async_and_persist_calls()
        {
            var pref = ActorOf(Props.Create(() => new AsyncPersistAndPersistMixedSyncAsyncActor(Name)));
            pref.Tell(new Cmd("a"));
            pref.Tell(new Cmd("b"));
            pref.Tell(new Cmd("c"));

            ExpectMsg("a");
            ExpectMsg("a-e1-1");    // persist, must be before next command

            var expected = new HashSet<string> { "b", "a-ea2-2" };
            var found = ExpectMsgAnyOf(expected.Cast<object>().ToArray());  // ea2 is PersistAsyn, b can be processed before it
            expected.Remove(found.ToString());
            ExpectMsgAnyOf(expected.Cast<object>().ToArray());

            ExpectMsg("b-e1-3");        // persist, must be before next command

            var expected2 = new HashSet<string> { "c", "b-ea2-4" };
            var found2 = ExpectMsgAnyOf(expected2.Cast<object>().ToArray());
            expected.Remove(found2.ToString());
            ExpectMsgAnyOf(expected2.Cast<object>().ToArray());

            ExpectMsg("c-e1-5");
            ExpectMsg("c-ea2-6");

            ExpectNoMsg(TimeSpan.FromMilliseconds(100));
        }
 static DisjunctiveExamplesSpec WitnessKForRegexPair(GrammarRule rule, int parameter,  DisjunctiveExamplesSpec spec, ExampleSpec rrSpec)
 {
     var result = new Dictionary<State, IEnumerable<object>>();
     foreach (var example in spec.DisjunctiveExamples)
     {
         State inputState = example.Key;
         var inp = (string)inputState[rule.Body[0]];
         var regexPair = (Tuple<Regex, Regex>)rrSpec.Examples[inputState];
         Regex left = regexPair.Item1;
         Regex right = regexPair.Item2;
         var rightMatches = right.Matches(inp).Cast<Match>().ToDictionary(m => m.Index);
         var matchPositions = new List<int>();
         foreach (Match m in left.Matches(inp))
         {
             if (rightMatches.ContainsKey(m.Index + m.Length))
                 matchPositions.Add(m.Index + m.Length);
         }
         var ks = new HashSet<int?>();
         foreach (int? pos in example.Value)
         {
             int occurrence = matchPositions.BinarySearch(pos.Value);
             if (occurrence < 0) continue;
             ks.Add(occurrence);
             ks.Add(occurrence - matchPositions.Count);
         }
         if (ks.Count == 0) return null;
         result[inputState] = ks.Cast<object>();
     }
     return new DisjunctiveExamplesSpec(result);
 }