Ejemplo n.º 1
0
        public void Test_transfer_2()
        {
            NewTagList.Clear();

            List <OneTag> tag_list = new List <OneTag>();

            // ***
            // 0) 准备内容
            tag_list.Add(BuildOne15693Tag("M201", 1, "111111"));
            NewTagList.Refresh(
                "M201",
                tag_list,
                (readerName, uid, antennaID) =>
            {
                // 获得标签内容
                return(new GetTagInfoResult
                {
                    TagInfo = BuildOne15693TagInfo(tag_list[0])
                });
                // return null;
            },
                null,
                null);

            // 检查一下
            Assert.AreEqual(1, NewTagList.Tags.Count);

            // ***
            // 1) M201 读卡器上把标签先拿走了

            {
                List <TagAndData> new_results     = new List <TagAndData>();
                List <TagAndData> changed_results = new List <TagAndData>();
                List <TagAndData> removed_results = new List <TagAndData>();

                List <TypeAndError> errors = new List <TypeAndError>();
                NewTagList.Refresh(
                    "M201",
                    new List <OneTag>(),
                    (readerName, uid, antennaID) =>
                {
                    throw new Exception("不应该走到这里 1");
                },
                    (new_tags, changed_tags, removed_tags) =>
                {
                    if (new_tags != null && new_tags.Count > 0)
                    {
                        throw new Exception("new_tags 不应该发生添加");
                    }
                    if (changed_tags != null && changed_tags.Count > 0)
                    {
                        throw new Exception("changed_tags 不应该发生添加");
                    }
                    if (removed_tags != null && removed_tags.Count > 0)
                    {
                        // 检查
                        Assert.AreEqual(1, removed_tags.Count);

                        var result = removed_tags[0];
                        // 这个时候,TagInfo 应该不是 null 了
                        Assert.AreNotEqual(null, result.OneTag.TagInfo);
                        // 比较除了 TagInfo 以外的成员
                        Assert.IsTrue(IsEqual(result.OneTag, tag_list[0], false));
                        // 专门比较 TagInfo
                        Assert.IsTrue(IsEqual(BuildOne15693TagInfo(tag_list[0]), result.OneTag.TagInfo));

                        removed_results.AddRange(removed_tags);
                    }
                },
                    (string type, string error) =>
                {
                    errors.Add(new TypeAndError
                    {
                        Type  = type,
                        Error = error
                    });
                });

                Assert.AreEqual(0, new_results.Count);
                Assert.AreEqual(0, changed_results.Count);  // 两阶段也是可能的
                Assert.AreEqual(1, removed_results.Count);

                Assert.AreEqual(0, NewTagList.Tags.Count);
            }

            // ***
            // 2) RL8600 读卡器上放了这张标签

            {
                List <TagAndData> new_results     = new List <TagAndData>();
                List <TagAndData> changed_results = new List <TagAndData>();
                List <TagAndData> removed_results = new List <TagAndData>();

                List <TypeAndError> errors = new List <TypeAndError>();

                List <OneTag> update_list = new List <OneTag>();
                update_list.Add(BuildOne15693Tag("RL8600", 2, "111111"));

                // 用 update_list 集合来刷新
                // 这次应该产生的是 add 动作
                NewTagList.Refresh(
                    "RL8600",
                    update_list,
                    (readerName, uid, antennaID) =>
                {
                    // 获得标签内容
                    return(new GetTagInfoResult
                    {
                        TagInfo = BuildOne15693TagInfo(update_list[0])
                    });
                },
                    (new_tags, changed_tags, removed_tags) =>
                {
                    if (new_tags != null && new_tags.Count > 0)
                    {
                        // 检查得到的 new_tags
                        Assert.AreEqual(1, new_tags.Count);
                        var result = new_tags[0];
                        // 这个时候,TagInfo 还是 null
                        Assert.AreEqual(null, result.OneTag.TagInfo);
                        Assert.IsTrue(IsEqual(result.OneTag, update_list[0]));

                        new_results.AddRange(new_tags);
                    }
                    if (changed_tags != null && changed_tags.Count > 0)
                    {
                        // throw new Exception("changed_tags 不应该发生添加");

                        // 这时候 new_results 里面已经有了内容
                        Assert.AreEqual(1, new_results.Count);

                        // 检查
                        Assert.AreEqual(1, changed_tags.Count);

                        var result = changed_tags[0];
                        // 比较除了 TagInfo 以外的成员
                        Assert.IsTrue(IsEqual(result.OneTag, update_list[0], false));

                        if (result.OneTag.TagInfo == null)
                        {
                        }
                        else
                        {
                            // 这个时候,TagInfo 应该不是 null 了
                            Assert.AreNotEqual(null, result.OneTag.TagInfo);
                            // 专门比较 TagInfo
                            Assert.IsTrue(IsEqual(BuildOne15693TagInfo(update_list[0]), result.OneTag.TagInfo));
                        }

                        changed_results.AddRange(changed_tags);
                    }
                    if (removed_tags != null && removed_tags.Count > 0)
                    {
                        throw new Exception("removed_tags 不应该发生添加");
                    }
                },
                    (string type, string error) =>
                {
                    errors.Add(new TypeAndError
                    {
                        Type  = type,
                        Error = error
                    });
                });

                Assert.AreEqual(1, new_results.Count);
                Assert.AreEqual(1, changed_results.Count);  // 两阶段也是可能的
                Assert.AreEqual(0, removed_results.Count);

                Assert.AreEqual(1, NewTagList.Tags.Count);
            }
        }
