Пример #1
0
        public void Test_ShouldHaveDefault_WithLambda_WithSpecifiedValue_WhenNotHasDefault_ShouldAssertFalse()
        {
            //---------------Set up test pack-------------------
            IClassDef    classDef                 = SetupClassDefWithAddProperty <BOFakeWithDefault>();
            const string propName                 = "NonDefaultProp";
            IPropDef     propDef                  = classDef.GetPropDef(propName);
            const string defaultValueString       = "SomeOtherValue";
            BOTester <BOFakeWithDefault> boTester = CreateGenericTester <BOFakeWithDefault>();

            //---------------Assert Precondition----------------
            Assert.IsNullOrEmpty(propDef.DefaultValueString);
            Assert.AreNotEqual(defaultValueString, propDef.DefaultValueString);
            //---------------Test Result -----------------------
            try
            {
                boTester.ShouldHaveDefault(bo => bo.NonDefaultProp, defaultValueString);
                Assert.Fail("Expected to throw an AssertionException");
            }
            //---------------Test Result -----------------------
            catch (AssertionException ex)
            {
                string expected = string.Format("The Property '{0}' for class '{1}' should have a default but does not", propName, "BOFakeWithDefault");
                StringAssert.Contains(expected, ex.Message);
            }
        }
Пример #2
0
        public void Test_ShouldHaveReadWriteRule_WithLambda_WriteNew_WhenIsNot_ShouldAssertFalse()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = SetupClassDef <FakeBOWithReadWriteRuleProp>();
            BOTester <FakeBOWithReadWriteRuleProp> boTester = CreateGenericTester <FakeBOWithReadWriteRuleProp>();
            const string propName     = "ReadWriteRuleReadOnly";
            var          propertyInfo =
                ReflectionUtilities.GetPropertyInfo <FakeBOWithReadWriteRuleProp, object>(bo => bo.ReadWriteRuleReadOnly);
            var propertyWrapper = propertyInfo.ToPropertyWrapper();
            const PropReadWriteRule expectedReadWriteRule = PropReadWriteRule.WriteNew;

            //---------------Assert Precondition----------------
            Assert.IsTrue(propertyWrapper.HasAttribute <AutoMapReadWriteRuleAttribute>());
            IPropDef propDef = classDef.GetPropDef(propName);

            Assert.IsNotNull(propDef);
            Assert.AreNotEqual(expectedReadWriteRule, propDef.ReadWriteRule);
            //---------------Test Result -----------------------
            try
            {
                boTester.ShouldHaveReadWriteRule(bo => bo.ReadWriteRuleReadOnly, expectedReadWriteRule);
                Assert.Fail("Expected to throw an AssertionException");
            }
            //---------------Test Result -----------------------
            catch (AssertionException ex)
            {
                string expected = string.Format(
                    "The Property '{0}' for class '{1}' should have a ReadWriteRule '{2}' but is '{3}'",
                    propDef.PropertyName,
                    propDef.ClassName, expectedReadWriteRule, propDef.ReadWriteRule);
                StringAssert.Contains(expected, ex.Message);
            }
        }
Пример #3
0
        public void Test_ShouldHavePropertyMapped_WithLambda_WhenGetterNotMapped_ShouldAssertFalse()
        {
            //---------------Set up test pack-------------------
            const string propertyName = "GetterNotMapped";

            SetupClassDefWithAddProperty <FakeBOWithIncorrectMappings>();
            var newValue = GetRandomString();
            BOTester <FakeBOWithIncorrectMappings> boTester = CreateGenericTester <FakeBOWithIncorrectMappings>();
            FakeBOWithIncorrectMappings            bo       = (FakeBOWithIncorrectMappings)boTester.BusinessObject;

            bo.GetterNotMapped = newValue;
            //---------------Assert Precondition----------------
            Assert.AreNotEqual(newValue, bo.GetterNotMapped);
            //---------------Test Result -----------------------
            try
            {
                boTester.ShouldHavePropertyMapped(bo1 => bo1.GetterNotMapped);
                Assert.Fail("Expected to throw an AssertionException");
            }
            //---------------Test Result -----------------------
            catch (AssertionException ex)
            {
                string expected = string.Format("The Getter And Setter for the Property '{0}' for class '{1}'"
                                                + " are not both mapped to the same BOProp. Check the Property in your code"
                                                , propertyName, "FakeBOWithIncorrectMappings");
                StringAssert.Contains(expected, ex.Message);
            }
        }
