Exemplo n.º 1
0
      public int Eval(string args) {
         string propertyName;
         args = Tokenizer.Next(args, out propertyName);

         SomeNode propertyNode;
         if (!ReplGlobals.Current.TryGetChild(propertyName, out propertyNode)) {
            throw new Exception($"Couldn't find property of name {propertyNode}.");
         }

         var propertyDto = propertyNode.PropertyDto;

         if (!propertyDto.HasSetter) {
            throw new Exception($"Property {propertyName} does not have a setter.");
         }

         string valueString;
         Tokenizer.Next(args, out valueString);
         object value = Convert.ChangeType(valueString, propertyDto.Type);

         var parameters = new[] { value };

         Console.WriteLine($"Invoking {propertyName} setter with params ({parameters.Join(", ")}.");

         var mobDto = propertyNode.Parent.MobDto;
         var result = ReplGlobals.ManagementObjectService.InvokeManagedOperationAsync(mobDto.FullName, propertyName, parameters).Result;

         Console.WriteLine("Result: ");
         ReplUtils.PrettyPrint(result);
         return 0;
      }
Exemplo n.º 2
0
 public void ShoudSelectIn()
 {
     var list = new[] {1, 2, 3, 4, 5};
     var inClause = new[] {1, 5};
     var resultList = list.Join(inClause, x => x, y => y, (x, y) => x);
     Assert.IsTrue(inClause.SequenceEqual(resultList));
 }
Exemplo n.º 3
0
 public void TestReadBlock()
 {
     var strings = new[] { "some", "new", "stuff" };
     string singleString = strings.Join(Environment.NewLine);
     var stringsTextReader = new StringsTextReader(strings);
     var buff = new char[8];
     Assert.AreEqual(8, stringsTextReader.ReadBlock(buff, 0, 8));
     Assert.AreEqual(singleString.Substring(0, 8), new string(buff));
 }
        public void Join_JoinStrings()
        {
            var strings = new[]
            {
                "a", "b", "c"
            };

            Assert.Equal("a,b,c", strings.Join(","));
        }
Exemplo n.º 5
0
        public void ReferenceOuter_ReferenceInner_ValueKey_ReferenceResult()
        {
            string[] outer = new [] {"0", "1", "2", "3", "4", "5", "6"};
            string[] inner = new [] {"0", "1", "2", "3", "4", "5", "6"};

            IEnumerable<string> result = outer.Join<string, string, int, string> (inner: inner, outerKeySelector: it => int.Parse (it), innerKeySelector: it => int.Parse (it), resultSelector: (o, i) => o);
            Assert.That (result.Count (), Is.EqualTo (result.Count ()));
            for (int i = 0; i < outer.Length; i++) {
                Assert.That (outer [i], Is.EqualTo (result.ElementAt (i)));
            }
        }
Exemplo n.º 6
0
        public void ReferenceOuter_ReferenceInner_ReferenceKey_ReferenceResult_Comparer()
        {
            IEqualityComparer<string> comparer = EqualityComparer<string>.Default;
            string[] outer = new [] {"0", "1", "2", "3", "4", "5", "6"};
            string[] inner = new [] {"0", "1", "2", "3", "4", "5", "6"};

            IEnumerable<string> result = outer.Join<string, string, string, string> (inner: inner, outerKeySelector: it => it, innerKeySelector: it => it, resultSelector: (o, i) => o, comparer: comparer);
            Assert.That (result.Count (), Is.EqualTo (result.Count ()));
            for (int i = 0; i < outer.Length; i++) {
                Assert.That (outer [i], Is.EqualTo (result.ElementAt (i)));
            }
        }
Exemplo n.º 7
0
 public void TestRead()
 {
     var strings = new[] { "some", "new", "stuff" };
     var stringsTextReader = new StringsTextReader(strings);
     foreach (char c in strings.Join(Environment.NewLine))
     {
         Assert.AreEqual((int)c, stringsTextReader.Read());
     }
     Assert.AreEqual(-1, stringsTextReader.Read());
     Assert.AreEqual(-1, stringsTextReader.Read());
     Assert.AreEqual(null, stringsTextReader.ReadLine());
     Assert.AreEqual(-1, stringsTextReader.Peek());
 }
