public void ShouldCallContainsKeysMethodOnDictionary() { var dictionary = new TestDictionary(20); Assert.That(dictionary, Does.ContainKey(20)); Assert.That(dictionary, !Does.ContainKey(10)); }
private void button16_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { TestDictionary td = new TestDictionary(openFileDialog1.FileName); Console.WriteLine(td); } }
public void FailsWhenNullDictionary() { TestDictionary dictionary = null; TestDelegate act = () => Assert.That(dictionary, new DictionaryContainsKeyValuePairConstraint("1", "World")); Assert.That(act, Throws.ArgumentException.With.Message.Contains("Expected: IDictionary But was: null")); }
public void TestContainsRemoveAdd() { var dictionary = new TestDictionary <int, string>(); dictionary.Add(new KeyValuePair <int, string>(0, "0")); Assert.AreEqual(1, dictionary.Count); Assert.True(dictionary.Contains(new KeyValuePair <int, string>(0, "0"))); Assert.True(dictionary.Remove(new KeyValuePair <int, string>(0, "0"))); Assert.False(dictionary.Contains(new KeyValuePair <int, string>(0, "0"))); Assert.AreEqual(0, dictionary.Count); }
public void WorksWithTypeThatImplementsGenericIDictionary() { var dictionary = new TestDictionary() { { 1, "World" }, { 2, "Universe" }, { 3, "Mundo" } }; Assert.That(dictionary, new DictionaryContainsKeyValuePairConstraint(3, "Mundo")); Assert.That(dictionary, Does.ContainKey(2).WithValue("Universe")); Assert.That(dictionary, Does.Not.ContainKey(1).WithValue("Universe")); }
public void Serializes_ListOfKvp_AsPocoList() { var map = new Dictionary <string, string> { { "foo", "bar" }, { "x", "y" } }; var dto = new TestDictionary { Dictionary = map, KvpList = map.ToList(), KvpEnumerable = map, }; var json = dto.ToJson(); Console.WriteLine(json); Assert.That(json, Is.EqualTo("{\"Dictionary\":{\"foo\":\"bar\",\"x\":\"y\"}," + "\"KvpList\":[{\"Key\":\"foo\",\"Value\":\"bar\"},{\"Key\":\"x\",\"Value\":\"y\"}]," + "\"KvpEnumerable\":[{\"Key\":\"foo\",\"Value\":\"bar\"},{\"Key\":\"x\",\"Value\":\"y\"}]}")); }
public void RoundtripWireformatSame() { var data = new TestDictionary() { Data = { { 1, "abc" }, { 0, "" }, { 2, "def" } } }; var clone = Serializer.DeepClone(data); Assert.Equal(3, clone.Data.Count); Assert.Equal("", clone.Data[0]); Assert.Equal("abc", clone.Data[1]); Assert.Equal("def", clone.Data[2]); using (var ms = new MemoryStream()) { Serializer.Serialize(ms, new TestIDictionary() { Data = { { 1, "abc" }, { 0, "" }, { 2, "def" } } }); var expectedHex = BitConverter.ToString(ms.ToArray()); ms.Position = 0; ms.SetLength(0); Serializer.Serialize(ms, data); var actualHex = BitConverter.ToString(ms.ToArray()); Assert.Equal(expectedHex, actualHex); } }
static void Main(string[] args) { TestDictionary testDict = new TestDictionary(); var result = testDict.TestDictionaryElements(); }
public void Serializes_ListOfKvp_AsPocoList() { var map = new Dictionary<string, string> { { "foo", "bar" }, { "x", "y" } }; var dto = new TestDictionary { Dictionary = map, KvpList = map.ToList(), KvpEnumerable = map, }; var json = dto.ToJson(); Console.WriteLine(json); Assert.That(json, Is.EqualTo("{\"Dictionary\":{\"foo\":\"bar\",\"x\":\"y\"}," + "\"KvpList\":[{\"Key\":\"foo\",\"Value\":\"bar\"},{\"Key\":\"x\",\"Value\":\"y\"}]," + "\"KvpEnumerable\":[{\"Key\":\"foo\",\"Value\":\"bar\"},{\"Key\":\"x\",\"Value\":\"y\"}]}")); }
static void Main(string[] args) { Console.WriteLine("Escolha uma opção"); Console.WriteLine("1-Delegagte"); Console.WriteLine("2-Lock"); Console.WriteLine("3-SocketTCP"); Console.WriteLine("4-Task"); Console.WriteLine("5-Threads"); Console.WriteLine("5-Collections"); var key = Console.ReadLine(); var opt = int.TryParse(key, out int result) ? result : 0; Console.WriteLine("\n"); switch (opt) { case 1: // Creates one delegate for each method. For the instance method, an // instance (mySC) must be supplied. For the static method, use the // class name. mySampleClass mySC = new mySampleClass(); myMethodDelegate myD1 = new myMethodDelegate(mySC.myStringMethod); myMethodDelegate myD2 = new myMethodDelegate(mySampleClass.mySignMethod); // Invokes the delegates. Console.WriteLine("{0} is {1}; use the sign \"{2}\".", 5, myD1(5), myD2(5)); Console.WriteLine("{0} is {1}; use the sign \"{2}\".", -3, myD1(-3), myD2(-3)); Console.WriteLine("{0} is {1}; use the sign \"{2}\".", 0, myD1(0), myD2(0)); break; case 2: Task.Run(async() => await AccountTest.MainSample()).Wait(); break; case 3: SynchronousSocketClient.StartClient(); break; case 4: TaskSample.MainSample(); break; case 5: ThreadSample.Run(); break; case 6: Console.WriteLine("Collections"); Console.WriteLine("1-ConcurrentDictionary"); Task.Run(async() => await TestDictionary.RunSample()).Wait(); break; default: Console.WriteLine("Opção inválida"); break; } }