ToString() public method

public ToString ( ) : string
return string
Beispiel #1
0
        // can't use ExpectedException since expected message is dynamic
        public void CanMockMethodAcceptingTestClass_WillErrorOnWrongParameter()
        {
            string t2Text = "@";
            string t3Text = "@";

            try
            {
                TestClass t1 = MockRepository.Mock <TestClass>();
                t1.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);
                TestClass t2 = MockRepository.Mock <TestClass>();
                t2.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);
                TestClass t3 = MockRepository.Mock <TestClass>();
                t3.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

                t2Text = t2.ToString();
                t3Text = t3.ToString();

                t1.Expect(x => x.MethodAcceptingTestClass(t2));

                t1.MethodAcceptingTestClass(t3);
                t1.VerifyExpectations(true);

                Assert.False(true, "Expected ExpectationViolationException");
            }
            catch (ExpectationViolationException ex)
            {
                string msg =
                    string.Format("TestClass.MethodAcceptingTestClass({0}); Expected #0, Actual #1.\r\n" +
                                  "TestClass.MethodAcceptingTestClass(equal to {1}); Expected #1, Actual #0.",
                                  t3Text, t2Text);

                Assert.Equal(msg, ex.Message);
            }
        }
Beispiel #2
0
        // can't use ExpectedException since expected message is dynamic
        public void CanMockMethodAcceptingTestClass_WillErrorOnWrongParameter()
        {
            string t2Text = "@";
            string t3Text = "@";

            try
            {
                MockRepository mocks = new MockRepository();
                TestClass      t1    = mocks.StrictMock <TestClass>();
                TestClass      t2    = mocks.StrictMock <TestClass>();
                TestClass      t3    = mocks.StrictMock <TestClass>();
                t2Text = t2.ToString();
                t3Text = t3.ToString();

                t1.MethodAcceptingTestClass(t2);
                mocks.ReplayAll();
                t1.MethodAcceptingTestClass(t3);
                mocks.VerifyAll();

                Assert.False(true, "Expected ExpectationViolationException");
            }
            catch (ExpectationViolationException ex)
            {
                string msg =
                    String.Format("TestClass.MethodAcceptingTestClass({0}); Expected #0, Actual #1.\r\n" +
                                  "TestClass.MethodAcceptingTestClass({1}); Expected #1, Actual #0.",
                                  t3Text,
                                  t2Text);

                Assert.Equal(msg, ex.Message);
            }
        }
 public void TestToString()
 {
     TestClass testclass = new TestClass() { ID = 5, Decimal = 3.3M, Float = 3.23423F, String = "blah, \"asdff\"" };
     testclass.Class = new TestClass() { ID = 5, Decimal = 3.3M, Float = 3.23423F, String = "blah, \"asdff\"" };
     string actual = testclass.ToString(',');
     Assert.AreEqual("5,\"blah, \"\"asdff\"\"\",3.3,3.23423,\"5,\"blah, \"\"asdff\"\"\",3.3,3.23423\"", actual);
 }
Beispiel #4
0
    public static void Main()
    {
        var test = new TestClass();

        Object[] objectsToCompare = { test,           test.ToString(), 123,
                                      123.ToString(), "some text",
                                      "Some Text" };
        string   s = "some text";

        foreach (var objectToCompare in objectsToCompare)
        {
            try {
                int i = s.CompareTo(objectToCompare);
                Console.WriteLine("Comparing '{0}' with '{1}': {2}",
                                  s, objectToCompare, i);
            }
            catch (ArgumentException e) {
                Console.WriteLine("Bad argument: {0} (type {1})",
                                  objectToCompare,
                                  objectToCompare.GetType().Name);
                Console.WriteLine("Exception information: {0}", e);
            }
            Console.WriteLine();
        }
    }
Beispiel #5
0
        public void ToString_ShouldReturnExpectedValue()
        {
            const string v = "v1";

            var obj = new TestClass(v);

            obj.ToString().ShouldBe(v);
        }
        public void ToString_ShouldReturnExpectedValue()
        {
            const int v = 1;

            var obj = new TestClass(v);

            obj.ToString().ShouldBe(v.ToString());
        }
Beispiel #7
0
        public void StrictMockToStringReturnsDescription()
        {
            TestClass t = MockRepository.Mock <TestClass>();

            int    hashCode = t.GetHashCode();
            string toString = t.ToString();

            Assert.Equal(String.Format("RemotingMock_{0}<TestClass>", hashCode), toString);
        }
