Exemple #1
1
        public void ComplexTest()
        {
            var instance = new TestClass
              {
            Bar = new TestClass1
            {
              Foo = "test"
            }
              };

              var str = TypeSerializer.SerializeToString(instance);

              var jsv = new JsvConverter();

              var result = jsv.DeserializeFromString<TestClass>(str);

              Assert.AreEqual("test", result.Bar.Foo);

              var foo = new TestClass1
              {
            Foo = "test1"
              };

              var result1 = jsv.DeserializeFromString<TestClass1>(TypeSerializer.SerializeToString(foo));

              Assert.AreEqual("test1", result1.Foo);
        }
		public void Should_return_actual_objects_HashCode()
		{
			const string testString = "Hello World!";
			var @class = new TestClass { TestValue = testString };
			var reader = new PropertyReader<TestClass>("TestValue");
			reader.GetItemHashCode(@class).ShouldEqual(testString.GetHashCode());
		}
        public void SerializeObject_WriteJson_AreEqual(string value)
        {
            var source = new TestClass { HighestCsrSeasonId = new Guid(value) };
            var target = JsonConvert.SerializeObject(source);

            Assert.AreEqual($"{{\"HighestCsrSeasonId\":\"{value}\"}}", target);
        }
		public void SetValueToNull()
		{
			ReflectorMember member = ReflectorMember.Create(GetMember("InnerClass"));
			TestClass testClass = new TestClass();
			member.SetValue(testClass, null);
			Assert.IsNull(testClass.InnerClass);
		}
 public void FindActualPropertyWithInvalidProperty()
 {
     TestClass testValue = new TestClass();
     testValue.Name = "My name";
     object property = DynamicValueUtility.FindActualProperty(testValue, "Name");
     Assert.IsNull(property, "Property found");
 }
Exemple #6
1
    //int count = 1;
    //static readonly string[] Tests = new String[] {   
    //"Add Object Authorization Rules", "Test Auth Begin Edit Rules"};

    protected override void OnCreate(Bundle bundle)
    {

      base.OnCreate(bundle);

      //Intent myIntent = new Intent(this.BaseContext, (Java.Lang.Class)new UnitDriven.MainActivity().Class); 
      //myIntent.AddFlags(ActivityFlags.NewTask); 
      //StartActivity(myIntent);

      Csla.DataPortal.ProxyTypeName = "Local";

      TestClass a = new TestClass();

      ////Csla.ApplicationContext.User = new System.Security.Principal.GenericPrincipal(new System.Security.Principal.GenericIdentity(string.Empty), new string[] { });
      // Get our button from the layout resource,
      // and attach an event to it
      //btnAddObjectAuthorizationRules = FindViewById<Button>(Resource.Id.btnAddObjectAuthorizationRules);
      //lblAddObjectAuthorizationRules = FindViewById<TextView>(Resource.Id.lblAddObjectAuthorizationRules);

      //btnAddObjectAuthorizationRules.Click += delegate { CheckAddObjectAuthorizationRules(); };

      ////System.Security.Principal.GenericPrincipal dontErase = new System.Security.Principal.GenericPrincipal(new System.Security.Principal.GenericIdentity(string.Empty), new string[] { });
      ////Csla.Security.UnauthenticatedPrincipal _principal = new Csla.Security.UnauthenticatedPrincipal();

      LoadTestItems(System.Reflection.Assembly.GetExecutingAssembly());
    }
		public void SetValue()
		{
			ReflectorMember member = ReflectorMember.Create(GetMember("Name"));
			TestClass testClass = new TestClass();
			member.SetValue(testClass, "Hello");
			Assert.AreEqual("Hello", testClass.Name);
		}
 public void CanDisposeWithUsings()
 {
   using(var myObject = new TestClass())
   {
     myObject.Should().NotBeNull();
   }
 }
        public void DictionaryOfObjects()
        {
            TestClass profileObject1 = new TestClass();
            profileObject1.Field1 = "apples";
            profileObject1.Field2 = 100;
            profileObject1.Field3 = false;

            TestClass profileObject2 = new TestClass();
            profileObject2.Field1 = "oranges";
            profileObject2.Field2 = 200;
            profileObject2.Field3 = true;

            Hashtable hash = new Hashtable();
            hash["object1"] = profileObject1;
            hash["object2"] = profileObject2;

            this.profile.SetProfile(this.ident, hash);

            IDictionary result = (IDictionary)this.profile.GetProfile(this.ident);

            Assert.AreEqual(hash.Count, result.Count, "item count");
            TestClass resultObject1 = (TestClass)result["object1"];
            Assert.AreEqual(profileObject1.Field1, resultObject1.Field1);
            Assert.AreEqual(profileObject1.Field2, resultObject1.Field2);
            Assert.AreEqual(profileObject1.Field3, resultObject1.Field3);

            TestClass resultObject2 = (TestClass)result["object2"];
            Assert.AreEqual(profileObject2.Field1, resultObject2.Field1);
            Assert.AreEqual(profileObject2.Field2, resultObject2.Field2);
            Assert.AreEqual(profileObject2.Field3, resultObject2.Field3);
        }
