Exemple #1
0
        public void Transfer_NegativeAmount()
        {
            _Account.Deposit(1000);
            var account2 = _Customer.CreateAccount();

            // We use a lambda expression to show equivalence class and to generate a random value within this equivalence class
            RunTest(Case(( double amount ) => amount.BelowOrEqual(0), out var value) &
                    Case("toAccount", ValidValue.IsValid),

                    // Act
                    () => _Account.Transfer(value, account2),

                    // Assert (and implicit Assume)
                    // After Act: Assert ArgumentOutOfRangeException is thrown with ParamName == "amount"
                    SmartAssert.Throw <ArgumentOutOfRangeException>("amount"),
                    // Before Act: Keep tracks of all public properties
                    // After Act: Assert all public properties have the same values
                    SmartAssert.NotChanged(),
                    // Before Act: Keep tracks of all public properties
                    // After Act: Assert all public properties have the same values
                    SmartAssert.NotChanged(account2),
                    // Before Act: Register to PropertyChangedEvent
                    // After Act: Assert PropertyChanged is not raised
                    SmartAssert.NotRaised_PropertyChanged(),
                    // Before Act: Register to PropertyChangedEvent
                    // After Act: Assert PropertyChanged is not raised
                    SmartAssert.NotRaised_PropertyChanged(account2),
                    // Before Act: Keep track of all public properties of _Account.Transactions
                    // After Act: Assert not property of _Account.Transactions changed (especially Count)
                    SmartAssert.NotChanged(_Account.Transactions),
                    // Before Act: Keep track of all public properties of account2.Transactions
                    // After Act: Assert not property of account2.Transactions changed (especially Count)
                    SmartAssert.NotChanged(account2.Transactions)
                    );
        }
Exemple #2
0
        public void Transfer_NoAccount2()
        {
            _Account.Deposit(1000);

            // We use a lambda expression to show equivalence class and to generate a random value within this equivalence class
            RunTest(Case(( double amount ) => amount.Range(0, false, 1000, true), out var value) &
                    Case("toAccount", ValidValue.IsInvalid),

                    // Act
                    () => _Account.Transfer(value, null),

                    // Assert (and implicit Assume)
                    // After Act: Assert ArgumentNullException is thrown with ParamName == "toAccount"
                    SmartAssert.Throw <ArgumentNullException>("toAccount"),
                    // Before Act: Register to PropertyChangedEvent
                    // After Act: Assert PropertyChanged is not raised
                    SmartAssert.NotRaised_PropertyChanged(),
                    // Before Act: Keep tracks of all public properties
                    // After Act: Assert all public properties have the same values
                    SmartAssert.NotChanged(),
                    // Before Act: Keep track of all public properties of _Account.Transactions
                    // After Act: Assert not property of _Account.Transactions changed (especially Count)
                    SmartAssert.NotChanged(_Account.Transactions)
                    );
        }
Exemple #3
0
        public void CreateAccount()
        {
            var previous = _Customer.CreateAccount();

            var account = RunTest( // We always can call CreateAccount
                AnyValue.IsValid,
                // Act
                () => _Customer.CreateAccount(),

                // Assert (and implicit Assume)
                // 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: Compute the expression _Customer.Account.Count + 1 and save its result
                // After Act: Assert current _Customer.Accounts.Count is the saved value (thus, that Count is one more than before)
                SmartAssert.Change(() => _Customer.Accounts.Count + 1)
                );

            // Assert
            Assert.AreSame(account, _Customer.Accounts.Last());
            Assert.AreEqual(previous.Id + 1, account.Id);
            Assert.AreSame(_Customer, account.Customer);
            Assert.AreEqual(0, account.Balance);
            Assert.IsEmpty(account.Transactions);
        }
Exemple #4
0
        public void Withdraw_TooBig()
        {
            _Account.Deposit(1000);
            // Assume
            Assert.AreEqual(1000, _Account.Balance);

            // We use a lambda expression to show equivalence class and to generate a random value within this equivalence class
            var success = RunTest(Case(( double amount ) => amount.Above(1000), out var value),
                                  // Act
                                  () => _Account.Withdraw(value),

                                  // Assert (and implicit Assume)
                                  // 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 _Account.Transactions
                                  // After Act: Assert not property of _Account.Transactions changed (especially Count)
                                  SmartAssert.NotChanged(_Account.Transactions)
                                  );

            Assert.IsFalse(success);
        }
Exemple #5
0
        public void CloseAccount_NotOurAccount()
        {
            // Arrange
            var customer2 = new Customer("You", "World");
            var account   = customer2.CreateAccount();

            var result = RunTest(CollectionItem.IsNotInCollection,
                                 // Act
                                 () => _Customer.CloseAccount(account),

                                 // Assert (and implicit Assume)
                                 // 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: Register to PropertyChangedEvent
                                 // Assert Act: Ensure not PropertyChanged is raised
                                 SmartAssert.NotRaised_PropertyChanged(),
                                 // 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)
                                 );

            // Assert
            Assert.IsFalse(result);
        }
