Ejemplo n.º 1
0
        public static void DatabaseDatIOTest(DatabaseDatFilePath inputFileName, DatabaseDatFilePath outputFileName)
        {
            var reader =
                new DatabaseDatFileReader(
                    inputFileName,
                    DBKind.User);
            var         isSuccessRead = false;
            DatabaseDat data          = null;

            try
            {
                data          = reader.ReadAsync().GetAwaiter().GetResult();
                isSuccessRead = true;
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
            }

            Assert.IsTrue(isSuccessRead);

            var writer         = new DatabaseDatFileWriter(outputFileName);
            var isSuccessWrite = false;

            try
            {
                writer.WriteAsync(data).GetAwaiter().GetResult();
                isSuccessWrite = true;
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
            }

            Assert.IsTrue(isSuccessWrite);

            Console.WriteLine(
                $@"Written FilePath : {DatabaseDatFileTestItemGenerator.TestWorkRootDir}\{outputFileName}");
        }
Ejemplo n.º 2
0
        public static void DatabaseDatReadTest(DatabaseDat resultDat, DatabaseDatFilePath readFileName, DBKind dbKind)
        {
            var reader = new DatabaseDatFileReader(readFileName, dbKind);

            DatabaseDat data         = null;
            var         readResult   = false;
            var         errorMessage = "";

            try
            {
                data       = reader.ReadSync();
                readResult = true;
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
                errorMessage = ex.Message;
            }


            // 正しく読めること
            if (!readResult)
            {
                throw new InvalidOperationException(
                          $"Error Occured. Message : {errorMessage}");
            }

            Console.WriteLine("Write Test Clear.");

            var readResultDataBytes = data.ToBinary().ToArray();

            // 元のデータと一致すること
            using (var stream = new FileStream(readFileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var bufLength = (int)stream.Length;
                var buf       = new byte[bufLength];
                stream.Read(buf, 0, bufLength);

                if (readResultDataBytes.Length != bufLength)
                {
                    throw new InvalidOperationException(
                              $"Data Length Not Match. " +
                              $"(answerLength: {bufLength}, readResultLength: {readResultDataBytes.Length})");
                }

                for (long i = 0; i < 0; i++)
                {
                    if (readResultDataBytes[i] != buf[i])
                    {
                        throw new InvalidOperationException(
                                  $"Data Byte Not Match. (index: {i}, answer: {buf[i]}," +
                                  $" readResult: {readResultDataBytes[i]})");
                    }
                }
            }

            // 意図したデータと一致すること
            var resultDataBytes = resultDat.ToBinary().ToArray();

            if (resultDataBytes.Length != readResultDataBytes.Length)
            {
                throw new InvalidOperationException(
                          $"Data Length Not Match. " +
                          $"(answerLength: {resultDataBytes.Length}, readResultLength: {readResultDataBytes.Length})");
            }

            for (long i = 0; i < 0; i++)
            {
                if (resultDataBytes[i] != readResultDataBytes[i])
                {
                    throw new InvalidOperationException(
                              $"Data Byte Not Match. (index: {i}, answer: {resultDataBytes[i]}," +
                              $" readResult: {readResultDataBytes[i]})");
                }
            }
        }