public static MarcRecord[] ParseAllFormat ( [NotNull] string database, [NotNull] IIrbisConnection connection, [NotNull] string[] lines ) { Sure.NotNullNorEmpty(database, "database"); Sure.NotNull(connection, "connection"); Sure.NotNull(lines, "lines"); List <MarcRecord> result = new List <MarcRecord>(); foreach (string line in lines) { MarcRecord record = new MarcRecord { HostName = connection.Host, Database = database }; record = ProtocolText.ParseResponseForAllFormat ( line, record ); // coverity[NULL_RETURNS] result.Add(record.ThrowIfNull("record")); } return(result.ToArray()); }
/// <summary> /// Constructor. /// </summary> public UpdateUserListCommand ( [NotNull] IIrbisConnection connection ) : base(connection) { }
public void SearchCommand_ApplyParameters_1() { Mock <IIrbisConnection> mock = GetConnectionMock(); IIrbisConnection connection = mock.Object; SearchCommand command = new SearchCommand(connection); SearchParameters parameters = new SearchParameters { Database = "IBIS", FirstRecord = 1, NumberOfRecords = 10, MinMfn = 100, MaxMfn = 200, SearchExpression = "A=AUTHOR$", FormatSpecification = "@brief", SequentialSpecification = "p(v300)" }; command.ApplyParameters(parameters); Assert.AreEqual(parameters.Database, command.Database); Assert.AreEqual(parameters.FirstRecord, command.FirstRecord); Assert.AreEqual(parameters.NumberOfRecords, command.NumberOfRecords); Assert.AreEqual(parameters.MinMfn, command.MinMfn); Assert.AreEqual(parameters.MaxMfn, command.MaxMfn); Assert.AreEqual(parameters.SearchExpression, command.SearchExpression); Assert.AreEqual(parameters.FormatSpecification, command.FormatSpecification); Assert.AreEqual(parameters.SequentialSpecification, command.SequentialSpecification); }
private Mock <IIrbisConnection> GetMock() { Mock <IIrbisConnection> result = new Mock <IIrbisConnection>(); IIrbisConnection connection = result.Object; // CommandFactory result.SetupGet(c => c.CommandFactory) .Returns(new CommandFactory(connection)); // ExecuteCommand result.Setup(c => c.ExecuteCommand(It.IsAny <AbstractCommand>())) .Returns((FormatCommand command) => ExecuteFormatCommand(command, false)); // ReadRecord result.Setup(c => c.ReadRecord(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <string>())) .Returns ( (string db, int mfn, bool flag, string fmt) => new MarcRecord { Database = db, Mfn = mfn } ); return(result); }
public MarcRecord ReadRecord ( [NotNull] IIrbisConnection connection ) { Sure.NotNull(connection, "connection"); Verify(true); if (Mfn != 0) { Record = connection.ReadRecord ( Database.ThrowIfNull("Database"), Mfn, false, null ); } else { Record = connection.SearchReadOneRecord ( "\"I={0}\"", Index ); } return(Record); }
/// <summary> /// Constructor. /// </summary> public UpdateIniFileCommand ( [NotNull] IIrbisConnection connection ) : base(connection) { }
/// <summary> /// Constructor. /// </summary> public ListProcessesCommand ( [NotNull] IIrbisConnection connection ) : base(connection) { }
/// <summary> /// Constructor. /// </summary> public MaxMfnCommand ( [NotNull] IIrbisConnection connection ) : base(connection) { }
public void BatchRecordFormatter_Construction_2a() { string connectionString = "Connection String"; string database = "IBIS"; string format = "Format"; int batchSize = 0; int[] range = { 1, 2, 3 }; Mock <IIrbisConnection> mock = GetMock(); IIrbisConnection connection = mock.Object; Func <string, IIrbisConnection> previousCreator = ConnectionFactory.ConnectionCreator; try { ConnectionFactory.ConnectionCreator = cs => connection; new BatchRecordFormatter ( connectionString, database, format, batchSize, range ); } finally { ConnectionFactory.ConnectionCreator = previousCreator; } }
/// <summary> /// Constructor. /// </summary> public ReloadMasterFileCommand ( [NotNull] IIrbisConnection connection ) : base(connection) { }
public void ConnectCommand_ExecuteRequest_2() { int returnCode = 0; string configuration = "Some=Text"; Mock <IIrbisConnection> mock = GetConnectionMock(); mock.SetupGet(c => c.Connected).Returns(true); IIrbisConnection connection = mock.Object; ConnectCommand command = new ConnectCommand(connection) { Username = "******", Password = "******" }; ResponseBuilder builder = new ResponseBuilder() .AppendAnsi(CommandCode.RegisterClient).NewLine() .AppendAnsi("12345678").NewLine() .AppendAnsi("1").NewLine() .AppendAnsi("123").NewLine() .AppendAnsi("64.2014").NewLine() .NewLine() .NewLine() .NewLine() .NewLine() .NewLine() .Append(returnCode).NewLine() .AppendAnsi("30").NewLine() .AppendAnsi(configuration); TestingSocket socket = (TestingSocket)connection.Socket; socket.Response = builder.Encode(); ClientQuery query = command.CreateQuery(); command.Execute(query); }
/// <summary> /// Constructor. /// </summary> public GblVirtualCommand ( [NotNull] IIrbisConnection connection ) : base(connection) { }
/// <summary> /// Constructor. /// </summary> public ReadBinaryFileCommand ( [NotNull] IIrbisConnection connection ) : base(connection) { }
/// <summary> /// Constructor. /// </summary> public DynamicCommand ( [NotNull] IIrbisConnection connection ) : base(connection) { }
/// <summary> /// Constructor. /// </summary> public ReadRecordCommand ( [NotNull] IIrbisConnection connection ) : base(connection) { }
public void BatchRecordFormatter_WholeDatabase_1() { string database = "IBIS"; string format = "Format"; int batchSize = 500; Mock <IIrbisConnection> mock = GetMock(); IIrbisConnection connection = mock.Object; BatchRecordFormatter batch = (BatchRecordFormatter)BatchRecordFormatter.WholeDatabase ( connection, database, format, batchSize ); Assert.AreSame(connection, batch.Connection); Assert.AreSame(database, batch.Database); Assert.AreSame(format, batch.Format); Assert.AreEqual(batchSize, batch.BatchSize); Assert.AreEqual(3, batch.TotalRecords); Assert.AreEqual(0, batch.RecordsFormatted); mock.Verify(c => c.GetMaxMfn(It.IsAny <string>()), Times.Once); }
/// <summary> /// Constructor. /// </summary> public DatabaseStatCommand ( [NotNull] IIrbisConnection connection ) : base(connection) { }
public void BatchRecordFormatter_FormatAll_1() { string database = "IBIS"; int batchSize = 500; string format = "Format"; Mock <IIrbisConnection> mock = GetMock(); IIrbisConnection connection = mock.Object; BatchRecordFormatter batch = (BatchRecordFormatter)BatchRecordFormatter.Interval ( connection, database, format, 1, 3, batchSize ); List <string> formatted = batch.FormatAll(); Assert.AreEqual(3, batch.RecordsFormatted); Assert.AreEqual(3, formatted.Count); Assert.AreEqual("Format IBIS 1", formatted[0]); Assert.AreEqual("Format IBIS 2", formatted[1]); Assert.AreEqual("Format IBIS 3", formatted[2]); mock.Verify(c => c.GetMaxMfn(It.IsAny <string>()), Times.Once); mock.Verify(c => c.FormatRecords(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IEnumerable <int> >()), Times.Once); }
/// <summary> /// Constructor. /// </summary> public ReloadDictionaryCommand ( [NotNull] IIrbisConnection connection ) : base(connection) { }
public void BatchRecordFormatter_Construction_1() { string database = "IBIS"; string format = "Format"; int batchSize = 500; int[] range = { 1, 2, 3 }; Mock <IIrbisConnection> mock = GetMock(); IIrbisConnection connection = mock.Object; BatchRecordFormatter batch = new BatchRecordFormatter ( connection, database, format, batchSize, range ); Assert.AreSame(connection, batch.Connection); Assert.AreSame(database, batch.Database); Assert.AreSame(format, batch.Format); Assert.AreEqual(batchSize, batch.BatchSize); Assert.AreEqual(0, batch.RecordsFormatted); Assert.AreEqual(range.Length, batch.TotalRecords); }
/// <summary> /// Constructor. /// </summary> public BatchRecordFormatter ( [NotNull] IIrbisConnection connection, [NotNull] string database, [NotNull] string format, int batchSize, [NotNull] IEnumerable <int> range ) { Sure.NotNull(connection, "connection"); Sure.NotNullNorEmpty(database, "database"); Sure.NotNullNorEmpty(format, "format"); Sure.NotNull(range, "range"); if (batchSize < 1) { Log.Error ( "BatchRecordFormatter::Constructor: " + "batchSize=" + batchSize ); throw new ArgumentOutOfRangeException("batchSize"); } Connection = connection; Database = database; BatchSize = batchSize; Format = format; _packages = range.Slice(batchSize).ToArray(); TotalRecords = _packages.Sum(p => p.Length); }
/// <summary> /// Constructor. /// </summary> public IrbisAlphabetTable ( IIrbisConnection client ) : this(client, FileName) { }
/// <summary> /// Constructor. /// </summary> public DeleteDatabaseCommand ( [NotNull] IIrbisConnection connection ) : base(connection) { }
/// <summary> /// Constructor. /// </summary> public RestartServerCommand ( [NotNull] IIrbisConnection connection ) : base(connection) { }
/// <summary> /// Constructor. /// </summary> /// <param name="connection"></param> public ActualizeRecordCommand ( [NotNull] IIrbisConnection connection ) : base(connection) { }
public void IrbisAlphabetTable_GetInstance_1() { string fileName = Path.Combine ( TestDataPath, IrbisAlphabetTable.FileName ); string text = File.ReadAllText(fileName); Mock <IIrbisConnection> mock = new Mock <IIrbisConnection>(); mock.Setup(c => c.ReadTextFile(It.IsAny <FileSpecification>())) .Returns(text); IIrbisConnection connection = mock.Object; IrbisAlphabetTable table1 = IrbisAlphabetTable.GetInstance(connection); Assert.AreEqual(182, table1.Characters.Length); IrbisAlphabetTable table2 = IrbisAlphabetTable.GetInstance(connection); Assert.AreSame(table1, table2); mock.Verify ( c => c.ReadTextFile(It.IsAny <FileSpecification>()), Times.Once ); }
public void SearchCommand_ExecuteRequest_2() { int returnCode = 0; Mock <IIrbisConnection> mock = GetConnectionMock(); IIrbisConnection connection = mock.Object; SearchCommand command = new SearchCommand(connection) { Database = "IBIS", SearchExpression = "A=AUTHOR$", MinMfn = 0, MaxMfn = 0, SequentialSpecification = "p(v300)", FormatSpecification = "(v300/)" }; ResponseBuilder builder = new ResponseBuilder() .StandardHeader(CommandCode.Search, 123, 456) .NewLine() .Append(returnCode) .NewLine() .Append(0) .NewLine(); TestingSocket socket = (TestingSocket)connection.Socket; socket.Response = builder.Encode(); ClientQuery query = command.CreateQuery(); ServerResponse response = command.Execute(query); Assert.AreEqual(returnCode, response.ReturnCode); Assert.IsNotNull(command.Found); Assert.AreEqual(0, command.Found.Count); }
/// <summary> /// Constructor. /// </summary> public TestingSocket ( [NotNull] IIrbisConnection connection ) : base(connection) { }
public void SearchCommand_Clone_1() { Mock <IIrbisConnection> mock = GetConnectionMock(); IIrbisConnection connection = mock.Object; SearchCommand first = new SearchCommand(connection) { Database = "IBIS", FirstRecord = 1, NumberOfRecords = 10, MinMfn = 100, MaxMfn = 200, SearchExpression = "A=AUTHOR$", FormatSpecification = "@brief", SequentialSpecification = "p(v300)" }; SearchCommand second = first.Clone(); Assert.AreEqual(first.Database, second.Database); Assert.AreEqual(first.FirstRecord, second.FirstRecord); Assert.AreEqual(first.NumberOfRecords, second.NumberOfRecords); Assert.AreEqual(first.MinMfn, second.MinMfn); Assert.AreEqual(first.MaxMfn, second.MaxMfn); Assert.AreEqual(first.SearchExpression, second.SearchExpression); Assert.AreEqual(first.FormatSpecification, second.FormatSpecification); Assert.AreEqual(first.SequentialSpecification, second.SequentialSpecification); }
/// <summary> /// Constructor. /// </summary> public ServerStatCommand ( [NotNull] IIrbisConnection connection ) : base(connection) { }