Exemplo n.º 1
0
        public void Should_ReturnSummaryModel()
        {
            //arrange
            InstantiateUndedrTest();
            var model = new BowlingLineScoreModel {Name="Test",Scores= "11|11|11|11|11|11|11|11|11|11"};

            _bowlingLineScoringStrategy
                .Setup(st => st.CalculateScores(It.IsAny<BowlingLine>()))
                //as Calculate scores doesnt return anything we need to manipulate the object that is passed to it
                .Callback((BowlingLine b) =>
                {
                    b.Players.First().TotalScore = 20;
                });

            //act
            var result = _underTest.SubmitScore(model);

            dynamic data = result.Data;

            //assert
            Assert.AreEqual(20,data.TotalScore);
            Assert.AreEqual("Test", data.Name);


        }
Exemplo n.º 2
0
        public JsonResult SubmitScore(BowlingLineScoreModel model)
        {
          
            try {
                //map model to a bowling line
                var addBowlingLineModel = new AddBowlingLineModel
                {
                    BowlingLineScores = new List<BowlingLineScoreModel> { model }
                };

                var bowlingLine = Mapper.Map<AddBowlingLineModel, BowlingLine>(addBowlingLineModel);

                _bowlingLineScoringStrategy.CalculateScores(bowlingLine);

                //map bowling line back to summary
                var summary = Mapper.Map<BowlingLine, BowlingLineSummaryModel>(bowlingLine);

                return Json(summary.BowlerSummaries.ToArray()[0]);
            }
            catch
            {
                return Json(new { success = false });

            }
        }
Exemplo n.º 3
0
        public void Should_ReturnFailureIfErrorIsThrown()
        {
            //arrange
            InstantiateUndedrTest();
            var model = new BowlingLineScoreModel();

            //act
            var result = _underTest.SubmitScore(model);

            dynamic data = result.Data;

            //assert
            Assert.IsFalse(data.success);      


        }