private static DataTable ConvertToDataTable <T>(IEnumerable <T> data)
        {
            Console.WriteLine("I N S I D E    G E N E R I C   M E T H O D");

            PropertyInfo[] properties = typeof(T).GetProperties();

            DataTable table = new DataTable();

            foreach (var prop in properties)
            {
                table.Columns.Add(prop.Name, prop.PropertyType).DataType = prop.PropertyType;
            }
            int loop = 1;

            foreach (var item in data)
            {
                object[] values = properties.Select(property => property.GetValue(item)).ToArray();
                table.Rows.Add(values);

                #region D E B U G G I N G    I N F O
                Console.WriteLine(@"Loop " + loop++ + " where concrete Type is: " + item.GetType().Name);
                FooA fooA = item as FooA;
                Console.WriteLine(@"     FooA cast is: " + (fooA == null ? "Null" : "Successful"));
                FooB fooB = item as FooB;
                Console.WriteLine(@"     FooB cast is: " + (fooB == null ? "Null" : "Successful"));
                #endregion
            }

            Console.WriteLine();
            return(table);
        }
Пример #2
0
        public void Test_RequiredSpecification()
        {
            var builder = new ValidationBuilder(typeof(FooB));
            var ruleSet = builder.LowLevelRules;

            Assert.AreEqual(1, ruleSet.Rules.Count);
            object rule = ruleSet.Rules[0];

            Assert.IsInstanceOf <RequiredSpecification>(rule);
            var property = CollectionUtils.FirstElement((rule as IPropertyBoundRule).Properties);

            Assert.AreEqual(typeof(FooB).GetProperty("Name"), property);

            var foo = new FooB {
                Name = "Bob"
            };

            Assert.IsTrue(ruleSet.Test(foo).Success);

            // should fail
            foo.Name = null;
            Assert.IsFalse(ruleSet.Test(foo).Success);

            // emtpy string should fail as well
            foo.Name = "";
            Assert.IsFalse(ruleSet.Test(foo).Success);
        }
        public void FailOnExistingObjectTypeMismatchTest()
        {
            var materializer = CreateMaterializer();
            var serializer   = JsonSerializer.Create(new JsonSerializerSettings
            {
                SerializationBinder = Mock.Of <ISerializationBinder>(_ => _.BindToType(null, "FooBB") == typeof(FooBB))
            });

            var reader         = new JsonTextReader(new StringReader(@"{ ""__typename"": ""FooBB"", ""stringValue"": ""123"" }"));
            var existingObject = new FooB();

            Assert.Throws <InvalidOperationException>(() => materializer.ReadJson(reader, typeof(FooB), existingObject, serializer));
        }
Пример #4
0
		public void Test_Validate_validation_disabled()
		{
			try
			{
				var foo = new FooB() { Name = "Bethany" };
				var validator = new DomainObjectValidator();
				validator.Validate(foo);
			}
			catch (EntityValidationException)
			{
				Assert.Fail("validation was disabled and should not have failed");
			}
		}
Пример #5
0
        public void InheritanceTest()
        {
            object  something = new FooB();
            FooBase foo       = GoInterface <FooBase> .From(something);

            Assert.That(foo.Foo() == "Foo");
            Assert.That(foo.Bar() == "Bar");
            Assert.That(foo.Baz(1) == "Baz");
            Assert.That(((IBaz)foo).Baz(false) == "Baz");
            Assert.That(foo.Baz() == "Baz");

            something = new FooB();
            IBaz baz = GoInterface <IBaz> .ForceFrom(something);

            Assert.That(((IBar)baz).Bar() == "Bar");
            Assert.That(((IBar2)baz).Bar() == "Bar");
            Assert.That(baz.Baz() == "Baz");
        }
 public FooProxy(FooA a, FooB b)
 {
     this.a = a;
     this.b = b;
 }
		public void Test_RequiredSpecification()
		{
			var builder = new ValidationBuilder(typeof(FooB));
			var ruleSet = builder.LowLevelRules;

			Assert.AreEqual(1, ruleSet.Rules.Count);
			object rule = ruleSet.Rules[0];
			Assert.IsInstanceOf<RequiredSpecification>(rule);
			var property = CollectionUtils.FirstElement((rule as IPropertyBoundRule).Properties);
			Assert.AreEqual(typeof(FooB).GetProperty("Name"), property);

			var foo = new FooB {Name = "Bob"};

			Assert.IsTrue(ruleSet.Test(foo).Success);

			// should fail
			foo.Name = null;
			Assert.IsFalse(ruleSet.Test(foo).Success);

			// emtpy string should fail as well
			foo.Name = "";
			Assert.IsFalse(ruleSet.Test(foo).Success);
		}
Пример #8
0
Файл: bar.cs Проект: mono/gert
	public void Run ()
	{
		FooB foo = new FooB ();
		if (foo == null) {
		}
	}
Пример #9
0
 public static int M3B(this FooB foo, int x)
 {
     return(foo.Value + x);
 }
Пример #10
0
 public static void M2B(this FooB foo, string name)
 {
 }
Пример #11
0
 public static void M1B(this FooB foo)
 {
 }
		public void Test_Validate_validation_disabled()
		{
			try
			{
				var foo = new FooB() { Name = "Bethany" };
				var validator = new DomainObjectValidator();
				validator.Validate(foo);
			}
			catch (EntityValidationException)
			{
				Assert.Fail("validation was disabled and should not have failed");
			}
		}