コード例 #1
0
ファイル: ToasterTests.cs プロジェクト: matry-ny/brain
        public void BreadSliceIsToastedWellTest()
        {
            var timerFake = new ToasterTimerFake();
            var toaster = new Toaster(timerFake);

            var isToasterRinged = false;
            //toaster.Ring += (sender, args) => { isToasterRinged = true; };
            toaster.Ring -= HandleTosterRing;
            toaster.Ring += HandleTosterRing;

            var freshSlice = new BreadSlice();
            var toastedSlice = new BreadSlice {State = BreadSliceState.Toasted};
            var burnedSlice = new BreadSlice {State = BreadSliceState.Burned};
            var niggaSlice = new BreadSlice {State = BreadSliceState.N***a};

            var slices = new[]
            {
                freshSlice, toastedSlice, burnedSlice, niggaSlice
            };

            // act
            toaster.Toast(slices, 0);
            timerFake.ReiseCompleteEvent();

            // assert
            Assert.IsTrue(_isToasterRinged);
            Assert.AreEqual(BreadSliceState.Toasted, freshSlice.State);
            Assert.AreEqual(BreadSliceState.Burned, toastedSlice.State);
            Assert.AreEqual(BreadSliceState.N***a, burnedSlice.State);
            Assert.AreEqual(BreadSliceState.N***a, niggaSlice.State);
        }
コード例 #2
0
ファイル: Toaster.cs プロジェクト: matry-ny/brain
 public void Toast(BreadSlice[] slices, int seconds)
 {
     if (slices == null)
     {
         throw new ArgumentNullException("slices");
     }
     _slices = slices;
     _timer.Start(seconds);
     _timer.Complete += HandleTimerComplete;
 }
コード例 #3
0
ファイル: Toaster.cs プロジェクト: matry-ny/brain
        private void UpdateBreadStatus(BreadSlice[] slices, int secondsSoFar)
        {
            if (secondsSoFar > 60)
            {
                foreach (var breadPart in slices)
                {
                    breadPart.State = BreadSliceState.Burned;
                }

                return;
            }

            foreach (var breadPart in slices)
            {
                var lastBreadState = Enum.GetValues(typeof(BreadSliceState)).Cast<BreadSliceState>().Max();
                if (breadPart.State < lastBreadState)
                {
                    breadPart.State++;
                }
            }
        }