public void Bulk_Deleted_Entities_Are_Gone() { var describeds = new List<DescribedThing>(); for (int i = 0; i < 20; i++) { describeds.Add(CreateDescribedThing()); } using (var unitOfWork = new UnitOfWork()) { var list = _provider.Query<DescribedThing>(unitOfWork) .OrderBy(x => x.Id) .Skip(10) .Take(10) .Select(x => x.Id) .ToArray(); var count = _provider.BulkDelete<DescribedThing>(x => list.Any(y => y == x.Id)); Assert.AreEqual(list.Length, count); var query = _provider .Query<DescribedThing>(unitOfWork) .Where(x => Enumerable.Contains(list, x.Id)) .ToArray(); Assert.IsFalse(query.Any()); } }
public void Bulk_Updated_Entities_Are_Changed() { this._provider.BulkUpdate<DescribedThing,string>( predicate: x => x.Description.StartsWith("h"), propertyExpression: x => x.Label, assignmentExpression: x => ""); using (var unitOfWork = new UnitOfWork()) { var things = this._provider.Query<DescribedThing>(unitOfWork) .Where(x => x.Description.StartsWith("h")); Assert.IsTrue(things.All(x => x.Label == "")); } }
public void Bulk_Inserted_Entities_Are_Present() { var things = new List<DescribedThing>(); var randomValue = Guid.NewGuid().ToString(); for (int i = 0; i < 10; i++) { var described = CreateDescribedThing(); things.Add(described); described.Label = randomValue; } this._provider.BulkInsert<DescribedThing,string>(things);//.BulkInsert<DescribedThing, string>(things); using (var unitOfWork = new UnitOfWork()) { var retrieved = this._provider.Query<DescribedThing>(unitOfWork) .Where(myDescribed => myDescribed.Label == randomValue); Assert.AreEqual(retrieved.Count(), 10); } }
public void Deleted_Entity_Is_Gone() { var described = CreateDescribedThing(); var id = described.Id; this._provider.Insert<DescribedThing, string>(described); using (var unitOfWork = new UnitOfWork()) { var retrieved = this._provider.Query<DescribedThing>(unitOfWork) .FirstOrDefault(myDescribed => myDescribed.Id == id); Assert.IsNotNull(retrieved); this._provider.Delete<DescribedThing, string>(id); retrieved = this._provider.Query<DescribedThing>(unitOfWork) .FirstOrDefault(myDescribed => myDescribed.Id == id); Assert.IsNull(retrieved); } }
public void Queryable_Is_Case_Insensitive() { var described = CreateDescribedThing(); var originalDescription = described.Description; this._provider.Insert<DescribedThing, string>(described); var describedUppercase = CreateDescribedThing(); describedUppercase.Description = originalDescription.ToUpper(); this._provider.Insert<DescribedThing, string>(describedUppercase); using (var unitOfWork = new UnitOfWork()) { var retrievedCount = this._provider.Query<DescribedThing>(unitOfWork) .Count(d => d.Description == originalDescription); var uppercaseCount = this._provider.Query<DescribedThing>(unitOfWork) .Count(d => d.Description == originalDescription.ToUpper()); // SQL server comparison Assert.IsTrue(retrievedCount == uppercaseCount); // .NET framework comparison using CaseInsensitiveQueryable: uppercaseCount = this._provider.Query<DescribedThing>() .Where(d => d.Description == originalDescription.ToUpper()) .ToList() .AsQueryable() .AsCaseInsensitive() .Count(); Assert.IsTrue(retrievedCount == uppercaseCount); } }
public void Modified_Entity_Change_Is_Persisted() { var described = CreateDescribedThing(); var id = described.Id; this._provider.Insert<DescribedThing, string>(described); var retrieved = this._provider.Get<DescribedThing, string>(id); var newDescription = string.Format("{0} {1}", Product.Department(), DateTime.Now.TimeOfDay); retrieved.Description = newDescription; this._provider.Update<DescribedThing, string>(retrieved); using (var unitOfWork = new UnitOfWork()) { retrieved = this._provider.Query<DescribedThing>(unitOfWork) .FirstOrDefault(myDescribed => myDescribed.Id == id); if (retrieved != null) Assert.AreEqual((object) retrieved.Description, newDescription); else Assert.Fail("Description was not updated"); } }