Beispiel #1
0
        public void ConvertTest01_Run()
        {
            using (var context = new TestContext.TestDbContext(TestTools.CreateNewContextOptions()))
            {
                context.CreateTestEmployees(5).CreateTestUsers(5).CreateTableModels(5);

                var modelTest     = context.Set <TableModel>().Include(m => m.User).Include(m => m.UserNull).Last();
                var viewModelTest = GridTools.Convert <TableModel, ViewModel>(modelTest);

                Assert.Equal(viewModelTest.Id, modelTest.Id);
                Assert.Equal(viewModelTest.Test, modelTest.Test);
                Assert.Equal(viewModelTest.Date, modelTest.Date);
                Assert.Equal(viewModelTest.DateNull, modelTest.DateNull);
                Assert.Equal(viewModelTest.UserId, modelTest.UserId);
                Assert.Equal(viewModelTest.UserNullId, modelTest.UserNullId);
                Assert.Equal(viewModelTest.IsBool, modelTest.IsBool);
                Assert.Equal(viewModelTest.IsBoolNull, modelTest.IsBoolNull);
                Assert.Equal(viewModelTest.Decimal, modelTest.Decimal);
                Assert.Equal(viewModelTest.DecimalNull, modelTest.DecimalNull);
                Assert.Equal(viewModelTest.User, modelTest.User);
                Assert.Equal(viewModelTest.UserNull, modelTest.UserNull);
                Assert.Equal(viewModelTest.DisplayName, modelTest.DisplayName);
                Assert.Equal(viewModelTest.CreatedDate, modelTest.CreatedDate);
                Assert.Equal(viewModelTest.LastUpdatedBy, modelTest.LastUpdatedBy);
                Assert.Equal(viewModelTest.LastUpdatedDate, modelTest.LastUpdatedDate);


                Assert.NotNull(viewModelTest.UserName);
                Assert.Null(viewModelTest.UserNull);
                Assert.NotNull(viewModelTest.UserNullName);
            }
        }
 public void GridController_Constructor_Run()
 {
     using (var context = new TestContext.TestDbContext(TestTools.CreateNewContextOptions()))
     {
         var manager    = new GridManager <TableModel, ViewModel, FindModel>(context);
         var controller = new GridController <TableModel, ViewModel, FindModel>(manager);
         Assert.NotNull(controller);
     }
 }
Beispiel #3
0
        public void MultipleIncludesTest01_MemoryTesting()
        {
            using (var context = new TestContext.TestDbContext(TestTools.CreateNewContextOptions()))
            {
                context.CreateTestUsers(10).CreateTableModels(5);
                var actual   = context.Set <TableModel>().MultipleIncludes("User", "EmployeeNull").ToList();
                var expected = context.Set <TableModel>().Include(i => i.User).Include(i => i.EmployeeNull).ToList();

                Assert.Equal(expected, actual);
            }
        }
        public async void GridController_GetGridResponseModelAsync_RunIsTypeJsonResult()
        {
            using (var context = new TestContext.TestDbContext(TestTools.CreateNewContextOptions()))
            {
                var manager    = new GridManager <TableModel, ViewModel, FindModel>(context);
                var controller = new GridController <TableModel, ViewModel, FindModel>(manager);
                var result     = await controller.GetGridResponseModelAsync(new RequestModel <FindModel>());

                Assert.IsType <Microsoft.AspNetCore.Mvc.JsonResult>(result);
            }
        }
        public async void GridController_GetGridModelAsync_ReturnIsTypeViewModel(int id)
        {
            using (var context = new TestContext.TestDbContext(TestTools.CreateNewContextOptions()))
            {
                context.CreateTestUsers(id).CreateTestEmployees(id).CreateTableModels(id);

                var manager    = new GridManager <TableModel, ViewModel, FindModel>(context);
                var controller = new GridController <TableModel, ViewModel, FindModel>(manager);
                var result     = await controller.GetGridModelAsync(id);

                Assert.IsType <ViewModel>(((Microsoft.AspNetCore.Mvc.JsonResult)result).Value);
            }
        }
        public async void GridController_GetGridListAsync_ReturnIsTypeSelectItemViewModel(int?keyId)
        {
            using (var context = new TestContext.TestDbContext(TestTools.CreateNewContextOptions()))
            {
                context.CreateTestUsers(256).CreateTestEmployees(256).CreateTableModels(256);

                var manager    = new GridManager <TableModel, ViewModel, FindModel>(context);
                var controller = new GridController <TableModel, ViewModel, FindModel>(manager);
                var result     = await controller.GetGridListAsync(keyId);

                Assert.IsType <System.Collections.Generic.List <ViewModel> >(((Microsoft.AspNetCore.Mvc.JsonResult)result).Value);
            }
        }
        public async void GridController_GetGridListAsync_RunIsTypeJsonResult(int?keyId)
        {
            using (var context = new TestContext.TestDbContext(TestTools.CreateNewContextOptions()))
            {
                context.CreateTestUsers(5).CreateTestEmployees(5).CreateTableModels(5);

                var manager    = new GridManager <TableModel, ViewModel, FindModel>(context);
                var controller = new GridController <TableModel, ViewModel, FindModel>(manager);
                var result     = await controller.GetGridListAsync(keyId);

                Assert.IsType <Microsoft.AspNetCore.Mvc.JsonResult>(result);
            }
        }
        public async void GridController_SaveGridRowModelAsync_SavedTypeIsViewModel(int id)
        {
            using (var context = new TestContext.TestDbContext(TestTools.CreateNewContextOptions()))
            {
                context.CreateTestUsers(id).CreateTestEmployees(id).CreateTableModels(id);

                var manager    = new GridManager <TableModel, ViewModel, FindModel>(context);
                var controller = new GridController <TableModel, ViewModel, FindModel>(manager);
                var model      = context.Set <TableModel>().Find(id);
                model.Test = "Test";
                var result = await controller.SaveGridRowModelAsync(model);

                Assert.IsType <ViewModel>(((Microsoft.AspNetCore.Mvc.JsonResult)result).Value);
                Assert.Equal("Test", ((ViewModel)((Microsoft.AspNetCore.Mvc.JsonResult)result).Value).Test);
            }
        }
