public async Task Schedule_SlotTimeRange_Create() { var testEntity = new SlotTimeRange(); var resultEntity = new SlotTimeRange(); var reader = new EntityReader <SlotTimeRange>(); // Create should update original object, and pass back a fresh-from-db object testEntity.Fill(testEntities[Arithmetic.Random(1, testEntities.Count)]); using (var writer = new EntityWriter <SlotTimeRange>(testEntity, new SlotTimeRangeSPConfig())) { resultEntity = await writer.SaveAsync(); } Assert.IsTrue(testEntity.Id != Defaults.Integer); Assert.IsTrue(testEntity.Key != Defaults.Guid); Assert.IsTrue(resultEntity.Id != Defaults.Integer); Assert.IsTrue(resultEntity.Key != Defaults.Guid); Assert.IsTrue(!resultEntity.FailedRules.Any()); // Object in db should match in-memory objects testEntity = reader.Read(x => x.Id == resultEntity.Id).FirstOrDefaultSafe(); Assert.IsTrue(!testEntity.IsNew); Assert.IsTrue(testEntity.Id != Defaults.Integer); Assert.IsTrue(testEntity.Key != Defaults.Guid); Assert.IsTrue(testEntity.Id == resultEntity.Id); Assert.IsTrue(testEntity.Key == resultEntity.Key); Assert.IsTrue(!testEntity.FailedRules.Any()); SlotTimeRangeTests.RecycleBin.Add(testEntity.Key); }
public static async Task Cleanup() { var reader = new EntityReader <SlotTimeRange>(); var toDelete = new SlotTimeRange(); foreach (Guid item in RecycleBin) { toDelete = reader.GetAll().Where(x => x.Key == item).FirstOrDefaultSafe(); using (var db = new EntityWriter <SlotTimeRange>(toDelete, new SlotTimeRangeSPConfig())) { await db.DeleteAsync(); } } }
public void Schedule_SlotTimeRange_Serialize() { var searchChar = "i"; var originalObject = new SlotTimeRange() { SlotName = searchChar, SlotDescription = searchChar }; var resultObject = new SlotTimeRange(); var resultString = Defaults.String; var serializer = new JsonSerializer <SlotTimeRange>(); resultString = serializer.Serialize(originalObject); Assert.IsTrue(resultString != Defaults.String); resultObject = serializer.Deserialize(resultString); Assert.IsTrue(resultObject.SlotName == searchChar); Assert.IsTrue(resultObject.SlotDescription == searchChar); }
public async Task Schedule_SlotTimeRange_Read() { var reader = new EntityReader <SlotTimeRange>(); var testEntity = new SlotTimeRange(); var lastKey = Defaults.Guid; await Schedule_SlotTimeRange_Create(); lastKey = SlotTimeRangeTests.RecycleBin.LastOrDefault(); testEntity = reader.Read(x => x.Key == lastKey).FirstOrDefaultSafe(); Assert.IsTrue(!testEntity.IsNew); Assert.IsTrue(testEntity.Id != Defaults.Integer); Assert.IsTrue(testEntity.Key != Defaults.Guid); Assert.IsTrue(testEntity.CreatedDate.Date == DateTime.UtcNow.Date); Assert.IsTrue(!testEntity.FailedRules.Any()); }
public async Task Schedule_SlotTimeRange_Update() { var reader = new EntityReader <SlotTimeRange>(); var resultEntity = new SlotTimeRange(); var testEntity = new SlotTimeRange(); var lastKey = Defaults.Guid; var originalId = Defaults.Integer; var originalKey = Defaults.Guid; await Schedule_SlotTimeRange_Create(); lastKey = SlotTimeRangeTests.RecycleBin.LastOrDefault(); testEntity = reader.Read(x => x.Key == lastKey).FirstOrDefaultSafe(); originalId = testEntity.Id; originalKey = testEntity.Key; Assert.IsTrue(!testEntity.IsNew); Assert.IsTrue(testEntity.Id != Defaults.Integer); Assert.IsTrue(testEntity.Key != Defaults.Guid); Assert.IsTrue(!testEntity.FailedRules.Any()); using (var writer = new EntityWriter <SlotTimeRange>(testEntity, new SlotTimeRangeSPConfig())) { resultEntity = await writer.SaveAsync(); } Assert.IsTrue(!resultEntity.IsNew); Assert.IsTrue(resultEntity.Id != Defaults.Integer); Assert.IsTrue(resultEntity.Key != Defaults.Guid); Assert.IsTrue(testEntity.Id == resultEntity.Id && resultEntity.Id == originalId); Assert.IsTrue(testEntity.Key == resultEntity.Key && resultEntity.Key == originalKey); Assert.IsTrue(!testEntity.FailedRules.Any()); testEntity = reader.Read(x => x.Id == originalId).FirstOrDefaultSafe(); Assert.IsTrue(!testEntity.IsNew); Assert.IsTrue(testEntity.Id == resultEntity.Id && resultEntity.Id == originalId); Assert.IsTrue(testEntity.Key == resultEntity.Key && resultEntity.Key == originalKey); Assert.IsTrue(testEntity.Id != Defaults.Integer); Assert.IsTrue(testEntity.Key != Defaults.Guid); Assert.IsTrue(!testEntity.FailedRules.Any()); }
public async Task Schedule_SlotTimeRange_Delete() { var reader = new EntityReader <SlotTimeRange>(); var testEntity = new SlotTimeRange(); var resultEntity = new SlotTimeRange(); var lastKey = Defaults.Guid; var originalId = Defaults.Integer; var originalKey = Defaults.Guid; await Schedule_SlotTimeRange_Create(); lastKey = SlotTimeRangeTests.RecycleBin.LastOrDefault(); testEntity = reader.Read(x => x.Key == lastKey).FirstOrDefaultSafe(); originalId = testEntity.Id; originalKey = testEntity.Key; Assert.IsTrue(testEntity.Id != Defaults.Integer); Assert.IsTrue(testEntity.Key != Defaults.Guid); Assert.IsTrue(testEntity.CreatedDate.Date == DateTime.UtcNow.Date); Assert.IsTrue(!testEntity.FailedRules.Any()); using (var writer = new EntityWriter <SlotTimeRange>(testEntity, new SlotTimeRangeSPConfig())) { resultEntity = await writer.DeleteAsync(); } Assert.IsTrue(resultEntity.IsNew); Assert.IsTrue(!testEntity.FailedRules.Any()); testEntity = reader.Read(x => x.Id == originalId).FirstOrDefaultSafe(); Assert.IsTrue(testEntity.Id != originalId); Assert.IsTrue(testEntity.Key != originalKey); Assert.IsTrue(testEntity.IsNew); Assert.IsTrue(testEntity.Key == Defaults.Guid); Assert.IsTrue(!testEntity.FailedRules.Any()); // Remove from RecycleBin (its already marked deleted) RecycleBin.Remove(lastKey); }