예제 #1
0
        public void TaskFailTest()
        {
            var task   = new UpdatePlatform(EmptyDbContext);
            var result = task.DoTask(null);

            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result.Exception);
        }
예제 #2
0
        public void TaskSuccessTest()
        {
            var listPlatformsTask = new ListPlatforms(DbContext);
            var allPlatforms      = listPlatformsTask.DoTask(null);
            var randomIndex       = new Random().Next(allPlatforms.Data.Count);
            var randomPlatform    = allPlatforms.Data[randomIndex];

            Assert.IsNotNull(randomPlatform);

            var oldPlatform = new Platform
            {
                Id       = randomPlatform.Id,
                Name     = randomPlatform.Name,
                Website  = randomPlatform.Website,
                Services = randomPlatform.Services
            };

            var task     = new UpdatePlatform(DbContext);
            var toUpdate = randomPlatform;

            UpdatePlatformModel(toUpdate);
            var result = task.DoTask(toUpdate);

            Assert.IsTrue(result.Success);
            Assert.IsNull(result.Exception);
            Assert.IsNull(result.Data);

            var getPlatformTask = new GetPlatform(DbContext);
            var platform        = getPlatformTask.DoTask(toUpdate.Id)?.Data;

            Assert.IsNotNull(platform);
            Assert.AreEqual(toUpdate.Name, platform.Name);
            Assert.AreEqual(toUpdate.Website, platform.Website);

            foreach (var service in toUpdate.Services)
            {
                var platformService = platform.PlatformServices.SingleOrDefault(ps => ps.ServiceId == service.Id);
                Assert.IsNotNull(platformService);
            }

            var revertPlatformResult = task.DoTask(oldPlatform);

            Assert.IsTrue(revertPlatformResult.Success);
            Assert.IsNull(revertPlatformResult.Exception);

            getPlatformTask = new GetPlatform(DbContext);
            platform        = getPlatformTask.DoTask(oldPlatform.Id)?.Data;

            Assert.IsNotNull(platform);
            Assert.AreEqual(oldPlatform.Name, platform.Name);
            Assert.AreEqual(oldPlatform.Website, platform.Website);
            Assert.AreEqual(oldPlatform.Services.Count, platform.PlatformServices.Count);
            foreach (var service in oldPlatform.Services)
            {
                var platformService = platform.PlatformServices.SingleOrDefault(ps => ps.ServiceId == service.Id);
                Assert.IsNotNull(platformService);
            }
        }
예제 #3
0
 public static string ToActualString(this UpdatePlatform platform) => UpdatePlatforms[platform];