示例#1
0
        public async Task CleanupWhenAddBusinessRulesThrowsException()
        {
            IDataPortal <RootThrowsException> dataPortal = _testDIContext.CreateDataPortal <RootThrowsException>();

            RootThrowsException.Counter = 0;

            // AddBusinessRules throw an ArgumentException
            // In .NET the exception will occur serverside and returned i DatPortalEventArgs
            try
            {
                await dataPortal.CreateAsync();
            }
            catch (DataPortalException ex)
            {
                Assert.IsTrue(ex.InnerException is ArgumentException);
            }

            // should fail again as type rules should be cleaned up
            // AddBusinessRules throw an ArgumentException
            try
            {
                await dataPortal.CreateAsync();
            }
            catch (DataPortalException ex)
            {
                Assert.IsTrue(ex.InnerException is ArgumentException);
            }
        }
示例#2
0
        public async Task SaveAsyncWithException()
        {
            var context = GetContext();
            await context.Assert.Try(async() =>
            {
                IDataPortal <Single2> dataPortal = _testDIContext.CreateDataPortal <Single2>();

                var result = await dataPortal.CreateAsync(555);
                Assert.IsNotNull(result);
                Assert.AreEqual(555, result.Id);
                Assert.IsTrue(result.IsNew);
                Assert.IsTrue(result.IsDirty);
                var lck = new AutoResetEvent(false);
                new Action(async() =>
                {
                    try
                    {
                        result = await result.SaveAsync();
                        Assert.Fail("Expected exception not thrown");
                    }
                    catch (Exception ex)
                    {
                        context.Assert.IsTrue(ex.GetType() == typeof(Csla.DataPortalException));
                    }
                    finally
                    {
                        lck.Set();
                    }
                }).Invoke();
                lck.WaitOne();
                context.Assert.Success();
            });

            context.Complete();
        }
示例#3
0
 /// <summary>
 /// Override to provide custom Model refresh behavior
 /// </summary>
 /// <param name="parameters">Parameters passed to data portal</param>
 /// <returns></returns>
 protected virtual async Task <T> DoRefreshAsync(params object[] parameters)
 {
     if (typeof(Core.IReadOnlyObject).IsAssignableFrom(typeof(T)) ||
         typeof(Core.IReadOnlyCollection).IsAssignableFrom(typeof(T)) ||
         typeof(Core.IEditableCollection).IsAssignableFrom(typeof(T)))
     {
         if (Server.DataPortal.GetCriteriaFromArray(parameters) is Server.EmptyCriteria)
         {
             return(await DataPortal.FetchAsync());
         }
         else
         {
             return(await DataPortal.FetchAsync(parameters));
         }
     }
     else
     {
         if (Server.DataPortal.GetCriteriaFromArray(parameters) is Server.EmptyCriteria)
         {
             return(await DataPortal.CreateAsync());
         }
         else
         {
             return(await DataPortal.FetchAsync(parameters));
         }
     }
 }
示例#4
0
        public async Task BeginCreate_overload_with_Criteria_passed_and_Id_set()
        {
            IDataPortal <Single> dataPortal = _testDIContext.CreateDataPortal <Single>();

            var created = await dataPortal.CreateAsync(100);

            Assert.AreEqual(created.Id, 100);
        }
示例#5
0
        public async Task BeginCreate_overload_without_parameters()
        {
            IDataPortal <Single> dataPortal = _testDIContext.CreateDataPortal <Single>();

            var created = await dataPortal.CreateAsync();

            Assert.AreEqual(created.Id, 0);
        }
示例#6
0
        public async Task CreateAsync_NoCriteria()
        {
            IDataPortal <Single> dataPortal = _testDIContext.CreateDataPortal <Single>();

            var result = await dataPortal.CreateAsync();

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Id);
        }
示例#7
0
 public async Task OnGet(int id)
 {
     if (id == -1)
     {
         Item = await _portal.CreateAsync();
     }
     else
     {
         Item = await _portal.FetchAsync(id);
     }
 }
示例#8
0
 public ItemEditViewModel(IDataPortal <PersonEdit> portal, int id)
 {
     PersonPortal = portal;
     Initialize();
     if (id == -1)
     {
         RefreshAsync <PersonEdit>(() => PersonPortal.CreateAsync());
     }
     else
     {
         RefreshAsync <PersonEdit>(() => PersonPortal.FetchAsync(id));
     }
 }
示例#9
0
        public async Task CreateAsync_Parrallel()
        {
            IDataPortal <SingleWithFactory> dataPortal = _testDIContext.CreateDataPortal <SingleWithFactory>();

            var list = new List <int>(500);

            for (var i = 0; i < 500; i++)
            {
                list.Add(i);
            }

            var tasks = list.AsParallel().Select(x => dataPortal.CreateAsync());
            await Task.WhenAll(tasks);
        }
示例#10
0
        public async Task SaveAsync()
        {
            IDataPortal <Single2> dataPortal = _testDIContext.CreateDataPortal <Single2>();

            var result = await dataPortal.CreateAsync(0);

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Id);
            Assert.IsTrue(result.IsNew);
            Assert.IsTrue(result.IsDirty);
            result = await result.SaveAsync();

            Assert.IsFalse(result.IsNew);
            Assert.IsFalse(result.IsDirty);
        }
示例#11
0
        public async Task CreateAndSaveAnyChildAsync()
        {
            IChildDataPortal <Child>            childDataPortal = _testDIContext.CreateChildDataPortal <Child>();
            IDataPortal <RootUpdateAllChildren> dataPortal      = _testDIContext.CreateDataPortal <RootUpdateAllChildren>();

            var root = await dataPortal.CreateAsync();

            await root.FetchChildAsync(childDataPortal);

            Assert.IsFalse(root.Child.IsDirty, "Child should not be dirty");
            Assert.AreEqual("Fetched", root.Child.Status, "Child status incorrect after fetch");

            root = await root.SaveAsync();

            Assert.AreEqual("Updated", root.Child.Status, "Child status incorrect after Save");
        }
