예제 #1
0
        public void TestMethodReadGenerateGlobalStructureInfo()
        {
            var s1 = BackupsController.GenerateGlobalStructureInfo(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..", "Data", "CV_Player_5295028.txt"));

            Assert.AreEqual(1378.068, Math.Round(s1.Pos.x, 3));
            Assert.AreEqual(-902.2444, Math.Round(s1.Pos.y, 4));
            Assert.AreEqual(-10097.43, Math.Round(s1.Pos.z, 2));

            Assert.AreEqual(358.5566, Math.Round(s1.Rot.x, 4));
            Assert.AreEqual(121.4577, Math.Round(s1.Rot.y, 4));
            Assert.AreEqual(359.9775, Math.Round(s1.Rot.z, 4));

            var s2 = BackupsController.GenerateGlobalStructureInfo(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..", "Data", "CV_Player_6130486.txt"));

            Assert.AreEqual(-4922.363, Math.Round(s2.Pos.x, 3));
            Assert.AreEqual(27.8112, Math.Round(s2.Pos.y, 4));
            Assert.AreEqual(2020.011, Math.Round(s2.Pos.z, 3));

            Assert.AreEqual(358.605, Math.Round(s2.Rot.x, 3));
            Assert.AreEqual(273.3854, Math.Round(s2.Rot.y, 4));
            Assert.AreEqual(3.907993, Math.Round(s2.Rot.z, 6));

            var s3 = BackupsController.GenerateGlobalStructureInfo(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..", "Data", "BA_Player_1077029.txt"));

            Assert.AreEqual(280.5, Math.Round(s3.Pos.x, 1));
            Assert.AreEqual(112, Math.Round(s3.Pos.y, 0));
            Assert.AreEqual(-332.5, Math.Round(s3.Pos.z, 1));

            Assert.AreEqual(0, Math.Round(s3.Rot.x, 0));
            Assert.AreEqual(270, Math.Round(s3.Rot.y, 0));
            Assert.AreEqual(0, Math.Round(s3.Rot.z, 0));
        }
        public async Task PostAsyncTest()
        {
            //Backup accounts
            //This API will initiate a complete backup of all todo items in the TodoItemServer. The backup is asynchronous and the API will return the the id for the initiated backup.

            //Request: POST /backups
            //Request body: N/A
            //Response body:

            //```
            //{
            // “backupId”: < backupId >
            //}
            //```

            // Arrange
            IBackupService backupService = new StubIBackupService()
            {
                InitiateAsync = () =>
                {
                    // Generate a random id
                    var generator = new Random();
                    var id        = 0;
                    lock (generator)
                    {
                        id = (new Random()).Next(1, int.MaxValue);
                    }

                    return(Task.FromResult(id));
                }
            };

            BackupsController target = new BackupsController(backupService)
            {
                Request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Post, Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } }
                }
            };

            // Act
            dynamic actual = await target.PostAsync();

            Assert.IsNotNull(actual);
            dynamic status = actual.Content;

            Assert.IsNotNull(status);
            Assert.IsTrue(0 < status.BackupId);
        }
        public void ExportTest()
        {
            //Export backup
            //This API will return the content of a specified backup id the CSV format specified below.

            //Request: GET / exports /{
            //        backup id}
            //      Request body: N / A
            //Response body:
            //  ```
            //  Username;TodoItemId;Subject;DueDate;Done
            //  {username};{todoitemid};{subject};{duedate};{done}
            //  ```

            // Arrange
            BackupStatus backupStatus = BackupStatus.InProgress;
            var          items        = new List <TodoItem>();
            var          date         = DateTime.Now;
            Random       random       = new Random();

            for (int i = 0; i < 2; i++)
            {
                date = date.AddDays(i);
                for (int j = 0; j < 5; j++)
                {
                    date = date.AddHours(j);
                    var done = random.Next(0, int.MaxValue);
                    items.Add(new TodoItem(i + j, "Sean Williams", string.Format("Subject {0}", i + j), date, Convert.ToBoolean(done)));
                }
            }
            IBackupService backupService = new StubIBackupService()
            {
                InitiateAsync = () =>
                {
                    // Generate a random id
                    var generator = new Random();
                    var id        = 0;
                    lock (generator)
                    {
                        id = random.Next(1, int.MaxValue);
                    }

                    return(Task.FromResult(id));
                },
                GetAll = () =>
                {
                    var rtnVal = new List <Backup.Backup>();

                    date = DateTime.Now;
                    for (int i = 0; i < 7; i++)
                    {
                        date = date.AddDays(i);
                        for (int j = 0; j < 24; j++)
                        {
                            date = date.AddHours(j);
                            rtnVal.Add(new Backup.Backup(i + j, date, backupStatus, items));
                        }
                    }

                    return(rtnVal);
                }
            };

            BackupsController target = new BackupsController(backupService)
            {
                Request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Get, Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } }
                }
            };


            // Act
            int backupId = 1;

            var actual = target.Export(backupId) as ResponseMessageResult;

            // Assert
            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Response.IsSuccessStatusCode);
            Assert.IsTrue(0 < actual.Response.Content.Headers.ContentLength);
        }
        public void GetFailedTest()
        {
            //List backups
            //This API will list all backups that have initiated.Backup status is one of the following:
            //•	In progress
            //•	OK
            //•	Failed
            //Request: GET / backups
            //Request body: N / A
            //Response body:
            //  ```
            //  [
            // {
            // “backupId”: “<backup id>”,
            //  “date”: “<backup date>”,

            //“status”: “<backup status>”
            //    },
            //    {
            //      …
            //    }
            //  ]
            //  ```

            // Arrange
            BackupStatus   backupStatus  = BackupStatus.Failed;
            IBackupService backupService = new StubIBackupService()
            {
                InitiateAsync = () =>
                {
                    // Generate a random id
                    var generator = new Random();
                    var id        = 0;
                    lock (generator)
                    {
                        id = (new Random()).Next(1, int.MaxValue);
                    }

                    return(Task.FromResult(id));
                },
                GetAll = () =>
                {
                    var rtnVal = new List <Backup.Backup>();

                    var date = DateTime.Now;
                    for (int i = 0; i < 7; i++)
                    {
                        date = date.AddDays(i);
                        for (int j = 0; j < 24; j++)
                        {
                            date = date.AddHours(j);
                            rtnVal.Add(new Backup.Backup(i + j, date, backupStatus, null));
                        }
                    }

                    return(rtnVal);
                }
            };

            BackupsController target = new BackupsController(backupService)
            {
                Request = new HttpRequestMessage()
                {
                    Method = HttpMethod.Get, Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } }
                }
            };

            // Act
            var actual = target.Get() as OkNegotiatedContentResult <IEnumerable <BackupViewModel> >;

            // Assert
            Assert.IsNotNull(actual);
            var backups = actual.Content;

            Assert.IsNotNull(backups);
            Assert.IsTrue(backups.Any());
            Assert.IsTrue(backups.All((b) => 0 <= b.BackupId));
            Assert.IsTrue(backups.All((b) => backupStatus == b.Status));
        }