public static void WriteSyncTest(DatabaseProject outputData, DatabaseProjectFilePath outputFileName)
        {
            var writer = new DatabaseProjectFileWriter(outputFileName);

            var isSuccess    = false;
            var errorMessage = "";

            try
            {
                writer.WriteSync(outputData);
                isSuccess = true;
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
            }

            // 出力成功すること
            if (!isSuccess)
            {
                throw new InvalidOperationException(
                          $"Error message: {errorMessage}");
            }

            Assert.True(true);
        }
Exemplo n.º 2
0
        public static void TypeSettingListTest(bool isSetNull, bool isError)
        {
            var instance            = new DatabaseProject();
            var changedPropertyList = new List <string>();

            instance.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); };

            var typeSettingList = isSetNull ? null : new DBTypeSettingList();

            var errorOccured = false;

            try
            {
                instance.TypeSettingList = typeSettingList;
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
                errorOccured = true;
            }

            // エラーフラグが一致すること
            Assert.AreEqual(errorOccured, isError);

            if (!errorOccured)
            {
                var propertyValue = instance.TypeSettingList;

                Assert.NotNull(typeSettingList);
                Assert.NotNull(propertyValue);

                // 取得した値が意図した値であること
                Assert.IsTrue(propertyValue.Equals(typeSettingList));
            }

            // 意図したとおりプロパティ変更通知が発火していること
            if (errorOccured)
            {
                Assert.AreEqual(changedPropertyList.Count, 0);
            }
            else
            {
                Assert.AreEqual(changedPropertyList.Count, 1);
                Assert.IsTrue(changedPropertyList[0].Equals(nameof(DatabaseProject.TypeSettingList)));
            }
        }
Exemplo n.º 3
0
        public static void ConstructorTest()
        {
            var errorOccured = false;

            try
            {
                var _ = new DatabaseProject();
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
                errorOccured = true;
            }

            // エラーが発生しないこと
            Assert.IsFalse(errorOccured);
        }
Exemplo n.º 4
0
        public static void SerializeTest()
        {
            var target = new DatabaseProject
            {
                DBKind = DBKind.System
            };
            var changedPropertyList = new List <string>();

            target.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); };

            var clone = DeepCloner.DeepClone(target);

            Assert.IsTrue(clone.Equals(target));

            // プロパティ変更通知が発火していないこと
            Assert.AreEqual(changedPropertyList.Count, 0);
        }
Exemplo n.º 5
0
        public static void ToBinaryTest(string testFilePath, DatabaseProject generatedData, int fileSize)
        {
            var generatedDataBuf = generatedData.ToBinary();

            using (var fs = new FileStream(testFilePath, FileMode.Open))
            {
                var length = (int)fs.Length;
                // ファイルサイズが規定でない場合誤作動防止の為テスト失敗にする
                Assert.AreEqual(length, fileSize);


                var fileData = new byte[length];
                fs.Read(fileData, 0, length);

                // binデータ出力
                fileData.Select((s, index) => $"=\"[{index}] = {{byte}} {s}\"").ToList()
                .ForEach(s => Console.WriteLine(s));

                Console.WriteLine();

                generatedDataBuf.Select((s, index) => $"=\"[{index}] = {{byte}} {s}\"").ToList()
                .ForEach(s => Console.WriteLine(s));

                for (var i = 0; i < generatedDataBuf.Length; i++)
                {
                    if (i == fileData.Length)
                    {
                        Assert.Fail(
                            $"データ帳が異なります。(期待値:{fileData.Length}, 実際:{generatedDataBuf.Length})");
                    }

                    if (fileData[i] != generatedDataBuf[i])
                    {
                        Assert.Fail(
                            $"offset: {i} のバイナリが異なります。(期待値:{fileData[i]}, 実際:{generatedDataBuf[i]})");
                    }
                }

                if (fileData.Length != generatedDataBuf.Length)
                {
                    Assert.Fail(
                        $"データ帳が異なります。(期待値:{fileData.Length}, 実際:{generatedDataBuf.Length})");
                }
            }
        }
Exemplo n.º 6
0
        public static void CDatabase0ProjectIOTest()
        {
            ChangeableDatabaseProjectFilePath inputFileName =
                $@"{DatabaseProjectFileTestItemGenerator.TestWorkRootDir}\CDatabase1.project";
            ChangeableDatabaseProjectFilePath outputFileName =
                $@"{DatabaseProjectFileTestItemGenerator.TestWorkRootDir}\OutputCDatabase1.project";

            var reader =
                new DatabaseProjectFileReader(
                    inputFileName,
                    DBKind.Changeable);
            DatabaseProject data          = null;
            var             isSuccessRead = false;

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

            Assert.IsTrue(isSuccessRead);

            var writer         = new DatabaseProjectFileWriter(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 : {outputFileName}");
        }
Exemplo n.º 7
0
        public static void ConstructorBTest(int typeSettingListLength, int dataSettingListLength,
                                            bool isError)
        {
            var             typeSettingList = CreateTypeSettingList(typeSettingListLength);
            DatabaseProject project         = null;

            if (typeSettingList != null)
            {
                project = new DatabaseProject
                {
                    TypeSettingList = typeSettingList
                };
            }

            var         dataSettingList = CreateDataSettingList(dataSettingListLength);
            DatabaseDat dat             = null;

            if (dataSettingList != null)
            {
                dat = new DatabaseDat
                {
                    SettingList = dataSettingList
                };
            }

            var errorOccured = false;

            try
            {
                var _ = new DatabaseMergedData(dat, project);
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
                errorOccured = true;
            }

            // エラーフラグが一致すること
            Assert.AreEqual(errorOccured, isError);
        }
Exemplo n.º 8
0
        public static void GenerateDatabaseProjectTest(int listLength, DBKind dbKind)
        {
            var typeSettingList     = CreateTypeSettingList(listLength);
            var dataSettingList     = CreateDataSettingList(listLength);
            var instance            = new DatabaseMergedData(typeSettingList, dataSettingList);
            var changedPropertyList = new List <string>();

            instance.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); };

            DatabaseProject result       = null;
            var             errorOccured = false;

            try
            {
                result = instance.GenerateDatabaseProject(dbKind);
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
                errorOccured = true;
            }

            // エラーが発生しないこと
            Assert.IsFalse(errorOccured);
            // DB種別が一致すること
            Assert.AreEqual(result.DBKind, dbKind);

            // データ数が正しいこと
            Assert.AreEqual(result.TypeSettingList.Count, listLength);
            for (var i = 0; i < listLength; i++)
            {
                // 内容が一致すること
                Assert.AreEqual(result.TypeSettingList[i].TypeName, typeSettingList[i].TypeName);
            }

            // プロパティ変更通知が発火していないこと
            Assert.AreEqual(changedPropertyList.Count, 0);
        }
        private static void Common(DatabaseProject resultData, DatabaseProjectFilePath readFileName, DBKind dbKind)
        {
            var reader = new DatabaseProjectFileReader(readFileName, dbKind);

            var             readResult   = false;
            DatabaseProject data         = null;
            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 = resultData.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]})");
                }
            }
        }