public void SubscribeToViewGetTopDishesEvent()
        {
            var topDishesView = new FakeTopDishesView();
            var dishesService = new Mock <IDishesAsyncService>();

            var actualInstance = new TopDishesPresenter(topDishesView, dishesService.Object);

            Assert.That(topDishesView.ContainsSubscribedMethod("OnGetTopDishes"), Is.True);
        }
        public void CreateAnInstanceImplementingITopDishesPresenter_WhenParametersAreCorrect()
        {
            var topDishesView = new Mock <ITopDishesView>();
            var dishesService = new Mock <IDishesAsyncService>();

            var actualInstance = new TopDishesPresenter(topDishesView.Object, dishesService.Object);

            Assert.That(actualInstance, Is.InstanceOf <ITopDishesPresenter>());
        }
        public void IDishesAsyncServiceField_ShouldBeDeclaredOfCorrectType()
        {
            var topDishesView = new Mock <ITopDishesView>();
            var dishesService = new Mock <IDishesAsyncService>();

            var actualInstance = new TopDishesPresenter(topDishesView.Object, dishesService.Object);

            var bindingFlags       = BindingFlags.NonPublic | BindingFlags.Instance;
            var dishesServiceField = typeof(TopDishesPresenter).GetField("dishesService", bindingFlags);

            Assert.That(dishesServiceField.FieldType, Is.EqualTo(typeof(IDishesAsyncService)));
        }
        public void ShouldThrowArgumentExceptionWithCorrectMessage_WhenTopDishesEventArgsDishesCountPropertyIsNegative(int invalidDishesCount)
        {
            var topDishesView = new Mock <ITopDishesView>();
            var dishesService = new Mock <IDishesAsyncService>();

            var topDishesPresenter = new TopDishesPresenter(topDishesView.Object, dishesService.Object);

            var topDishesEventArgs = new TopDishesEventArgs(invalidDishesCount, true);

            Assert.That(
                () => topDishesPresenter.OnGetTopDishes(null, topDishesEventArgs),
                Throws.InstanceOf <ArgumentException>().With.Message.Contains("dishesCount parameter must be greater than or equal to 0."));
        }
        public void ShouldSetCorrectValueToIDishesAsyncServiceField()
        {
            var topDishesView = new Mock <ITopDishesView>();
            var dishesService = new Mock <IDishesAsyncService>();

            var actualInstance = new TopDishesPresenter(topDishesView.Object, dishesService.Object);

            var bindingFlags            = BindingFlags.NonPublic | BindingFlags.Instance;
            var dishesServiceField      = typeof(TopDishesPresenter).GetField("dishesService", bindingFlags);
            var dishesServiceFieldValue = dishesServiceField.GetValue(actualInstance);

            Assert.That(dishesServiceFieldValue, Is.Not.Null);
        }
        public void InvokeIDishesAsyncService_GetTopCountDishesByRatingMethodOnceWithCorrectAddSampleDataValue(bool addSampleData)
        {
            var topDishesView = new Mock <ITopDishesView>();

            topDishesView.SetupGet(view => view.Model).Returns(new TopDishesViewModel());

            var dishesService = new Mock <IDishesAsyncService>();

            var topDishesPresenter = new TopDishesPresenter(topDishesView.Object, dishesService.Object);

            var topDishesEventArgs = new TopDishesEventArgs(3, addSampleData);

            topDishesPresenter.OnGetTopDishes(null, topDishesEventArgs);

            dishesService.Verify(service => service.GetTopCountDishesByRating(It.IsAny <int>(), addSampleData), Times.Once);
        }
        public void InvokeIDishesAsyncService_GetTopCountDishesByRatingMethodOnceWithCorrectDishesCountValue(int dishesCount)
        {
            var topDishesView = new Mock <ITopDishesView>();

            topDishesView.SetupGet(view => view.Model).Returns(new TopDishesViewModel());

            var dishesService = new Mock <IDishesAsyncService>();

            var topDishesPresenter = new TopDishesPresenter(topDishesView.Object, dishesService.Object);

            var topDishesEventArgs = new TopDishesEventArgs(dishesCount, true);

            topDishesPresenter.OnGetTopDishes(null, topDishesEventArgs);

            dishesService.Verify(service => service.GetTopCountDishesByRating(dishesCount, It.IsAny <bool>()), Times.Once);
        }