Пример #1
0
        public void should_create_a_new_user()
        {
            var updateUser = new UpdateUser
                {
                  Username = "******",
                  EmailAddress = "f",
                  Name = "fo",
                  Password = "******"
                };
            User user=null;
            WithDbContext(context => user= GetInstance<UpdateUserHandler>().Handle(updateUser));

            WithDbContext(context =>
                              {
                                  var foundUser = context.Find<User>(user.Id);

                                  foundUser.ShouldNotBeNull();
                                  var compare = new KellermanSoftware.CompareNetObjects.CompareObjects();

                                  // savedJob is a proxy
                                  compare.MaxDifferences = 1;

                                  compare.Compare(user, foundUser);
                              });
        }
Пример #2
0
        public void Should_Save_a_Job()
        {
            var fixture = new Fixture();
            var job = fixture.Build<Job>()
                .Without(c => c.Id)
                .CreateAnonymous();
            using (var saveContext = DbContext())
            {
                var repo = new Repository<Job>(saveContext);
                repo.InsertOrUpdate(job);
                repo.Save();
            }

            Job savedJob;
            using (var readContext = DbContext())
            {
                var repo1 = new Repository<Job>(readContext);
                savedJob = repo1.Find(job.Id);
            }
            //            savedJob.Id.ShouldEqual(1);
            var compare = new KellermanSoftware.CompareNetObjects.CompareObjects();

            // savedJob is a proxy
            compare.MaxDifferences = 1;

            compare.Compare(job, savedJob);
            (compare.Differences.Count <= 1).ShouldBeTrue();

            Debug.WriteLine(compare.DifferencesString);
        }
Пример #3
0
        public void FactoryMethodShouldWorkWhenInStandardModeTest()
        {
            DateTime then = DateTime.Now;
            long ft = then.ToFileTime();
            DateTime expected = DateTime.FromFileTime( ft );

            //
            DateTime actual = Tessl.From<DateTime>( new Func<long,DateTime>(DateTime.FromFileTime), ft );

            //
            var comparer = new KellermanSoftware.CompareNetObjects.CompareObjects();
            comparer.IgnoreIndexersWhichCantBeCompared = true;
            Assert.IsTrue( comparer.Compare( expected, actual ), comparer.DifferencesString );
            Assert.AreEqual<int>( then.Year, actual.Year );
            Assert.AreEqual<int>( then.Month, actual.Month );
            Assert.AreEqual<int>( then.Day, actual.Day );
            Assert.IsTrue( expected.CompareTo( actual ) == 0, "Expected CompareTo() to return 0" );
        }
Пример #4
0
        public async Task CompareShouldBeEqual(string prj1, string prj2)
        {
            var baseDir = Path.Combine(GetCurrentDir(), "..", "TestAssemblies");
            var prj1Bin = await CompileProject(Path.Combine(baseDir, prj1));

            var prj2Bin = await CompileProject(Path.Combine(baseDir, prj2));

            using (var msIn = new MemoryStream(prj1Bin))
                using (var msOut = new MemoryStream())
                {
                    Hydra.ReferenceAssembly.createRefAsm(msIn, msOut);
                    prj1Bin = msOut.ToArray();
                }

            using (var msIn = new MemoryStream(prj2Bin))
                using (var msOut = new MemoryStream())
                {
                    Hydra.ReferenceAssembly.createRefAsm(msIn, msOut);
                    prj2Bin = msOut.ToArray();
                }

            var areEqual = prj1Bin.SequenceEqual(prj2Bin);

            if (false == areEqual)
            {
                var comparer = new KellermanSoftware.CompareNetObjects.CompareObjects();

                var guid = Guid.NewGuid();
                File.WriteAllBytes($"failed_test_1_{guid}", prj1Bin);
                File.WriteAllBytes($"failed_test_2_{guid}", prj2Bin);

                comparer.MaxDifferences = 100;
                comparer.Compare(
                    AssemblyDefinition.ReadAssembly(new MemoryStream(prj1Bin)),
                    AssemblyDefinition.ReadAssembly(new MemoryStream(prj2Bin)));
                var diffString = comparer.DifferencesString;
                Assert.True(areEqual, $"Test failed for {prj1} -> {prj2}: {diffString}");
            }
        }
