Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amironov73 committed Oct 4, 2017
1 parent 195d34d commit 3a17b8b
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 54 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
@@ -1,6 +1,10 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://EditorConfig.org

root=true

[*]
end_of_line = CRLF
trim_trailing_whitespace = true
indent_style = space

Expand Down
43 changes: 35 additions & 8 deletions Source/Classic/Libs/ManagedIrbis/Source/Fst/FstFile.cs
Expand Up @@ -15,8 +15,8 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using AM;
using AM.Collections;
using AM.IO;
using AM.Runtime;
Expand All @@ -40,7 +40,8 @@ namespace ManagedIrbis.Fst
[MoonSharpUserData]
[DebuggerDisplay("FileName = {FileName}")]
public sealed class FstFile
: IHandmadeSerializable
: IHandmadeSerializable,
IVerifiable
{
#region Properties

Expand Down Expand Up @@ -149,34 +150,60 @@ public static FstFile ParseLocalFile

#region IHandmadeSerializable members

/// <summary>
/// Restore object state from specified stream.
/// </summary>
/// <inheritdoc cref="IHandmadeSerializable.RestoreFromStream" />
public void RestoreFromStream
(
BinaryReader reader
)
{
Code.NotNull(reader, "reader");

FileName = reader.ReadNullableString();
reader.ReadCollection(Lines);
}

/// <summary>
/// Save object state to specified stream.
/// </summary>
/// <inheritdoc cref="IHandmadeSerializable.SaveToStream" />
public void SaveToStream
(
BinaryWriter writer
)
{
Code.NotNull(writer, "writer");

writer.WriteNullable(FileName);
writer.WriteCollection(Lines);
}

#endregion

#region IVerifiable members

/// <inheritdoc cref="IVerifiable.Verify" />
public bool Verify
(
bool throwOnError
)
{
Verifier<FstFile> verifier = new Verifier<FstFile>(this, throwOnError);

foreach (FstLine line in Lines)
{
verifier.VerifySubObject(line);
}

return verifier.Result;
}

#endregion

#region Object members

/// <inheritdoc cref="object.ToString" />
public override string ToString()
{
return FileName.ToVisibleString();
}

#endregion
}
}
Expand Down
128 changes: 102 additions & 26 deletions Source/Classic/Libs/ManagedIrbis/Source/Fst/FstLine.cs
Expand Up @@ -10,12 +10,13 @@
#region Using directives

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

using AM;
using AM.IO;
using AM.Logging;
Expand All @@ -33,43 +34,72 @@

namespace ManagedIrbis.Fst
{
//
// ТВП состоит из набора строк, каждая из которых содержит
// следующие три параметра, разделенные знаком пробел:
// * формат выборки данных, представленный на языке форматирования системы,
// * идентификатор поля(ИП),
// * метод индексирования(МИ).
//

/// <summary>
/// FST file line.
/// </summary>
[PublicAPI]
[XmlRoot("line")]
[MoonSharpUserData]
[DebuggerDisplay("{Tag} {Method} {Format}")]
public sealed class FstLine
: IHandmadeSerializable
: IHandmadeSerializable,
IVerifiable
{
#region Properties

/// <summary>
/// Line number.
/// </summary>
[XmlIgnore]
[JsonIgnore]
[Browsable(false)]
public int LineNumber { get; set; }

/// <summary>
/// Field tag.
/// </summary>
[CanBeNull]
[JsonProperty("tag")]
public string Tag { get; set; }
[XmlElement("tag")]
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
[Description("Метка поля")]
[DisplayName("Метка поля")]
public int Tag { get; set; }

/// <summary>
/// Index method.
/// </summary>
[JsonProperty("method")]
[XmlElement("method")]
[JsonProperty("method", DefaultValueHandling = DefaultValueHandling.Include)]
[Description("Метод")]
[DisplayName("Метод")]
public FstIndexMethod Method { get; set; }

/// <summary>
/// Format itself.
/// </summary>
[CanBeNull]
[JsonProperty("format")]
[XmlElement("format")]
[JsonProperty("format", NullValueHandling = NullValueHandling.Ignore)]
[Description("Формат")]
[DisplayName("Формат")]
public string Format { get; set; }

/// <summary>
/// Arbitrary user data.
/// </summary>
[CanBeNull]
[XmlIgnore]
[JsonIgnore]
[Browsable(false)]
public object UserData { get; set; }

#endregion

#region Construction
Expand Down Expand Up @@ -152,20 +182,36 @@ public static FstLine ParseStream
);
}

FstIndexMethod method = (FstIndexMethod) int.Parse
(
parts[1]
);
FstLine result = new FstLine
{
Tag = parts[0],
Method = method,
Tag = NumericUtility.ParseInt32(parts[0]),
Method = (FstIndexMethod)int.Parse(parts[1]),
Format = parts[2]
};

return result;
}

/// <summary>
/// Should serialize the <see cref="Tag"/> field?
/// </summary>
[ExcludeFromCodeCoverage]
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeTag()
{
return Tag != 0;
}

/// <summary>
/// Should serialize the <see cref="Format"/> field?
/// </summary>
[ExcludeFromCodeCoverage]
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeFormat()
{
return !string.IsNullOrEmpty(Format);
}

/// <summary>
/// Convert line to the IRBIS format.
/// </summary>
Expand All @@ -192,38 +238,68 @@ public string ToFormat()

#region IHandmadeSerializable

/// <summary>
/// Restore object state from specified stream.
/// </summary>
/// <inheritdoc cref="IHandmadeSerializable.RestoreFromStream" />
public void RestoreFromStream
(
BinaryReader reader
)
{
Code.NotNull(reader, "reader");

LineNumber = reader.ReadPackedInt32();
Tag = reader.ReadNullableString();
Tag = reader.ReadPackedInt32();
Method = (FstIndexMethod) reader.ReadPackedInt32();
Format = reader.ReadNullableString();
}

/// <summary>
/// Save object state to specified stream.
/// </summary>
/// <inheritdoc cref="IHandmadeSerializable.SaveToStream" />
public void SaveToStream
(
BinaryWriter writer
)
{
writer.WritePackedInt32(LineNumber);
writer.WriteNullable(Tag);
writer.WritePackedInt32((int)Method);
writer.WriteNullable(Format);
Code.NotNull(writer, "writer");

writer.WritePackedInt32(LineNumber)
.WritePackedInt32(Tag)
.WritePackedInt32((int)Method)
.WriteNullable(Format);
}

#endregion

#region IVerifiable members

/// <inheritdoc cref="IVerifiable.Verify" />
public bool Verify
(
bool throwOnError
)
{
Verifier<FstLine> verifier = new Verifier<FstLine>(this, throwOnError);

verifier
.NotNullNorEmpty(Format, "Format");

return verifier.Result;
}

#endregion

#region Object members

/// <inheritdoc cref="object.ToString" />
public override string ToString()
{
return string.Format
(
"{0} {1} {2}",
Tag,
(int)Method,
Format.ToVisibleString()
);
}

#endregion
}
}
Expand Up @@ -320,7 +320,14 @@ public static MarcRecord ParseResponseForWriteRecord
Code.NotNull(response, "response");
Code.NotNull(record, "record");

string first = response.RequireUtfString();
// Если в БД нет autoin.gbl, сервер не присылает
// обработанную запись.

string first = response.GetUtfString();
if (string.IsNullOrEmpty(first))
{
return record;
}
string second = response.GetUtfString();
if (string.IsNullOrEmpty(second))
{
Expand Down

0 comments on commit 3a17b8b

Please sign in to comment.