Example #1
0
        public void TaskSuccessTest()
        {
            var task         = new AddPlatform(DbContext);
            var testPlatform = TestsModel.Platform;
            var result       = task.DoTask(testPlatform);

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

            var platformId = result.Data;

            Assert.IsNotNull(platformId);
            Assert.IsTrue(platformId > 0);

            var getPlatformTask = new GetPlatform(DbContext);
            var platform        = getPlatformTask.DoTask(platformId.Value)?.Data;

            Assert.IsNotNull(platform);
            Assert.AreEqual(testPlatform.Name, platform.Name);
            Assert.AreEqual(testPlatform.Website, platform.Website);
            Assert.AreEqual(testPlatform.Services.Count, platform.Services.Count);
            foreach (var service in testPlatform.Services)
            {
                Assert.IsTrue(platform.Services.Exists(s => s.Id == service.Id));
            }

            var removePlatformTask = new RemovePlatform(DbContext);
            var removeResult       = removePlatformTask.DoTask(platform);

            Assert.IsTrue(removeResult.Success);
            Assert.IsNull(removeResult.Exception);
        }
Example #2
0
        public void TaskSuccessTest()
        {
            var listPlatforms  = new ListPlatforms(DbContext);
            var allPlatforms   = listPlatforms.DoTask(null);
            var randomIndex    = new Random().Next(allPlatforms.Data.Count);
            var randomPlatform = allPlatforms.Data[randomIndex];

            Assert.IsNotNull(randomPlatform);

            var task   = new GetPlatform(DbContext);
            var result = task.DoTask(randomPlatform.Id);

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

            var platform = result.Data;

            Assert.AreEqual(randomPlatform.Name, platform.Name);
            Assert.AreEqual(randomPlatform.Website, platform.Website);
            Assert.IsNotNull(platform.Services);
            Assert.IsTrue(platform.Services.Any());
            foreach (var service in platform.Services)
            {
                Assert.IsTrue(randomPlatform.Services.Exists(s => s.Id == service.Id));
            }
        }
Example #3
0
        public void TaskFailTest()
        {
            var task   = new GetPlatform(EmptyDbContext);
            var result = task.DoTask(0);

            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result.Exception);
        }
Example #4
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);
            }
        }