public void CreateFileTransactionally_Rollback()
        {
            if (Environment.OSVersion.Version.Major < 6)
            {
                Assert.Ignore("TxF not supported");
                return;
            }

            string filePath = testFixturePath.CombineAssert("temp").Combine("temp2");

            infosCreated.Add(filePath);

            // simply write something to to file.
            using (StreamWriter wr = File.CreateText(filePath))
                wr.WriteLine("Hello");

            using (var tx = new FileTransaction("Rollback tx"))
            {
                tx.Begin();

                using (FileStream fs = tx.Open(filePath, FileMode.Truncate))
                {
                    byte[] str = new UTF8Encoding().GetBytes("Goodbye");
                    fs.Write(str, 0, str.Length);
                    fs.Flush();
                }

                tx.Rollback();
            }

            Assert.That(File.ReadAllLines(filePath)[0], Is.EqualTo("Hello"));
        }
        public void FailingResource_TxStillRolledBack()
        {
            if (Environment.OSVersion.Version.Major < 6)
            {
                Assert.Ignore("TxF not supported");
                return;
            }

            using (var tx = new FileTransaction())
            {
                tx.Enlist(new R());
                tx.Begin();
                try
                {
                    try
                    {
                        tx.Rollback();
                        Assert.Fail("Tests is wrong or the transaction doesn't rollback resources.");
                    }
                    catch (Exception)
                    {
                    }

                    Assert.That(tx.Status == TransactionStatus.RolledBack);
                }
                catch (RollbackResourceException rex)
                {
                    // good.
                    Assert.That(rex.FailedResources[0].First, Is.InstanceOf(typeof(R)));
                }
            }
        }
 public void CanCreate_AndFind_Directory_WithinTx()
 {
     using (ITransaction tx = new FileTransaction("s"))
     {
         var da = (IDirectoryAdapter)tx;
         Assert.That(da.Exists("something"), Is.False);
         da.Create("something");
         Assert.That(da.Exists("something"));
         tx.Rollback();
     }
 }
Example #4
0
        public void CanCreate_AndFind_Directory_WithinTx()
        {
            if (Environment.OSVersion.Version.Major < 6)
            {
                Assert.Ignore("TxF not supported");
                return;
            }

            using (var tx = new FileTransaction("s"))
            {
                tx.Begin();
                Assert.That((tx as IDirectoryAdapter).Exists("something"), Is.False);
                (tx as IDirectoryAdapter).Create("something");
                Assert.That((tx as IDirectoryAdapter).Exists("something"));
                tx.Rollback();
            }
        }
        public void Using_TransactionScope_IsDistributed_AlsoTestingStatusWhenRolledBack()
        {
            if (Environment.OSVersion.Version.Major < 6)
            {
                Assert.Ignore("TxF not supported");
                return;
            }

            using (new TransactionScope())
            {
                using (var tx = new FileTransaction())
                {
                    tx.Begin();

                    Assert.That(tx.IsAmbient);

                    tx.Rollback();
                    Assert.That(tx.IsRollbackOnlySet);
                    Assert.That(tx.Status, Is.EqualTo(TransactionStatus.RolledBack));
                }
            }
        }