示例#12
0
        private async void PersonEditPage_Load(object sender, EventArgs e)
        {
            var        personInfo = (PersonInfo)Context;
            PersonEdit personEdit;

            if (personInfo == null)
            {
                personEdit = await _portal.CreateAsync();
            }
            else
            {
                personEdit = await _portal.FetchAsync(personInfo.Id);
            }
            nameTextBox.DataBindings.Add(nameof(nameTextBox.Text), personEdit, nameof(personEdit.Name));
            saveButton.DataBindings.Add(nameof(saveButton.Enabled), personEdit, nameof(personEdit.IsSavable));
            errorProvider1.DataSource = personEdit;
        }
示例#13
0
        private async void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            var context = Context as PersonInfo;

            ViewModel.Model = await ViewModel.RefreshAsync <PersonEdit>(async() =>
            {
                if (context == null)
                {
                    return(await _portal.CreateAsync());
                }
                else
                {
                    return(await _portal.FetchAsync(context.Id));
                }
            });

            DataContext = ViewModel;
        }
示例#14
0
        public async Task TestValidationRulesAfterSerialization()
        {
            IDataPortal <HasRulesManager> dataPortal = _testDIContext.CreateDataPortal <HasRulesManager>();

            UnitTestContext context = GetContext();
            var             root    = await dataPortal.CreateAsync(new HasRulesManager.Criteria());

            root.Name = "";
            context.Assert.AreEqual(false, root.IsValid, "root should not start valid");

            root = root.Clone();
            context.Assert.AreEqual(false, root.IsValid, "root should not be valid after clone");
            root.Name = "something";
            context.Assert.AreEqual(true, root.IsValid, "root should be valid after property set");
            root = root.Clone();
            context.Assert.AreEqual(true, root.IsValid, "root should be valid after second clone");
            context.Assert.Success();

            context.Complete();
        }
示例#15
0
        public void CreateAsync_WithException()
        {
            var lck = new AutoResetEvent(false);

            new Action(async() =>
            {
                IDataPortal <Single2> dataPortal = _testDIContext.CreateDataPortal <Single2>();

                try
                {
                    var result = await dataPortal.CreateAsync(9999);
                    Assert.Fail("Expected exception not thrown");
                }
                catch (Exception ex)
                {
                    Assert.IsInstanceOfType(ex, typeof(Csla.DataPortalException));
                }
                finally
                {
                    lck.Set();
                }
            }).Invoke();
            lck.WaitOne();
        }
示例#16
0
        private async Task <Root> CreateRootInstanceAsync(Root.Criteria criteria)
        {
            IDataPortal <Root> dataPortal = _testDIContext.CreateDataPortal <Root>();

            return(await dataPortal.CreateAsync(criteria));
        }
示例#17
0
        public async Task BeginCreate_Calling_BO_Without_DP_CREATE_Returns_no_Error_info()
        {
            IDataPortal <CustomerWO_DP_XYZ> dataPortal = _testDIContext.CreateDataPortal <CustomerWO_DP_XYZ>();

            await dataPortal.CreateAsync();
        }
示例#18
0
        public async Task BeginCreate_with_exception()
        {
            IDataPortal <Single> dataPortal = _testDIContext.CreateDataPortal <Single>();

            await dataPortal.CreateAsync(9999);
        }
示例#19
0
        private async Task <HasRulesManager2> CreateHasRulesManager2Async(string ident)
        {
            IDataPortal <HasRulesManager2> dataPortal = _testDIContext.CreateDataPortal <HasRulesManager2>();

            return(await dataPortal.CreateAsync(new HasRulesManager2.Criteria(ident)));
        }
示例#20
0
        private async Task <HasRulesManager2> CreateHasRulesManager2Async()
        {
            IDataPortal <HasRulesManager2> dataPortal = _testDIContext.CreateDataPortal <HasRulesManager2>();

            return(await dataPortal.CreateAsync());
        }
示例#21
0
        private async Task <HasRulesManager> CreateHasRulesManagerAsync()
        {
            IDataPortal <HasRulesManager> dataPortal = _testDIContext.CreateDataPortal <HasRulesManager>();

            return(await dataPortal.CreateAsync(new HasRulesManager.Criteria()));
        }
示例#22
0
        private async Task <T> CreateWithoutCriteriaAsync <T>()
        {
            IDataPortal <T> dataPortal = _testDIContext.CreateDataPortal <T>();

            return(await dataPortal.CreateAsync());
        }
示例#23
0
        private async Task <RootList> CreateRootListInstanceAsync()
        {
            IDataPortal <RootList> dataPortal = DataPortalFactory.CreateDataPortal <RootList>();

            return(await dataPortal.CreateAsync());
        }
示例#24
0
        private async Task <Root> CreateRootInstanceAsync(Root.Criteria criteria)
        {
            IDataPortal <Root> dataPortal = DataPortalFactory.CreateDataPortal <Root>();

            return(await dataPortal.CreateAsync(criteria));
        }
示例#25
0
        // GET: Person/Create
        public async Task <ActionResult> Create()
        {
            var obj = await PersonEditPortal.CreateAsync();

            return(View(obj));
        }
示例#26
0
        private async Task <RootList> CreateRootListInstanceAsync()
        {
            IDataPortal <RootList> dataPortal = _testDIContext.CreateDataPortal <RootList>();

            return(await dataPortal.CreateAsync());
        }