示例#1
0
        public void TestUpdate()
        {
            E.Test entity = Assert.ScriptCalled(_databaseFixture, Query.Select, () => _queryable.ToList().First());

            string oldString = entity.Description;
            string newString = oldString == FirstRandomText ? SecondRandomText : FirstRandomText;

            _databaseFixture.SetResult(Query.Update, new[] { new object[] { entity.Id, entity.Name, newString } });

            Assert.PropertyChanged((INotifyPropertyChanged)entity, nameof(E.Test.Description),
                                   () => entity.Description = newString);

            Assert.ScriptCalled(_databaseFixture, Query.Update, () => _databaseFixture.ObjectProvider.GetQueryable <E.Test>().Where(x => x == entity).Save());
        }
示例#2
0
        public void TestInsert()
        {
            List <E.Test> cachedItems = Assert.ScriptCalled(_databaseFixture, Query.Select, () => _databaseFixture.ObjectProvider.GetQueryable <E.Test>().ForceLoad().ToList());
            int           newId       = cachedItems.Count == 0 ? 1 : cachedItems.Max(x => x.Id) + 1;
            string        name        = $"Testname {DateTime.Now:g}";
            string        description = FirstRandomText;

            _databaseFixture.SetResult(Query.Insert, new[] { new object[] { newId, name, description } });

            E.Test entity = _databaseFixture.ObjectProvider.CreateObject <E.Test>();
            Assert.NotNull(entity);
            entity.Name        = name;
            entity.Description = description;

            _output.WriteLine($"Entity created, Name: {entity.Name}");

            Assert.PropertyChanged((INotifyPropertyChanged)entity, nameof(E.Test.Id),
                                   () => Assert.ScriptCalled(_databaseFixture, Query.Insert, () => _databaseFixture.ObjectProvider.GetQueryable <E.Test>().Where(x => x == entity).Save()));

            Assert.Equal(entity.Id, newId);
            _output.WriteLine($"First entity saved, new Id: {entity.Id} -> passed");
        }