public void RunQuerySelectTest() { // Arrange string query = "SELECT TOP 1 HistoricalLogCount FROM HistoricalAdventureLogCounts"; string field = "HistoricalLogCount"; // Act string result = _queryHelper.SelectQuery(query, field); bool tryParseResult = int.TryParse(result, out int logCount); // Assert Assert.True(tryParseResult); }
public async Task PostAdventureLogTest(string url) { // Arrange var client = _factory.CreateClient(); var itemToSend = new AdventureLog { UserId = null, LogTitle = "Session 22: More Stuff", LogBody = "<p><b>The elf jumped over the lazy dwarf.</b></p>" }; var sentContent = JsonConvert.SerializeObject(itemToSend); string beforeLogCountQueryResult = _queryHelper.SelectQuery("SELECT TOP 1 HistoricalLogCount FROM HistoricalAdventureLogCounts", "HistoricalLogCount"); int beforeLogCount = int.Parse(beforeLogCountQueryResult); // Act var send = await client.PostAsync(url, new StringContent(sentContent, Encoding.UTF8, "application/json")); string afterLogCountQueryResult = _queryHelper.SelectQuery("SELECT TOP 1 HistoricalLogCount FROM HistoricalAdventureLogCounts", "HistoricalLogCount"); int afterLogCount = int.Parse(afterLogCountQueryResult); string createdLogTitleQueryResult = _queryHelper.SelectQuery($"SELECT LogTitle FROM AdventureLogs WHERE AdventureLogID = {afterLogCount}", "LogTitle"); string createdLogBodyQueryResult = _queryHelper.SelectQuery($"SELECT LogBody FROM AdventureLogs WHERE AdventureLogID = {afterLogCount}", "LogBody"); // Assert send.EnsureSuccessStatusCode(); // Status Code 200-299 Assert.Equal("application/json; charset=utf-8", send.Content.Headers.ContentType.ToString()); Assert.Equal(itemToSend.LogTitle, createdLogTitleQueryResult); Assert.Equal(itemToSend.LogBody, createdLogBodyQueryResult); Assert.NotEqual(beforeLogCount, afterLogCount); }