Beispiel #8
0
        public void ToString_Works_ForAllWrappedTypes()
        {
            var _SUT1 = new SemanticType <TestClass>(_TestClass);
            var _SUT2 = new SemanticType <string>(_TestString);
            var _SUT3 = new SemanticType <int>(_TestInt);

            Assert.That(_SUT1.ToString() == _TestClass.ToString());
            Assert.That(_SUT2.ToString() == _TestString);
            Assert.That(_SUT3.ToString() == _TestInt.ToString());
        }
Beispiel #9
0
 private void PrintTestClass(TestClass info, string desc)
 {
     if (info == null)
     {
         Debug.Log(desc + "null");
     }
     else
     {
         Debug.Log(desc + info.ToString());
     }
 }
Beispiel #10
0
        public void StrictMockToStringReturnsDescription()
        {
            TestClass t = MockRepository.Mock <TestClass>();

            t.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

            int    hashCode = t.GetHashCode();
            string toString = t.ToString();

            Assert.Equal(String.Format("RemotingMock_{0}<TestClass>", hashCode), toString);
        }
Beispiel #11
0
Datei: test.cs Projekt: mono/gert
	static void Main (string [] args)
	{
		string xsd = @"
			<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
				<xs:element name='TestClass'>
					<xs:complexType>
						<xs:sequence>
							<xs:element name='UnknownItemSerializer'
								type='UnknownItemSerializerType' />
						</xs:sequence>
					</xs:complexType>
				</xs:element>
				<xs:complexType name='UnknownItemSerializerType'>
					<xs:sequence>
						<xs:element name='DerivedClass_1'>
							<xs:complexType>
								<xs:sequence>
									<xs:element name='value' type='xs:integer' />
								</xs:sequence>
							</xs:complexType>
						</xs:element>
					</xs:sequence>
					<xs:attribute name='type' type='xs:string' use='required' />
				</xs:complexType>
			</xs:schema>
			";

		TestClass a = new TestClass ();
		DerivedClass_1 d1 = new DerivedClass_1 ();

		a.Item = d1;
		String s = a.ToString ();

		XmlTextReader xtr = new XmlTextReader (new StringReader (s));

		XmlValidatingReader vr = new XmlValidatingReader (xtr);
		vr.Schemas.Add (XmlSchema.Read (new StringReader (xsd), null));
		vr.ValidationType = ValidationType.Schema;

		while (vr.Read ()) {
		}

	}
        /// <summary>
        /// The string representation of the ScenarioResult.
        /// </summary>
        /// <returns>Returns a verbose string representation of the result.</returns>
        public override string ToString()
        {
            StringBuilder s = new StringBuilder();

            s.AppendLine("Started: " + Started.ToString());
            s.AppendLine("Finished: " + Finished.ToString());
            TimeSpan duration = Finished.Subtract(Started);

            s.AppendLine("Duration: " + duration.ToString());
            s.AppendLine("TestMethod: " + TestMethod.ToString());
            s.AppendLine("TestClass: " + TestClass.ToString());
            s.AppendLine("Result: " + Result.ToString());
            if (Exception != null)
            {
                s.AppendLine();
                s.AppendLine("Exception:");
                s.AppendLine(Exception.Message);
                s.AppendLine(Exception.StackTrace);
            }
            return(s.ToString());
        }
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);

			// Get our button from the layout resource,
			// and attach an event to it
			Button button = FindViewById<Button> (Resource.Id.myButton);
			button.Click += delegate {
				button.Text = string.Format ("{0} clicks!", count++);
				TestClass test = new TestClass ();
				test.ABoolean = count % 2 == 0;
				test.ADouble -= count;
				test.AFloat -= count;
				test.ALong -= count;
				test.AnInt += count;
				test.AString = button.Text;
				test.Toast (this, test.ToString());
			};

		}
Beispiel #14
0
        public static void bat(string _ip)
        {
            Client.Client cl = new Client.Client(_ip, 5255, "jak", "kaj");
            cl.Connect();

            object tcl2 = new TestClass();
            bool   b    = cl.Get(ref tcl2, "gigel", typeof(TestClass));

            if (!b)
            {
                Console.WriteLine("Nope.");
            }

            Console.WriteLine(tcl2);
            Console.WriteLine("and should be : ");

            TestClass tcl1 = new TestClass(true);

            tcl1.b        = new double[] { 666.66, 777.777 };
            tcl1.inrr     = new Innerer(true);
            tcl1.a        = 871;
            tcl1.dsa._asd = "merge";
            Console.WriteLine(tcl1.ToString());
        }
