public async Task Transfer_ChangesBalance_WhenAccountExists( MangaContext context, Guid originAccountId, Guid destinationAccountId, double amount, double expectedOriginBalance) { var presenter = new Presenter(); var accountRepository = new AccountRepository(context); var unitOfWork = new UnitOfWork(context); var entityFactory = new EntityFactory(); var sut = new Transfer( entityFactory, presenter, accountRepository, unitOfWork ); await sut.Execute( new TransferInput( originAccountId, destinationAccountId, new PositiveAmount(amount))); var actual = presenter.Transfers.First(); Assert.Equal(expectedOriginBalance, actual.UpdatedBalance); }
public async Task Register_WritesOutput_InputIsValid(double amount) { var ssn = new SSN("8608178888"); var name = new Name("Ivan Paulovich"); var password = new Password("Sahil@123"); var entityFactory = new DefaultEntitiesFactory(); var presenter = new Presenter(); var context = new MangaContext(); var customerRepository = new CustomerRepository(context); var accountRepository = new AccountRepository(context); var registerUser = new RegisterUser(new UserManager <IdentityUser>()); var sut = new Register( entityFactory, presenter, customerRepository, accountRepository, registerUser ); await sut.Execute(new Input( ssn, name, password, new PositiveAmount(amount))); var actual = presenter.Registers.First(); Assert.NotNull(actual); Assert.Equal(ssn.ToString(), actual.Customer.SSN); Assert.Equal(name.ToString(), actual.Customer.Name); Assert.Equal(amount, actual.Account.CurrentBalance); //Assert.Equal(password, actual.Customer.Password); }
public async Task Register_WritesOutput_InputIsValid(double amount) { var ssn = new SSN("8608178888"); var name = new Name("Ivan Paulovich"); var entityFactory = new EntityFactory(); var presenter = new Presenter(); var context = new MangaContext(); var customerRepository = new CustomerRepository(context); var accountRepository = new AccountRepository(context); var unitOfWork = new UnitOfWork(context); var sut = new Register( entityFactory, presenter, customerRepository, accountRepository, unitOfWork ); await sut.Execute(new RegisterInput( ssn, name, new PositiveAmount(amount))); var actual = presenter.Registers.First(); Assert.NotNull(actual); Assert.Equal(ssn.ToString(), actual.Customer.SSN); Assert.Equal(name.ToString(), actual.Customer.Name); Assert.Equal(amount, actual.Account.CurrentBalance); }
public RegisterUser(UserManager <AppIdentityUser> userManager, SignInManager <AppIdentityUser> signInManager, IGenerateToken generateToken, MangaContext mangaContext) { this.userManager = userManager; this.signInManager = signInManager; this.generateToken = generateToken; this.mangaContext = mangaContext; }
public async Task Withdraw_Valid_Amount( MangaContext context, Guid accountId, double amount, double expectedBalance) { var presenter = new Presenter(); var accountRepository = new AccountRepository(context); var unitOfWork = new UnitOfWork(context); var sut = new Withdraw( presenter, accountRepository, unitOfWork ); await sut.Execute(new Input( accountId, new PositiveAmount(amount))); var actual = presenter.Withdrawals.First(); Assert.Equal(expectedBalance, actual.UpdatedBalance); }
public async Task Add_ChangesDatabase() { DbContextOptions <MangaContext> options = new DbContextOptionsBuilder <MangaContext>() .UseInMemoryDatabase("test_database") .Options; await using MangaContext context = new MangaContext(options); await context.Database.EnsureCreatedAsync() .ConfigureAwait(false); EntityFactory factory = new EntityFactory(); ICustomer customer = factory.NewCustomer( new SSN("198608177955"), new Name("Ivan Paulovich")); IUser user = factory.NewUser( customer.Id, new ExternalUserId("github/ivanpaulovich"), new Name("Ivan Paulovich")); UserRepository userRepository = new UserRepository(context); await userRepository.Add(user) .ConfigureAwait(false); CustomerRepository customerRepository = new CustomerRepository(context); await customerRepository.Add(customer) .ConfigureAwait(false); await context.SaveChangesAsync() .ConfigureAwait(false); Assert.Equal(2, context.Customers.Count()); }
public async Task Add_ChangesDatabase() { var options = new DbContextOptionsBuilder <MangaContext>() .UseInMemoryDatabase(databaseName: "test_database") .Options; var factory = new EntityFactory(); var customer = factory.NewCustomer( new SSN("198608177955"), new Name("Ivan Paulovich")); var user = factory.NewUser( customer, new ExternalUserId("github/ivanpaulovich")); using (var context = new MangaContext(options)) { context.Database.EnsureCreated(); var userRepository = new UserRepository(context); await userRepository.Add(user); var customerRepository = new CustomerRepository(context); await customerRepository.Add(customer); Assert.Equal(2, context.Customers.Count()); } }
public StandardFixture() { Context = new MangaContext(); AccountRepository = new AccountRepository(Context); CustomerRepository = new CustomerRepository(Context); UnitOfWork = new UnitOfWork(Context); EntityFactory = new EntityFactory(); }
public StandardFixture() { Context = new MangaContext(); AccountRepository = new AccountRepository(Context); CustomerRepository = new CustomerRepository(Context); UserRepository = new UserRepository(Context); UnitOfWork = new UnitOfWork(Context); EntityFactory = new EntityFactory(); UserService = new UserService(); CustomerService = new CustomerService(EntityFactory, CustomerRepository); SecurityService = new SecurityService(EntityFactory, UserRepository); AccountService = new AccountService(EntityFactory, AccountRepository); }
public async Task Should_Not_Perform_Deposit_With_Amount_Less_Than_Zero(double amount) { var presenter = new Presenter(); var context = new MangaContext(); var accountRepository = new AccountRepository(context); var sut = new Deposit( presenter, accountRepository ); await Assert.ThrowsAsync <AmountShouldBePositiveException>(() => sut.Execute(new Input(context.DefaultAccountId, new PositiveAmount(amount)))); }
public async Task Get_ReturnsCustomer() { DbContextOptions <MangaContext> options = new DbContextOptionsBuilder <MangaContext>() .UseInMemoryDatabase("test_database") .Options; await using var context = new MangaContext(options); context.Database.EnsureCreated(); var repository = new CustomerRepository(context); ICustomer customer = await repository.GetBy(SeedData.DefaultCustomerId) .ConfigureAwait(false); Assert.NotNull(customer); }
public async Task Get_ReturnsCustomer() { var options = new DbContextOptionsBuilder <MangaContext>() .UseInMemoryDatabase(databaseName: "test_database") .Options; ICustomer customer = null; using (var context = new MangaContext(options)) { context.Database.EnsureCreated(); var repository = new CustomerRepository(context); customer = await repository.Get(new Guid("197d0438-e04b-453d-b5de-eca05960c6ae")); } Assert.NotNull(customer); }
public async Task Deposit_ChangesBalance_WhenAccountExists(double amount) { var presenter = new Presenter(); var context = new MangaContext(); var accountRepository = new AccountRepository(context); var sut = new Deposit( presenter, accountRepository ); await sut.Execute( new Input(context.DefaultAccountId, new PositiveAmount(amount))); var output = presenter.Deposits.First(); Assert.Equal(amount, output.Transaction.Amount); }
public async Task Get_ReturnsCustomer() { var options = new DbContextOptionsBuilder <MangaContext>() .UseInMemoryDatabase(databaseName: "test_database") .Options; ICustomer customer = null; using (var context = new MangaContext(options)) { context.Database.EnsureCreated(); var repository = new CustomerRepository(context); customer = await repository.GetBy(context.DefaultCustomerId); Assert.NotNull(customer); } }
public async Task Withdraw_Valid_Amount(string accountId, double amount) { var presenter = new Presenter(); var context = new MangaContext(); var accountRepository = new AccountRepository(context); var sut = new Withdraw( presenter, accountRepository ); await sut.Execute(new Input( Guid.Parse(accountId), new PositiveAmount(amount))); var actual = presenter.Withdrawals.First(); Assert.Equal(3900, actual.UpdatedBalance); }
public async Task Add_ChangesDatabase() { var options = new DbContextOptionsBuilder <MangaContext>() .UseInMemoryDatabase(databaseName: "test_database") .Options; var factory = new DefaultEntitiesFactory(); var customer = factory.NewCustomer("198608177955", "Ivan Paulovich"); using (var context = new MangaContext(options)) { var repository = new CustomerRepository(context); await repository.Add(customer); } using (var context = new MangaContext(options)) { Assert.Equal(1, context.Users.Count()); } }
public CustomerRepository(MangaContext context) { _context = context; }
public CustomerRepository(MangaContext context) => this._context = context ??
public CustomerRepository(MangaContext context) { _context = context ?? throw new ArgumentNullException(nameof(context)); }
public AccountRepository(MangaContext context) { _context = context; }
public TestUserService(MangaContext mangaContext) { _sessionId = Guid.NewGuid(); _mangaContext = mangaContext; }
private void Init([NotNull] MetadataJson json, [NotNull] IReadOnlyFileSystem rootFs) { Root = new MangaContext(json, new ProjectDirectoryListingProvider(json, rootFs)); }
/// <summary> /// </summary> /// <param name="context"></param> public AccountRepository(MangaContext context) => this._context = context ??
public UserRepository(MangaContext context) { _context = context; }
public AccountRepository(MangaContext context) { this._context = context ?? throw new ArgumentNullException(nameof(context)); }
public UserRepository(MangaContext context) => this._context = context;