Пример #5
0
        void printThens(List <object> expectedEvents, List <object> actualEvents, object command)
        {
            var comparer = new KellermanSoftware.CompareNetObjects.CompareObjects();

            if (!comparer.Compare(expectedEvents, actualEvents))
            {
                _suuccess = false;
                printCommand(command, ConsoleColor.Red);
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Then - ");
                Console.WriteLine("Expected: ");
                Console.ForegroundColor = ConsoleColor.Red;
                foreach (var e in expectedEvents)
                {
                    Console.WriteLine(e);
                }
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Found: ");
                Console.ForegroundColor = ConsoleColor.Red;
                foreach (var e in actualEvents)
                {
                    Console.WriteLine(e);
                }
            }
            else
            {
                printCommand(command, ConsoleColor.Green);
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Then - ");
                Console.ForegroundColor = ConsoleColor.Green;
                foreach (var e in expectedEvents)
                {
                    Console.WriteLine(e);
                }
            }
        }
Пример #6
0
 void printThens(List<object> expectedEvents, List<object> actualEvents, object command)
 {
     var comparer = new KellermanSoftware.CompareNetObjects.CompareObjects();
     if(!comparer.Compare(expectedEvents, actualEvents))
     {
         _suuccess = false;
         printCommand(command, ConsoleColor.Red);
         Console.ForegroundColor = ConsoleColor.Cyan;
         Console.WriteLine("Then - ");
         Console.WriteLine("Expected: ");
         Console.ForegroundColor = ConsoleColor.Red;
         foreach(var e in expectedEvents)
             Console.WriteLine(e);
         Console.ForegroundColor = ConsoleColor.Cyan;
         Console.WriteLine("Found: ");
         Console.ForegroundColor = ConsoleColor.Red;
         foreach (var e in actualEvents)
             Console.WriteLine(e);
     }
     else
     {
         printCommand(command, ConsoleColor.Green);
         Console.ForegroundColor = ConsoleColor.Cyan;
         Console.WriteLine("Then - ");
         Console.ForegroundColor = ConsoleColor.Green;
         foreach (var e in expectedEvents)
             Console.WriteLine(e);
     }
 }
