Example #1
0
 static void Main()
 {
     /* ==========================
      * Binary file comparison
      * ==========================
      * This program will create a new model and populate it, then serialize
      * it both in JSON format and with BinaryPack. It will then print
      * the size in bytes of the resulting serialized data, both before
      * and after a compression with gzip. */
     FileSizeComparer.Run <JsonResponseModel>();
 }
Example #2
0
        public void Test_Comparison_Fails_For_Different_Files()
        {
            // This test just checks the file size comparer, not the matching algorithm
            var mockIo = Substitute.For <IIO>();

            var comparer = new FileSizeComparer();

            comparer.Init(mockIo);

            var fileA = "a.file";
            var fileB = "different.foo";

            Assert.That(comparer.WantsToHandle(fileA), Is.True);
            Assert.That(comparer.WantsToHandle(fileB), Is.True);

            // Setup the io to return different sizes
            mockIo.ReadFile(fileA).Returns(MakeStreamFromString("a"));
            mockIo.ReadFile(fileB).Returns(MakeStreamFromString("different"));

            Assert.That(() => comparer.Handle(fileA, fileB), Throws.Exception);
        }
Example #3
0
        public void Test_Comparison_Is_Valid_For_Same_File_Sizes()
        {
            // This test expects the files to be of equal length and must not fail
            var mockIo = Substitute.For <IIO>();


            var comparer = new FileSizeComparer();

            comparer.Init(mockIo);

            var fileA = "a.file";
            var fileB = "different.foo";

            Assert.That(comparer.WantsToHandle(fileA), Is.True);
            Assert.That(comparer.WantsToHandle(fileB), Is.True);

            // Mock the io to check for file size only
            mockIo.ReadFile(fileA).Returns(MakeStreamFromString("123"));
            mockIo.ReadFile(fileB).Returns(MakeStreamFromString("abc"));

            Assert.That(() => comparer.Handle(fileA, fileB), Throws.Nothing);
        }