public void WhenGivenInputIsNotBetweenOneandThousandExpectValidationError()
        {
            //Arrange
            var model = new FizzBuzzViewModel
            {
                UserInput    = 1001,
                FizzBuzzList = null
            };
            //Act
            var results = Validate(model);

            //Assert
            Assert.AreNotEqual(0, results.Count);
        }
Example #2
0
        public void Should_FizzBuzzViewModel_When_Number_Multiple_Of_Five_Then_Result_Buzz()
        {
            var fizzBuzzModel = new FizzBuzzViewModel();

            fizzBuzzModel.Number = 25;
            fizzBuzzModel.FizzBuzz.Execute(string.Empty);

            StringAssert.AreEqualIgnoringCase("Buzz", fizzBuzzModel.FizzBuzzResult);

            fizzBuzzModel.Number = 1025;
            fizzBuzzModel.FizzBuzz.Execute(string.Empty);

            StringAssert.AreEqualIgnoringCase("Buzz", fizzBuzzModel.FizzBuzzResult);
        }
Example #3
0
        public ActionResult FizzBuzz(int value, int?page)
        {
            int pageSize   = 20;
            int pageNumber = (page ?? 1);

            var model = new FizzBuzzViewModel();

            model.UserPosition = value;
            var fizzBuzz = new MyFizzBuzz();

            model.FizzBuzzNumbers = fizzBuzz.GetFizzBuzz(model.UserPosition).ToPagedList(pageNumber, pageSize);

            return(View(model));
        }
Example #4
0
        public ActionResult DisplayFizzBuzz(FizzBuzzViewModel model)
        {
            model.PageSize          = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Pagesize"));
            model.PageCount         = Convert.ToInt32(Math.Ceiling((double)(Convert.ToDouble(model.InputNumber) / Convert.ToDouble(model.PageSize))));
            model.DisplayList       = mappingClass.Map(_fizzBuzzManager.Generate(model.InputNumber)).DisplayList;
            model.FizzBuzzPagedList = model.DisplayList.Skip(model.CurrentPageIndex * model.PageSize).Take(model.PageSize).ToList();


            if (model.FizzBuzzPagedList != null)
            {
                return(View("Display", model));
            }

            return(View("Display"));
        }
Example #5
0
        public void Index_Get_ReturnsViewWithDefaultModel()
        {
            // Arrange
            FizzBuzzViewModel expectedViewModel = FizzBuzzViewModel.CreateDefault();

            // Act
            //TODO: invoke the Index() action
            var result = _controller.Index() as ViewResult;

            // Assert
            //TODO: assert that the correct ActionResult is returned
            //TODO: assert that the correct ViewModel is used
            Assert.IsNotNull(_controller);
            Assert.That(result.Model, Is.EqualTo(expectedViewModel));
        }
Example #6
0
        public ActionResult Index(FizzBuzzViewModel model, int?page)
        {
            int pageSize   = 20;
            int pageNumber = (page ?? 1);

            if (ModelState.IsValid)
            {
                var fizzBuzz = new MyFizzBuzz(() => DateTime.UtcNow);
                model.FizzBuzzNumbers = fizzBuzz.GetFizzBuzz(model.UserPosition).ToPagedList(pageNumber, pageSize);

                return(RedirectToAction("FizzBuzz", new { value = model.UserPosition, page = 1 }));
            }
            else
            {
                return(View(model));
            }
        }
Example #7
0
            public void DisplayFizzBuzzReturnsViewModel()
            {
                // Arrange
                fizzBuzzViewModelCollection.InputNumber = 50;
                //Mockup function call in FizzBuzz Business logic
                fizzBuzzManager.Setup(FizzBuzzMock => FizzBuzzMock.Generate(It.IsAny <int>())).Returns(GetMockFizzBuzz(50));
                fizzBuzzController = new FizzBuzzController(fizzBuzzManager.Object);

                // Act
                var result = fizzBuzzController.DisplayFizzBuzz(fizzBuzzViewModelCollection) as ViewResult;

                fizzBuzzViewModelCollection = (FizzBuzzViewModel)result.Model;

                // Assert
                Assert.AreEqual("FizzBuzzViewModel", result.Model.GetType().Name);
                Assert.AreEqual(50, fizzBuzzViewModelCollection.DisplayList.Count);
                Assert.AreEqual("Display", result.ViewName);
            }
