Example #1
0
        private bool ModifyAtomically(WidgetDto widgetDto)
        {
            widgetDto.WidgetTitle  = Rand.AnyTitle;
            widgetDto.ImportantStr = Rand.AnyText;

            return(true);
        }
Example #2
0
        public void AtomicCommit()
        {
            List <string> comments = new List <string> ();
            // First version:
            string comment = Rand.AnyComment;

            comments.Add(comment);
            WidgetDto widgetDto = new WidgetDto()
            {
                WidgetTitle  = Rand.AnyTitle,
                ImportantStr = Rand.AnyText,
            }.SetObjectAsReady(comment) as WidgetDto;

            // Second version, using lambda:
            comment = Rand.AnyComment;
            comments.Add(comment);
            bool result = widgetDto.ModifyAtomic <WidgetDto> (() => {
                widgetDto.WidgetTitle  = Rand.AnyTitle;
                widgetDto.ImportantStr = Rand.AnyText;
                return(true);
            }, comment);

            Assert.IsTrue(result, "Did not commit atomic operation.");

            // Third version, using delegate:
            comment = Rand.AnyComment;
            comments.Add(comment);
            result = widgetDto.ModifyAtomic <WidgetDto> (ModifyAtomically, comment);
            Assert.IsTrue(result, "Did not commit atomic operation.");

            var versions = OdCepManager.Versioning.GetAllVersions(typeof(WidgetDto), widgetDto.Uuid);

            Assert.AreEqual(3, versions.Count, "Returned incorrect number of versions.");

            for (int i = 0; i < 3; ++i)
            {
                var       val           = versions[i];
                WidgetDto retrVerionObj = (WidgetDto)val.Key;
                string    retrComment   = val.Value;

                Assert.AreEqual(comments[i], retrComment, "Comment not as expected.");
            }
        }