public async Task CreatePost_Post_ModelError()
        {
            var context = MakeContext();

            var controller = new OperatorController(
                context.CurrentUserService,
                context.BranchesDao,
                context.MailDaoMock.Object)
            {
                ControllerContext = context.ControllerContext,
                TempData          = context.TempDataDictionary
            };

            var destinationBranch = context.Branches[0];
            var vm = new CreatePostViewModel
            {
                PersonFrom          = "personFrom",
                PersonTo            = "personTo",
                DestinationBranchId = destinationBranch.Id,
                AddressTo           = "addressTo"
            };

            controller.ModelState.AddModelError("", "error");
            var r = await controller.CreatePost(vm) as ViewResult;

            Assert.NotNull(r);
            Assert.Null(r.ViewName);
            var returnedVm = r.Model as CreatePostViewModel;

            Assert.NotNull(returnedVm);
            Assert.Equal(context.Branches, returnedVm.AllBranches);
            context.MailDaoMock.Verify(
                m => m.CreateAsync(It.IsAny <Post>(), It.IsAny <User>()),
                Times.Never);
        }
        public async Task CreatePost_Post_Success()
        {
            var myBranchIndex = 0;
            var context       = MakeContext(myBranchIndex: myBranchIndex);

            var controller = new OperatorController(
                context.CurrentUserService,
                context.BranchesDao,
                context.MailDaoMock.Object)
            {
                ControllerContext = context.ControllerContext,
                TempData          = context.TempDataDictionary
            };

            var destinationBranch   = context.Branches[0];
            var personFrom          = "personFrom";
            var personTo            = "personTo";
            var addressTo           = "addressFrom";
            var destinationBranchId = destinationBranch.Id;
            var vm = new CreatePostViewModel
            {
                PersonFrom          = personFrom,
                PersonTo            = personTo,
                DestinationBranchId = destinationBranchId,
                AddressTo           = addressTo
            };

            var r = await controller.CreatePost(vm) as ViewResult;

            Assert.NotNull(r);
            Assert.Null(r.ViewName);
            var returnedVm = r.Model as CreatePostViewModel;

            Assert.NotNull(returnedVm);
            Assert.Equal(context.Branches, returnedVm.AllBranches);
            Assert.Single(context.Mail);
            var post = context.Mail.First();

            Assert.Equal(personFrom, post.PersonFrom);
            Assert.Equal(personTo, post.PersonTo);
            Assert.Equal(context.Branches[myBranchIndex].Id, post.BranchId);
            Assert.Equal(context.Branches[myBranchIndex].Id, post.SourceBranchId);
            Assert.Equal(destinationBranchId, post.DestinationBranchId);
            Assert.Equal(addressTo, post.AddressTo);
            Assert.Equal(PostState.Created, post.State);
            Assert.Null(returnedVm.PersonFrom);
            Assert.Null(returnedVm.PersonTo);
            Assert.Null(returnedVm.DestinationBranchId);
            Assert.Null(returnedVm.AddressTo);
            Assert.NotNull(context.TempDataDictionary.Get <MessageViewModel>("message"));
        }
        public async Task CreatePost_Get()
        {
            var context = MakeContext();

            var controller = new OperatorController(
                context.CurrentUserService,
                context.BranchesDao,
                context.MailDaoMock.Object)
            {
                ControllerContext = context.ControllerContext,
                TempData          = context.TempDataDictionary
            };

            var r = await controller.CreatePost() as ViewResult;

            Assert.NotNull(r);
            Assert.Null(r.ViewName);
            var vm = r.Model as CreatePostViewModel;

            Assert.NotNull(vm);

            Assert.Same(context.Branches, vm.AllBranches);
        }