Пример #4
0
        public void Test_ShouldHaveDefault_WithLambda_WhenHasDefault_ShouldAssertTrue()
        {
            //---------------Set up test pack-------------------
            SetupClassDef <BOFakeWithDefault>();
            BOTester <BOFakeWithDefault> boTester = CreateGenericTester <BOFakeWithDefault>();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            boTester.ShouldHaveDefault(bo => bo.DefaultProp);
            //---------------Test Result -----------------------
            Assert.IsTrue(true, "If it has got here then passed");
        }
        public void Test_this_WithFirstName_WhenPropHasError_ShouldShowError()
        {
            //---------------Set up FakeObservableBO pack-------------------
            var FakeObservableBO = new FakeObservableBO();
            var boTester         = new BOTester <FakeObservableBO>();

            //---------------Assert Precondition----------------
            boTester.ShouldBeCompulsory(emp => emp.Prop1);
            //---------------Execute Test ----------------------
            var errorForFirstName = FakeObservableBO["Prop1"];

            //---------------Test Result -----------------------
            StringAssert.Contains("FakeObservableBO.Prop 1' is a compulsory field and has no value", errorForFirstName);
        }
Пример #6
0
        public void Test_ShouldNotBeCompulsory_WithLambda_WhenNonCompulsory_ShouldAssertTrue()
        {
            //---------------Set up test pack-------------------
            SetupClassDef <BOFakeWithCompulsory>();
            BOTester <BOFakeWithCompulsory> boTester = CreateGenericTester <BOFakeWithCompulsory>();
            var propertyInfo    = ReflectionUtilities.GetPropertyInfo <BOFakeWithCompulsory, object>(bo => bo.NonCompulsoryProp);
            var propertyWrapper = propertyInfo.ToPropertyWrapper();

            //---------------Assert Precondition----------------
            Assert.IsFalse(propertyWrapper.HasAttribute <AutoMapCompulsoryAttribute>());
            //---------------Execute Test ----------------------
            boTester.ShouldNotBeCompulsory(bo => bo.NonCompulsoryProp);
            //---------------Test Result -----------------------
            Assert.IsTrue(true, "If it has got here then passed");
        }
        public void Test_Error_WhenPropHasError_ShouldShowError()
        {
            //---------------Set up test pack-------------------
            var FakeObservableBO = new FakeObservableBO();
            var boTester         = new BOTester <FakeObservableBO>();

            //---------------Assert Precondition----------------
            boTester.ShouldBeCompulsory(emp => emp.Prop1);
            boTester.ShouldBeCompulsory(emp => emp.Prop2);
            //---------------Execute Test ----------------------
            var error = FakeObservableBO.Error;

            //---------------Test Result -----------------------
            StringAssert.Contains("FakeObservableBO.Prop 1' is a compulsory field and has no value", error);
            StringAssert.Contains("FakeObservableBO.Prop 2' is a compulsory field and has no value", error);
        }
