Mock单元测试

/// <summary>
        /// 普通插入
        /// </summary>
        [Fact]
        public void InsertOrder_Tests()
        {
            _sqlMapper.Setup(d => d.BeginTransaction());
            _sqlMapper.Setup(d => d.CommitTransaction());
            _sqlMapper.Setup(d => d.RollBackTransaction());
            _sqlMapper.Setup(d => d.QueryForObject<int>("queryMaxVersion", It.IsAny<IList<int>>())).Returns(10);

            _reidsDb.Setup(d => d.StringSet(It.IsAny<RedisKey>(), It.IsAny<RedisValue>(), It.IsAny<TimeSpan>(), It.IsAny<When>(), It.IsAny<CommandFlags>())).Returns(true);
            var model = new TempletModel()
            {
                PlatformId = 0,
                PlatformOwnerIds = 2,
                Name = "ss",
                Code = "12121",
                Type = 0,
                ImageUrl = null,
            };

            _sqlMapper.Setup(d => d.Insert("insTemplet", model)).Returns(() =>
            {
                model.Id = 1;
                return 1;
            });

            var resp = this._templetService.Create(model);
            Assert.True(resp != null && resp.Id > 0);
        }

 

posted @ 2018-05-22 17:02  zslm___  阅读(314)  评论(0编辑  收藏  举报