Пример #1
0
        /// <summary>
        /// 往数据库添加一系列模拟的数据行。
        /// </summary>
        /// <typeparam name="TModel">数据表的实体类型。</typeparam>
        /// <param name="length">添加的行数。</param>
        /// <param name="before">添加前的回调函数。</param>
        /// <param name="after">添加后的回调函数。</param>
        /// <returns>返回添加的实体列表。</returns>
        public TModel[] AddMockModels <TModel>(int length = 1, Action <TModel> before = null, Action <TModel> after = null)
        {
            if (length < 1)
            {
                throw new ArgumentOutOfRangeException("length");
            }
            TModel[] models = new TModel[length];
            using (var context = this.Context)
            {
                for (int i = 0; i < length; i++)
                {
                    var model = GA.CreateMockModel <TModel>();
                    if (before != null)
                    {
                        before(model);
                    }
                    context.Add(model);
                    if (after != null)
                    {
                        after(model);
                    }
                    models[i] = model;
                }
            }

            return(models);
        }
Пример #2
0
        public async void AddDbTests()
        {
            var s     = this.CreateService <MyServices>();
            var model = GA.CreateMockModel <Models.Member>();

            model.Id = 0;
            Assert.True(await s.Add(model));
            Assert.Equal(1, await s.Count());
            Assert.False(await s.Add(model));
        }
Пример #3
0
        public void Add()
        {
            var model = GA.CreateMockModel <Models.Member>();

            model.Id = 0;
            var command = new CMD.Add <Models.Member> {
                Entity = model
            };

            Assert.Equal(1, this.Execute(command).Result);
            Assert.Equal(1, this.Execute(new CMD.GetIdentity <Models.Member>()).Result);
            var r = GA.Compare(model, this.Context.FindOne <Models.Member>(1));

            Assert.Null(r);
        }
Пример #4
0
        public async void AddTest()
        {
            var s = ServiceFactory.CreateMockService <MyServices>(null, f =>
                                                                  f.Mock(c => false)
                                                                  .Mock(c => 1)
                                                                  .Mock(c => 1)
                                                                  .Mock(c => true)
                                                                  );

            var model = GA.CreateMockModel <Models.Member>();

            model.Id = 0;
            Assert.True(await s.Add(model));
            Assert.Equal(1, await s.Count());
            Assert.False(await s.Add(model));
        }