public void TestSetup()
        {
            backingEntity = new MockModelATableEntity();
            model = new MockModelA(backingEntity);
            propertyManager = model.Property;

            // --

            myBackingEntity = new MyTableEntity();
            myModel = new MyModel(myBackingEntity);
        }
 public void ShouldReadFromInjectedBackingStore()
 {
     backingEntity = new MockModelATableEntity { Text = "Hello" };
     model = new MockModelA(backingEntity);
     model.Text.ShouldBe("Hello");
 }
        public void ShouldLookupWithPartialKeys()
        {
            var context = new MockModelAContext();
            context.DeleteTable();
            var entity = new MockModelATableEntity("P1", "R1");
            var mock = new MockModelA(entity) { Text = "FooBar", Number = 42 };
            mock.Property.Save(context);

            // ---

            context = new MockModelAContext();

            var propManager = TablePropertyManager<MockModelA, MockModelATableEntity>.Lookup(context, "Z", "X", KeyQueryType.StartsWith);
            propManager.ShouldBe(null);

            propManager = TablePropertyManager<MockModelA, MockModelATableEntity>.Lookup(context, "P", "R", KeyQueryType.StartsWith);
            propManager.GetValue<string>(m => m.Text).ShouldBe("FooBar");

            propManager = TablePropertyManager<MockModelA, MockModelATableEntity>.Lookup(context, "P1", "R", KeyQueryType.StartsWith);
            propManager.GetValue<string>(m => m.Text).ShouldBe("FooBar");

            propManager = TablePropertyManager<MockModelA, MockModelATableEntity>.Lookup(context, "P", "R1", KeyQueryType.StartsWith);
            propManager.GetValue<string>(m => m.Text).ShouldBe("FooBar");

            propManager = TablePropertyManager<MockModelA, MockModelATableEntity>.Lookup(context, "P1", "R1", KeyQueryType.StartsWith);
            propManager.GetValue<string>(m => m.Text).ShouldBe("FooBar");
        }
        public void ShouldReturnNullFromLookup()
        {
            var context = new MockModelAContext();
            context.DeleteTable();
            var entity = new MockModelATableEntity("P1", "R1");
            var mock = new MockModelA(entity) { Text = "FooBar", Number = 42 };
            mock.Property.Save(context);

            // ---

            context = new MockModelAContext();
            var propManager = TablePropertyManager<MockModelA, MockModelATableEntity>.Lookup(context, "P1", "R-2-NEW-ID");
            propManager.ShouldBe(null);
        }
        public void ShouldCreateFromLookup()
        {
            var context = new MockModelAContext();
            context.DeleteTable();
            var entity = new MockModelATableEntity("P1", "R1");
            var mock = new MockModelA(entity) { Text = "FooBar", Number = 42 };
            mock.Property.Save(context);

            // ---
            // Lookup
            context = new MockModelAContext();
            var propManager1 = TablePropertyManager<MockModelA, MockModelATableEntity>.Lookup(context, "P1", "R1");
            propManager1.GetValue<string>(m => m.Text).ShouldBe("FooBar");
            propManager1.GetValue<string>(m => m.Partition).ShouldBe("P1");
            propManager1.GetValue<string>(m => m.Id).ShouldBe("R1");

            // ---
            // LookupOrCreate
            var propManager3 = TablePropertyManager<MockModelA, MockModelATableEntity>.LookupOrCreate(context, "P1", "R1");
            propManager3.GetValue<string>(m => m.Text).ShouldBe("FooBar");
            propManager3.GetValue<string>(m => m.Partition).ShouldBe("P1");
            propManager3.GetValue<string>(m => m.Id).ShouldBe("R1");
        }
        public void ShouldSaveChangesToTable()
        {
            var client = CloudSettings.CreateTableClient();
            var context = new MockModelAContext();
            client.DeleteTableIfExist(context.TableName);

            // ---

            var entity = new MockModelATableEntity("P1", "R1");
            var mock = new MockModelA(entity) {Text = "FooBar", Number = 42};
            mock.Property.Save(context);

            // ---

            var query = context.CreateQuery().Where(m => m.PartitionKey == "P1" && m.RowKey == "R1");
            query.ToList().Count.ShouldBe(1);

            query = context.CreateQuery().Where(m => m.PartitionKey == "P1" && m.RowKey == "R2");
            query.ToList().Count.ShouldBe(0);

            // ---

            client.DeleteTableIfExist(context.TableName);
        }
        public void ShouldHaveSingletonInstanceOfPropertyCache()
        {
            var model1 = new MockModelA(new MockModelATableEntity());
            var model2 = new MockModelA(new MockModelATableEntity());

            model1.Property.PropertyCache.ShouldNotBe(null);
            model1.Property.PropertyCache.ShouldBe(model2.Property.PropertyCache);
        }