Exemplo n.º 8
0
        public void InnerSequenceIsBuffered()
        {
            var outer = new[] { 1, 2, 3 };
            var inner = new[] { 10, 0, 2 }.Select(x => 10 / x);
            var query = outer.Join(inner, x => x, y => y, (x, y) => x + y);

            using (var iterator = query.GetEnumerator())
            {
                // Even though we could sensibly see the first element before anything
                // is returned, that doesn't happen: the inner sequence is read completely
                // before we start reading the outer sequence
                Assert.Throws<DivideByZeroException>(() => iterator.MoveNext());
            }
        }
Exemplo n.º 9
0
        public void OuterSequenceIsStreamed()
        {
            var outer = new[] { 10, 0, 2 }.Select(x => 10 / x);
            var inner = new[] { 1, 2, 3 };
            var query = outer.Join(inner, x => x, y => y, (x, y) => x + y);

            using (var iterator = query.GetEnumerator())
            {
                // First element is fine
                Assert.IsTrue(iterator.MoveNext());
                Assert.AreEqual(2, iterator.Current);

                // Attempting to get to the second element causes division by 0
                Assert.Throws<DivideByZeroException>(() => iterator.MoveNext());
            }
        }
Exemplo n.º 10
0
        public static string GetUserName(string name = null)
        {
            if (name != null)
            {
                string parts = name.Split(' ').Join(new[] { ".", "_" }.Rand());
                return parts.ToLower();
            }
            else
            {
                switch (FakerRandom.Rand.Next(2))
                {
                    case 0:
                        return new Regex(@"\W").Replace(Name.GetFirstName(), "").ToLower();
                    case 1:
                        var parts = new[] { Name.GetFirstName(), Name.GetLastName() }.Select(n => new Regex(@"\W").Replace(n, ""));
						return parts.Join(new[] { ".", "_" }.Rand()).ToLower();
                    default: throw new ApplicationException();
                }
            }
        }
Exemplo n.º 11
0
        public static void Abort(ref System.Threading.Thread thread, System.TimeSpan timeout, System.Threading.ThreadState state = System.Threading.ThreadState.Stopped)
        {
            //If the worker IsAlive and has the requested state.
            if (thread != null && (thread.IsAlive && thread.ThreadState.HasFlag(state)))
            {
                //Attempt to join
                if (false == thread.Join(timeout))
                {
                    try
                    {
                        //Abort
                        thread.Abort();
                    }
                    catch (System.Threading.ThreadAbortException) { System.Threading.Thread.ResetAbort(); }
                    catch { throw; } //Cancellation not supported
                }

                //Reset the state of the thread to indicate success
                thread = null;
            }
        }
Exemplo n.º 12
0
        public void FirstOuterMatchesLastInnerLastOuterMatchesFirstInnerSameNumberElements()
        {
            CustomerRec[] outer = new []
            {
                new CustomerRec{ name = "Prakash", custID = 98022 },
                new CustomerRec{ name = "Tim", custID = 99021 },
                new CustomerRec{ name = "Robert", custID = 99022 }
            };
            OrderRec[] inner = new []
            {
                new OrderRec{ orderID = 45321, custID = 99022, total = 50 },
                new OrderRec{ orderID = 43421, custID = 29022, total = 20 },
                new OrderRec{ orderID = 95421, custID = 98022, total = 9 }
            };
            JoinRec[] expected = new []
            {
                new JoinRec{ name = "Prakash", orderID = 95421, total = 9 },
                new JoinRec{ name = "Robert", orderID = 45321, total = 50 }
            };

            Assert.Equal(expected, outer.Join(inner, e => e.custID, e => e.custID, createJoinRec));
        }
Exemplo n.º 13
0
        private void JoinSample()
        {
            string[] names = new[] {"Robin", "Ruth", "Bob", "Emma"};
            string[] colors = new[] {"Red", "Blue", "Beige", "Green"};

            List<string> list = names.Join(colors, name => name[0], color => color[0], (name, color) => name + "-" + color).ToList();
            System.Console.WriteLine("result sequence:");
            foreach(var item in list)
            System.Console.WriteLine(item);

            //Func<string, int> calc = s => s.Length;

            
        }
Exemplo n.º 14
0
        protected string GetCompilerDefines()
        {
            var defines = new[] {
                "/d:Framework_4_0"
            };

            return defines.Join(" ");
        }
Exemplo n.º 15
0
 public void should_join_strings()
 {
     var values = new[] { "a", "sequence", "of", "strings" };
     values.Join(",").Should().Be("a,sequence,of,strings");
     values.Join("|").Should().Be("a|sequence|of|strings");
 }
