public void UpdateWithoutRetry()
        {
            const string sampleKey = "sample::0000000000";
            var          repo      = new SampleModelRepository();

            repo.RemoveDocument(sampleKey);

            var model0 = new SampleModel
            {
                Key            = sampleKey,
                SampleProperty = 1
            };

            repo.CreateDocument(model0);

            var model1 = repo.GetDocument(sampleKey);
            var model2 = repo.GetDocument(sampleKey);

            model1.SampleProperty = model0.SampleProperty + 2;
            model1 = repo.SaveDocument(model1);

            model2.SampleProperty = model0.SampleProperty + 1;
            var result = repo.UpdateDocument(model2);

            Assert.AreEqual(3, model1.SampleProperty);
            Assert.AreEqual(2, result.SampleProperty);
            Assert.AreNotEqual(model1.CasValue, result.CasValue);

            repo.RemoveDocument(sampleKey);
        }
        public void UpdateWithRetry()
        {
            const string sampleKey = "sample::0000000000";
            var          repo      = new SampleModelRepository();

            repo.RemoveDocument(sampleKey);

            var model0 = new SampleModel
            {
                Key            = sampleKey,
                SampleProperty = 1,
            };

            model0 = repo.CreateDocument(model0);

            var model1 = repo.GetDocument(sampleKey);
            var model2 = repo.GetDocument(sampleKey);

            model1.SampleProperty = model0.SampleProperty + 1;
            model1 = repo.SaveDocument(model1);

            var count = 0;

            model2 = repo.UpdateDocumentWithRetry(model2, model =>
            {
                count += 1;
                if (count == 1)
                {
                    model1.SampleProperty = model1.SampleProperty + 1;
                    repo.SaveDocument(model1);
                }

                model.SampleProperty = model.SampleProperty + 1;
            });

            Assert.AreEqual(2, count);

            var model3 = repo.GetDocument(sampleKey);

            Assert.AreEqual(3, model1.SampleProperty);
            Assert.AreEqual(4, model2.SampleProperty);
            Assert.AreEqual(4, model3.SampleProperty);

            repo.RemoveDocument(sampleKey);
        }
        public void GetDocument()
        {
            const string sampleKey = "sample::9999";
            // setup a sample document to retrieve for the get document test
            var repo  = new SampleModelRepository();
            var model = new SampleModel
            {
                Key            = sampleKey,
                SampleProperty = 99
            };

            repo.SaveDocument(model);

            var retrievedDocument = repo.GetDocument(sampleKey);

            Assert.AreEqual(sampleKey, retrievedDocument.Key);
            Assert.AreEqual(model.SampleProperty, retrievedDocument.SampleProperty);

            // cleanup after our test
            repo.RemoveDocument(sampleKey);
        }
        public void GetDocument()
        {
            const string sampleKey = "sample::9999";
            // setup a sample document to retrieve for the get document test
            var repo = new SampleModelRepository();
            var model = new SampleModel
                {
                    Key = sampleKey,
                    SampleProperty = 99
                };
            repo.SaveDocument(model);

            var retrievedDocument = repo.GetDocument(sampleKey);

            Assert.AreEqual(sampleKey, retrievedDocument.Key);
            Assert.AreEqual(model.SampleProperty, retrievedDocument.SampleProperty);

            // cleanup after our test
            repo.RemoveDocument(sampleKey);
        }
        public void UpdateWithRetry()
        {
            const string sampleKey = "sample::0000000000";
            var repo = new SampleModelRepository();
            repo.RemoveDocument(sampleKey);

            var model0 = new SampleModel
                {
                    Key = sampleKey,
                    SampleProperty = 1,
                };
            model0 = repo.CreateDocument(model0);

            var model1 = repo.GetDocument(sampleKey);
            var model2 = repo.GetDocument(sampleKey);

            model1.SampleProperty = model0.SampleProperty + 1;
            model1 = repo.SaveDocument(model1);

            var count = 0;
            model2 = repo.UpdateDocumentWithRetry(model2, model =>
                {
                    count += 1;
                    if (count == 1)
                    {
                        model1.SampleProperty = model1.SampleProperty + 1;
                        repo.SaveDocument(model1);
                    }

                    model.SampleProperty = model.SampleProperty + 1;
                });

            Assert.AreEqual(2, count);

            var model3 = repo.GetDocument(sampleKey);
            Assert.AreEqual(3, model1.SampleProperty);
            Assert.AreEqual(4, model2.SampleProperty);
            Assert.AreEqual(4, model3.SampleProperty);

            repo.RemoveDocument(sampleKey);
        }
        public void UpdateWithoutRetry()
        {
            const string sampleKey = "sample::0000000000";
            var repo = new SampleModelRepository();
            repo.RemoveDocument(sampleKey);

            var model0 = new SampleModel
                {
                    Key = sampleKey,
                    SampleProperty = 1
                };
            repo.CreateDocument(model0);

            var model1 = repo.GetDocument(sampleKey);
            var model2 = repo.GetDocument(sampleKey);

            model1.SampleProperty = model0.SampleProperty + 2;
            model1 = repo.SaveDocument(model1);

            model2.SampleProperty = model0.SampleProperty + 1;
            var result = repo.UpdateDocument(model2);

            Assert.AreEqual(3, model1.SampleProperty);
            Assert.AreEqual(2, result.SampleProperty);
            Assert.AreNotEqual(model1.CasValue, result.CasValue);

            repo.RemoveDocument(sampleKey);
        }