コード例 #1
0
        public void Assert_json_correctly_generates_errors_for_arrays_of_objects_with_properties_of_different_types_or_names()
        {
            var actual = new
            {
                MyObjects = new[]
                {
                    new { MyFirstArrayObjectProp = 1, MySecondArrayObjectProp = 2.0, MyThirdArrayObjectProp = "Hello!" }
                }
            };

            var exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(actual))
                .AssertJson(new
                {
                    MyObjects = new[]
                    {
                        new { MyFirstArrayObjectProp = 1.0, MySecondArrayObjectProp1 = 2.0, MyThirdArrayObjectProp = 1 }
                    }
                })
                .Execute();
            });

            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MyFirstArrayObjectProp' is not of the same type as the property in the response. Expected type: 'Double'. Actual type: 'Integer'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MySecondArrayObjectProp1' was not present in the response."));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MyThirdArrayObjectProp' is not of the same type as the property in the response. Expected type: 'Int32'. Actual type: 'String'"));
        }
コード例 #2
0
        public void Test_Divide1_Exception()
        {
            uut.Clear();
            uut.Add1(10);

            Assert.Catch <Exception>(() => uut.Divide1(0));
        }
コード例 #3
0
        public void InvalidLicenseKeyPassedToInit()
        {
            var licenseKey = "07C54D83E0CC806F017B369D33E755E8253E8F95";

            Assert.Catch <VideoPlayerLicenseException>(() => FormsVideoPlayer.Init(licenseKey), "FormsVideoPlayer.Init(licenseKey)");
            Assert.IsFalse(FormsVideoPlayer.IsInitialized, "FormsVideoPlayer.IsInitialized");
            Assert.AreEqual(VideoPlayerLicense.LicenseType, LicenseType.Trial, "License should be in trial mode.");
        }
コード例 #4
0
        public void Constructor_WhenViewModelIsNull_ExceptionExpected()
        {
            WindowTwoViewModel viewModel = null;

            // ReSharper disable once ExpressionIsAlwaysNull
            // ReSharper disable once ObjectCreationAsStatement
            Assert.Catch <ArgumentNullException>(() => new EnterCorrectTextInWindowTwoState(viewModel));
        }
コード例 #5
0
        public void Handle_WhenContextIsNull_ExceptionExpected()
        {
            var      viewModel = TestHelper.CreateWindowTwoViewModel();
            var      state     = new EnterCorrectTextInWindowTwoState(viewModel);
            IContext context   = null;

            // ReSharper disable once ExpressionIsAlwaysNull
            Assert.Catch <ArgumentNullException>(() => state.Go(context));
        }
コード例 #6
0
        public void Assert_on_status_throws_an_excepetion_if_the_status_does_not_match()
        {
            var exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedHttpClient(HttpStatusCode.BadGateway))
                .AssertStatus(HttpStatusCode.OK)
                .Execute();
            });

            Assert.IsTrue(exception.FailedResults.All(x => x.Status == ResultStatus.Failed && x.AssertType == typeof(StatusCodeAssert)));
        }
コード例 #7
0
        public void Assert_json_correctly_handles_empty_response_bodies()
        {
            var exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(""))
                .AssertJson(new {})
                .Execute();
            });

            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("JsonAssert: Empty response body."));
        }
コード例 #8
0
        public void Assert_contains_a_single_header_throws_an_excepetion_if_the_header_is_not_a_match()
        {
            var exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedHttpClient(HttpStatusCode.OK))
                .AssertContainsHeader("my_key", "my_value")
                .Execute();
            });

            Assert.IsTrue(exception.FailedResults.All(x => x.Status == ResultStatus.Failed && x.AssertType == typeof(ContainsHeaderAssert)));
        }
コード例 #9
0
        public void Assert_json_throws_a_correct_exception_for_a_property_name_case_mismatch()
        {
            var exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient("{ \"myProperty\": 321 }"))
                .AssertJson(new
                {
                    MyProperty = 123
                })
                .Execute();
            });

            Assert.AreEqual("The expected property 'MyProperty' was not present in the response.", exception.FailedResults.Single().Message);
        }
