public void AskQuestion_ShouldSendTheEmailToTheCustomer() { //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.GenerateMock <IUserMailer>(); userMailer.Expect( y => y.AskQuestionCustomerVersion(Arg <string> .Is.Equal("email"), 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(); }
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(); }