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 CreateDocument()
        {
            const string sampleKey = "sample::1234";
            var repo = new SampleModelRepository();
            var model = new SampleModel
                {
                    Key = sampleKey,
                    SampleProperty = 99
                };
            var savedModel = repo.CreateDocument(model);

            Assert.AreEqual(model.SampleProperty, savedModel.SampleProperty);
            // validate that the created at property was set since we used the create document method
            Assert.IsNotNull(savedModel.CreatedAt);

            // cleanup after ourselves
            repo.RemoveDocument(sampleKey);
        }
        public void CreateDocument()
        {
            const string sampleKey = "sample::1234";
            var          repo      = new SampleModelRepository();
            var          model     = new SampleModel
            {
                Key            = sampleKey,
                SampleProperty = 99
            };
            var savedModel = repo.CreateDocument(model);

            Assert.AreEqual(model.SampleProperty, savedModel.SampleProperty);
            // validate that the created at property was set since we used the create document method
            Assert.IsNotNull(savedModel.CreatedAt);

            // cleanup after ourselves
            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);
        }