コード例 #1
0
ファイル: GumMachine.cs プロジェクト: votrongdao/Pattern
 public GumMachine(int balls, IOutputWritter writter)
 {
     _balls = balls;
     _writter = writter;
     SoldOut = new SoldOutState(this,_writter);
     NoPenny = new NoPennyState(this, _writter);
     Sold = new SoldState(this, _writter);
     HasPenny = new HasPennyState(_writter, this);
     CurrentState = _balls<=0 ? SoldOut : NoPenny;
 }
コード例 #2
0
 public GumballMachine(int ballCount)
 {
     SoldOutState    = new SoldOutState(this);
     NoQuarterState  = new NoQuarterState(this);
     HasQuarterState = new HasQuarterState(this);
     SoldState       = new SoldState(this);
     BallCount       = ballCount;
     if (ballCount > 0)
     {
         State = NoQuarterState;
     }
 }
コード例 #3
0
 public GumballMachine(int numberOfGumballs)
 {
     Count = numberOfGumballs;
     if (Count > 0)
     {
         State = new NoQuarterState(this);
     }
     else
     {
         State = new SoldOutState(this);
     }
 }
コード例 #4
0
        public void ToStringTest()
        {
            var stringWriter              = new StringWriter();
            var gumballMachine            = new GumballMachineContext(2, stringWriter);
            var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" +
                                            $" { 2 } gumball{ ( 2 != 1 ? "s" : "" ) } " +
                                            $"Machine is { BaseConstants.TO_STRING_NO_QUARTER_STATE })";
            var soldOutState = new SoldOutState(gumballMachine, stringWriter);

            Assert.AreEqual(soldOutState.ToString(), BaseConstants.TO_STRING_SOLD_OUT_STATE);
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }
コード例 #5
0
        public GumballMachine(int count)
        {
            this.Count = count;

            SoldOutState = new SoldOutState(this);
            SoldState    = new SoldState(this);
            HasCoinState = new HasCoinState(this);
            NoCoinState  = new NoCoinState(this);
            WinnerState  = new WinnerState(this);

            CurrentState = Count > 0 ? NoCoinState : SoldOutState;
        }
コード例 #6
0
        public GumballMachine(int numberOfGumballs)
        {
            GumballMachineSoldState       = new SoldState(this);
            GumballMachineNoQuarterState  = new NoQuarterState(this);
            GumballMachineHasQuarterState = new HasQuarterState(this);
            GumballMachineSoldOutState    = new SoldOutState(this);
            GumballMachineWinnerState     = new WinnerState(this);

            Count = numberOfGumballs;
            if (Count > 0)
            {
                State = GumballMachineNoQuarterState;
            }
        }
コード例 #7
0
        public GumballMachine(int numberGumballs)
        {
            SoldOutState    = new SoldOutState(this);
            NoQuarterState  = new NoQuarterState(this);
            HasQuarterState = new HasQuarterState(this);
            SoldState       = new SoldState(this);

            State = SoldOutState;

            this.Count = numberGumballs;
            if (numberGumballs > 0)
            {
                State = NoQuarterState;
            }
        }
コード例 #8
0
        public void DispenseTest()
        {
            var stringWriter              = new StringWriter();
            var result                    = new StringWriter();
            var gumballMachine            = new GumballMachineContext(2, stringWriter);
            var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" +
                                            $" { 2 } gumball{ ( 2 != 1 ? "s" : "" ) }" +
                                            $" { 0 } quarter{ ( 0 != 1 ? "s" : "" ) } " +
                                            $"Machine is { BaseConstants.TO_STRING_NO_QUARTER_STATE })";
            var soldOutState = new SoldOutState(gumballMachine, stringWriter);

            soldOutState.Dispense();
            result.WriteLine(BaseConstants.DISPENSE_SOLD_OUT_STATE);

            Assert.AreEqual(result.ToString(), stringWriter.ToString());
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }
コード例 #9
0
        public void ReFillWithSomeBallsTest()
        {
            var stringWriter              = new StringWriter();
            var result                    = new StringWriter();
            var gumballMachine            = new GumballMachineContext(0, stringWriter);
            var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" +
                                            $" { 10 } gumball{ ( 10 != 1 ? "s" : "" ) }" +
                                            $" { 0 } quarter{ ( 0 != 1 ? "s" : "" ) } " +
                                            $"Machine is { BaseConstants.TO_STRING_NO_QUARTER_STATE })";
            var soldOutState = new SoldOutState(gumballMachine, stringWriter);

            soldOutState.ReFill(10);
            result.WriteLine(MultiGumbalMachineConstants.GetReFillSoldOutStateConst(10));

            Assert.AreEqual(result.ToString(), stringWriter.ToString());
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: dany19991/oop_playground
    public GumballMachine(int count)
    {
        noQarterState   = new NoQarterState(this);
        hasQuarterState = new HasQuarterState(this);
        soldState       = new SoldState(this);
        soldOutState    = new SoldOutState(this);
        winnerState     = new WinnerState(this);

        this.count = count;

        if (count > 0)
        {
            setState(noQarterState);
        }
        else
        {
            setState(soldOutState);
        }
    }
コード例 #11
0
        public void EjectQuarterWithSomeQuartersTest()
        {
            var stringWriter              = new StringWriter();
            var result                    = new StringWriter();
            var gumballMachine            = new GumballMachineContext(2, stringWriter);
            var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" +
                                            $" { 2 } gumball{ ( 2 != 1 ? "s" : "" ) }" +
                                            $" { 0 } quarter{ ( 0 != 1 ? "s" : "" ) } " +
                                            $"Machine is { BaseConstants.TO_STRING_HAS_QUARTER_STATE })";
            var soldOutState = new SoldOutState(gumballMachine, stringWriter);

            gumballMachine.InsertQuarter();
            gumballMachine.InsertQuarter();
            soldOutState.EjectQuarter();
            result.WriteLine(BaseConstants.INSERT_QUARTER_NO_QUARTER_STATE);
            result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(2));
            result.WriteLine(MultiGumbalMachineConstants.GetEjectQuarterSoldOutStateConst(2));

            Assert.AreEqual(result.ToString(), stringWriter.ToString());
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }
コード例 #12
0
ファイル: SoldOutStateTest.cs プロジェクト: egoshin-igor/OOD
 public SoldOutStateTest()
 {
     _gumballMachineWithStateMock = new Mock <GumballMachineWithStateContext>();
     _soldOutState = new SoldOutState(_gumballMachineWithStateMock.Object);
 }