Beispiel #15
0
        public void StartPipeAsync()
        {
            var key = Guid.NewGuid().ToString();

            using (var pipe = cli.StartPipe())
            {
                long t1 = 0;
                pipe.IncrByAsync(key, 10);

                pipe.SetAsync("StartPipeAsyncTestSet_null", Null);
                string t3 = "";
                pipe.GetAsync("StartPipeAsyncTestSet_null");

                pipe.SetAsync("StartPipeAsyncTestSet_string", String);
                string t4 = null;
                pipe.GetAsync("StartPipeAsyncTestSet_string");

                pipe.SetAsync("StartPipeAsyncTestSet_bytes", Bytes);
                byte[] t6 = null;
                pipe.GetAsync <byte[]>("StartPipeAsyncTestSet_bytes");

                pipe.SetAsync("StartPipeAsyncTestSet_class", Class);
                TestClass t8 = null;
                pipe.GetAsync <TestClass>("StartPipeAsyncTestSet_class");
            }

            using (var pipe = cli.StartPipe())
            {
                var  tasks = new List <Task>();
                long t1    = 0;
                tasks.Add(pipe.IncrByAsync(key, 10).ContinueWith(t => t1 = t.Result));

                pipe.SetAsync("StartPipeAsyncTestSet_null", Null);
                string t3 = "";
                tasks.Add(pipe.GetAsync("StartPipeAsyncTestSet_null").ContinueWith(t => t3 = t.Result));

                pipe.SetAsync("StartPipeAsyncTestSet_string", String);
                string t4 = null;
                tasks.Add(pipe.GetAsync("StartPipeAsyncTestSet_string").ContinueWith(t => t4 = t.Result));

                pipe.SetAsync("StartPipeAsyncTestSet_bytes", Bytes);
                byte[] t6 = null;
                tasks.Add(pipe.GetAsync <byte[]>("StartPipeAsyncTestSet_bytes").ContinueWith(t => t6 = t.Result));

                pipe.SetAsync("StartPipeAsyncTestSet_class", Class);
                TestClass t8 = null;
                tasks.Add(pipe.GetAsync <TestClass>("StartPipeAsyncTestSet_class").ContinueWith(t => t8 = t.Result));

                var ret = pipe.EndPipe();
                Task.WaitAll(tasks.ToArray());

                Assert.Equal(10L, ret[0]);
                Assert.Equal("", ret[2].ToString());
                Assert.Equal(String, ret[4].ToString());
                Assert.Equal(Bytes, ret[6]);
                Assert.Equal(Class.ToString(), ret[8].ToString());

                Assert.Equal(10L, t1);
                Assert.Equal("", t3);
                Assert.Equal(String, t4);
                Assert.Equal(Bytes, t6);
                Assert.Equal(Class.ToString(), t8.ToString());
            }
        }
Beispiel #16
0
        internal Test Prepare(Assembly executionReadyAssembly, Assembly jasSharpAssembly)
        {
            var module = executionReadyAssembly.Modules.First();
            var getPreparedTestExecutionMethod =
                jasSharpAssembly
                .GetType(typeof(SpecHelper).Namespace + "." + typeof(SpecHelper).Name)
                .GetMethod(nameof(SpecHelper.GetTestExecutionMethods), BindingFlags.Static | BindingFlags.NonPublic);

            var testClass        = executionReadyAssembly.GetTypes().First(x => x.ToString() == TestClass.ToString());
            var executionMethods = (Delegate[][])getPreparedTestExecutionMethod.Invoke(null, new object[] { testClass, FullName });

            return
                (new Test(
                     TestClass,
                     Path,
                     Description,
                     new TestExecution(executionMethods[0], executionMethods[2], executionMethods[1][0]),
                     IsFocused,
                     IsExcluded,
                     SourceFilename,
                     LineNumber));
        }
Beispiel #17
0
        public void SetAndGetMember()
        {
            dynamic Temp = new TestClass();

            Assert.Equal((string)null, Temp.A);
            Temp.A = "Testing";
            Temp.B = 1;
            int B = Temp.B;

            Assert.Equal("Testing", Temp.A);
            Assert.Equal <int>(1, B);
            Assert.Equal("TestClass this\r\n\tSystem.String A = Testing\r\n\tSystem.Int32 B = 1\r\n", Temp.ToString());
            Temp.C = new Func <int>(() => 1);
            Assert.Equal("TestClass this\r\n\tSystem.String A = Testing\r\n\tSystem.Int32 B = 1\r\n\tSystem.Func<System.Int32> C = System.Func`1[System.Int32]\r\n", Temp.ToString());
            Assert.Equal <int>(1, Temp.C());
        }
Beispiel #18
0
 public override string ToString()
 {
     return("data: " + data + "  testClass" + testClass.ToString());
 }
 public void SerialiseTest()
 {
     Assert.AreEqual(a.ToString(), JsonConvert.Serialise(a));
 }
Beispiel #20
0
        public void TestOptionalClassSetToString()
        {
            var test = new TestClass().Optional();

            Assert.Equal("test class", test.ToString());
        }