public void ImplicitlyTypedLocalVariablesAndArraysTest() { var i = 5; Assert.AreEqual("System.Int32", i.GetType().FullName, "int로 컴파일"); var s = "ohyecloudy"; Assert.AreEqual("System.String", s.GetType().FullName, "string으로 컴파일"); var ia = new[] { 0, 1, 2 }; Assert.AreEqual("System.Int32[]", ia.GetType().FullName, "int array로 컴파일"); var istr = new[] { "ohyecloudy", "hello" }; Assert.AreEqual("System.String[]", istr.GetType().FullName, "string array로 컴파일"); var expr = from c in (new List<Customer>()) where c.City == "London" select c; Assert.AreEqual("WhereListIterator`1", expr.GetType().Name); var list = new List<int>(); Assert.AreEqual("List`1", list.GetType().Name); Assert.IsTrue(list.GetType().IsGenericType); // null 초기화 X // var mem = null; // 초기화 표현에 사용 X // var i = (i = 20); X // int i = (i = 20); O // multiple declarator 사용 X // var i, j, k; X }
public void TypeConverter_CanConvertCommentList_IsTrue() { var converter = new TypeConverter<IEnumerable<Comment>>(); var list = new List<Comment> {new Comment(), new Comment()}; var canConvert = converter.CanConvert(list.GetType()); Assert.IsTrue(canConvert); }
public void TypeConverter_CanConvertImageList_IsTrue() { var converter = new TypeConverter<IEnumerable<Image>>(); var list = new List<Image> {new Image(), new Image()}; var canConvert = converter.CanConvert(list.GetType()); Assert.IsTrue(canConvert); }
public void Ad() { var s = new string[] { "a", "b" }; var s1 = new List<string>() { "a", "b" }; var a = s.GetType(); var b = s1.GetType(); }
public void GetGenericArgumentCount_WhenGivenTypeWithOneGenericArgument_ReturnsOne() { // ARRANGE var item = new List<string>(); var type = item.GetType(); // ACT var actual = type.GetGeneGetGenricArgumentCount(); // ASSERT Assert.AreEqual(1, actual); }
public void EmptyCollectionTest() { List<int> list = new List<int>(); try { list.Sum(); } catch (ArgumentException e) { Assert.AreEqual(e.Message, string.Format("{0} is empty", list.GetType())); } }
public void GetTypeFromTypeName() { var ps = new List<Persion>(); var t = ps.GetType(); Console.WriteLine(t); Console.WriteLine(t.FullName); var t2 = Type.GetType(t.FullName); Assert.AreEqual(t, t2); Console.WriteLine(typeof(Dictionary<string, Persion>).FullName); var pa1 = new Persion[0]; var pa2 = new Persion[10]; var t3 = Type.GetType(pa1.GetType().FullName); Console.WriteLine(t3.FullName); var t4 = Type.GetType(pa2.GetType().FullName); Console.WriteLine(t4.FullName); }
public void RegisterSingleByInstanceNonGeneric_InstanceOfSameTypeAsService_Succeeds() { // Arrange var container = ContainerFactory.New(); object impl = new List<int>(); // Act container.RegisterSingleton(impl.GetType(), impl); }
public void ReturnsTrueForDerivingClass() { var genericType = typeof (List<>); var toCheck = new List<string>(); Assert.IsTrue(TypeHelper.IsSubclassOfRawGeneric(genericType, toCheck.GetType())); }
public void ReturnsFalseForNonDerivingClass() { var genericType = typeof (SavableModelBase<>); var toCheck = new List<string>(); Assert.IsFalse(TypeHelper.IsSubclassOfRawGeneric(genericType, toCheck.GetType())); }
public void GetAllSubCommoditiesTest() { //Commodity target = new Commodity(); // TODO: Initialize to an appropriate value List<Commodity> expected = new List<Commodity> { new Commodity { CommodityID = 5, Name = "Yellow Wheat",LongName = "",CommodityTypeID = 1, ParentID = 1 }, new Commodity { CommodityID = 6, Name = "Green Wheat",LongName = "",CommodityTypeID = 1, ParentID = 1 }, new Commodity { CommodityID = 8, Name = "Beans",LongName = "",CommodityTypeID = 1, ParentID = 3 }, }; List<Commodity> actual = this.MockCommodityRepository.GetAllSubCommodities(); Assert.IsInstanceOfType(actual, expected.GetType()); // Test type Assert.AreEqual(actual.Count, expected.Count); //are all elemetnts found foreach (var commodityExp in expected) { Assert.IsTrue(actual.Contains(actual.Find(c => c.CommodityID == commodityExp.CommodityID))); } //Assert.AreEqual(expected, actual); }
public void TestWriteListInt32() { List<int> value = new List<int>() { 3155, 3155 }; var name = "test"; var attribute = XFireAttributeFactory.Instance.GetAttribute(value.GetType()); using (var ms = new MemoryStream()) { using (var writer = new BinaryWriter(ms)) { attribute.WriteAll(writer, name, value); } var expected = new byte[] { 0x04, 0x74, 0x65, 0x73, 0x74, 0x04, 0x02, 0x02, 0x00, 0x53, 0x0c, 0x00, 0x00, 0x53, 0x0c, 0x00, 0x00 }; Assert.IsTrue(ms.ToArray().SequenceEqual(expected)); } }
public void GetListType() { var li = new List<int>(); Assert.AreEqual(typeof(int),ReflectionHelper.GetListType(li.GetType())); var ls = new List<string>(); Assert.AreEqual(typeof(string),ReflectionHelper.GetListType(ls.GetType())); var aString = ""; Assert.AreNotEqual(typeof(string),ReflectionHelper.GetListType(aString.GetType())); }
public void IsTypeListOfT() { var o = 1; Assert.IsFalse(ReflectionHelper.IsTypeListOfT(o.GetType())); var li = new List<int>(); Assert.IsTrue(ReflectionHelper.IsTypeListOfT(li.GetType())); var ld = new List<double>(); Assert.IsTrue(ReflectionHelper.IsTypeListOfT(ld.GetType())); }
public void IsDictionaryOfKV() { var o = 1; Assert.IsFalse(ReflectionHelper.IsDictionaryOfKV(o.GetType())); var li = new List<int>(); Assert.IsFalse(ReflectionHelper.IsDictionaryOfKV(li.GetType())); var dsi = new Dictionary<string, int>(); Assert.IsTrue(ReflectionHelper.IsDictionaryOfKV(dsi.GetType())); }
public void CanSerializeILInstructions() { CanExtracMethodFromType(); List<OpCode> codes = new List<OpCode>(); //mono cecil does all the work of getting out the IL codes from the raw binary data //reading bit by bit foreach (var il in _method.Body.Instructions) { object operand = null; var operandAsString = il.Operand as string; var operandAsInstruction = il.Operand as Mono.Cecil.Cil.Instruction; var operandAsMethodReference = il.Operand as Mono.Cecil.MethodReference; var operandAsParameterDef = il.Operand as Mono.Cecil.ParameterDefinition; // stand alone commmand that doesn't need a paramters if (il.Operand == null) { operand = null; } else if (operandAsInstruction != null) { operand = new OpCode() { Name = operandAsInstruction.OpCode.Name, Operand = operandAsInstruction.Operand }; } //load a string else if (operandAsString != null) { operand = operandAsString; } //load a constant number else if (il.Operand is int) { operand = il.Operand; } //something like a call virtual, for a method on a type else if (operandAsMethodReference != null) { operand = new Compile.Types.MethodReference() {FullName = operandAsMethodReference.FullName }; } else if (operandAsParameterDef != null) { //operand = new Compile.Types.ParameterDefinition() { FullName = operandAsParameterDef.Method.; } else { int xxx = 3; } var newCode = new OpCode() { Name = il.OpCode.Name, Operand = operand }; codes.Add(newCode); } //dammit i hate serialization. this isn't working but just do whatever is needed to serialize this information SerializeObject(codes.GetType(), codes); }
public void IsGenericTypeWithFirstDynamicTypeArgument_WhenGivenGenericTypeWithNonDynamicType_ReturnsFalse() { // ARRANGE var item = new List<string>(); var type = item.GetType(); // ACT var actual = type.IsGenericTypeWithFirstDynamicTypeArgument(); // ASSERT Assert.IsFalse(actual); }
public void IsGenericType_WhenGivenGenericType_ReturnsTrue() { // ARRANGE var item = new List<string>(); var type = item.GetType(); // ACT var actual = type.IsGenericType(); // ASSERT Assert.IsTrue(actual); }
public void Run() { var list = new List<int>(); var type = list.GetType(); Console.WriteLine(type); }
public void IsGenericTypeWithFirstDynamicTypeArgument_WhenGivenGenericTypeWithDynamicType_ReturnsTrue() { // ARRANGE var item = new List<ExpandoObject>(); var type = item.GetType(); // ACT var actual = type.IsGenericTypeWithFirstDynamicTypeArgument(); // ASSERT Assert.IsTrue(actual); }
public void TypeConverter_CanConvertInt_IsFalse() { var converter = new TypeConverter<Image>(); var list = new List<int> {1, 2, 3}; Assert.IsFalse(converter.CanConvert(list.GetType())); }