Esempio n. 1
0
        public static async Task Cleanup()
        {
            var reader   = new EntityReader <ScheduleSlot>();
            var toDelete = new ScheduleSlot();

            foreach (Guid item in RecycleBin)
            {
                toDelete = reader.GetAll().Where(x => x.Key == item).FirstOrDefaultSafe();
                using (var db = new EntityWriter <ScheduleSlot>(toDelete, new ScheduleSlotSPConfig()))
                {
                    await db.DeleteAsync();
                }
            }
        }
Esempio n. 2
0
        public async Task Schedule_ScheduleSlot_Read()
        {
            var reader     = new EntityReader <ScheduleSlot>();
            var testEntity = new ScheduleSlot();
            var lastKey    = Defaults.Guid;

            await Schedule_ScheduleSlot_Create();

            lastKey = ScheduleSlotTests.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());
        }
Esempio n. 3
0
        public async Task Schedule_ScheduleSlot_Create()
        {
            var testEntity   = new ScheduleSlot();
            var resultEntity = new ScheduleSlot();
            var reader       = new EntityReader <ScheduleSlot>();
            var scheduleTest = new ScheduleInfoTests();
            var slotTest     = new SlotInfoTests();

            // Create base records
            await scheduleTest.Schedule_ScheduleInfo_Create();

            testEntity.ScheduleKey = ScheduleInfoTests.RecycleBin.LastOrDefault();
            await slotTest.Schedule_SlotInfo_Create();

            testEntity.SlotKey = SlotInfoTests.RecycleBin.LastOrDefault();

            // Create should update original object, and pass back a fresh-from-db object
            using (var writer = new EntityWriter <ScheduleSlot>(testEntity, new ScheduleSlotSPConfig()))
            {
                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());

            ScheduleSlotTests.RecycleBin.Add(testEntity.Key);
        }
Esempio n. 4
0
        public async Task Schedule_ScheduleSlot_Delete()
        {
            var reader       = new EntityReader <ScheduleSlot>();
            var testEntity   = new ScheduleSlot();
            var resultEntity = new ScheduleSlot();
            var lastKey      = Defaults.Guid;
            var originalId   = Defaults.Integer;
            var originalKey  = Defaults.Guid;

            await Schedule_ScheduleSlot_Create();

            lastKey = ScheduleSlotTests.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 <ScheduleSlot>(testEntity, new ScheduleSlotSPConfig()))
            {
                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);
        }