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);
        }
        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);
        }
예제 #3
0
        public void Test_ShouldBeCompulsory_WithLambda_WhenCompulsory_ShouldAssertTrue()
        {
            //---------------Set up test pack-------------------
            SetupClassDef <BOFakeWithCompulsory>();
            BOTester <BOFakeWithCompulsory> boTester = CreateGenericTester <BOFakeWithCompulsory>();
            var propertyInfo    = ReflectionUtilities.GetPropertyInfo <BOFakeWithCompulsory, object>(bo => bo.CompulsoryProp);
            var propertyWrapper = propertyInfo.ToPropertyWrapper();

            //---------------Assert Precondition----------------
            Assert.IsTrue(propertyWrapper.HasAttribute <AutoMapCompulsoryAttribute>());
            //---------------Execute Test ----------------------
            boTester.ShouldBeCompulsory(bo => bo.CompulsoryProp);
            //---------------Test Result -----------------------
            Assert.IsTrue(true, "If it has got here then passed");
        }
예제 #4
0
        public void Test_ShouldBeCompulsory_WithLambda_WhenNotCompulsory_ShouldAssertFalse()
        {
            //---------------Set up test pack-------------------
            SetupClassDef <BOFakeWithCompulsory>();
            BOTester <BOFakeWithCompulsory> boTester = CreateGenericTester <BOFakeWithCompulsory>();
            const string propName        = "NonCompulsoryProp";
            var          propertyInfo    = ReflectionUtilities.GetPropertyInfo <BOFakeWithCompulsory, object>(bo => bo.NonCompulsoryProp);
            var          propertyWrapper = propertyInfo.ToPropertyWrapper();

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