Click here to Skip to main content
15,886,806 members
Articles / Web Development / CSS

15 Steps to Develop a Product Management System in Only a Day

Rate me:
Please Sign up or sign in to vote.
4.83/5 (51 votes)
23 Mar 2010GPL34 min read 247.9K   4.8K   163  
The article introduces how to easily develop business solutions in RapidWebDev through developing a product management system with the special requirement step by step.
using System;
using NBehave.Narrator.Framework;
using NBehave.Spec.NUnit;
using NUnit.Framework;

namespace NBehave.Examples
{
    [Theme("Account transfers and deposits")]
    public class AccountSpecs
    {
        [Story]
        public void Transfer_to_cash_account()
        {

            Account savings = null;
            Account cash = null;

            var transferStory = new Story("Transfer to cash account");

            transferStory
                .AsA("savings account holder")
                .IWant("to transfer money from my savings account")
                .SoThat("I can get cash easily from an ATM");

            transferStory
                .WithScenario("Savings account is in credit")

                    .Given("my savings account balance is $balance", 100, accountBalance => { savings = new Account(accountBalance); })
                        .And("my cash account balance is $balance", 10, accountBalance => { cash = new Account(accountBalance); })
                    .When("I transfer $amount to cash account", 20, transferAmount => savings.TransferTo(cash, transferAmount))
                    .Then("my savings account balance should be $balance", 80, expectedBalance => savings.Balance.ShouldEqual(expectedBalance))
                        .And("my cash account balance should be $balance", 30, expectedBalance => cash.Balance.ShouldEqual(expectedBalance))

                    .Given("my savings account balance is 400")
                        .And("my cash account balance is 100")
                    .When("I transfer 100 to cash account")
                    .Then("my savings account balance should be 300")
                        .And("my cash account balance should be 200")

                    .Given("my savings account balance is 500")
                        .And("my cash account balance is 20")
                    .When("I transfer 30 to cash account")
                    .Then("my savings account balance should be 470")
                        .And("my cash account balance should be 50");

            transferStory
                .WithScenario("Savings account is overdrawn")

                    .Given("my savings account balance is  -20")
                        .And("my cash account balance is 10")
                    .When("I transfer 20 to cash account")
                    .Then("my savings account balance should be -20")
                        .And("my cash account balance should be 10");


        }

        [Story]
        public void Withdraw_from_savings_account_pending()
        {

            var transferStory = new Story("Withdraw from savings account");

            transferStory
                .AsA("savings account holder")
                .IWant("to withdraw money from my savings account")
                .SoThat("I can pay for things with cash");

            transferStory
                .WithScenario("Savings account is in credit")
                    .Pending("ability to withdraw from accounts")

                    .Given("my savings account balance is 400")
                    .When("I withdraw $amount from my savings account", 100)
                    .Then("my savings account balance should be 300");

        }

        [Story]
        public void Deposit_not_implemented_properly()
        {

            var transferStory = new Story("Deposit to cash account");

            transferStory
                .AsA("savings account holder")
                .IWant("to deposit money into my cash account")
                .SoThat("I can have money for later");

            Account cash = null;

            transferStory
                .WithScenario("Savings account is in credit")
                .Given("my cash account balance is", 100,
                       accountBalance => { cash = new Account(accountBalance); })
                .When("I deposit into my cash account", 20, depositAmount => cash.Deposit(depositAmount))
                .Then("my cash account balance should be", 120,
                      expectedBalance => cash.Balance.ShouldEqual(expectedBalance));

        }
    }

    public class Account
    {
        private int _accountBalance;

        public Account(int accountBalance)
        {
            _accountBalance = accountBalance;
        }

        public int Balance
        {
            get { return _accountBalance; }
            set { _accountBalance = value; }
        }

        public void TransferTo(Account account, int amount)
        {
            if (_accountBalance > 0)
            {
                account.Balance = account.Balance + amount;
                Balance = Balance - amount;
            }
        }

        public void Withdraw(int amount)
        {
            if (amount > Balance)
                throw new ArgumentException("Amount exceeds balance", "amount");

            Balance -= amount;
        }

        public void Deposit(int amount)
        {
            // not implemented yet, do nothing for now
        }

        public override string ToString()
        {
            return string.Format("[Balance: {0}]", Balance);
        }
    }




}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
President TCWH
China China
I've worked as a software architect and developer based on Microsoft .NET framework and web technology since 2002, having rich experience on SaaS, multiple-tier web system and website development. I've devoted into open source project development since 2003, and have created 3 main projects including DataQuicker (ORM), ExcelQuicker (Excel Report Generator), and RapidWebDev (Enterprise-level CMS)

I worked in BenQ (8 mo), Bleum (4 mo), Newegg (1 mo), Microsoft (3 yr) and Autodesk (5 yr) before 2012. Now I own a startup company in Shanghai China to deliver the exceptional results to global internet users by leveraging the power of Internet and the local excellence.

Comments and Discussions