public void create_should_add_message_to_repository()
 {
     //mock the repo
     var mockRepo = new Mock<IMessageRepository>();
     //set expectations
     mockRepo.Expect(r => r.Add(model)).Returns(1);
     var mockValidationRunner = new Mock<IValidationRunner>();
     var service = new InMemoryMessageService(mockRepo.Object,
                                              mockValidationRunner.Object);
     controller = new MessageController(service, null);
     var result = controller.Create(model);
     mockRepo.VerifyAll();
 }
 public void create_should_add_flash_message_if_save_is_successful()
 {
     var mockService = new Mock<IMessageService>();
     mockService.Expect(s => s.Add(model)).Returns(1);
     controller = new MessageController(mockService.Object, null);
     var result = controller.Create(model);
     Assert.IsTrue(controller.ModelState.IsValid, "model state is invalid");
     Assert.Contains(controller.TempData,
                     new KeyValuePair<string, object>
                         ("flash",
                          "Message successfully created"),
                     "Flash message is missing");
     mockService.VerifyAll();
 }
 public void create_should_redirect_to_list_view_after_successful_save()
 {
     var mockService = new Mock<IMessageService>();
     mockService.Expect(s => s.Add(model)).Returns(1);
     controller = new MessageController(mockService.Object, null);
     var result = controller.Create(model);
     result.AssertRedirectToRouteResult("browse");
     mockService.VerifyAll();
 }
        public void SetUp()
        {
            MockMembership = new Mock<MembershipProvider>();
            MockMembershipUser = new Mock<MembershipUser>();
            user = new Mock<IPrincipal>();
            identity = new Mock<IIdentity>();
            httpContext = new Mock<HttpContextBase>();
            request = new Mock<HttpRequestBase>();
            controllerbase = new Mock<ControllerBase>();

            SetupMocks(Username, UserId);

            controller = GetController();

            model = new Message()
                        {
                            Subject = "My newsletter subject",
                            Name = "October newsletter",
                            Text = "Hello subscriber",
                            Html = "Hello <b>subscriber</b>"
                        };
        }
 public void Setup()
 {
     service = new Mock<IMessageService>();
     service.Expect( s => s.GetById( It.IsAny<int>() ) ).Returns( new Message{ Id = 1 } );
     controller = new MessageController( service.Object );
 }