public void ShouldHaveRule_WithMinAndMax_WhenMaxNotMatch_ShouldAssertFalse() { //---------------Set up test pack------------------- IPropDef propDef = new PropDefFake(); const int actualMaxInt = 22; const int expectedMaxInt = 25; const int minInt = 1; propDef.AddPropRule(GetPropRuleInt(minInt, actualMaxInt)); var tester = new PropDefTester(propDef); //---------------Assert Precondition---------------- Assert.AreEqual(1, propDef.PropRules.Count); var propRule = propDef.PropRules[0] as IPropRuleComparable <int>; Assert.IsNotNull(propRule); Assert.AreEqual(actualMaxInt, propRule.MaxValue); Assert.AreEqual(minInt, propRule.MinValue); //---------------Execute Test ---------------------- try { tester.ShouldHaveRule <PropRuleInteger, int>(minInt, expectedMaxInt); Assert.Fail("Expected to throw an AssertionException"); } //---------------Test Result ----------------------- catch (AssertionException ex) { var expected = string.Format("The Property '{0}' for class '{1}'", propDef.PropertyName, propDef.ClassName); StringAssert.Contains(expected, ex.Message); StringAssert.Contains("MaxValue Should Be '" + expectedMaxInt, ex.Message); } }
public void Test_ShouldHavePropRuleDate_WhenSpecifyMinAndMaxDate_WhenMaxDoesNotMatch_ShouldAssertFalse() { //---------------Set up test pack------------------- IPropDef propDef = new PropDefFake(); DateTime?minDate = null; var maxDate = DateTime.Today.AddDays(3); propDef.AddPropRule(GetPropRuleDate(minDate, maxDate)); var tester = new PropDefTester(propDef); //---------------Assert Precondition---------------- Assert.AreEqual(1, propDef.PropRules.Count); Assert.IsInstanceOf <PropRuleDate>(propDef.PropRules[0]); //---------------Execute Test ---------------------- try { tester.ShouldHaveRule <PropRuleDate, DateTime>(minDate, maxDate.AddDays(-1)); Assert.Fail("Expected to throw an AssertionException"); } //---------------Test Result ----------------------- catch (AssertionException ex) { var expected = string.Format("The Property '{0}' for class '{1}'", propDef.PropertyName, propDef.ClassName); StringAssert.Contains(expected, ex.Message); StringAssert.Contains("MaxValue Should Be ", ex.Message); } }
public void Test_ShouldHavPropRuleDate_WhenNotHas_ShouldAssertFalse() { //---------------Set up test pack------------------- IPropDef propDef = new PropDefFake(); propDef.AddPropRule(MockRepository.GenerateMock <IPropRule>()); var tester = new PropDefTester(propDef); //---------------Assert Precondition---------------- Assert.AreEqual(1, propDef.PropRules.Count); Assert.IsNotInstanceOf <PropRuleDate>(propDef.PropRules[0]); //---------------Execute Test ---------------------- try { tester.ShouldHaveRule <PropRuleDate>(); Assert.Fail("Expected to throw an AssertionException"); } //---------------Test Result ----------------------- catch (AssertionException ex) { var expected = string.Format("The Property '{0}' for class '{1}' should have a rule of type ", propDef.PropertyName, propDef.ClassName); StringAssert.Contains(expected, ex.Message); } }
public void Test_ShouldHaveRule_WhenNotHas_ShouldAssertFalse() { //---------------Set up test pack------------------- var propDef = GetPropDef(); propDef.Compulsory = false; var tester = new PropDefTester(propDef); //---------------Assert Precondition---------------- Assert.IsFalse(propDef.Compulsory); Assert.IsNotNullOrEmpty(propDef.PropertyName); Assert.IsNotNullOrEmpty(propDef.ClassName); //---------------Execute Test ---------------------- try { tester.ShouldHaveRule(); Assert.Fail("Expected to throw an AssertionException"); } //---------------Test Result ----------------------- catch (AssertionException ex) { var expected = string.Format("The Property '{0}' for class '{1}' should have Rules set", propDef.PropertyName, propDef.ClassName); StringAssert.Contains(expected, ex.Message); } }
public void Test_ShouldHaveRule_WhenHas_ShouldAssertTrue() { //---------------Set up test pack------------------- var propDef = new PropDefFake(); propDef.AddPropRule(MockRepository.GenerateMock <IPropRule>()); var tester = new PropDefTester(propDef); //---------------Assert Precondition---------------- Assert.AreEqual(1, propDef.PropRules.Count); //---------------Execute Test ---------------------- tester.ShouldHaveRule(); //---------------Test Result ----------------------- Assert.IsTrue(true, "If it has got here then passed"); }
public void Test_ShouldHavePropRuleDate_WhenHas_ShouldAssertTrue() { //---------------Set up test pack------------------- var propDef = new PropDefFake(); propDef.AddPropRule(GetPropRuleDate()); var tester = new PropDefTester(propDef); //---------------Assert Precondition---------------- Assert.AreEqual(1, propDef.PropRules.Count); Assert.IsInstanceOf <PropRuleDate>(propDef.PropRules[0]); //---------------Execute Test ---------------------- tester.ShouldHaveRule <PropRuleDate>(); //---------------Test Result ----------------------- Assert.IsTrue(true, "If it has got here then passed"); }
public void Test_ShouldHavePropRuleDate_WhenSpecifyMinAndMaxDate_WhenRuleMatches_ShouldAssertTrue() { //---------------Set up test pack------------------- var propDef = new PropDefFake(); var minDate = DateTime.Today; var maxDate = DateTime.Today.AddDays(3); propDef.AddPropRule(GetPropRuleDate(minDate, maxDate)); var tester = new PropDefTester(propDef); //---------------Assert Precondition---------------- Assert.AreEqual(1, propDef.PropRules.Count); Assert.IsInstanceOf <PropRuleDate>(propDef.PropRules[0]); //---------------Execute Test ---------------------- var expectedMaxDate = maxDate.AddDays(1).AddMilliseconds(-1);//Rule automatically moves it to the last millisecond of the Day. tester.ShouldHaveRule <PropRuleDate, DateTime>(minDate, expectedMaxDate); //---------------Test Result ----------------------- Assert.IsTrue(true, "If it has got here then passed"); }
public void ShouldHaveRule_WithMinandMax_WhenHas_WhenMinAndMaxMatchRule_ShouldAssertTrue() { //---------------Set up test pack------------------- IPropDef propDef = new PropDefFake(); const int minInt = 22; const int maxInt = 999; propDef.AddPropRule(GetPropRuleInt(minInt, maxInt)); var tester = new PropDefTester(propDef); //---------------Assert Precondition---------------- Assert.AreEqual(1, propDef.PropRules.Count); Assert.IsInstanceOf <PropRuleInteger>(propDef.PropRules[0]); var propRule = propDef.PropRules[0] as IPropRuleComparable <int>; Assert.IsNotNull(propRule); Assert.AreEqual(minInt, propRule.MinValue); Assert.AreEqual(maxInt, propRule.MaxValue); //---------------Execute Test ---------------------- tester.ShouldHaveRule <PropRuleInteger, int>(minInt, maxInt); //---------------Test Result ----------------------- Assert.IsTrue(true, "If it has got here then passed"); }