Example #1
0
        public void Entity_CrudEntity_Create()
        {
            var newCustomer    = new CustomerInfo();
            var resultCustomer = new CustomerInfo();
            var dbCustomer     = new CustomerInfo();

            // Create should update original object, and pass back a fresh-from-db object
            newCustomer.Fill(testEntities[Arithmetic.Random(1, 5)]);
            resultCustomer = newCustomer.Create();
            Assert.IsTrue(newCustomer.ID != TypeExtension.DefaultInteger);
            Assert.IsTrue(newCustomer.Key != TypeExtension.DefaultGuid);
            Assert.IsTrue(resultCustomer.ID != TypeExtension.DefaultInteger);
            Assert.IsTrue(resultCustomer.Key != TypeExtension.DefaultGuid);

            // Object in db should match in-memory objects
            dbCustomer = dbCustomer.Read(x => x.ID == resultCustomer.ID).FirstOrDefaultSafe();
            Assert.IsTrue(dbCustomer.ID != TypeExtension.DefaultInteger);
            Assert.IsTrue(dbCustomer.Key != TypeExtension.DefaultGuid);
            Assert.IsTrue(dbCustomer.ID == resultCustomer.ID && resultCustomer.ID == newCustomer.ID);
            Assert.IsTrue(dbCustomer.Key == resultCustomer.Key && resultCustomer.Key == newCustomer.Key);

            recycleBin.Add(newCustomer.ID);
        }
        public void Data_SaveableDatabase_Insert()
        {
            var dataStore = SaveableDatabase <CustomerInfo> .Construct();

            var testEntity   = new CustomerInfo();
            var resultEntity = new CustomerInfo();
            var oldID        = TypeExtension.DefaultInteger;
            var oldKey       = TypeExtension.DefaultGuid;
            var newID        = TypeExtension.DefaultInteger;
            var newKey       = TypeExtension.DefaultGuid;

            // Create and insert record
            testEntity.Fill(testEntities[Arithmetic.Random(1, 5)]);
            oldID  = testEntity.ID;
            oldKey = testEntity.Key;
            Assert.IsTrue(testEntity.IsNew);
            Assert.IsTrue(testEntity.ID == TypeExtension.DefaultInteger);
            Assert.IsTrue(testEntity.Key == TypeExtension.DefaultGuid);

            // Do Insert and check passed entity and returned entity
            resultEntity = dataStore.Save(testEntity, true);
            Assert.IsTrue(testEntity.ID != TypeExtension.DefaultInteger);
            Assert.IsTrue(testEntity.Key != TypeExtension.DefaultGuid);
            Assert.IsTrue(resultEntity.ID != TypeExtension.DefaultInteger);
            Assert.IsTrue(resultEntity.Key != TypeExtension.DefaultGuid);

            // Pull from DB and retest
            testEntity = dataStore.GetByID(resultEntity.ID);
            Assert.IsTrue(testEntity.IsNew == false);
            Assert.IsTrue(testEntity.ID != oldID);
            Assert.IsTrue(testEntity.Key != oldKey);
            Assert.IsTrue(testEntity.ID != TypeExtension.DefaultInteger);
            Assert.IsTrue(testEntity.Key != TypeExtension.DefaultGuid);

            // Cleanup
            recycleBin.Add(testEntity.ID);
        }