Esempio n. 1
0
        public void op_Exclude_Operations_bool()
        {
            try
            {
                using (var temp = new TempDirectory())
                {
                    var resourceManager = Guid.NewGuid();
                    Recovery.MasterDirectory = temp.Info.ToDirectory("Recovery");
                    var operation1 = new Operation(resourceManager)
                    {
                        Info = Guid.NewGuid().ToString()
                    };

                    Recovery.Include(operation1);

                    var operation2 = new Operation(resourceManager)
                    {
                        Info = Guid.NewGuid().ToString()
                    };

                    Recovery.Include(operation2);
                    Recovery.Exclude(operation1, true);
                    var expected = Recovery.ItemFile(operation1, "Commit").FullName;
                    foreach (var actual in Recovery.MasterFile(operation1).Lines())
                    {
                        Assert.NotEqual(expected, actual);
                    }
                }
            }
            finally
            {
                Recovery.MasterDirectory = null;
            }
        }
Esempio n. 2
0
        public void op_Include_Operation()
        {
            try
            {
                using (var temp = new TempDirectory())
                {
                    Recovery.MasterDirectory = temp.Info.ToDirectory("Recovery");
                    var operation = new Operation(Guid.NewGuid())
                    {
                        Info = Guid.NewGuid().ToString()
                    };

                    Recovery.Include(operation);

                    var expected = Recovery.ItemFile(operation).FullName;
                    foreach (var actual in Recovery.MasterFile(operation).Lines())
                    {
                        Assert.Equal(expected, actual);
                    }
                }
            }
            finally
            {
                Recovery.MasterDirectory = null;
            }
        }
Esempio n. 3
0
        public void op_Include_Operations()
        {
            try
            {
                using (var temp = new TempDirectory())
                {
                    var resourceManager = Guid.NewGuid();
                    Recovery.MasterDirectory = temp.Info.ToDirectory("Recovery");
                    var operation = new Operation(resourceManager)
                    {
                        Info = Guid.NewGuid().ToString()
                    };

                    Recovery.Include(operation);
                    var first = Recovery.ItemFile(operation).FullName;
                    Assert.Equal(first, Recovery.MasterFile(operation).Lines().First());

                    operation = new Operation(resourceManager)
                    {
                        Info = Guid.NewGuid().ToString()
                    };

                    Recovery.Include(operation);
                    var last = Recovery.ItemFile(operation).FullName;
                    Assert.Equal(first, Recovery.MasterFile(operation).Lines().First());
                    Assert.Equal(last, Recovery.MasterFile(operation).Lines().Last());
                }
            }
            finally
            {
                Recovery.MasterDirectory = null;
            }
        }
Esempio n. 4
0
        public virtual bool Undo()
        {
            Trace.WriteIf(Tracing.Is.TraceVerbose, "Identity.ResourceManager={0}, Identity.Instance={1}".FormatWith(Identity.ResourceManager, Identity.Instance));
            if (null == Info)
            {
                throw new InvalidOperationException();
            }

            Trace.WriteIf(Tracing.Is.TraceVerbose, "Commands.Count={0}".FormatWith(Commands.Count));
            if (0 == Commands.Count)
            {
                return(true);
            }

            foreach (var command in Commands.Reverse())
            {
                Recovery.Include(this);
                if (!command.Revert())
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 5
0
        public virtual void Done(bool success)
        {
            if (null != Info)
            {
                Trace.WriteIf(Tracing.Is.TraceVerbose, "Identity.ResourceManager={0}, Identity.Instance={1}".FormatWith(Identity.ResourceManager, Identity.Instance));
            }

            Recovery.Exclude(this, success);
        }
Esempio n. 6
0
        public void op_MasterFile_Operation()
        {
            var operation = new Operation(Guid.NewGuid())
            {
                Info = Guid.NewGuid().ToString()
            };

            var id = operation.Identity;

            var expected = Recovery.MasterDirectory.ToFile("{0}.master".FormatWith(id.ResourceManager)).FullName;
            var actual   = Recovery.MasterFile(operation).FullName;

            Assert.Equal(expected, actual);
        }
Esempio n. 7
0
        public void op_ItemFile_Operation_stringNull()
        {
            var operation = new Operation(Guid.NewGuid())
            {
                Info = Guid.NewGuid().ToString()
            };

            var id = operation.Identity;

            var expected = Recovery.MasterDirectory.ToDirectory(id.ResourceManager).ToFile("{0}.xml".FormatWith(id.Instance)).FullName;
            var actual   = Recovery.ItemFile(operation, null).FullName;

            Assert.Equal(expected, actual);
        }
Esempio n. 8
0
 public void op_MasterFile_OperationNull()
 {
     Assert.Throws <ArgumentNullException>(() => Recovery.MasterFile(null));
 }
Esempio n. 9
0
 public void op_ItemFile_OperationNull_string()
 {
     Assert.Throws <ArgumentNullException>(() => Recovery.ItemFile(null, "Example"));
 }
Esempio n. 10
0
 public void op_Exclude_OperationNull_bool()
 {
     Assert.Throws <ArgumentNullException>(() => Recovery.Exclude(null, false));
 }
Esempio n. 11
0
 public void op_Include_OperationNull()
 {
     Assert.Throws <ArgumentNullException>(() => Recovery.Include(null));
 }