Пример #1
0
        public void Argument_WrongThrow()
        {
            var exception = Assert.Catch(() => RunTest(AnyValue.IsValid,
                                                       () => MyClass.Method(""),
                                                       SmartAssert.Throw <ArgumentNullException>("pp"))
                                         );

            Assert.AreEqual("Exception 'System.ArgumentNullException' was expected, but was 'System.ArgumentOutOfRangeException'", exception.Message);
        }
Пример #2
0
        public void Argument_WrongName()
        {
            var exception = Assert.Catch(() => RunTest(AnyValue.IsValid,
                                                       () => MyClass.Method(null),
                                                       SmartAssert.Throw <ArgumentNullException>("pp"))
                                         );

            Assert.AreEqual("Exception's ParamName should be 'pp', but was 'p'", exception.Message);
        }
Пример #3
0
        public void Argument_NoThrow()
        {
            var exception = Assert.Catch(() => RunTest(AnyValue.IsValid,
                                                       () => MyClass.Method("PASS!"),
                                                       SmartAssert.Throw <ArgumentNullException>("pp"))
                                         );

            Assert.AreEqual("Exception 'System.ArgumentNullException' was expected", exception.Message);
        }
Пример #4
0
 public void Exception()
 {
     RunTest(AnyValue.IsValid,
             () => GetNumberAsync(-10).Result,
             SmartAssert.Throw(( AggregateException e ) =>
     {
         Assert.AreEqual(1, e.InnerExceptions.Count);
         Assert.IsAssignableFrom(typeof(ArgumentOutOfRangeException), e.InnerExceptions[0]);
     }));
 }
Пример #5
0
        public void HappyPath_WrongException()
        {
            var exception = Assert.Catch(() =>
                                         RunTest(AnyValue.IsValid,
                                                 () => MyClass.Method(null),
                                                 SmartAssert.Throw <ArithmeticException>())
                                         );

            Assert.AreEqual("Exception 'System.ArithmeticException' was expected, but was 'System.ArgumentNullException'", exception.Message);
        }
Пример #6
0
        public void HappyPath_NoException()
        {
            var exception = Assert.Catch(() =>
                                         RunTest(AnyValue.IsValid,
                                                 () => MyClass.Method("pass"),
                                                 SmartAssert.Throw <ArithmeticException>())
                                         );

            Assert.AreEqual("Exception 'System.ArithmeticException' was expected", exception.Message);
        }
Пример #7
0
        public void Argument_WrongMessage()
        {
            var exception = Assert.Catch(() =>
                                         RunTest(AnyValue.IsValid,
                                                 () => MyClass.Method(null),
                                                 SmartAssert.Throw <ArgumentNullException>("p", "p should not be null!!"))
                                         );

            Assert.AreEqual("Exception's Message should be 'p should not be null!!', but was 'p should not be null!'", exception.Message);
        }
 public void NullAddress()
 {
     // Act part: implement another case.
     // This case is an error, should be treated specifically (one error at a time)
     RunTest(Case("name", ValidString.HasContent) &
             Case("address", ValidString.IsNull),
             () => new Customer("Ludovic Dubois", null),
             // Assert Part
             // Ensure the ArgumentNullException is thrown when the Customer is created
             // Better than Assert.Catch, as you can still have Smart Assertions after catching the failure
             SmartAssert.Throw <ArgumentNullException>("address"));
 }
 public void EmptyName()
 {
     // Act part: implement another case.
     // This case is an error, should be treated specifically (one error at a time)
     RunTest(Case("name", ValidString.IsEmpty) &
             Case("address", ValidString.HasContent),
             () => new Customer("", "Montreal"),
             // Assert Part
             // Ensure the ArgumentOutOfRangeException is thrown when the Customer is created
             // Better than Assert.Catch, as you can still have Smart Assertions after catching the failure
             SmartAssert.Throw <ArgumentOutOfRangeException>("name"));
 }
Пример #10
0
        public void HappyPath_Message()
        {
            var run = false;

            RunTest(AnyValue.IsValid,
                    () => MyClass.Method("throw"),
                    SmartAssert.Throw <ArithmeticException>(e =>
            {
                run = true;
                Assert.AreEqual("Wrong Computation", e.Message);
            }));
            Assert.IsTrue(run);
        }
Пример #11
0
        public void Argument_HappyPath_Message_Other()
        {
            var run = false;

            RunTest(AnyValue.IsValid,
                    () => MyClass.Method(null),
                    SmartAssert.Throw <ArgumentNullException>("p",
                                                              "p should not be null!",
                                                              e =>
            {
                run = true;
                Assert.IsTrue(e.Message.StartsWith("p should not be null!"));
            }));
            Assert.IsTrue(run);
        }
Пример #12
0
        public void SetAddress_Null()
        {
            RunTest(ValidString.IsNull,
                    // Act
                    // To Test Assignment, use Assign
                    Assign(() => _Customer.Address, null),

                    // Assert (and implicit Assume)
                    // After Act: Assert ArgumentOutOfRangeException is thrown with ParamName == "value" and Message == "Address Cannot be empty not null!" (omitting Parameter Name: value)
                    SmartAssert.Throw <ArgumentNullException>("value", "Address cannot be empty nor null!"),
                    // Before Act: Register to PropertyChangedEvent
                    // After Act: Assert not PropertyChanged is raised
                    SmartAssert.NotRaised_PropertyChanged(),
                    // Before Act: keep track of all properties and fields
                    // After Act: Assert no property nor field changed => the _Customer is not changed at all
                    SmartAssert.NotChanged(NotChangedKind.All)
                    );
        }
Пример #13
0
        public void CloseAccount_NoAccount()
        {
            RunTest(CollectionItem.IsNull,
                    // Act
                    () => _Customer.CloseAccount(null),

                    // Assert (and implicit Assume)
                    // After: Assert ArgumentNullException is thrown for the right parameter (optional) with the right error message (optional)
                    SmartAssert.Throw <ArgumentNullException>("account", "account belonging to this customer is required"),
                    // Before Act: Register to PropertyChangedEvent
                    // After Act: Assert not PropertyChanged is raised
                    SmartAssert.NotRaised_PropertyChanged(),
                    // Before Act: Keep track of all properties and fields
                    // After Act: Assert no property nor field changed => the _Customer is not changed at all
                    SmartAssert.NotChanged(NotChangedKind.All),
                    // Before Act: Keep track of all public properties of _Customer.Accounts
                    // After Act: Assert current _Customer.Accounts public properties are the saved value (thus, that _Customer.Accounts did not changed at all)
                    SmartAssert.NotChanged(_Customer.Accounts)
                    );
        }
Пример #14
0
 public void Argument_HappyPath_Message()
 {
     RunTest(AnyValue.IsValid,
             () => MyClass.Method(null),
             SmartAssert.Throw <ArgumentNullException>("p", "p should not be null!"));
 }
Пример #15
0
 public void Argument_HappyPath()
 {
     RunTest(AnyValue.IsValid,
             () => MyClass.Method(null),
             SmartAssert.Throw <ArgumentNullException>("p"));
 }
Пример #16
0
 public void HappyPath()
 {
     RunTest(AnyValue.IsValid,
             () => MyClass.Method("throw"),
             SmartAssert.Throw <ArithmeticException>());
 }