Exemplo n.º 16
0
 public void TestReadToEnd()
 {
     var strings = new[] {"some", "new", "stuff"};
     var stringsTextReader = new StringsTextReader(strings);
     Assert.AreEqual(strings.Join(Environment.NewLine), stringsTextReader.ReadToEnd());
 }
Exemplo n.º 17
0
        public void InnerKeySelectorNull()
        {
            CustomerRec[] outer = new []
            {
                new CustomerRec{ name = "Prakash", custID = 98022 },
                new CustomerRec{ name = "Tim", custID = 99021 },
                new CustomerRec{ name = "Robert", custID = 99022 }
            };
            AnagramRec[] inner = new []
            {
                new AnagramRec{ name = "miT", orderID = 43455, total = 10 },
                new AnagramRec{ name = "Prakash", orderID = 323232, total = 9 }
            };

            Assert.Throws<ArgumentNullException>("innerKeySelector", () => outer.Join(inner, e => e.name, null, createJoinRec, new AnagramEqualityComparer()));
        }
Exemplo n.º 18
0
        public void SkipsNullElements()
        {
            string[] outer = new [] { null, string.Empty };
            string[] inner = new [] { null, string.Empty };
            string[] expected = new [] { string.Empty };

            Assert.Equal(expected, outer.Join(inner, e => e, e => e, (x, y) => y, EqualityComparer<string>.Default));
        }
Exemplo n.º 19
0
 public void Join()
 {
     var ints1 = new[] { 1, 2, 3, 4 };
     var ints2 = new[] { 3, 4, 5, 6 };
     var join = ints1.Join(ints2, x => x, x => x, (x, y) => x + y).ToArray();
     AssertEquals(@join.Length, 2);
     AssertEquals(@join[0], 6);
     AssertEquals(@join[1], 8);
 }
Exemplo n.º 20
0
		public void join_lists()
		{
			var values = new[] { 0, 2 };
			var fixtures = CreateSequentialFixtures(3);
			
			var sut = CreateDynamicList(values);

			var expected = values.Join(fixtures, x => x, x => x.Value, (x, i) => new
			{
				JoinValue = x,
				Identifier = i.Id
			}).ToList();

			var result = sut.Join(fixtures, x => x, x => x.Value, (x, i) => new
			{
				JoinValue = x,
				Identifier = i.Id
			}).ToList();

			Assert.Equal(expected.Count(), result.Count());

			for (int i = 0; i < expected.Count; i++)
			{
				Assert.Equal(expected[i].Identifier, result[i].Identifier);
				Assert.Equal(expected[i].JoinValue, result[i].JoinValue);
			}
		}
Exemplo n.º 21
0
        public void NullComparer()
        {
            CustomerRec[] outer = new []
            {
                new CustomerRec{ name = "Prakash", custID = 98022 },
                new CustomerRec{ name = "Tim", custID = 99021 },
                new CustomerRec{ name = "Robert", custID = 99022 }
            };
            AnagramRec[] inner = new []
            {
                new AnagramRec{ name = "miT", orderID = 43455, total = 10 },
                new AnagramRec{ name = "Prakash", orderID = 323232, total = 9 }
            };
            JoinRec[] expected = new [] { new JoinRec{ name = "Prakash", orderID = 323232, total = 9 } };

            Assert.Equal(expected, outer.Join(inner, e => e.name, e => e.name, createJoinRec, null));
        }
Exemplo n.º 22
0
 public void NoMatches()
 {
     CustomerRec[] outer = new []
     {
         new CustomerRec{ name = "Prakash", custID = 98022 },
         new CustomerRec{ name = "Bob", custID = 99022 },
         new CustomerRec{ name = "Tim", custID = 99021 },
         new CustomerRec{ name = "Robert", custID = 99022 }
     };
     OrderRec[] inner = new []
     {
         new OrderRec{ orderID = 45321, custID = 18022, total = 50 },
         new OrderRec{ orderID = 43421, custID = 29022, total = 20 },
         new OrderRec{ orderID = 95421, custID = 39021, total = 9 }
     };
     Assert.Empty(outer.Join(inner, e => e.custID, e => e.custID, createJoinRec));
 }
