protected object Convert2Date(RecWrapper rec, string field, string[] fieldvalues, object data) { DateTime dt; return !DateTime.TryParseExact(fieldvalues[0], "dd/MMM/yyyy:HH:mm:ss zzzzz", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt) ? string.Empty : dt.ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); }
protected object Convert2Byte(RecWrapper rec, string field, string[] fieldvalues, object data) { var rawValue = string.Empty; if (fieldvalues.Length >= 1) rawValue = fieldvalues[0]; var fileSizeRegex = new Regex(@"([\w\S]*)\s*([\w]*)", RegexOptions.Compiled); var valueMatch = fileSizeRegex.Match(rawValue); if (valueMatch.Success) { var value = valueMatch.Groups[1].Value; var unit = valueMatch.Groups[2].Value; double result = double.Parse(value); switch (unit) { case "KB" : return (int) result*1024; case "MB" : return (int) result*1048576; case "GB" : return (int) result*1073741824; } } return 0; }
protected object Convert2Date(RecWrapper rec, string field, string[] fieldvalues, object data) { DateTime dt; var dtStr = fieldvalues[0] + " " + fieldvalues[1]; if (DateTime.TryParseExact(dtStr, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) return dt.ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); return string.Empty; }
protected static object Convert2Date(RecWrapper rec, string field, string[] values, object data) { DateTime dt; var recorder = data as WamppServerErrorUnifiedRecorder; return DateTime.TryParseExact(values[0], "ddd MMM dd HH:mm:ss yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None,out dt) ? dt.AddSeconds(recorder == null ? 0 : recorder.Zone).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture) : string.Empty; }
protected object Convert2Date(RecWrapper rec, string field, string[] values, object data) { DateTime dt; if (DateTime.TryParseExact(values[0], DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) return dt.ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); return string.Empty; }
protected static object Convert2Date(RecWrapper rec, string field, string[] values, object data) { DateTime dt; var recorder = data as EndianSyslogUnifiedRecorder; var dtStr = values[0]; if (DateTime.TryParseExact(dtStr, "MMM dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) return dt.AddSeconds(recorder == null ? 0 : recorder.zone).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); return string.Empty; }
protected static object Convert2Date(RecWrapper rec, string field, string[] values, object data) { DateTime dt; var recorder = data as Srx3600MobileFwRecorder; if (DateTime.TryParseExact(values[0], "yyyy MMM d H:m:s", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) return dt.AddSeconds(recorder == null ? 0 : recorder.Zone).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); return string.Empty; }
public void ClearRecord_SetValueInRecWrapper_ClearSettedValue() { //Arrange var rec = new RecWrapper {ComputerName = "lorem Ipsum"}; //Act MappedDataHelper.ClearRecord(rec); //Assert Assert.IsNull(rec.ComputerName); }
protected static object Convert2Date(RecWrapper rec, string field, string[] values, object data) { DateTime dt; var recorder = data as MerakMailUnifiedRecorder; if (DateTime.TryParseExact(values[0], "ddd, dd MMM yyyy HH:mm:ss zzz", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) return dt.AddSeconds(recorder == null ? 0 : recorder.zone) .ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); return string.Empty; }
protected static object Convert2IpAddressesSplit(RecWrapper rec, string field, string[] values, object data) { if (!string.IsNullOrEmpty(values[0])) { var vals = values[0].Split(new[] { ',' }, 2); if (vals.Length > 1) rec.CustomStr9 = vals[1]; return vals[0]; } return values[0]; }
public void ClearRecord_IfRecIsNotNull_NotReturn() { //Arrange var rec = new RecWrapper(); //Act // ReSharper disable ExpressionIsAlwaysNull MethodTestHelper.RunInstanceMethod<RecorderBase>("ClearRecord", _recorderBase, new object[] { rec }); // ReSharper restore ExpressionIsAlwaysNull //Assert }
public void Apply_IfTargetAndContextIsNotNull_ReturnNextInstructionDo() { //Arrange var target = new RecWrapper(); object context = "lorem ipsum"; var pro = new TextProperty(); //Act // ReSharper disable ExpressionIsAlwaysNull var actual = st.Apply(target, context); // ReSharper restore ExpressionIsAlwaysNull //Assert Assert.AreEqual(actual, NextInstruction.Do); }
public void Apply_IfConstraintsIsNull_ReturnNextInstructionDo() { //Arrange FieldTestHelper.SetInstanceFieldValue("Constraints", _constraintCollection, null); var recWrapper = new RecWrapper(); object context = null; //Act // ReSharper disable ExpressionIsAlwaysNull var actual = _constraintCollection.Apply(recWrapper, context); // ReSharper restore ExpressionIsAlwaysNull //Assert Assert.AreEqual(NextInstruction.Do, actual); }
public void Apply_IfConstraintsAreEmpty_ReturnNextInstructionDo() { //Arrange var target = new RecWrapper(); object context = null; //Act // ReSharper disable ExpressionIsAlwaysNull var actual = _constraintCollection.Apply(target, context); // ReSharper restore ExpressionIsAlwaysNull //Assert Assert.AreEqual(NextInstruction.Do, actual); }
public void Convert2Date_IfDataIsEmpty_ReturnStringEmpty() { //Arrange var rec = new RecWrapper(); string field = null; string[] values = {String.Empty}; object data = null; //Act // ReSharper disable ExpressionIsAlwaysNull var actual = MethodTestHelper.RunInstanceMethod<WebwasherAuditUnifiedRecorder, object >("Convert2Date", _webWasherAuditUnifiedRecorder, new[] { rec, field, values, data }); // ReSharper restore ExpressionIsAlwaysNull //Assert Assert.AreEqual(actual, String.Empty); }
public void Convert2Date_IfDateTimeFormatIsMMM_dd_yyyy_Return_YYYY_MM_dd() { //Arrange var rec = new RecWrapper(); string field = String.Empty; string[] values = { "Jul 22 20:38:14 2010" }; object data = new LabrisAdministrativeUnifiedRecorder(); //Act // ReSharper disable ExpressionIsAlwaysNull var actual = MethodTestHelper.RunInstanceMethod<LabrisAdministrativeUnifiedRecorder, object>("Convert2Date", _labrisAdministrativeUnifiedRecorder, new[] { rec, field, values, data }); // ReSharper restore ExpressionIsAlwaysNull //Assert Assert.AreEqual(actual, "2010/07/22 20:38:14"); }
public void Convert2Date_IfDateTimeFormatIsNotCorrect_ReturnStringEmpty() { //Arrange var rec = new RecWrapper(); string field = null; string[] values = { "2014/09/09 08:54:15" }; object data = new UbuntuAuthUnifiedRecorder(); //Act // ReSharper disable ExpressionIsAlwaysNull var actual = MethodTestHelper.RunInstanceMethod<UbuntuAuthUnifiedRecorder, object>("Convert2Date", _ubuntuAuthUnifiedRecorder, new[] { rec, field, values, data }); // ReSharper restore ExpressionIsAlwaysNull //Assert Assert.AreEqual(actual, String.Empty); }
public void Convert2Date_IfDataIsNull_ReturnNullReferenceException() { //Arrange var rec = new RecWrapper(); string field = null; string[] values = null; object data = null; //Act // ReSharper disable ExpressionIsAlwaysNull MethodTestHelper.RunInstanceMethod<UbuntuAuthUnifiedRecorder>("Convert2Date", _ubuntuAuthUnifiedRecorder, new[] { rec, field, values, data }); // ReSharper restore ExpressionIsAlwaysNull //Assert //Unhandled NullReferanceException }
public static bool ProcessLine(DataMappingInfo headerInfo, string line, RecWrapper rec, object data, out string[] fields, ref Exception error, char[] separators) { try { ClearRecord(rec); fields = line.Split(separators); foreach (var info in headerInfo.Mappings) { var i = 0; foreach (var index in info.SourceIndex) { info.SourceValues[i++] = index != -1 ? (fields.Length > index ? fields[index] : string.Empty) : null; } info.MappedField.SetValue(rec, info.MethodInfo != null ? info.MethodInfo(rec, info.Original[0][0], info.SourceValues, data) : info.SourceValues[0], null); } return true; } catch (Exception e) { fields = null; error = e; } return false; }
protected static object VersionConcat(RecWrapper record, string field, string[] values, object data) { if (string.IsNullOrEmpty(values[0])) return HttpHelper.UrlDecode(values[1]); if (string.IsNullOrEmpty(values[1])) return HttpHelper.UrlDecode(values[0]); return HttpHelper.UrlDecode(values[0] + " " + values[1]); }
protected static object DescriptionSplitter(RecWrapper rec, string field, string[] values, object data) { if (string.IsNullOrEmpty(values[0])) { rec.CustomStr1 = string.Empty; return string.Empty; } var uriStr = HttpHelper.UrlDecode(values[0]); var parts = uriStr.Split(new[] { ';' }, 2); if (parts.Length == 2) rec.CustomStr1 = StringHelper.MakeSureLength(parts[1], 900); return StringHelper.MakeSureLength(parts[0], 900); }
protected static object CustomStr5Splitter(RecWrapper record, string field, string[] values, object data) { return StringHelper.MakeSureLength(values[0], 900); }
protected static object CustomStr1Splitter(RecWrapper record, string field, string[] values, object data) { if (string.IsNullOrEmpty(values[0])) return values[0]; var uriStr = HttpHelper.UrlDecode(values[0]); if (uriStr.Length > 1800) record.CustomStr10 = uriStr.Substring(900, 900); else if (uriStr.Length > 900) record.CustomStr10 = uriStr.Substring(900, uriStr.Length - 900); return StringHelper.MakeSureLength(uriStr, 900); }
private object Convert2Date(RecWrapper rec, string field, string[] fieldvalues, object data) { DateTime dt; return DateTime.TryParseExact(fieldvalues[0], DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt) ? dt.ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture) : string.Empty; }
private object Convert2Date(RecWrapper rec, string field, string[] fieldvalues, object data) { DateTime dt; var recorder = data as WatchGuardFirewallUnifiedRecorder; if (DateTime.TryParseExact(fieldvalues[0], "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) return dt.AddSeconds(recorder == null ? 0 : recorder.Zone) .ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); return string.Empty; }
public void Convert2Date_IfValuesHasOneItem_ReturnIndexOutOfRangeException() { //Arrange var rec = new RecWrapper(); string field = null; string[] values = { "2014-09-09" }; object data = new NetscalerUnifiedRecorder(); //Act // ReSharper disable ExpressionIsAlwaysNull MethodTestHelper.RunInstanceMethod<NetscalerUnifiedRecorder>("Convert2Date", _netscalerUnifiedRecorder, new[] { rec, field, values, data }); // ReSharper restore ExpressionIsAlwaysNull //Assert //Unhandled IndexOutOfRangeException }
private object Convert2Date(RecWrapper rec, string field, string[] fieldValues, object data) { DateTime dt; var recorder = data as ZyxelZywallUsgUnifiedRecorder; var dtStr = fieldValues[0]; if (DateTime.TryParseExact(dtStr, "MMM dd HH:mm:ss yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) return dt.AddSeconds(recorder == null ? 0 : recorder.zone).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); return string.Empty; }
public void Convert2Date_IfDateTimeFormatIsMM_dd_YYYY_Return_YYYY_MM_dd() { //Arrange var rec = new RecWrapper(); string field = String.Empty; string[] values = { "07/21/2013", "6:06:25 PM" }; object data = new EmcStorageRepUnifiedRecorder(); //Act // ReSharper disable ExpressionIsAlwaysNull var actual = MethodTestHelper.RunInstanceMethod<EmcStorageRepUnifiedRecorder, object>("Convert2Date", _emcStorageRepUnifiedRecorder, new[] { rec, field, values, data }); // ReSharper restore ExpressionIsAlwaysNull //Assert Assert.AreEqual(actual, "2013/07/21 06:06:25"); }
protected static object HttpDecode(RecWrapper rec, string field, string[] values, object data) { if (values != null && values.Length >= 1) return HttpHelper.UrlDecode(values[0]); return string.Empty; }
public void Convert2Date_IfDateTimeFormatIsY_M_d_Return_YYYY_MM_dd() { //Arrange var rec = new RecWrapper(); var field = String.Empty; string[] values = {"2014-09-09", "08:54:15"}; object data = new NetscalerUnifiedRecorder(); //Act // ReSharper disable ExpressionIsAlwaysNull var actual = MethodTestHelper.RunInstanceMethod<NetscalerUnifiedRecorder, object>("Convert2Date", _netscalerUnifiedRecorder, new[] { rec, field, values, data }); // ReSharper restore ExpressionIsAlwaysNull //Assert Assert.AreEqual(actual, "2014/09/09 08:54:15"); }