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)); } }
public void TaskFailTest() { var task = new ListPlatforms(EmptyDbContext); var result = task.DoTask(null); Assert.IsFalse(result.Success); Assert.IsNotNull(result.Exception); }
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); } }
public void TaskSuccessTest() { var task = new ListPlatforms(DbContext); var result = task.DoTask(null); Assert.IsTrue(result.Success); Assert.IsNull(result.Exception); Assert.IsNotNull(result.Data); Assert.IsTrue(result.Data.Any()); foreach (var platform in result.Data) { Assert.IsTrue(platform.Name.Length > 0); Assert.IsNotNull(platform.Services); if (platform.Services.Any()) { foreach (var service in platform.Services) { Assert.IsTrue(service.Name.Length > 0); } } } }