Exemplo n.º 1
0
        public static void SetCommonEventListTest(int commonEventLength, bool isError)
        {
            var instance            = new CommonFileData();
            var changedPropertyList = new List <string>();

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

            var errorOccured = false;

            try
            {
                instance.SetCommonEventList(MakeCommonEventList(commonEventLength));
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
                errorOccured = true;
            }

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

            // 意図したとおりプロパティ変更通知が発火していること
            if (isError)
            {
                Assert.AreEqual(changedPropertyList.Count, 0);
            }
            else
            {
                Assert.AreEqual(changedPropertyList.Count, 1);
                Assert.IsTrue(changedPropertyList[0].Equals(nameof(CommonFileData.CommonEventList)));
            }
        }
Exemplo n.º 2
0
        public static void WriteSyncTest(CommonFileData outputData, string outputFileName)
        {
            var writer = new CommonFileWriter(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.º 3
0
        public static void GetAllCommonEventTest(int commonEventLength)
        {
            var instance = new CommonFileData();

            instance.SetCommonEventList(MakeCommonEventList(commonEventLength));
            var changedPropertyList = new List <string>();

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

            var errorOccured = false;

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

            // エラーが発生しないこと
            Assert.IsFalse(errorOccured);

            // 取得件数が意図した値と一致すること
            var eventsLength = instance.GetAllCommonEvent().Count();

            Assert.AreEqual(eventsLength, commonEventLength);

            // プロパティ変更通知が発火していないこと
            Assert.AreEqual(changedPropertyList.Count, 0);
        }
        /** ========================================
         *  マップデータオブジェクト作成
         *  ======================================== */

        public static CommonFileData GenerateCommon000Data()
        {
            var commonEventList = new List <CommonEvent>
            {
                CommonEventDataFileTestItemGenerator.CommonEvent00Data.GenerateCommonEvent000(),
            };

            var result = new CommonFileData();

            result.SetCommonEventList(commonEventList);

            return(result);
        }
Exemplo n.º 5
0
        public static void SerializeTest()
        {
            var target = new CommonFileData();

            target.SetCommonEventList(MakeCommonEventList(1));
            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.º 6
0
        public static void CommonEventListTest(bool isNull, bool isError)
        {
            var instance            = new CommonFileData();
            var changedPropertyList = new List <string>();

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

            var list = isNull
                ? null
                : new CommonEventList();

            var errorOccured = false;

            try
            {
                instance.CommonEventList = list;
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
                errorOccured = true;
            }

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

            if (!errorOccured)
            {
                var getList = instance.CommonEventList;

                // セットした値と取得した値が一致すること
                Assert.NotNull(getList);
                Assert.IsTrue(getList.Equals(list));
            }

            // 意図したとおりプロパティ変更通知が発火していること
            if (errorOccured)
            {
                Assert.AreEqual(changedPropertyList.Count, 0);
            }
            else
            {
                Assert.AreEqual(changedPropertyList.Count, 1);
                Assert.IsTrue(changedPropertyList[0].Equals(nameof(CommonFileData.CommonEventList)));
            }
        }
Exemplo n.º 7
0
        public static void Common003to005IOTest()
        {
            const string inputFileName  = "Common003to005_コモンイベント003.common";
            var          outputFileName = $"Output{inputFileName}";

            var reader =
                new CommonFileReader($@"{CommonEventDataFileTestItemGenerator.TestWorkRootDir}\{inputFileName}");
            var            isSuccessRead = false;
            CommonFileData data          = null;

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

            Assert.IsTrue(isSuccessRead);

            var writer = new CommonFileWriter(
                $@"{CommonEventDataFileTestItemGenerator.TestWorkRootDir}\{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 : {CommonEventDataFileTestItemGenerator.TestWorkRootDir}\{outputFileName}");
        }
Exemplo n.º 8
0
        public static void CommonReadTest(string inputFileName)
        {
            var outputFileName = $"Output{inputFileName}";

            var reader =
                new CommonFileReader($@"{CommonEventDataFileTestItemGenerator.TestWorkRootDir}\{inputFileName}");
            var            isSuccessRead = false;
            CommonFileData data          = null;

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

            Assert.IsTrue(isSuccessRead);

            var writer = new CommonFileWriter(
                $@"{CommonEventDataFileTestItemGenerator.TestWorkRootDir}\{outputFileName}");
            var isSuccessWrite = false;

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

            Assert.IsTrue(isSuccessWrite);
        }
Exemplo n.º 9
0
        private static void Common(CommonFileData resultData, string readFileName)
        {
            var filePath = $@"{CommonFileTestItemGenerator.TestWorkRootDir}\{readFileName}";
            var reader   = new CommonFileReader(filePath);

            CommonFileData 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(filePath, 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]})");
                }
            }
        }