Exemple #6
0
        public void HasSubscriberSameValue()
        {
            var mc = new MyClass(false);

            Assert.AreEqual(0, mc.MyProperty);

            RunTest(NotifyPropertyChanged.HasSubscriberSameValue,
                    Assign(() => mc.MyProperty, 0),
                    SmartAssert.NotRaised_PropertyChanged(mc));

            Assert.AreEqual(0, mc.MyProperty);
        }
        public void HasSubscriberSameValue_RaiseOtherProperty()
        {
            var mc = new MyClass("OtherProperty");

            Assert.AreEqual(0, mc.MyProperty);

            RunTest(NotifyPropertyChanged.HasSubscriberSameValue,
                    Assign(() => mc.MyProperty, 0),
                    SmartAssert.NotRaised_PropertyChanged(mc, nameof(MyClass.MyProperty)));

            Assert.AreEqual(0, mc.MyProperty);
        }
Exemple #8
0
        public void HasSubscriberSameValue_PropertyChanged()
        {
            var exception = Assert.Catch <SmartTestException>(() =>
            {
                var mc = new MyClass(true);
                Assert.AreEqual(0, mc.MyProperty);

                RunTest(NotifyPropertyChanged.HasSubscriberSameValue,
                        Assign(() => mc.MyProperty, 0),
                        SmartAssert.NotRaised_PropertyChanged(mc));
            });

            Assert.AreEqual("Event 'PropertyChanged' was unexpected", exception.Message);
        }
Exemple #9
0
        public void Deposit_Negative()
        {
            // We use a lambda expression to show equivalence class and to generate a random value within this equivalence class
            RunTest(Case(( double amount ) => amount.BelowOrEqual(0), out var value),
                    // Act
                    () => _Account.Deposit(value),

                    // Assert (and implicit Assume)
                    // After Act: Assert ArgumentOutOfRangeException is thrown with ParamName == "amount"
                    SmartAssert.Throw <ArgumentOutOfRangeException>("amount"),
                    // 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)
                    );
        }
Exemple #10
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)
                    );
        }
Exemple #11
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)
                    );
        }
Exemple #12
0
        public void Transfer_TooBig()
        {
            _Account.Deposit(1000);
            var account2 = _Customer.CreateAccount();

            // Assume
            Assert.AreEqual(1000, _Account.Balance);

            // We use a lambda expression to show equivalence class and to generate a random value within this equivalence class
            var success = RunTest(Case(( double amount ) => amount.Above(1000), out var value) &
                                  Case("toAccount", ValidValue.IsValid),

                                  // Act
                                  () => _Account.Transfer(value, account2),

                                  // Assert (and implicit Assume)
                                  // Before Act: Keep tracks of all public properties
                                  // After Act: Assert all public properties have the same values
                                  SmartAssert.NotChanged(),
                                  // Before Act: Keep tracks of all public properties of account2
                                  // After Act: Assert all public properties of account2 have the same values
                                  SmartAssert.NotChanged(account2),
                                  // Before Act: Register to PropertyChangedEvent
                                  // After Act: Assert no PropertyChanged is raised
                                  SmartAssert.NotRaised_PropertyChanged(),
                                  // Before Act: Register to PropertyChangedEvent
                                  // After Act: Assert no PropertyChanged is raised for account2
                                  SmartAssert.NotRaised_PropertyChanged(account2),
                                  // Before Act: Keep track of all public properties of _Account.Transactions
                                  // After Act: Assert not property of _Account.Transactions changed (especially Count)
                                  SmartAssert.NotChanged(_Account.Transactions),
                                  // Before Act: Keep track of all public properties of account2.Transactions
                                  // After Act: Assert not property of account2.Transactions changed (especially Count)
                                  SmartAssert.NotChanged(account2.Transactions)
                                  );

            Assert.IsFalse(success);
        }
Exemple #13
0
        public void CloseAccount_HappyPath()
        {
            var account = _Customer.CreateAccount();

            var result = RunTest(CollectionItem.IsInCollection,
                                 // Act
                                 () => _Customer.CloseAccount(account),

                                 // Assert (and implicit Assume)
                                 // 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: Register to PropertyChangedEvent
                                 // After Act: Assert not PropertyChanged is raised
                                 SmartAssert.NotRaised_PropertyChanged(),
                                 // Before Act: Compute the expression _Customer.Account.Count - 1 and save its result
                                 // After Act: Assert current _Customer.Accounts.Count is the saved value (thus, that Count is one less than before)
                                 SmartAssert.Change(() => _Customer.Accounts.Count - 1)
                                 );

            // Assert
            Assert.IsTrue(result);
        }