Ejemplo n.º 2
0
        public void Test_add_2()
        {
            NewTagList.Clear();

            List <OneTag> tag_list = new List <OneTag>();

            // 准备内容
            tag_list.Add(BuildOne15693Tag("M201", 1, "111111"));

            List <TagAndData> new_results     = new List <TagAndData>();
            List <TagAndData> changed_results = new List <TagAndData>();
            List <TagAndData> removed_results = new List <TagAndData>();

            List <TypeAndError> errors = new List <TypeAndError>();

            NewTagList.Refresh(
                "*",
                tag_list,
                (readerName, uid, antennaID) =>
            {
                // 获得标签内容
                return(new GetTagInfoResult
                {
                    TagInfo = BuildOne15693TagInfo(tag_list[0])
                });
                // return null;
            },
                (new_tags, changed_tags, removed_tags) =>
            {
                if (new_tags != null && new_tags.Count > 0)
                {
                    // 检查得到的 new_tags
                    Assert.AreEqual(1, new_tags.Count);
                    var result = new_tags[0];
                    // 这个时候,TagInfo 还是 null
                    Assert.AreEqual(null, result.OneTag.TagInfo);
                    Assert.IsTrue(IsEqual(result.OneTag, tag_list[0]));

                    new_results.AddRange(new_tags);
                }
                if (changed_tags != null && changed_tags.Count > 0)
                {
                    Assert.AreEqual(1, changed_tags.Count);

                    var result = changed_tags[0];
                    // 这个时候,TagInfo 应该不是 null 了
                    Assert.AreNotEqual(null, result.OneTag.TagInfo);
                    // 比较除了 TagInfo 以外的成员
                    Assert.IsTrue(IsEqual(result.OneTag, tag_list[0], false));
                    // 专门比较 TagInfo
                    Assert.IsTrue(IsEqual(BuildOne15693TagInfo(tag_list[0]), result.OneTag.TagInfo));

                    changed_results.AddRange(changed_tags);
                }
                if (removed_tags != null)
                {
                    removed_results.AddRange(removed_tags);
                }
            },
                (string type, string error) =>
            {
                errors.Add(new TypeAndError
                {
                    Type  = type,
                    Error = error
                });
            });

            Assert.AreEqual(1, new_results.Count);
            Assert.AreEqual(1, changed_results.Count);
            Assert.AreEqual(0, removed_results.Count);

            Assert.AreEqual(1, NewTagList.Tags.Count);
        }
Ejemplo n.º 3
0
        public void Test_add_1()
        {
            NewTagList.Clear();

            List <OneTag> tag_list = new List <OneTag>();

            // 准备内容
            tag_list.Add(BuildOne15693Tag("M201", 1, "111111"));

            List <TagAndData> new_results     = new List <TagAndData>();
            List <TagAndData> changed_results = new List <TagAndData>();
            List <TagAndData> removed_results = new List <TagAndData>();

            List <TypeAndError> errors = new List <TypeAndError>();

            NewTagList.Refresh(
                "*",
                tag_list,
                (readerName, uid, antennaID) =>
            {
                // 获得标签内容
                return(new GetTagInfoResult {
                });
                // return null;
            },
                (new_tags, changed_tags, removed_tags) =>
            {
                if (new_tags != null)
                {
                    new_results.AddRange(new_tags);
                }
                if (changed_tags != null)
                {
                    changed_results.AddRange(changed_tags);
                }
                if (removed_tags != null)
                {
                    removed_results.AddRange(removed_tags);
                }
            },
                (string type, string error) =>
            {
                errors.Add(new TypeAndError
                {
                    Type  = type,
                    Error = error
                });
            });

            Assert.AreEqual(1, new_results.Count);

            // 检查得到的 new_results
            var result = new_results[0];

            Assert.AreEqual(null, result.OneTag.TagInfo);
            Assert.IsTrue(IsEqual(result.OneTag, tag_list[0]));

            Assert.AreEqual(0, changed_results.Count);
            Assert.AreEqual(0, removed_results.Count);

            Assert.AreEqual(1, NewTagList.Tags.Count);
        }