コード例 #10
0
        public void Assert_json_correctly_generates_multiple_level_nested_error_messages()
        {
            var actual = new
            {
                MyInt               = 123,
                MyDouble            = 123.123,
                MyString            = "Hello!!!!????",
                MyFirstNestedObject = new
                {
                    MyInt                = 123,
                    MyDouble             = 123.123,
                    MyString             = "Hello!!!!????",
                    MySecondNestedObject = new
                    {
                        MyInt    = 123,
                        MyDouble = 123.123,
                        MyString = "Hello!!!!????"
                    }
                }
            };

            var exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(actual))
                .AssertJson(new
                {
                    MyInt               = 1234,
                    MyDouble            = 123.123,
                    MyString            = "Hello!!!!????",
                    MyFirstNestedObject = new
                    {
                        MyInt                = 123,
                        MyDouble             = 123.123,
                        MyString             = "World...",
                        MySecondNestedObject = new
                        {
                            MyInt    = 1234,
                            MyDouble = 123.123,
                            MyString = ":("
                        }
                    }
                })
                .Execute();
            });

            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyInt' does not have the same value as the property in the response. Expected value: '1234'. Actual value: '123'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyFirstNestedObject.MyString' does not have the same value as the property in the response. Expected value: 'World...'. Actual value: 'Hello!!!!????'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyFirstNestedObject.MySecondNestedObject.MyInt' does not have the same value as the property in the response. Expected value: '1234'. Actual value: '123'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyFirstNestedObject.MySecondNestedObject.MyString' does not have the same value as the property in the response. Expected value: ':('. Actual value: 'Hello!!!!????'"));
        }
コード例 #11
0
        public void Assert_json_throws_a_correct_exception_for_a_value_mismatch()
        {
            var exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient("{ \"Test\": 321 }"))
                .AssertJson(new
                {
                    Test = 123
                })
                .Execute();
            });

            Assert.AreEqual("The expected property 'Test' does not have the same value as the property in the response. Expected value: '123'. Actual value: '321'", exception.FailedResults.Single().Message);
        }
コード例 #12
0
        public void Assert_json_throws_a_correct_exception_when_multiple_properties_of_different_types_are_not_present_in_the_response()
        {
            var exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(new { Test = 777 }))
                .AssertJson(new
                {
                    MyInt    = 123,
                    MyDouble = 123.123,
                    MyString = "Hello!!!!????"
                })
                .Execute();
            });

            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyInt' was not present in the response."));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyDouble' was not present in the response."));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyString' was not present in the response."));
        }
コード例 #13
0
        public void Assert_contains_multiple_headers_throws_an_excepetion_if_the_headers_are_not_a_match()
        {
            var exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedHttpClient(HttpStatusCode.OK))
                .AssertContainsHeader("my_key", new[] { "my_value1", "my_value2" })
                .Execute();
            });

            Assert.IsTrue(exception.FailedResults.All(x => x.Status == ResultStatus.Failed && x.AssertType == typeof(ContainsHeaderAssert)));

            exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedHttpClient(HttpStatusCode.OK, headers: new List <KeyValuePair <string, IEnumerable <string> > > {
                    new KeyValuePair <string, IEnumerable <string> >("my_key", new[] { "my_value11", "my_value22" })
                }))
                .AssertContainsHeader("my_key", new[] { "my_value1", "my_value2" })
                .Execute();
            });

            Assert.IsTrue(exception.FailedResults.All(x => x.Status == ResultStatus.Failed && x.AssertType == typeof(ContainsHeaderAssert)));

            exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedHttpClient(HttpStatusCode.OK, headers: new List <KeyValuePair <string, IEnumerable <string> > > {
                    new KeyValuePair <string, IEnumerable <string> >("my_key", new[] { "my_value1", "my_value2" })
                }))
                .AssertContainsHeader("my_key2", new[] { "my_value1", "my_value2" })
                .Execute();
            });

            Assert.IsTrue(exception.FailedResults.All(x => x.Status == ResultStatus.Failed && x.AssertType == typeof(ContainsHeaderAssert)));

            exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedHttpClient(HttpStatusCode.OK, headers: new List <KeyValuePair <string, IEnumerable <string> > > {
                    new KeyValuePair <string, IEnumerable <string> >("my_key", new[] { "my_value1" })
                }))
                .AssertContainsHeader("my_key", new[] { "my_value1", "my_value2" })
                .Execute();
            });

            Assert.IsTrue(exception.FailedResults.All(x => x.Status == ResultStatus.Failed && x.AssertType == typeof(ContainsHeaderAssert)));
        }
