Example #1
0
        public async Task Core_Entity_CustomerInfo_Insert_Key()
        {
            var testEntity   = new CustomerInfo();
            var resultEntity = new CustomerInfo();

            // Create and insert record
            testEntity.Fill(testEntities[Arithmetic.Random(1, testEntities.Count)]);
            testEntity.Id  = -1;
            testEntity.Key = Guid.NewGuid();
            var oldId  = testEntity.Id;
            var oldKey = testEntity.Key;

            Assert.IsTrue(testEntity.Id == -1);
            Assert.IsTrue(testEntity.Key != Guid.Empty);
            Assert.IsTrue(!testEntity.FailedRules.Any());

            // Do Insert and check passed entity and returned entity
            using (var writer = new EntityWriter <CustomerInfo>(new CustomerSPConfig(new ConnectionStringFactory().GetDefaultConnection(), testEntity)))
            {
                resultEntity = await writer.CreateAsync();
            }
            Assert.IsTrue(testEntity.Id != -1);
            Assert.IsTrue(testEntity.Key != Guid.Empty);
            Assert.IsTrue(resultEntity.Id != -1);
            Assert.IsTrue(resultEntity.Key != Guid.Empty);
            Assert.IsTrue(!resultEntity.FailedRules.Any());

            // Pull from DB and retest
            testEntity = new EntityReader <CustomerInfo>(new ConnectionStringFactory().GetDefaultConnection()).GetById(resultEntity.Id);
            Assert.IsTrue(testEntity.IsNew == false);
            Assert.IsTrue(testEntity.Id != oldId);
            Assert.IsTrue(testEntity.Key == oldKey);
            Assert.IsTrue(testEntity.Id != -1);
            Assert.IsTrue(testEntity.Key != Guid.Empty);
            Assert.IsTrue(!testEntity.FailedRules.Any());

            // Cleanup
            RecycleBin.Add(testEntity.Key);
        }
Example #2
0
        public async Task Core_Entity_CustomerInfo_Update()
        {
            var testEntity   = new CustomerInfo();
            var reader       = new EntityReader <CustomerInfo>(new ConnectionStringFactory().GetDefaultConnection());
            var oldFirstName = string.Empty;
            var newFirstName = DateTime.UtcNow.Ticks.ToString();
            var entityId     = -1;
            var entityKey    = Guid.Empty;

            // Create and capture original data
            await Core_Entity_CustomerInfo_Insert();

            testEntity           = reader.GetAll().OrderByDescending(x => x.CreatedDate).FirstOrDefaultSafe();
            oldFirstName         = testEntity.FirstName;
            entityId             = testEntity.Id;
            entityKey            = testEntity.Key;
            testEntity.FirstName = newFirstName;
            Assert.IsTrue(testEntity.IsNew == false);
            Assert.IsTrue(testEntity.Id != -1);
            Assert.IsTrue(testEntity.Key != Guid.Empty);
            Assert.IsTrue(!testEntity.FailedRules.Any());

            // Do Update
            using (var writer = new EntityWriter <CustomerInfo>(new CustomerSPConfig(new ConnectionStringFactory().GetDefaultConnection(), testEntity)))
            {
                testEntity = await writer.UpdateAsync();
            }
            Assert.IsTrue(!testEntity.FailedRules.Any());

            // Pull from DB and retest
            testEntity = reader.GetById(entityId);
            Assert.IsTrue(testEntity.IsNew == false);
            Assert.IsTrue(testEntity.Id == entityId);
            Assert.IsTrue(testEntity.Key == entityKey);
            Assert.IsTrue(testEntity.Id != -1);
            Assert.IsTrue(testEntity.Key != Guid.Empty);
            Assert.IsTrue(!testEntity.FailedRules.Any());
        }
Example #3
0
        public async Task Core_Entity_CustomerInfo_Delete()
        {
            var reader     = new EntityReader <CustomerInfo>(new ConnectionStringFactory().GetDefaultConnection());
            var testEntity = new CustomerInfo();
            var oldId      = -1;
            var oldKey     = Guid.Empty;

            // Insert and baseline test
            await Core_Entity_CustomerInfo_Insert();

            testEntity = reader.GetAll().OrderByDescending(x => x.CreatedDate).FirstOrDefaultSafe();
            oldId      = testEntity.Id;
            oldKey     = testEntity.Key;
            Assert.IsTrue(testEntity.IsNew == false);
            Assert.IsTrue(testEntity.Id != -1);
            Assert.IsTrue(testEntity.Key != Guid.Empty);
            Assert.IsTrue(!testEntity.FailedRules.Any());

            // Do delete
            using (var writer = new EntityWriter <CustomerInfo>(new CustomerSPConfig(new ConnectionStringFactory().GetDefaultConnection(), testEntity)))
            {
                testEntity = await writer.DeleteAsync();
            }
            Assert.IsTrue(!testEntity.FailedRules.Any());

            // Pull from DB and retest
            testEntity = reader.GetAll().Where(x => x.Id == oldId).FirstOrDefaultSafe();
            Assert.IsTrue(testEntity.IsNew);
            Assert.IsTrue(testEntity.Id != oldId);
            Assert.IsTrue(testEntity.Key != oldKey);
            Assert.IsTrue(testEntity.Id == -1);
            Assert.IsTrue(testEntity.Key == Guid.Empty);
            Assert.IsTrue(!testEntity.FailedRules.Any());

            // Add to recycle bin for cleanup
            RecycleBin.Add(testEntity.Key);
        }