Ejemplo n.º 1
0
        public void empty_engine_results()
        {
            var keywordResult = new KeywordResult
            {
                Keyword = "keyword",
                Date = DateTime.UtcNow,
                Engine = Engine.None,
                Version = "1",
                EngineResults = new List<EngineResult>()
            };

            var bytes = keywordResult.ToBinary();

            AssertEx.PropertyValuesAreEquals(keywordResult, KeywordResult.TryGetFromBinary(bytes));
        }
Ejemplo n.º 2
0
        public void exist_engine_results()
        {
            var keywordResult = new KeywordResult
            {
                Keyword = "keyword",
                Date = DateTime.UtcNow,
                Engine = Engine.None,
                Version = "1",
                EngineResults = new List<EngineResult>{
                        new EngineResult{
                        Title="Title",
                        Url = "Url",
                        ItemHtml="<b>Html</b>"
                    }
                }
            };

            var bytes = keywordResult.ToBinary();

            var actual = KeywordResult.TryGetFromBinary(bytes);

            AssertEx.PropertyValuesAreEquals(keywordResult, actual);
        }
Ejemplo n.º 3
0
        public static KeywordResult TryGetFromBinary(byte[] data)
        {
            using (var mem = new MemoryStream(data))
            using (var bin = new BinaryReader(mem))
            {
                var result = new KeywordResult
                {
                    Keyword = bin.ReadString(),
                    Date = DateTime.FromBinary(bin.ReadInt64()),
                    Engine = (Engine)bin.ReadInt32(),
                    Version = bin.ReadString(),
                    EngineResults = new List<EngineResult>()
                };

                var count = bin.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    EngineResult engineResult = new EngineResult
                        {
                            Title = bin.ReadString(),
                            Url = bin.ReadString(),
                            ItemHtml = bin.ReadString()
                        };
                    result.EngineResults.Add(engineResult);
                }

                return result;
            }
        }