Пример #7
0
        static void Main(string[] args)
        {
            //TestNXMLParser testXMLParser = new TestNXMLParser();
            //testXMLParser.Run();

            //NSXMLNodeOptions xmlNodeOPtions = (NSXMLNodeOptions)0x800004;

            #if TEST_COLOR
            GSNamedColor nColor1 = (GSNamedColor)GSNamedColor.Alloc().InitWithCatalogName("list1", "color1");
            GSNamedColor nColor2 = (GSNamedColor)GSNamedColor.Alloc().InitWithCatalogName("list2", "color2");
            GSNamedColor nColor11 = (GSNamedColor)GSNamedColor.Alloc().InitWithCatalogName("list1", "color1");

            //Why does it work without having to override GetHashCode and Equals ???
            System.Diagnostics.Debug.Assert(nColor1.Equals(nColor11));
            #endif

            //#if TEST

            #if TEST_PATH
            NSString strPath = @"";
            NSString strPathRes = null;

            strPath = "/tmp/scratch.tiff";
            strPathRes = strPath.LastPathComponent();
            System.Diagnostics.Debug.Assert(strPathRes.IsEqualToString(@"scratch.tiff"));

            strPath = "/tmp/scratch";
            strPathRes = strPath.LastPathComponent();
            System.Diagnostics.Debug.Assert(strPathRes.IsEqualToString(@"scratch"));

            strPath = "/tmp/";
            strPathRes = strPath.LastPathComponent();
            System.Diagnostics.Debug.Assert(strPathRes.IsEqualToString(@"tmp"));

            strPath = "scratch///";
            strPathRes = strPath.LastPathComponent();
            System.Diagnostics.Debug.Assert(strPathRes.IsEqualToString(@"scratch"));

            strPath = "/";
            strPathRes = strPath.LastPathComponent();
            System.Diagnostics.Debug.Assert(strPathRes.IsEqualToString(@"/"));
            #endif

            //string xibPath = @"C:/Developer/cygwin/home/Vincent/projects/CocoaBuilder/Tests/Button/ButtonTextAlign/ButtonTextAlign/en.lproj/ButtonTextAlign.xib";
            //string xibPath = @"/Users/v.richomme/Developer/CocoaBuilder/Tests/Button/ButtonTextAlign/ButtonTextAlign/en.lproj/ButtonTextAlign.xib";

            //var tmp = new GSModelLoaderFactory();

            //string fullPath = System.Reflection.Assembly.GetAssembly(typeof(Smartmobili.Cocoa.Program)).Location;
            string progPath = System.Reflection.Assembly.GetAssembly (typeof(Smartmobili.Cocoa.Program)).Location;
            string progDir = Path.GetDirectoryName(progPath);
            string xibPath = progDir + "/../../../Tests/Button/ButtonTextAlign/ButtonTextAlign/en.lproj/ButtonTextAlign.xib";

            //NSData data = NSData.Alloc().InitWithContentsOfFile(xibPath);
            //if (data != null)
            IBDocument ibDoc = (IBDocument)IBDocument.Alloc().Init();
            if (ibDoc.ReadFromURL((NSURL)NSURL.FileURLWithPath(xibPath), ""))
            {
               // var u = GSXibKeyedUnarchiver.Alloc().InitForReadingWithData(data);
                //id container = u.DecodeObjectForKey(@"IBDocument.Objects");
                //if (container == null || container.IsKindOfClass(IBObjectContainer.Class) == false)
                if (false)
                {
                    //result = NO;
                }
                else
                {
                    //NSArray rootObjects = (NSArray)u.DecodeObjectForKey(@"IBDocument.RootObjects");
                    var rootObjects = ibDoc.RootObjects;

                    NSWindowTemplate nsWindow = (NSWindowTemplate)rootObjects.Where(o =>
                    (o != null) && (o.IsKindOfClass(NSWindowTemplate.Class))).FirstOrDefault();
                    if (nsWindow != null)
                    {
                        if (nsWindow.View != null)
                        {
                            NSView view = (NSView)nsWindow.View;
                            // We want to see differences between buttons starting from the upper button to the lower one
                            // Note tha origin in cocoa is the left bottom side
                            var btnArray = view.SubViews.Where(o => (o != null) && (o.GetType() == typeof(NSButton))).OrderByDescending(x => ((NSButton)x).Frame.Origin.Y).ToArray();
                            if (btnArray != null && btnArray.Length > 0)
                            {
                                KellermanSoftware.CompareNetObjects.CompareObjects compareObjects = new KellermanSoftware.CompareNetObjects.CompareObjects();
                                if (!compareObjects.Compare(btnArray[0], btnArray[1]))
                                {
                                    System.Diagnostics.Trace.WriteLine(compareObjects.DifferencesString);
                                    Console.WriteLine(compareObjects.DifferencesString);
                                }
                                if (!compareObjects.Compare(btnArray[0], btnArray[2]))
                                {
                                    System.Diagnostics.Trace.WriteLine(compareObjects.DifferencesString);
                                    Console.WriteLine(compareObjects.DifferencesString);
                                }
                                if (!compareObjects.Compare(btnArray[0], btnArray[3]))
                                {
                                    System.Diagnostics.Trace.WriteLine(compareObjects.DifferencesString);
                                    Console.WriteLine(compareObjects.DifferencesString);
                                }
                                if (!compareObjects.Compare(btnArray[0], btnArray[4]))
                                {
                                    System.Diagnostics.Trace.WriteLine(compareObjects.DifferencesString);
                                    Console.WriteLine(compareObjects.DifferencesString);
                                }
                            }
                        }
                    }
                }
            }

            //#endif
        }
Пример #8
0
        public void NewWith4ParametersShouldConstructNewObjectWhenInStandardModeTest()
        {
            //
            var expected = new DateTime(
                                2000,
                                1,
                                2,
                                new System.Globalization.GregorianCalendar( System.Globalization.GregorianCalendarTypes.Localized ) );
            var actual = Tessl.New<DateTime, int, int, int, System.Globalization.GregorianCalendar>(
                                2000,
                                1,
                                2,
                                Tessl.New<System.Globalization.GregorianCalendar, System.Globalization.GregorianCalendarTypes>(System.Globalization.GregorianCalendarTypes.Localized));

            //
            var comparer = new KellermanSoftware.CompareNetObjects.CompareObjects();
            comparer.IgnoreIndexersWhichCantBeCompared = true;
            Assert.IsTrue( comparer.Compare( expected, actual ), comparer.DifferencesString );
            Assert.AreEqual<int>( 2000,  actual.Year);
            Assert.AreEqual<int>( 1, actual.Month);
            Assert.AreEqual<int>( 2, actual.Day);
            Assert.IsTrue( expected.CompareTo(actual) == 0, "Expected CompareTo() to return 0");
        }