Beispiel #9
0
        public void OrderByListTest01_MemoryTesting()
        {
            using (var context = new TestContext.TestDbContext(TestTools.CreateNewContextOptions()))
            {
                context.CreateTestUsers(5);

                var str = new System.Collections.Generic.List <string>()
                {
                    "CreatedDate", "DisplayName desc"
                };
                var actual   = context.Set <User>().AsQueryable().OrderByList(str);
                var expected = context.Set <User>().AsQueryable().OrderBy(o => o.CreatedDate).ThenByDescending(t => t.DisplayName);

                Assert.Equal(expected, actual);
                Assert.Equal(expected.ToList(), actual.ToList());
            }
        }
Beispiel #10
0
        public void MultipleIncludesTest01_PerformanceTest()
        {
            using (var context = new TestContext.TestDbContext(TestTools.CreateNewContextOptions()))
            {
                context.CreateTestUsers(10).CreateTableModels(5);

                var expectedwatch = System.Diagnostics.Stopwatch.StartNew();
                var expected      = context.Set <TableModel>().Include(i => i.User).Include(i => i.EmployeeNull).ToList();
                expectedwatch.Stop();

                var      actualwatch = System.Diagnostics.Stopwatch.StartNew();
                var      actual      = context.Set <TableModel>().AsQueryable();
                string[] includes    = { "User", "EmployeeNull" };
                var      actuallist  = includes.Aggregate(actual, (current, include) => current.Include(include)).ToList();
                actualwatch.Stop();

                Assert.True(actualwatch.ElapsedTicks <= expectedwatch.ElapsedTicks);
            }
        }
        public async void GridController_GetGridResponseModelAsync_ReturnIsTypeSelectItemViewModel(int currentPage, int pageSize, int?keyId)
        {
            using (var context = new TestContext.TestDbContext(TestTools.CreateNewContextOptions()))
            {
                context.CreateTestUsers(3).CreateTestEmployees(3).CreateTableModels(3);

                var manager    = new GridManager <TableModel, ViewModel, FindModel>(context);
                var controller = new GridController <TableModel, ViewModel, FindModel>(manager);

                var rm = new RequestModel <FindModel>();
                rm.CurrentPage = currentPage;
                rm.PageSize    = pageSize;
                rm.KeyId       = keyId;

                var result = await controller.GetGridResponseModelAsync(rm);

                Assert.IsType <Models.ResponseModel <ViewModel> >(((Microsoft.AspNetCore.Mvc.JsonResult)result).Value);
            }
        }
        public async void GridController_SaveGridListAsync_SavedTypeIsViewModel(int id)
        {
            using (var context = new TestContext.TestDbContext(TestTools.CreateNewContextOptions()))
            {
                context.CreateTestUsers(id).CreateTestEmployees(id).CreateTableModels(id);

                var manager    = new GridManager <TableModel, ViewModel, FindModel>(context);
                var controller = new GridController <TableModel, ViewModel, FindModel>(manager);
                var list       = context.Set <TableModel>().ToList();
                foreach (var item in list)
                {
                    item.Test = "Test";
                }
                var result = await controller.SaveGridListAsync(list);

                Assert.IsType <System.Collections.Generic.List <ViewModel> >(((Microsoft.AspNetCore.Mvc.JsonResult)result).Value);
                foreach (var item in (System.Collections.Generic.List <ViewModel>)((Microsoft.AspNetCore.Mvc.JsonResult)result).Value)
                {
                    Assert.Equal("Test", item.Test);
                }
            }
        }