Exemplo n.º 23
0
        public void OuterSameKeyMoreThanOneElementAndMatches()
        {
            CustomerRec[] outer = new []
            {
                new CustomerRec{ name = "Prakash", custID = 98022 },
                new CustomerRec{ name = "Bob", custID = 99022 },
                new CustomerRec{ name = "Tim", custID = 99021 },
                new CustomerRec{ name = "Robert", custID = 99022 }
            };
            OrderRec[] inner = new []
            {
                new OrderRec{ orderID = 45321, custID = 98022, total = 50 },
                new OrderRec{ orderID = 43421, custID = 99022, total = 20 },
                new OrderRec{ orderID = 95421, custID = 99021, total = 9 }
            };
            JoinRec[] expected = new []
            {
                new JoinRec{ name = "Prakash", orderID = 45321, total = 50 },
                new JoinRec{ name = "Bob", orderID = 43421, total = 20 },
                new JoinRec{ name = "Tim", orderID = 95421, total = 9 },
                new JoinRec{ name = "Robert", orderID = 43421, total = 20 }
            };

            Assert.Equal(expected, outer.Join(inner, e => e.custID, e => e.custID, createJoinRec));
        }
Exemplo n.º 24
0
 public void SingleElementEachAndDoesntMatch()
 {
     CustomerRec[] outer = new [] { new CustomerRec { name = "Prakash", custID = 98922 } };
     OrderRec[] inner = new [] { new OrderRec { orderID = 45321, custID = 98022, total = 50 } };
     Assert.Empty(outer.Join(inner, e => e.custID, e => e.custID, createJoinRec));
 }
Exemplo n.º 25
0
        public void SingleElementEachAndMatches()
        {
            CustomerRec[] outer = new [] { new CustomerRec { name = "Prakash", custID = 98022 } };
            OrderRec[] inner = new [] { new OrderRec { orderID = 45321, custID = 98022, total = 50 } };
            JoinRec[] expected = new [] { new JoinRec { name = "Prakash", orderID = 45321, total = 50 } };

            Assert.Equal(expected, outer.Join(inner, e => e.custID, e => e.custID, createJoinRec));
        }
Exemplo n.º 26
0
 public void OuterNonEmptyInnerEmpty()
 {
     CustomerRec[] outer = new []
     {
         new CustomerRec{ name = "Tim", custID = 43434 },
         new CustomerRec{ name = "Bob", custID = 34093 }
     };
     OrderRec[] inner = { };
     Assert.Empty(outer.Join(inner, e => e.custID, e => e.custID, createJoinRec));
 }
Exemplo n.º 27
0
 public override void CancelDownload(System.Threading.Thread downloadThread)
 {
     cancel = true;
     if (downloadThread != null)
     {
         downloadThread.Abort();
         downloadThread.Join(3000);
     }
 }
Exemplo n.º 28
0
        public void SimpleJoin()
        {
            var outer = new[] {"apple", "banana", "orange", "pineapple", "pear"};
            var inner = new[] {"paul", "adam", "alex"};

            var result = outer.Join(inner,
                fruit => fruit[0],
                person => person[0],
                (fruit, person) => person + ":" + fruit);
            result.AssertSequenceEqual("adam:apple", "alex:apple", "paul:pineapple", "paul:pear");
        }
Exemplo n.º 29
0
        public void InnerNullNoComparer()
        {
            CustomerRec[] outer = new[]
            {
                new CustomerRec{ name = "Prakash", custID = 98022 },
                new CustomerRec{ name = "Tim", custID = 99021 },
                new CustomerRec{ name = "Robert", custID = 99022 }
            };
            AnagramRec[] inner = null;

            Assert.Throws<ArgumentNullException>("inner", () => outer.Join(inner, e => e.name, e => e.name, createJoinRec));
        }
Exemplo n.º 30
0
        public void ResultSelectorNullNoComparer()
        {
            CustomerRec[] outer = new[]
            {
                new CustomerRec{ name = "Prakash", custID = 98022 },
                new CustomerRec{ name = "Tim", custID = 99021 },
                new CustomerRec{ name = "Robert", custID = 99022 }
            };
            AnagramRec[] inner = new[]
            {
                new AnagramRec{ name = "miT", orderID = 43455, total = 10 },
                new AnagramRec{ name = "Prakash", orderID = 323232, total = 9 }
            };

            Assert.Throws<ArgumentNullException>("resultSelector", () => outer.Join(inner, e => e.name, e => e.name, (Func<CustomerRec, AnagramRec, JoinRec>)null));
        }