Example #8
0
        //// ----------------------------------------------------------------------------------------------------------

        public ActionResult List(string totalCount, int page = 1)
        {
            try
            {
                if (!String.IsNullOrWhiteSpace(totalCount))
                {
                    int actualTotalCount;

                    if (!int.TryParse(totalCount, out actualTotalCount))
                    {
                        ModelState.AddModelError("TotalCountNonNumeric", "Value must be numeric!");
                    }
                    else
                    {
                        var pagedResults = this.fizzBuzzRepository.Get(actualTotalCount)
                                           .OrderBy(fb => fb.Value)
                                           .Skip((page - 1) * PageSize)
                                           .Take(PageSize);
                        var pagingInfo = new PagingInfo
                        {
                            CurrentPage  = page,
                            ItemsPerPage = PageSize,
                            TotalItems   = actualTotalCount
                        };

                        var viewModel = new FizzBuzzViewModel
                        {
                            FizzBuzzEntries = pagedResults.ToList(),
                            PagingInfo      = pagingInfo
                        };

                        return(View(viewModel));
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("error", ex.Message);
            }

            return(View());
        }
        public void WhenRequestedWithPositiveIntergerFromOneToThousandWhenCurrentDayIsNotWednesDayFizzBuzzListShouldBeReturned()
        {
            // Arrange.
            var input = new FizzBuzzViewModel {
                UserInput = 5
            };

            var fizzBuzzList = new List <FizzBuzz>
            {
                new FizzBuzz()
                {
                    Description = "1", Color = string.Empty
                },
                new FizzBuzz()
                {
                    Description = "2", Color = string.Empty
                },
                new FizzBuzz()
                {
                    Description = "Fizz", Color = "blue"
                }
            };

            fizzBuzzProvider.Stub(x => x.GetFizzBuzzList(null)).IgnoreArguments()
            .Return(new FizzBuzzResponse()
            {
                FizzBuzzList = fizzBuzzList
            });

            // Act.
            ViewResult result = fizzBuzzController.FizzBuzzList(input) as ViewResult;

            var model = result?.Model as FizzBuzzViewModel;

            // Assert.
            if (model != null)
            {
                Assert.AreEqual(3, model.FizzBuzzList.Count);
            }
        }
Example #10
0
        public void Index_Post_ValidModel_ReturnsViewWithPostedModel()
        {
            // Arrange
            //TODO: create the model that is posted
            var random          = new Random();
            var postedViewModel = new FizzBuzzViewModel
            {
                FizzFactor = random.Next(1, int.MaxValue),
                BuzzFactor = random.Next(1, int.MaxValue),
                LastNumber = null
            };

            // Act
            //TODO: invoke the Index(FizzBuzzViewModel model) action
            var result = _controller.Index(postedViewModel) as ViewResult;

            // Assert
            //TODO: assert that the correct ActionResult is returned
            //TODO: assert that the posted ViewModel is used again in the View
            Assert.IsNotNull(result);
            Assert.That(result.Model, Is.EqualTo(postedViewModel));
        }
Example #11
0
        public void Should_FizzBuzzViewModel_Initial_FizzBuzzResult_IsEmpty()
        {
            var fizzBuzzModel = new FizzBuzzViewModel();

            Assert.IsEmpty(fizzBuzzModel.FizzBuzzResult);
        }
Example #12
0
 public FizzBuzzViewModelTests()
 {
     _httpClient = new FakeHttpClient();
     _viewModel  = new FizzBuzzViewModel(_httpClient);
 }
 public ViewResult Index()
 {
     return(View(FizzBuzzViewModel.CreateDefault()));
 }
Example #14
0
 public IActionResult Result(FizzBuzzViewModel model)
 {
     return(View(model));
 }