Example #6
0
        public void CreateFileTransactionally_ThenRollback()
        {
            var filePath = _TfPath.Combine("transacted-file");

            // simply write something to to file.
            using (var wr = File.CreateText(filePath))
                wr.WriteLine("CreateFileTransactionally_ThenRollback");

            using (ITransaction tx = new FileTransaction("rollback tx"))
            {
                var fa = (IFileAdapter)tx;
                using (var fs = fa.Open(filePath, FileMode.Truncate))
                {
                    var str = new UTF8Encoding().GetBytes("Goodbye");
                    fs.Write(str, 0, str.Length);
                    fs.Flush();
                }

                tx.Rollback();
            }

            File.ReadAllLines(filePath)
            .First().Should().Be.EqualTo("CreateFileTransactionally_ThenRollback");
        }
		public void CanCreate_AndFind_Directory_WithinTx()
		{
            if (Environment.OSVersion.Version.Major < 6)
            {
                Assert.Ignore("TxF not supported");
                return;
            }

			using (var tx = new FileTransaction("s"))
			{
				tx.Begin();
				Assert.That((tx as IDirectoryAdapter).Exists("something"), Is.False);
				(tx as IDirectoryAdapter).Create("something");
				Assert.That((tx as IDirectoryAdapter).Exists("something"));
				tx.Rollback();
			}
		}
		public void Using_TransactionScope_IsDistributed_AlsoTestingStatusWhenRolledBack()
        {
            if (Environment.OSVersion.Version.Major < 6)
            {
                Assert.Ignore("TxF not supported");
                return;
            }

            using (new TransactionScope())
			{
				using (var tx = new FileTransaction())
				{
					tx.Begin();

					Assert.That(tx.IsAmbient);

					tx.Rollback();
					Assert.That(tx.IsRollbackOnlySet);
					Assert.That(tx.Status, Is.EqualTo(TransactionStatus.RolledBack));
				}
			}
		}
		public void FailingResource_TxStillRolledBack()
		{
            if (Environment.OSVersion.Version.Major < 6)
            {
                Assert.Ignore("TxF not supported");
                return;
            }

			using (var tx = new FileTransaction())
			{
				tx.Enlist(new R());
				tx.Begin();
				try
				{
					try
					{
						tx.Rollback();
						Assert.Fail("Tests is wrong or the transaction doesn't rollback resources.");
					}
					catch (Exception)
					{
					}

					Assert.That(tx.Status == TransactionStatus.RolledBack);
				}
				catch (RollbackResourceException rex)
				{
					// good.
					Assert.That(rex.FailedResources[0].First, Is.InstanceOf(typeof (R)));
				}
			}
		}
		public void CanCreate_AndFind_Directory_WithinTx()
		{
			using (ITransaction tx = new FileTransaction("s"))
			{
				var da = (IDirectoryAdapter) tx;
				Assert.That(da.Exists("something"), Is.False);
				da.Create("something");
				Assert.That(da.Exists("something"));
				tx.Rollback();
			}
		}
		public void CreateFileTransactionally_Rollback()
		{
			if (Environment.OSVersion.Version.Major < 6)
			{
				Assert.Ignore("TxF not supported");
				return;
			}

			var filePath = testFixturePath.CombineAssert("temp").Combine("temp2");
			infosCreated.Add(filePath);

			// simply write something to to file.
			using (var wr = File.CreateText(filePath))
			{
				wr.WriteLine("Hello");
			}

			using (ITransaction tx = new FileTransaction("Rollback tx"))
			{
				var fa = (IFileAdapter)tx;
				using (var fs = fa.Open(filePath, FileMode.Truncate))
				{
					var str = new UTF8Encoding().GetBytes("Goodbye");
					fs.Write(str, 0, str.Length);
					fs.Flush();
				}

				tx.Rollback();
			}

			Assert.That(File.ReadAllLines(filePath)[0], Is.EqualTo("Hello"));
		}
Example #12
0
		public void CreateFileTransactionally_ThenRollback()
		{
			var filePath = _TfPath.Combine("transacted-file");

			// simply write something to to file.
			using (var wr = File.CreateText(filePath))
				wr.WriteLine("CreateFileTransactionally_ThenRollback");

			using (ITransaction tx = new FileTransaction("rollback tx"))
			{
				var fa = (IFileAdapter) tx;
				using (var fs = fa.Open(filePath, FileMode.Truncate))
				{
					var str = new UTF8Encoding().GetBytes("Goodbye");
					fs.Write(str, 0, str.Length);
					fs.Flush();
				}

				tx.Rollback();
			}

			File.ReadAllLines(filePath)
				.First().Should().Be.EqualTo("CreateFileTransactionally_ThenRollback");
		}