public async Task <Api.Domain.Domain> GetDomainById(int id) { using (MySqlConnection connection = new MySqlConnection(await _connectionInfo.GetConnectionStringAsync())) { await connection.OpenAsync().ConfigureAwait(false); MySqlCommand command = new MySqlCommand(DomainDaoResources.SelectDomainById, connection); command.Parameters.AddWithValue("id", id); command.Prepare(); Api.Domain.Domain domain = null; using (DbDataReader reader = await command.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { domain = new Api.Domain.Domain( reader.GetInt32("id"), reader.GetString("name")); } } connection.Close(); return(domain); } }
public async Task CreateDomainCorrectlyInsertsDomain() { Api.Domain.Domain domain = await _domainDao.CreateDomain(Domain1, 321); List <Api.Domain.Domain> domains = TestHelpers.GetAllDomains(ConnectionString); Assert.That(domains.Count, Is.EqualTo(1)); Assert.That(domain, Is.EqualTo(domains[0])); }
public async Task GetDomainByIdReturnsDomainWhenDomainExists() { int domainId = TestHelpers.CreateDomain(ConnectionString, Domain1); Api.Domain.Domain domain = await _domainDao.GetDomainById(domainId); Assert.That(domain.Id, Is.EqualTo(domainId)); Assert.That(domain.Name, Is.EqualTo(Domain1)); }
public static List <Api.Domain.Domain> GetAllDomains(string connectionString) { List <Api.Domain.Domain> domains = new List <Api.Domain.Domain>(); using (DbDataReader reader = MySqlHelper.ExecuteReader(connectionString, "SELECT * FROM domain")) { while (reader.Read()) { Api.Domain.Domain domain = new Api.Domain.Domain( reader.GetInt32("id"), reader.GetString("name")); domains.Add(domain); } } return(domains); }
public async Task <Api.Domain.Domain> CreateDomain(string name, int createdBy) { using (MySqlConnection connection = new MySqlConnection(await _connectionInfo.GetConnectionStringAsync())) { await connection.OpenAsync().ConfigureAwait(false); MySqlCommand command = new MySqlCommand(DomainDaoResources.InsertDomain, connection); command.Parameters.AddWithValue("name", name); command.Parameters.AddWithValue("createdBy", createdBy); command.Prepare(); await command.ExecuteNonQueryAsync(); Api.Domain.Domain newDomain = new Api.Domain.Domain( (int)command.LastInsertedId, name); connection.Close(); return(newDomain); } }
public async Task GetDomainsByIdReturnsNullWhenDomainDoesntExist() { Api.Domain.Domain domain = await _domainDao.GetDomainById(1); Assert.That(domain, Is.Null); }