public void TestAccountProperties() { long id = 1; string name = "Test Account"; long priority = 7; long? categoryId = null; string description = "description"; AccountKind accountKind = AccountKind.Source; RepositoryBag repositories = new RepositoryBag(); //Act Account account = new Account(id, name, categoryId, priority, accountKind, description, DateTime.Today, repositories); var properties = account.GetProperties().ToList(); Assert.Equal(7, properties.Count); Assert.Contains(Account.PROP_ID, properties); Assert.Contains(Account.PROP_ACCOUNT_KIND, properties); Assert.Contains(Account.PROP_CATEGORY, properties); Assert.Contains(Account.PROP_CURRENT_STATE, properties); Assert.Contains(Account.PROP_DESCRIPTION, properties); Assert.Contains(Account.PROP_NAME, properties); Assert.Contains(Account.PROP_PRIORITY, properties); }
/// <summary> /// Creates a new instance of an Account object, and initializes it with the specified properties. /// </summary> /// <param name="owner"></param> /// <param name="kind"></param> /// <param name="subscription"></param> public Account(User owner, AccountKind kind, Subscription subscription) { this.OwnerId = owner?.Id ?? throw new ArgumentNullException(nameof(owner)); this.Owner = owner; this.SubscriptionId = subscription?.Id ?? throw new ArgumentNullException(nameof(subscription)); this.Subscription = subscription; this.Kind = kind; this.Key = Guid.NewGuid(); }
protected BaseAccount(Guid bankAccountId, string name, decimal amount, string details, DateTime dueDate, AccountKind kind = AccountKind.Simple) { BankAccountId = bankAccountId; Name = name; Amount = amount; Details = details; DueDate = dueDate; Kind = kind; }
/// <summary> /// From DTO Constructor /// </summary> public Account(long id, string name, long?categoryId, long priority, AccountKind accountKind, string description, DateTime date, RepositoryBag repositories) { if (repositories == null) { throw new ArgumentNullException(nameof(repositories)); } this.Id = id; this.Name = name; this.CategoryId = categoryId; this.Priority = priority; this.AccountKind = accountKind; this.Description = description; this.CurrentDate = date; this.Repositories = repositories; }
public static string GetAccountKind(AccountKind value) { switch (value) { case AccountKind.FundsManagerAccount: return(Constants.AccountType.FundsManager); case AccountKind.ManagedAccount: return(Constants.AccountType.Managed); case AccountKind.SelfTradedAccount: return(Constants.AccountType.SelfTraded); } throw new ArgumentOutOfRangeException("value"); }
public async Task CreateAccount( string username, string password, AccountKind kind = AccountKind.User) { if (!usernameRestriction.IsMatch(username)) { throw new InvalidUsernameException(username); } var hashedPassword = HashPasswordWithGeneratedSalt(password); var account = new UserAccount { Username = username, HashedPassword = hashedPassword, Kind = kind }; try { await db.Accounts.AddAsync(account); await db.SaveChangesAsync(); } catch (DbUpdateException e) { if (e.InnerException is PostgresException ex) { switch (ex.SqlState) { case PostgresErrorCodes.UniqueViolation: case PostgresErrorCodes.DuplicateObject: throw new UsernameNotUniqueException(username, e); default: throw e; } } else { throw e; } } return; }
public Expense(Guid bankAccountId, string name, decimal amount, string details, DateTime dueDate, AccountKind kind = AccountKind.Simple, params ExpensePayment[] payments) : base(bankAccountId, name, amount, details, dueDate, kind) { Payments = payments; }
public static string ToSerialString(this AccountKind value) => value switch {
public void TestAccountPropertyValues() { using (var testDbInfo = SetupUtil.CreateTestDb()) { //Arrange Mock <ILog> mockLog = new Mock <ILog>(); AccountRepository repo = new AccountRepository(testDbInfo.ConnectionString, mockLog.Object); AccountStateRepository stateRepo = new AccountStateRepository(testDbInfo.ConnectionString, mockLog.Object); long id; string name = "Test Account"; long priority = 7; long? categoryId = null; string description = "description"; AccountKind accountKind = AccountKind.Source; Money initialFunds = 123.45; DateTime timestamp = DateTime.Now; AccountDto accountDto = new AccountDto() { Name = name, Priority = priority, Description = description, CategoryId = categoryId, AccountKind = accountKind, }; repo.Upsert(accountDto); id = accountDto.Id.Value; AccountStateDto stateDto = new AccountStateDto() { AccountId = id, Funds = initialFunds.InternalValue, IsClosed = false, Timestamp = timestamp, }; stateRepo.Upsert(stateDto); RepositoryBag repositories = SetupUtil.CreateMockRepositoryBag(testDbInfo.ConnectionString, mockLog.Object, repo, stateRepo); //Act Account account = new Account(accountDto.Id.Value, accountDto.Name, accountDto.CategoryId, accountDto.Priority, accountDto.AccountKind, accountDto.Description, timestamp, repositories); var propertyValues = account.GetPropertyValues().ToList(); AccountState state = DtoToModelTranslator.FromDto(stateDto, repositories); //Assert Assert.Equal(7, propertyValues.Count); Assert.Equal(id, propertyValues.First(x => x.Property.Equals(Account.PROP_ID)).Value); Assert.Equal(name, propertyValues.First(x => x.Property.Equals(Account.PROP_NAME)).Value); Assert.Equal(description, propertyValues.First(x => x.Property.Equals(Account.PROP_DESCRIPTION)).Value); Assert.Equal(accountKind, propertyValues.First(x => x.Property.Equals(Account.PROP_ACCOUNT_KIND)).Value); Assert.Equal(null, propertyValues.First(x => x.Property.Equals(Account.PROP_CATEGORY)).Value); Assert.Equal(priority, propertyValues.First(x => x.Property.Equals(Account.PROP_PRIORITY)).Value); Assert.Equal(state, propertyValues.First(x => x.Property.Equals(Account.PROP_CURRENT_STATE)).Value); } }
private AccountDto MakeAccount(string name, long?categoryId = null, string description = "", long priority = 5, AccountKind accountKind = AccountKind.Sink) { return(new AccountDto() { Name = name, CategoryId = categoryId, Description = description, Priority = priority, AccountKind = accountKind }); }