public void CreateStatusFileTest()
        {
            FileHelper.FileSystem = new MockFileSystem(new Dictionary <string, MockFileData>());
            StatusFile statusFile     = new StatusFile("site1");
            string     statusFilePath = @"c:\site1\status.xml";

            Assert.IsFalse(FileHelper.FileSystem.File.Exists(statusFilePath));
            statusFile.LoadOrCreate();
            Assert.IsTrue(FileHelper.FileSystem.File.Exists(statusFilePath));
        }
        public void SaveStatusFileTest()
        {
            string   profileName = "site";
            DateTime startTime   = DateTime.Now;
            DateTime endTime     = DateTime.Now.AddHours(1);

            StatusFileTestData[] tests = new StatusFileTestData[]
            {
                new StatusFileTestData()
                {
                    State             = DeployState.Succeeded,
                    ObjectsAdded      = 10,
                    ObjectsUpdated    = 20,
                    ObjectsDeleted    = 30,
                    ParametersChanged = 40,
                    BytesCopied       = 50,
                    StartTime         = DateTime.UtcNow,
                    EndTime           = DateTime.UtcNow.AddHours(1),
                    Complete          = true
                }
            };

            System.IO.Abstractions.FileBase MockFile = FileHelper.FileSystem.File;

            for (int i = 0; i < tests.Length; i++)
            {
                StatusFile statusFile = new StatusFile(profileName);
                statusFile.State             = tests[i].State;
                statusFile.ObjectsAdded      = tests[i].ObjectsAdded;
                statusFile.ObjectsUpdated    = tests[i].ObjectsUpdated;
                statusFile.ObjectsDeleted    = tests[i].ObjectsDeleted;
                statusFile.ParametersChanged = tests[i].ParametersChanged;
                statusFile.BytesCopied       = tests[i].BytesCopied;
                statusFile.StartTime         = tests[i].StartTime;
                statusFile.EndTime           = tests[i].EndTime;
                statusFile.Complete          = tests[i].Complete;

                statusFile.Save();

                Assert.IsTrue(MockFile.Exists(@"c:\" + profileName + @"\status.xml"));

                statusFile = new StatusFile(profileName);
                statusFile.LoadOrCreate();

                VerifyStatusFile(tests[i], statusFile);
            }
        }
        public void LoadStatusFileTest()
        {
            StatusFile statusFile  = null;
            string     profileName = "site";

            List <string> tests = new List <string>()
            {
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<status>" +
                "</status>",

                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<status>" +
                "    <state>failed</state>" +
                "    <startTime>3/17/2014</startTime>" +
                "    <endTime>3/18/2014</endTime>" +
                "    <complete>true</complete>" +
                "    <objectsAdded>100</objectsAdded>" +
                "    <objectsUpdated>1000</objectsUpdated>" +
                "    <objectsDeleted>10000</objectsDeleted>" +
                "    <parametersChanged>100000</parametersChanged>" +
                "    <bytesCopied>1000000</bytesCopied>" +
                "</status>",

                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<status>" +
                "    <state>InvalidState</state>" +
                "    <startTime>InvalidTime</startTime>" +
                "    <endTime>InvalidTime</endTime>" +
                "    <complete>NotBool</complete>" +
                "    <objectsAdded>NotNum</objectsAdded>" +
                "    <objectsUpdated>NotNum</objectsUpdated>" +
                "    <objectsDeleted>NotNum</objectsDeleted>" +
                "    <parametersChanged>NotNum</parametersChanged>" +
                "    <bytesCopied>NotNum</bytesCopied>" +
                "</status>",
            };

            var expected = new[] {
                new StatusFileTestData(),
                new StatusFileTestData()
                {
                    State             = DeployState.Failed,
                    StartTime         = DateTime.Parse("3/17/2014"),
                    EndTime           = DateTime.Parse("3/18/2014"),
                    Complete          = true,
                    ObjectsAdded      = 100,
                    ObjectsUpdated    = 1000,
                    ObjectsDeleted    = 10000,
                    ParametersChanged = 100000,
                    BytesCopied       = 1000000
                },
                new StatusFileTestData()
            };


            for (int i = 0; i < tests.Count; i++)
            {
                FileHelper.FileSystem = new MockFileSystem(new Dictionary <string, MockFileData>()
                {
                    {
                        @"c:\site\status.xml", new MockFileData(tests[i])
                    }
                });

                statusFile = new StatusFile(profileName);
                statusFile.LoadOrCreate();

                VerifyStatusFile(expected[i], statusFile);
            }
        }