Пример #9
0
        public void NewWith2ParametersShouldConstructNewObjectWhenInStandardModeTest()
        {
            //
            string filename = "filename";
            string args = "args";
            var expected2 = new System.Diagnostics.ProcessStartInfo( filename, args );
            var actual2 = Tessl.New<System.Diagnostics.ProcessStartInfo, string, string>( filename, args );

            //
            var comparer = new KellermanSoftware.CompareNetObjects.CompareObjects();
            comparer.IgnoreIndexersWhichCantBeCompared = true;
            Assert.IsTrue( comparer.Compare( expected2, actual2 ), comparer.DifferencesString );
            Assert.AreEqual<string>( filename, expected2.FileName );
            Assert.AreEqual<string>( filename, actual2.FileName );
            Assert.AreEqual<string>( args, expected2.Arguments );
            Assert.AreEqual<string>( args, actual2.Arguments );
        }
Пример #10
0
        public void NewWith1ParameterShouldConstructNewObjectWhenInStandardModeTest()
        {
            decimal expected = new decimal(123.45);
            //
            decimal actual   = Tessl.New<decimal, double>( 123.45 );
            //
            var comparer = new KellermanSoftware.CompareNetObjects.CompareObjects();
            Assert.IsTrue(comparer.Compare(actual, expected), comparer.DifferencesString);
            Assert.AreEqual<decimal>(expected, actual);

            //try a class with plenty of fields
            string aFilename = "filename";
            var expected2 = new System.Diagnostics.ProcessStartInfo(aFilename);
            var actual2 = Tessl.New<System.Diagnostics.ProcessStartInfo, string>(aFilename);
            comparer.IgnoreIndexersWhichCantBeCompared = true;
            //
            Assert.IsTrue(comparer.Compare(expected2, actual2), comparer.DifferencesString);
            Assert.AreEqual<string>(aFilename, expected2.FileName);
            Assert.AreEqual<string>(aFilename, actual2.FileName);
        }
Пример #11
0
        public void NewShouldConstructNewObjectWhenInStandardModeTest()
        {
            object expected = new object();
            //
            object actual = Tessl.New<object>();
            //
            var comparer = new KellermanSoftware.CompareNetObjects.CompareObjects();
            Assert.IsTrue(comparer.Compare(actual, expected), comparer.DifferencesString);

            //try a class with plenty of fields
            var expected2 = new System.Diagnostics.ProcessStartInfo();
            //
            var actual2 = Tessl.New<System.Diagnostics.ProcessStartInfo>();
            //
            comparer.IgnoreIndexersWhichCantBeCompared = true;
            Assert.IsTrue( comparer.Compare(expected2, actual2), comparer.DifferencesString);
        }
Пример #12
0
        public void InitShouldInitialiseObjectWhenInStandardModeTest()
        {
            System.Diagnostics.ProcessStartInfo expected=
                new System.Diagnostics.ProcessStartInfo
                {
                    Arguments="Args",
                    CreateNoWindow=true,
                    Domain="Domain"
                };
            System.Diagnostics.ProcessStartInfo actual = Tessl.Init<System.Diagnostics.ProcessStartInfo>(
                new System.Diagnostics.ProcessStartInfo
                {
                    Arguments="Args",
                    CreateNoWindow=true,
                    Domain="Domain"
                });

            //
            var comparer = new KellermanSoftware.CompareNetObjects.CompareObjects();
            comparer.IgnoreIndexersWhichCantBeCompared = true;
            Assert.IsTrue( comparer.Compare( expected, actual ), comparer.DifferencesString );
            Assert.AreEqual<string>( "Domain", actual.Domain );
        }