public void TestSerializeAndDeserialize()
        {
            var dictionary = new BinaryTreeDictionary <int, string>();

            dictionary.Add(8, "eight");
            dictionary.Add(3, "three");
            dictionary.Add(6, "six");
            dictionary.Add(4, "four");

            var name   = "some-name";
            var stream = new MemoryStream();

            var storageMock = new Mock <IStorage>();

            storageMock.Setup(s => s.GetWriteStream(name))
            .Returns(stream);
            storageMock.Setup(s => s.GetReadStream(name))
            .Returns(stream);

            var serializer = new BinaryTreeDictionarySerializer(storageMock.Object);

            serializer.Save(name, dictionary, closeStream: false);
            stream.Position = 0;
            var newDictionary = serializer.Load <int, string>(name);

            CollectionAssert.AreEquivalent(dictionary.ToList(), newDictionary.ToList());
        }
Esempio n. 2
0
            public void TestSerializeAndDeserialize()
            {
                var dict = new BinaryTreeDictionary <int, string>();

                dict.Add(1, "first value");
                dict.Add(3, "third value");
                dict.Add(7, "seventh value");

                var name   = "testFile";
                var stream = new MemoryStream();

                var storageMock = new Mock <IStorage>();

                storageMock.Setup(s => s.GetWriteStream(name))
                .Returns(stream);
                storageMock.Setup(s => s.GetReadStream(name))
                .Returns(stream);

                var serializer = new BinarySearchTreeSerializer(storageMock.Object);

                serializer.Save(name, dict, closeStream: false);
                stream.Position = 0;
                var newDict = serializer.Load <int, string>(name);

                CollectionAssert.AreEquivalent(dict.ToList(), newDict.ToList());
            }
Esempio n. 3
0
        public void TestReturnCollection()
        {
            var dict = new BinaryTreeDictionary <int, string>();

            dict.Add(1, "first value");
            dict.Add(3, "third value");

            var defaultDict = new Dictionary <int, string>()
            {
                { 1, "first value" },
                { 3, "third value" }
            };

            CollectionAssert.AreEqual(defaultDict, dict.ToList());
        }