public void TaskFailTest() { var task = new UpdateUserAccount(EmptyDbContext); var result = task.DoTask(null); Assert.IsFalse(result.Success); Assert.IsNotNull(result.Exception); }
public void TaskSuccessTest() { var testUser = TestsModel.User; testUser.Type = UserType.PublisherAdministrator; var addUserTask = new AddUser(DbContext, new AddPerson(DbContext, new FormattingService()), new FormattingService()); var addUserResult = addUserTask.DoTask(testUser); Assert.IsTrue(addUserResult.Success); Assert.IsNull(addUserResult.Exception); var paymentService = new ListServices(DbContext).DoTask(null).Data.SingleOrDefault(s => s.Name.ToLower() == "payment"); Assert.IsNotNull(paymentService); var allPlatforms = new ListPlatforms(DbContext).DoTask(null).Data.ToList(); var paymentPlatforms = new List <Platform>(); foreach (var platform in allPlatforms) { paymentPlatforms.AddRange(from service in platform.Services where service.Id == paymentService.Id select platform); } var paymentPlatform = paymentPlatforms[new Random().Next(0, paymentPlatforms.Count)]; var userAccount = new UserAccount { IsPreferred = true, Platform = paymentPlatform, User = testUser, Username = "******" + DateTime.Now.Ticks }; var addUserAccountTask = new AddUserAccount(DbContext); var addUserAccountResult = addUserAccountTask.DoTask(userAccount); Assert.IsTrue(addUserAccountResult.Success); Assert.IsNull(addUserAccountResult.Exception); Assert.IsNotNull(addUserAccountResult.Data); var getUserAccountTask = new GetUserAccount(DbContext); var getUserAccountResult = getUserAccountTask.DoTask(userAccount.Id); Assert.IsTrue(getUserAccountResult.Success); Assert.IsNull(getUserAccountResult.Exception); Assert.IsNotNull(getUserAccountResult.Data); Assert.AreEqual(userAccount.PlatformId, getUserAccountResult.Data.PlatformId); Assert.AreEqual(userAccount.UserId, getUserAccountResult.Data.UserId); Assert.AreEqual(userAccount.IsPreferred, getUserAccountResult.Data.IsPreferred); Assert.AreEqual(userAccount.Username, getUserAccountResult.Data.Username); userAccount.Username = "******" + DateTime.Now.Ticks; userAccount.IsPreferred = false; var task = new UpdateUserAccount(DbContext); var result = task.DoTask(userAccount); Assert.IsTrue(result.Success); Assert.IsNull(result.Exception); getUserAccountTask = new GetUserAccount(DbContext); getUserAccountResult = getUserAccountTask.DoTask(userAccount.Id); Assert.AreEqual(userAccount.PlatformId, getUserAccountResult.Data.PlatformId); Assert.AreEqual(userAccount.UserId, getUserAccountResult.Data.UserId); Assert.AreEqual(userAccount.IsPreferred, getUserAccountResult.Data.IsPreferred); Assert.AreEqual(userAccount.Username, getUserAccountResult.Data.Username); var person = testUser.Person; var removeUserTask = new RemoveUser(DbContext); var removeUserResult = removeUserTask.DoTask(testUser); Assert.IsTrue(removeUserResult.Success); Assert.IsNull(removeUserResult.Exception); var removePersonTask = new RemovePerson(DbContext); var removePersonResult = removePersonTask.DoTask(person); Assert.IsTrue(removePersonResult.Success); Assert.IsNull(removePersonResult.Exception); }