public IUpdateableItem RetrieveDataById(string id) { var dataQuery = $"SELECT * FROM Items WHERE Id={id}"; Connection.Open(); using var cmd = new SqliteCommand(dataQuery, Connection); using var reader = cmd.ExecuteReader(); if (!reader.Read()) { throw new IOException("No data available"); } var items = new List <IUpdateableItem>(); while (reader.Read()) { var dataRow = DataSchema.ExtractProperties(reader); var item = TypeFactory.BindType(dataRow); items.Add(item); } Connection.Close(); if (items.Count() > 1) { throw new DataException("Duplicate Ids found in the database."); } return(items[0]); }
public void TestUpdate(string dataType, string name, int sellIn, int quality, int expectedSellIn, int expectedQuality) { // Arrange var newItem = TypeFactory.BindType(new DataRow() { DataType = dataType, Name = name, Quality = quality, SellIn = sellIn }); var items = new List <IUpdateableItem>() { newItem }; // Act Transaction.UpdateQuality(ref items); // Assert var item = items.Last(); item.Name.Should().Be(name); item.SellIn.Should().Be(expectedSellIn); item.Quality.Should().Be(expectedQuality); }
public IEnumerable <IUpdateableItem> RetrieveData() { var dataQuery = "SELECT * FROM Items"; Connection.Open(); using var cmd = new SqliteCommand(dataQuery, Connection); using var reader = cmd.ExecuteReader(); if (!reader.Read()) { throw new IOException("No data available"); } var items = new List <IUpdateableItem>(); while (reader.Read()) { var dataRow = DataSchema.ExtractProperties(reader); var item = TypeFactory.BindType(dataRow); items.Add(item); } Connection.Close(); return(items); }