Exemplo n.º 1
0
        public async Task TestCanInsertAndGetList()
        {
            var collection = _db.GetCollection <SimplePerson>();

            var person = new SimplePerson()
            {
                Id        = Guid.NewGuid(),
                FirstName = "John",
                LastName  = "Smith"
            };

            var insertResult = await collection.InsertAsync(person);

            Assert.True(insertResult.IsGuid);
            Assert.Equal(person.Id, insertResult.AsGuid);

            var listResult = await collection.Query().ToListAsync();

            Assert.Single(listResult);
            var resultPerson = listResult[0];

            Assert.Equal(person.Id, resultPerson.Id);
            Assert.Equal(person.FirstName, resultPerson.FirstName);
            Assert.Equal(person.LastName, resultPerson.LastName);
        }
Exemplo n.º 2
0
        public async Task TestInsertingSameRecordTwiceRaisesException()
        {
            var collection = _db.GetCollection <SimplePerson>();

            var person = new SimplePerson()
            {
                Id        = Guid.NewGuid(),
                FirstName = "John",
                LastName  = "Smith"
            };

            await collection.InsertAsync(person);

            await Assert.ThrowsAnyAsync <LiteAsyncException>(async() => await collection.InsertAsync(person));
        }