/// <summary> /// Asynchronously delete a previously logged item from the data store. /// </summary> /// <param name="timestamp">the timestamp that was logged (string)</param> /// <param name="operation">the operation that was logged (string)</param> /// <param name="identifier">the identifier that was logged (string)</param> /// <param name="ipAddress">the ip address that was logged (string)</param> /// <param name="errorType">the error type that was logged (string)</param> /// <returns>Task (bool) whether the log deletion was successful</returns> public async Task <bool> DeleteLogFromDataStoreAsync(string timestamp, string operation, string identifier, string ipAddress, string errorType) { try { // Currently the timestamp is expected to be in the following format: "HH:mm:ss:ff UTC yyyyMMdd". string[] splitResult = timestamp.Split(' '); if (splitResult.Length != 3) { throw new ArgumentException(Constants.TimestampFormatIncorrect); } // Create the log record to be found, the parameters to this function should make it unique among the data store, // i.e no unique operation should have the same timestamp. LogRecord logRecord = new LogRecord(splitResult[0] + " " + splitResult[1], operation, identifier, ipAddress, errorType); LogRecord resultRecord = await _maskingService.MaskAsync(logRecord, false).ConfigureAwait(false) as LogRecord; // Asynchronously find the id field of the log in the data store, passing the collection/table name. string id = await _dsLoggingDAO.FindIdFieldAsync(resultRecord, splitResult[2]).ConfigureAwait(false); // Asynchronously delete the log by id in the data store. await _dsLoggingDAO.DeleteAsync(id, splitResult[2]).ConfigureAwait(false); return(true); } catch { // Any exceptions result in a failed deletion. return(false); } }
public async Task LogDAO_CreateAsync_SuccessfulCreation(string timestamp, string operation, string identifier, string ipAddress, string errorType, string date) { // Arrange: LogRecord record = new LogRecord(timestamp, operation, identifier, ipAddress, errorType); // Act: bool result = await logDAO.CreateAsync(record, date).ConfigureAwait(false); Assert.IsTrue(result); // Cleanup: find the Id of the log we created and delete it. string id = await logDAO.FindIdFieldAsync(record, date).ConfigureAwait(false); //bool deleteResult = await logDAO.DeleteAsync(id, date).ConfigureAwait(false); //Assert.IsTrue(deleteResult); }