Пример #8
0
        public void Test_ShouldNotHaveDefault_WithLambda_WithSpecifiedValue_WhenNotHasDefault_ShouldAssertTrue()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = SetupClassDef <BOFakeWithDefault>();
            BOTester <BOFakeWithDefault> boTester = CreateGenericTester <BOFakeWithDefault>();
            const string propName           = "NonDefaultProp";
            const string defaultValueString = "SomeValue";
            IPropDef     propDef            = classDef.GetPropDef(propName);

            //---------------Assert Precondition----------------
            Assert.IsNullOrEmpty(propDef.DefaultValueString);
            //---------------Execute Test ----------------------
            boTester.ShouldNotHaveDefault(bo => bo.NonDefaultProp, defaultValueString);
            //---------------Test Result -----------------------
            Assert.IsTrue(true, "If it has got here then passed");
        }
Пример #9
0
        public void Test_ShouldHaveReadWriteRule_WithLambda_ReadOnly_WhenIs_ShouldAssertTrue()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = SetupClassDef <FakeBOWithReadWriteRuleProp>();
            BOTester <FakeBOWithReadWriteRuleProp> boTester = CreateGenericTester <FakeBOWithReadWriteRuleProp>();
            const string propName        = "ReadWriteRuleReadOnly";
            var          propertyInfo    = ReflectionUtilities.GetPropertyInfo <FakeBOWithReadWriteRuleProp, object>(bo => bo.ReadWriteRuleReadOnly);
            var          propertyWrapper = propertyInfo.ToPropertyWrapper();

            //---------------Assert Precondition----------------
            Assert.IsTrue(propertyWrapper.HasAttribute <AutoMapReadWriteRuleAttribute>());
            Assert.IsNotNull(classDef.GetPropDef(propName));
            //---------------Execute Test ----------------------
            boTester.ShouldHaveReadWriteRule(bo => bo.ReadWriteRuleReadOnly, PropReadWriteRule.ReadOnly);
            //---------------Test Result -----------------------
            Assert.IsTrue(true, "If it has got here then passed");
        }
Пример #10
0
        public void Test_ShouldNotHaveDefault_WithLambda_WhenHasDefault_ShouldAssertFalse()
        {
            //---------------Set up test pack-------------------
            SetupClassDefWithAddProperty <BOFakeWithDefault>();
            const string propName = "DefaultProp";
            BOTester <BOFakeWithDefault> boTester = CreateGenericTester <BOFakeWithDefault>();

            //---------------Assert Precondition----------------
            //---------------Test Result -----------------------
            try
            {
                boTester.ShouldNotHaveDefault(bo => bo.DefaultProp);
                Assert.Fail("Expected to throw an AssertionException");
            }
            //---------------Test Result -----------------------
            catch (AssertionException ex)
            {
                string expected = string.Format("The Property '{0}' for class '{1}' should not have a default but does", propName, "BOFakeWithDefault");
                StringAssert.Contains(expected, ex.Message);
            }
        }
Пример #11
0
        public void Test_ShouldNotBeCompulsory_WithLambda_WhenCompulsory_ShouldAssertFalse()
        {
            //---------------Set up test pack-------------------
            SetupClassDef <BOFakeWithCompulsory>();
            BOTester <BOFakeWithCompulsory> boTester = CreateGenericTester <BOFakeWithCompulsory>();
            const string propName        = "CompulsoryProp";
            var          propertyInfo    = ReflectionUtilities.GetPropertyInfo <BOFakeWithCompulsory, object>(bo => bo.CompulsoryProp);
            var          propertyWrapper = propertyInfo.ToPropertyWrapper();

            //---------------Assert Precondition----------------
            Assert.IsTrue(propertyWrapper.HasAttribute <AutoMapCompulsoryAttribute>());
            //---------------Execute Test ----------------------
            try
            {
                boTester.ShouldNotBeCompulsory(bo => bo.CompulsoryProp);
                Assert.Fail("Expected to throw an AssertionException");
            }
            //---------------Test Result -----------------------
            catch (AssertionException ex)
            {
                string expected = string.Format("The Property '{0}' for class '{1}' should not be compulsory", propName, "BOFakeWithCompulsory");
                StringAssert.Contains(expected, ex.Message);
            }
        }