Exemple #10
1
        private static void Main(string[] args)
        {
            var testClass = new TestClass("TestInstance");

            Console.WriteLine("Test of integer param to a method. Expected value: 5 Return Value:" + testClass.Add(2, 3));
            Console.WriteLine("Test of double  param to a method. Expected value: 4 Return Value:" + testClass.Subtract(6, 2));

            Console.WriteLine("Test of return value of a method. Expected value: TestInstance  Return Value:" + testClass.GetName());
            Console.WriteLine("Test of generic parameters to a method. Expected value: TestClass  Return Value:" + testClass.GetTypeName<TestClass>());
            Console.WriteLine("Test of generic parameters to a method. Expected value: TestClass  Return Value:" + testClass.GetTypeName<TestClass>(testClass));

            string name = "Punit", name2 = string.Empty;

            Console.WriteLine("Test of ref parameters to a method. Expected value: Punit.appended Return Value:" + testClass.GetRefValue(ref name));
            Console.WriteLine("Value of name (ref)" + name);

            Console.WriteLine("Test of out parameters to a method. Expected value: new Value Return Value:" + testClass.GetOutValue(out name2));
            Console.WriteLine("Value of name (out)" + name2);

            Console.WriteLine("Test of static method. Expected value: NewInstance Return Value:" + TestClass.Create().Name);
            Console.WriteLine("Test of array as parameter to a method. Expected value: 2 Return Value:" + testClass.GetArrayCount(new[] { "new1", "new2" }));

            Console.WriteLine("Test of optional parameter to a method. Expected value: 8 Return Value:" + testClass.AddOptional(3));
            Console.WriteLine("Test of optional parameter to a method. Expected value: 10 Return Value:" + testClass.AddOptional(3, 7));

            Console.WriteLine("Test call of delegate");

            TestClass.MyDelegate delegateDefinition = new TestClass.MyDelegate(DelegateCalled);
            testClass.CallDelegate(delegateDefinition);

            Console.WriteLine("Name is: " + testClass.NameProperty);
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
 public void IsDisposedIsFalseByDefault()
 {
   var myObject = new TestClass();
   myObject.Should().NotBeNull();
   myObject.IsDisposed.Should().BeFalse();
   //Assert.False(myObject.IsDisposed);
 }
 public void Return_TestAttribute_When_GetAttribute_Is_Called_With_Member()
 {
     var testClass = new TestClass();
     var memberInfo = ReflectionUtility.GetMemberInfo(() => testClass.TestProperty);
     var attribute = ReflectionUtility.GetAttribute<TestAttribute>(memberInfo);
     Assert.IsNotNull(attribute);
 }
        public void ReadOnlyProperty_instance_setter()
        {
            var instance = new TestClass();
            dynamic expando = new Expando(instance);

            expando.ReadOnlyFullName = "John Doe";
        }
        public void SetPropertyPathValue_GivenSecondLevelProperty_ReturnsCorrectValue()
        {
            var test = new TestClass();
            ReflectionHelper.SetPropertyPathValue(test, "InnerTestClassObject.SomeIntProperty", 42);

            Assert.AreEqual(42, test.InnerTestClassObject.SomeIntProperty);
        }
		public void IfPropertyStepping ()
		{
			var test = new TestClass ();
			if (test.OneLineProperty == "someInvalidValue6049e709-7271-41a1-bc0a-f1f1b80d4125")/*0c64d51c-40b3-4d20-b7e3-4e3e641ec52a*/
				return;
			Console.Write ("");/*ac7625ef-ebbd-4543-b7ff-c9c5d26fd8b4*/
		}
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     if (TestClass.Any() != null)
         return;
     for (int x = 0; x < 5; ++x)
     {
         var TempObject = new TestClass();
         TempObject.BoolReference = true;
         TempObject.ByteArrayReference = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
         TempObject.ByteReference = 12;
         TempObject.CharReference = 'v';
         TempObject.DecimalReference = 1.4213m;
         TempObject.DoubleReference = 1.32645d;
         TempObject.EnumReference = TestEnum.Value2;
         TempObject.FloatReference = 1234.5f;
         TempObject.GuidReference = Guid.NewGuid();
         TempObject.IntReference = 145145;
         TempObject.LongReference = 763421;
         //TempObject.ManyToManyIEnumerable = new TestClass[] { new TestClass(), new TestClass() };
         //TempObject.ManyToManyList = new TestClass[] { new TestClass(), new TestClass(), new TestClass() }.ToList();
         //TempObject.ManyToOneIEnumerable = new TestClass[] { new TestClass(), new TestClass(), new TestClass() };
         //TempObject.ManyToOneItem = new TestClass();
         //TempObject.ManyToOneList = new TestClass[] { new TestClass(), new TestClass(), new TestClass() }.ToList();
         //TempObject.Map = new TestClass();
         TempObject.NullStringReference = null;
         TempObject.ShortReference = 5423;
         TempObject.StringReference = "agsdpghasdg";
         TempObject.Save();
     }
 }
		public void CheckIfNull ()
		{
			var testClass = new TestClass ();
			testClass.TestMethod (null);/*d42a19ec-98db-4166-a3b4-fc102ebd7905*/
			testClass.TestMethod ("notNull");/*f633d197-cb92-418a-860c-4d8eadbe2342*/
			Console.Write ("");/*6d50c480-1cd1-49a9-9758-05f65c07c037*/
		}
        public void CreateFields_ForClass_ReturnsFieldsWithAllProperties()
        {
            TestClass tc = new TestClass();
             	var fields = new List<Field>( FieldBuilder.CreateFields(tc,"kl",FieldKind.Data));

            Assert.AreEqual(4,fields.Count);
        }
        public void EndsWith_test()
        {
            var candidateObject = new TestClass() { Department = "Sales & Marketing" };

            Assert.That(new DynamicSpecification<TestClass>("Department", OperationType.EndsWith, "Marketing").IsSatisfiedBy(candidateObject), Is.True);
            Assert.That(new DynamicSpecification<TestClass>("Department", OperationType.EndsWith, "HR").IsSatisfiedBy(candidateObject), Is.False);
        }
 public void GetValue_instance_not_null()
 {
     var runtimeDynamicType = new RuntimeDynamicType(typeof(TestClass));
     var instance = new TestClass { Name = "noName" };
     var result = runtimeDynamicType.GetValue(instance, "Name");
     Assert.AreEqual(instance.Name, result);
 }
		public void SetValueWithTypeConversion()
		{
			ReflectorMember member = ReflectorMember.Create(GetMember("Count"));
			TestClass testClass = new TestClass();
			member.SetValue(testClass, "99");
			Assert.AreEqual(99, testClass.Count);
		}
 public void TryGetValue_instance_not_null_invalid_property()
 {
     var runtimeDynamicType = new RuntimeDynamicType(typeof(TestClass));
     var instance = new TestClass { Name = "NoName" };
     var result = runtimeDynamicType.TryGetValue(instance, "nothing");
     Assert.AreEqual(Undefined.Value, result);
 }
 public void ChangePropertySameType()
 {
     TestClass rootValue = new TestClass("root");
     DynamicValueUtility.PropertyValue result = DynamicValueUtility.FindProperty(rootValue, "someName");
     result.ChangeProperty("nonRoot");
     Assert.AreEqual("nonRoot", rootValue.Name, "Property not changed");
 }
        public void TestDeepProfilingInterceptionBehavior()
        {
            var profilerId = Guid.NewGuid();
            var mockProfiler = new Mock<IProfiler>();
            mockProfiler.Setup(p => p.Id).Returns(profilerId);
            var mockProfilerProvider = new Mock<IProfilerProvider>();
            mockProfilerProvider.Setup(provider => provider.Start(It.IsAny<string>(), It.IsAny<IProfilingStorage>(), It.IsAny<string[]>())).Returns(mockProfiler.Object);
            ProfilingSession.ProfilerProvider = mockProfilerProvider.Object;
            ProfilingSession.Start("test");
            var stepCalled = false;
            mockProfiler.Setup(p => p.Step(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<string>())).Callback<string, IEnumerable<string>, string>((name, tags, executeType) =>
                {
                    stepCalled = true;
                });

            var testObj = new TestClass();
            var method1 = typeof(TestClass).GetMethod("Method1");

            var mockFilter = new Mock<IDeepProfilingFilter>();
            mockFilter.Setup(f => f.ShouldBeProfiled(typeof(TestClass))).Returns(true);
            var target = new DeepProfilingInterceptionBehavior() as IInterceptionBehavior;

            Assert.AreEqual(Type.EmptyTypes, target.GetRequiredInterfaces());
            Assert.IsTrue(target.WillExecute);

            var mockInput1 = new Mock<IMethodInvocation>();
            mockInput1.Setup(i => i.MethodBase).Returns(method1);
            mockInput1.Setup(i => i.Target).Returns(testObj);

            target.Invoke(mockInput1.Object, () => ((input, next) => { testObj.Method1(); return null; }));
            Assert.IsTrue(stepCalled);
            Assert.IsTrue(testObj.Method1Invoked);
        }
 public void ShouldDetectStreamInconsistentConfiguration()
 {
     var obj = new TestClass();
     var mstream = new MemoryStream();
     var serializer = CreateSerializer();
     serializer.Serialize(obj, mstream);
     mstream.Seek(0, SeekOrigin.Begin);
     var deserializer = CreateDeserializer();
     try
     {
         deserializer.Deserialize<TestClass>(mstream);
         if(serializeWithStamps != deserializeWithStamps)
         {
             Assert.Fail("Should not deserialize when stream configuration is inconsistent.");
         }
     }
     catch(Exception e)
     {
         if(serializeWithStamps == deserializeWithStamps)
         {
             Console.WriteLine(e.Message);
             Assert.Fail("Should deserialize when stream configuration is correct.");
         }
     }
 }
        public MFTestResults SystemReflectionType_ObjectGetType_Test0()
        {
            bool fRes = true;

            ///
            /// Test object.GetType method for various types (including
            /// reflection types and arrays of reflection types).
            /// 
            object o = (object)1;
            fRes &= (o.GetType() == typeof(int));

            o = (object)typeof(Type);
            fRes &= o.GetType() == typeof(Type).GetType();

            o = AppDomain.CurrentDomain.GetAssemblies();
            fRes &= o.GetType() == typeof(Assembly[]);

            o = new TestClass();
            fRes &= o.GetType() == typeof(TestClass);

            o = new TestStruct();
            fRes &= o.GetType() == typeof(TestStruct);

            o = new MyDelegate(MyDelegateImpl);
            fRes &= o.GetType() == typeof(MyDelegate);

            o = (new MyDelegate(MyDelegateImpl)).Method;
            Debug.Print("object (MethodInfo) GetType: " + o.GetType().ToString());

            MethodInfo mi = typeof(SystemReflectionTypeTests).GetMethod("MyDelegateImpl", BindingFlags.Static | BindingFlags.NonPublic);
            fRes &= o.GetType() == mi.GetType();

            return fRes ? MFTestResults.Pass : MFTestResults.Fail;
        }
        public void SerializeObject_AreEqual()
        {
            var source = new TestClass { HighestCsrSeasonId = null };
            var target = JsonConvert.SerializeObject(source);

            Assert.AreEqual($"{{\"HighestCsrSeasonId\":null}}", target);
        }
