private LogTO InsertLog(string message, string source, LogTO.LogType type) { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(URL); // Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // Create a new product var log = new LogTO() { Message = message, Source = source, Type = type.ToString() }; Uri logUri = null; HttpResponseMessage response = client.PostAsJsonAsync(API, log).Result; Assert.IsTrue(response.IsSuccessStatusCode); Assert.AreEqual((int)response.StatusCode, 201, "Failed to create"); logUri = response.Headers.Location; int id; if (!int.TryParse(logUri.Segments.GetValue(logUri.Segments.Length - 1).ToString(), out id)) { Assert.Fail("Failed to find log id"); } log.LogId = id; response = client.GetAsync( API + "/" + id.ToString()).Result; Assert.IsTrue(response.IsSuccessStatusCode); var insertedLog = response.Content.ReadAsAsync<LogTO>().Result; Assert.AreEqual(log.LogId, insertedLog.LogId, "Failed to insert"); Assert.AreEqual(message, insertedLog.Message,"Message are not equal"); Assert.AreEqual(source, insertedLog.Source,"Source is not equal"); Assert.AreEqual(type.ToString(), insertedLog.Type,"type is not same"); return insertedLog; }
private LogTO InsertLog(string message, string source, LogTO.LogType type) { IMsSqlLogService repository = new MsSqlLogService(); LogController controller = new LogController(repository); LogTO log = new LogTO(); log.Message = message; log.Source = source; log.Type = type.ToString(); LogTO insertedLog = repository.Insert(log); Assert.AreNotEqual(0, insertedLog.LogId, "Failed to insert"); Assert.AreEqual(message, insertedLog.Message,"Message are not equal"); Assert.AreEqual(source, insertedLog.Source,"Source is not equal"); Assert.AreEqual(type.ToString(), insertedLog.Type,"type is not same"); return insertedLog; }