public void AskQuestion_ShouldReturnAJsonWithErrorIfMailerThrowsException()
        {
            //Arrange
            var wishListBuilder = MockRepository.GenerateStub<IViewModelBuilder>();
            wishListBuilder.Stub(x => x.Build()).Return(new WishListViewModel());
            var pathBarGenerator = MockRepository.GenerateStub<IPathBarGenerator>();

            var settingManager = new FakeSettingManager();

            var userMailer = MockRepository.GenerateStub<IUserMailer>();
            userMailer.Stub(
                y =>
                y.AskQuestionAdminVersion(Arg<string>.Is.Anything,
                              Arg<AskQuestionEmailTemplateViewModel>.Is.Anything)).Throw(new Exception());

            var conrtoller = new ServicesController(wishListBuilder, pathBarGenerator, userMailer, settingManager);

            //Act
            var result = conrtoller.AskQuestion("name", "email", "phone", "question") as JsonResult;
            //Assert
            var actual = result.Data as OporationWithoutReturnValueJsonModel;
            actual.HasError.Should().BeTrue();
        }
        public void AskQuestion_ShouldSendTheEmailToTheAdmin()
        {
            //Arrange
            var wishListBuilder = MockRepository.GenerateStub<IViewModelBuilder>();
            wishListBuilder.Stub(x => x.Build()).Return(new WishListViewModel());
            var pathBarGenerator = MockRepository.GenerateStub<IPathBarGenerator>();

            var settingManager = new FakeSettingManager();
            var adminEmailAddress = settingManager.AdminEmail();

            var userMailer = MockRepository.GenerateMock<IUserMailer>();
            userMailer.Expect(
                y =>
               y.AskQuestionAdminVersion(Arg<string>.Is.Equal(adminEmailAddress),
                              Arg<AskQuestionEmailTemplateViewModel>.Matches(
                                  x =>
                                  x.Email == "email" && x.Name == "name" && x.Phone == "phone" &&
                                  x.Question == "question"))).Repeat.Once();

            var conrtoller = new ServicesController(wishListBuilder, pathBarGenerator, userMailer, settingManager);

            //Act
            var result = conrtoller.AskQuestion("name","email","phone","question");
            //Assert
            userMailer.VerifyAllExpectations();
        }
        private static ServicesController CreateDefaultServicesController()
        {
            var wishListBuilder = MockRepository.GenerateStub<IViewModelBuilder>();
            wishListBuilder.Stub(x => x.Build()).Return(new WishListViewModel());
            var pathBarGenerator = MockRepository.GenerateStub<IPathBarGenerator>();

            var userMailer = MockRepository.GenerateStub<IUserMailer>();

            var settingManager = new FakeSettingManager();

            var conrtoller = new ServicesController(wishListBuilder, pathBarGenerator, userMailer, settingManager);
            return conrtoller;
        }