Exemple #28
0
        public void LockingTest()
        {
            Task.Factory.StartNew(() =>
            {
                using (var repo = new FileSystemRepository<TestClass, String, String>("Test", x => Tuple.Create(x.ID, x.StringValue)))
                {
                    var obj = new TestClass("key", "value");
                    repo.Insert(obj);
                    repo.SaveChanges();

                    repo.Remove(obj);
                    repo.SaveChanges();
                }
            });

            Task.Factory.StartNew(() =>
            {
                using (var repo = new FileSystemRepository<TestClass, String, String>("Test", x => Tuple.Create(x.ID, x.StringValue)))
                {
                    var obj = new TestClass("key", "value");
                    repo.Insert(obj);
                    repo.SaveChanges();

                    repo.Remove(obj);
                    repo.SaveChanges();
                }
            });
        }
Exemple #29
0
        static void Main(string[] args)
        {
            /*
            User u1 = new User("ivo", "katunarić", 25);
            User u2 = new User("isus", "krist", 2015);

            Blog b1 = new Blog("little blog", "this is content", null);
            Blog b2 = new Blog("second blog", "this is more content", null);

            Console.WriteLine("-------");

            u1.Blogs.Add(b1);
            u1.Blogs.Add(b2);

            Console.WriteLine(u1.Blogs.Count);
            */
            //Console.WriteLine(u1.GetPropertyByName("Name"));
            //u1.SetPropertyByName("Name", "Mirko");

            Expression<Func<TestClass, string>> f = (x) => x.Name;

            MemberExpression ex = (MemberExpression) f.Body;
            var propertyInfo = (PropertyInfo) ex.Member;

            TestClass y = new TestClass();
            propertyInfo.SetValue(y, "Mirela");

            Console.WriteLine(propertyInfo.GetValue(y));
        }
        protected override void Given()
        {
            DependencyResolver.SetCurrentResolver(new StructureMapAdapter());

            this.collection = new NameValueCollection{{":Modes", "1,2,4"}};
            this.resource = new TestClass();
        }