コード例 #14
0
        public void Assert_json_correctly_generates_a_length_mismatch_error_for_arrays_of_different_lenghts()
        {
            var actual = new
            {
                MyInts = new[] { 1, 2, 4 }
            };

            var exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(actual))
                .AssertJson(new
                {
                    MyInts = new[] { 1, 2, 4, 5 }
                })
                .Execute();
            });

            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected array property 'MyInts' is not of the same length as the array in the response. Expected length: '4'. Actual length: '3'"));
        }
コード例 #15
0
        public void Assert_json_correctly_generates_a_type_mismatch_error_for_arrays_of_different_types()
        {
            var actual = new
            {
                MyInts = new[] { 1, 2, 4 }
            };

            var exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(actual))
                .AssertJson(new
                {
                    MyInts = new[] { "1", "2", "4" }
                })
                .Execute();
            });

            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyInts[0]' is not of the same type as the property in the response. Expected type: 'String'. Actual type: 'Integer'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyInts[1]' is not of the same type as the property in the response. Expected type: 'String'. Actual type: 'Integer'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyInts[2]' is not of the same type as the property in the response. Expected type: 'String'. Actual type: 'Integer'"));
        }
コード例 #16
0
ファイル: ProcedureTest.cs プロジェクト: tmakij/MiniPascal
 public void ProcedureCallBooleanFalse()
 {
     Assert.Catch <TypeMismatchException>(() => Redirect(@"begin procedure hello(i:boolean);begin writeln(\""HelloWorld\"",i);end; hello(1); end."));
 }
コード例 #17
0
        public void WhenExperienceIsZeroThrowsException()
        {
            var salaryStrategy = new SalaryStrategyForProgrammer();

            Assert.Catch <NotSupportedException>(() => salaryStrategy.CalculateSalary(0));
        }
 public void Translate_HexValueNot3Or6Long_Throws()
 {
     Assert.IsInstanceOf(typeof(ArgumentException), Assert.Catch(() => HTMLColorTranslator.Translate("#22")));
     Assert.IsInstanceOf(typeof(ArgumentException), Assert.Catch(() => HTMLColorTranslator.Translate("#F423")));
     Assert.IsInstanceOf(typeof(ArgumentException), Assert.Catch(() => HTMLColorTranslator.Translate("#F3A45DD")));
 }
 public void Translate_UnrecognisedInput_Throws()
 {
     Assert.IsInstanceOf(typeof(ArgumentException), Assert.Catch(() => HTMLColorTranslator.Translate("NOT A HTML COLOR")));
 }
 public void Translate_NullInput_Throws()
 {
     Assert.IsInstanceOf(typeof(NullReferenceException), Assert.Catch(() => HTMLColorTranslator.Translate(null)));
 }
コード例 #21
0
        public void Assert_json_correctly_generates_errors_for_nested_arrays_of_objects_with_properties_of_different_types_or_names()
        {
            var actual = new
            {
                MyObjects = new[]
                {
                    new
                    {
                        MyFirstArrayObjectProp  = 1,
                        MySecondArrayObjectProp = 2.0,
                        MyNestedObjects         = new[]
                        {
                            new
                            {
                                MyFirstArrayObjectProp     = 1,
                                MySecondArrayObjectProp    = 2,
                                MySecondLevelNestedObjects = new [] { "123" },
                                MyWrongValueProperty       = 12
                            },
                            new
                            {
                                MyFirstArrayObjectProp     = 1,
                                MySecondArrayObjectProp    = 2,
                                MySecondLevelNestedObjects = new [] { "123" },
                                MyWrongValueProperty       = 12
                            },
                            new
                            {
                                MyFirstArrayObjectProp     = 1,
                                MySecondArrayObjectProp    = 2,
                                MySecondLevelNestedObjects = new [] { "123" },
                                MyWrongValueProperty       = 12
                            }
                        }
                    }
                }
            };

            var exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(actual))
                .AssertJson(new
                {
                    MyObjects = new[]
                    {
                        new
                        {
                            MyFirstArrayObjectProp  = "1",   // Wrong Type
                            MySecondArrayObjectProp = 2,     // Wrong Type
                            MyNestedObjects         = new[]
                            {
                                new
                                {
                                    MyFirstArrayObjectProp1    = 1,             // Wrong Name
                                    MySecondArrayObjectProp    = 2.0,           // Wrong Type
                                    MySecondLevelNestedObjects = new[] { 123 }, // Wrong Type
                                    MyWrongValueProperty       = 13             // Wrong Value
                                },
                                new
                                {
                                    MyFirstArrayObjectProp1    = 1,             // Wrong Name
                                    MySecondArrayObjectProp    = 2.0,           // Wrong Type
                                    MySecondLevelNestedObjects = new[] { 123 }, // Wrong Type
                                    MyWrongValueProperty       = 13             // Wrong Value
                                },
                                new
                                {
                                    MyFirstArrayObjectProp1    = 1,             // Wrong Name
                                    MySecondArrayObjectProp    = 2.0,           // Wrong Type
                                    MySecondLevelNestedObjects = new[] { 123 }, // Wrong Type
                                    MyWrongValueProperty       = 13             // Wrong Value
                                }
                            }
                        }
                    }
                })
                .Execute();
            });

            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MyFirstArrayObjectProp' is not of the same type as the property in the response. Expected type: 'String'. Actual type: 'Integer'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MySecondArrayObjectProp' is not of the same type as the property in the response. Expected type: 'Int32'. Actual type: 'Float'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MyNestedObjects[0].MyFirstArrayObjectProp1' was not present in the response."));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MyNestedObjects[0].MySecondArrayObjectProp' is not of the same type as the property in the response. Expected type: 'Double'. Actual type: 'Integer'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MyNestedObjects[0].MySecondLevelNestedObjects[0]' is not of the same type as the property in the response. Expected type: 'Int32'. Actual type: 'String'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MyNestedObjects[0].MyWrongValueProperty' does not have the same value as the property in the response. Expected value: '13'. Actual value: '12'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MyNestedObjects[1].MyFirstArrayObjectProp1' was not present in the response."));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MyNestedObjects[1].MySecondArrayObjectProp' is not of the same type as the property in the response. Expected type: 'Double'. Actual type: 'Integer'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MyNestedObjects[1].MySecondLevelNestedObjects[0]' is not of the same type as the property in the response. Expected type: 'Int32'. Actual type: 'String'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MyNestedObjects[1].MyWrongValueProperty' does not have the same value as the property in the response. Expected value: '13'. Actual value: '12'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MyNestedObjects[2].MyFirstArrayObjectProp1' was not present in the response."));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MyNestedObjects[2].MySecondArrayObjectProp' is not of the same type as the property in the response. Expected type: 'Double'. Actual type: 'Integer'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MyNestedObjects[2].MySecondLevelNestedObjects[0]' is not of the same type as the property in the response. Expected type: 'Int32'. Actual type: 'String'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The expected property 'MyObjects[0].MyNestedObjects[2].MyWrongValueProperty' does not have the same value as the property in the response. Expected value: '13'. Actual value: '12'"));
        }