コード例 #1
0
        public async Task StockMail_Post_WrongAddress()
        {
            var returnUrlPath  = "/index";
            var returnUrlQuery = "?indexquery=indexquery";
            var returnUrl      = returnUrlPath + returnUrlQuery;
            var context        = MakeContext(returnUrlPath, returnUrlQuery);

            var postId = 1;

            context.Mail.Add(new Post
            {
                Id = postId
            });

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

            var r = await controller.StockMail(postId, null, returnUrl) as RedirectResult;

            Assert.NotNull(r);
            Assert.Equal(returnUrl, r.Url);

            context.MailDaoMock.Verify(m => m.StockAsync(
                                           It.IsAny <long>(),
                                           It.IsAny <string>(),
                                           It.IsAny <User>()),
                                       Times.Never);

            var message = controller.TempData.Get <MessageViewModel>("message");

            Assert.NotNull(message);
            Assert.Equal(MessageType.Error, message.Type);
        }
コード例 #2
0
        public async Task StockMail_Post_Success()
        {
            var returnUrlPath  = "/index";
            var returnUrlQuery = "?indexquery=indexquery";
            var returnUrl      = returnUrlPath + returnUrlQuery;
            var context        = MakeContext(returnUrlPath, returnUrlQuery);

            var postId  = 1;
            var address = "address";

            context.Mail.Add(new Post
            {
                Id = postId
            });

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

            var r = await controller.StockMail(postId, address, returnUrl) as RedirectResult;

            Assert.NotNull(r);
            Assert.Equal(returnUrl, r.Url);

            var post = context.Mail.First();

            Assert.Equal(address, post.BranchStockAddress);
            Assert.Equal(PostState.InBranchStock, post.State);

            var message = controller.TempData.Get <MessageViewModel>("message");

            Assert.NotNull(message);
            Assert.Equal(MessageType.Info, message.Type);
        }
コード例 #3
0
        public async Task Index_Get()
        {
            bool withoutAddressOnly  = true;
            long?sourceBranchId      = 0;
            long?destinationBranchId = 1;
            var  options             = new ListOptions
            {
                Filters = new Dictionary <string, string>
                {
                    { "withoutAddressOnly", withoutAddressOnly.ToString() },
                    { "sourceBranchId", sourceBranchId.Value.ToString() },
                    { "destinationBranchId", destinationBranchId.Value.ToString() },
                    { "personFrom", "2" },
                    { "personTo", "3" },
                    { "addressTo", "4" }
                },
                SortKey   = "PersonFrom",
                SortOrder = SortOrder.Descending
            };
            var returnUrlPath  = "/index";
            var returnUrlQuery = "?indexquery=indexquery";
            var returnUrl      = returnUrlPath + returnUrlQuery;
            var myBranchIndex  = 0;

            var context = MakeContext(returnUrlPath, returnUrlQuery, myBranchIndex);
            var random  = new Random();

            for (int i = 0; i < 100; ++i)
            {
                context.Mail.Add(new Post
                {
                    Id                  = random.Next(),
                    PersonFrom          = "personFrom" + random.Next(),
                    PersonTo            = "personTo" + random.Next(),
                    AddressTo           = "addressTo" + random.Next(),
                    SourceBranchId      = random.Next() % context.Branches.Count(),
                    DestinationBranchId = random.Next() % context.Branches.Count(),
                    BranchId            = context.Branches[myBranchIndex].Id,
                    State               = PostState.InBranchStock
                });
            }

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

            var r = await controller.Index(options) as ViewResult;

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

            Assert.NotNull(vm);
            var expectedMail = (await mailDao.GetAllForStock(
                                    branch: context.Branches[myBranchIndex],
                                    withoutAddressOnly: withoutAddressOnly,
                                    filterSourceBranchId: sourceBranchId,
                                    filterDestinationBranchId: destinationBranchId,
                                    filterPersonFrom: options.Filters["personFrom"],
                                    filterPersonTo: options.Filters["personTo"],
                                    filterAddressTo: options.Filters["addressTo"],
                                    sortKey: options.SortKey,
                                    sortOrder: options.SortOrder))
                               .ToPaginatedList(options.Page, StockmanController.PageSize);

            Assert.Same(context.Branches, vm.AllBranches);
            Assert.Equal(expectedMail, vm.Mail);
            Assert.Same(options, vm.CurrentListOptions);
            Assert.Equal(returnUrl, vm.ReturnUrl);
        }