public async void Handle_DeleteAccount() { var instance = BogusData.Bots.Generate(); var account = instance.Account; var proxy = BogusData.Proxies.Generate(); account.Proxy = proxy; using (var context = NewContext) { context.Instances.Add(instance); await context.SaveChangesAsync(); } var deleteAccount = new FORFarm.Application.Accounts.Commands.DeleteAccount.DeleteAccount { ID = account.ID }; var deleteAccountHandler = new DeleteAccountHandler(NewContext); await deleteAccountHandler.Handle(deleteAccount, CancellationToken.None); using (var context = NewContext) { context.Instances.ToList().Should().BeEmpty(); context.Accounts.ToList().Should().BeEmpty(); var uProxy = context.Proxies.Find(proxy.ID); uProxy.ActiveAccounts.Should().BeEmpty(); } }
public async Task Succeed_With_Valid_Request() { var command = new DeleteAccountCommand() { Id = 1 }; var unitOfWork = new Mock <IWriteOnlyUnitOfWork>(); var repo = new Mock <IRepository>(); repo.Setup(p => p.UnitOfWork).Returns(unitOfWork.Object); var account = new Account( new AccountId(1), new AccountHolder( new FirstName("Ben"), new LastName("Kennedy"))); repo.Setup(p => p.FindAsync(It.IsAny <IScalar <Account> >())).ReturnsAsync(account); var sut = new DeleteAccountHandler(repo.Object); await sut.Handle(command, new CancellationToken()); repo.Verify(p => p.FindAsync(It.IsAny <IScalar <Account> >()), Times.Once()); unitOfWork.Verify(p => p.Remove(It.IsAny <Account>()), Times.Once()); unitOfWork.Verify(p => p.CommitAsync(), Times.Once()); }