예제 #1
0
        public void Configurable_array_matcher_creates_error_messages_correctly()
        {
            var exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(new
                {
                    IntArray    = new[] { 1, 2, 3 },
                    ObjectArray = new[]
                    {
                        new { StrProperty = "123" },
                        new { StrProperty = "456" },
                        new { StrProperty = "789" },
                        new { StrProperty = "999" }
                    }
                }))
                .AssertJson(new
                {
                    IntArray    = Matchers.ConfigurableJsonArrayMatcher(new[] { 1, 2 }, true),
                    ObjectArray = Matchers.ConfigurableJsonArrayMatcher(new[]
                    {
                        new { StrProperty = Matchers.Int },
                        new { StrProperty = Matchers.Int },
                        new { StrProperty = Matchers.Int }
                    }, false)
                })
                .Execute();
            });

            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The property 'IntArray' did not match the specified matcher. Message: The expected array property 'IntArray' is not of the same length as the array in the response. Expected length: '2'. Actual length: '3'"));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The property 'ObjectArray' did not match the specified matcher. Message: The property 'ObjectArray[0].StrProperty' did not match the specified matcher. Message: Type mismatch. Expected: 'Integer', Actual: 'String'."));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The property 'ObjectArray' did not match the specified matcher. Message: The property 'ObjectArray[1].StrProperty' did not match the specified matcher. Message: Type mismatch. Expected: 'Integer', Actual: 'String'."));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The property 'ObjectArray' did not match the specified matcher. Message: The property 'ObjectArray[2].StrProperty' did not match the specified matcher. Message: Type mismatch. Expected: 'Integer', Actual: 'String'."));
        }
예제 #2
0
        public void Assert_json_handles_multiple_levels_of_nested_objects_correctly()
        {
            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!!!!????"
                    }
                }
            };

            Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(actual))
            .AssertJson(actual)
            .Execute();
        }
예제 #3
0
        public void Type_matchers_generates_a_correct_error_message_if_match_returns_false()
        {
            var exception = Assert.Catch <AssertFailedException>(() =>
            {
                Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(new
                {
                    TestStr    = "123",
                    TestInt    = 123,
                    TestFloat  = 1.23f,
                    TestRegex  = "Hello!",
                    TestArray  = new[] { 1, 2, 3 },
                    TestObject = new { Prop = 123 }
                }))
                .AssertJson(new
                {
                    TestStr    = Matchers.Int,
                    TestInt    = Matchers.String,
                    TestFloat  = Matchers.Regex("^He"),
                    TestRegex  = Matchers.Float,
                    TestArray  = Matchers.Object,
                    TestObject = Matchers.Array
                })
                .Execute();
            });

            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The property 'TestStr' did not match the specified matcher. Message: Type mismatch. Expected: 'Integer', Actual: 'String'."));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The property 'TestInt' did not match the specified matcher. Message: Type mismatch. Expected: 'String', Actual: 'Integer'."));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The property 'TestFloat' did not match the specified matcher. Message: The RegexMatcher did not match the actual value: '1.23'."));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The property 'TestRegex' did not match the specified matcher. Message: Type mismatch. Expected: 'Float', Actual: 'String'."));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The property 'TestArray' did not match the specified matcher. Message: Type mismatch. Expected: 'Object', Actual: 'Array'."));
            Assert.IsTrue(exception.FailedResults.Single().Message.Contains("The property 'TestObject' did not match the specified matcher. Message: Type mismatch. Expected: 'Array', Actual: 'Object'."));
        }
예제 #4
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'"));
        }
예제 #5
0
        // seed user claims data
        public async Task InitUserClaims(IServiceProvider serviceProvider)
        {
            using (var scope = serviceProvider.GetService <IServiceScopeFactory>().CreateScope())
            {
                // claim
                var userManager = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();

                if (userManager.Users.Any())
                {
                    foreach (var user in userManager.Users)
                    {
                        if (user.UserName.Equals("*****@*****.**"))
                        {
                            // Using in basket service
                            // Apply policy claim and role for Authorize
                            // add claim: admin
                            await userManager.AddClaimsAsync(user, Claims.Get());

                            // add role: Admin
                            await userManager.AddToRoleAsync(user, "Admin");
                        }
                        else
                        {
                            // add role: User
                            await userManager.AddToRoleAsync(user, "User");
                        }
                    }
                }
            }
        }
예제 #6
0
 public void Configurable_array_matcher_handles_variable_length_arrays_correctly()
 {
     Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(new
     {
         IntArray    = new[] { 1, 2, 3 },
         ObjectArray = new[]
         {
             new { StrProperty = "123" },
             new { StrProperty = "456" },
             new { StrProperty = "789" },
             new { StrProperty = "999" }
         }
     }))
     .AssertJson(new
     {
         IntArray    = Matchers.ConfigurableJsonArrayMatcher(new [] { 1, 2 }, false),
         ObjectArray = Matchers.ConfigurableJsonArrayMatcher(new[]
         {
             new { StrProperty = Matchers.String },
             new { StrProperty = Matchers.String },
             new { StrProperty = Matchers.String }
         }, false)
     })
     .Execute();
 }
예제 #7
0
        private static void InitUserClaims(IApplicationBuilder app)
        {
            using (var scope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                var userManager = scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >();

                // add users
                foreach (var user in GetDefaultUser())
                {
                    userManager.CreateAsync(user).Wait();
                }

                if (userManager.Users.Any())
                {
                    foreach (var user in userManager.Users)
                    {
                        // add claim and role for admin
                        if (user.UserName.Equals("*****@*****.**"))
                        {
                            // add claim: admin
                            userManager.AddClaimsAsync(user, Claims.Get()).Wait();

                            // add role: Administrator
                            //userManager.AddToRoleAsync(user, "Administrator").Wait();
                        }
                    }
                }
            }
        }
예제 #8
0
 public void Assert_contains_a_single_header_does_not_throw_an_excepetion_if_the_header_is_a_match()
 {
     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_value" })
     }))
     .AssertContainsHeader("my_key", "my_value")
     .Execute();
 }
예제 #9
0
 public void Assert_json_does_not_throw_an_exception_for_a_property_name_case_mismatch_if_ignore_case_is_specified()
 {
     Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient("{ \"myProperty\": 123 }"))
     .AssertJson(new
     {
         MyProperty = 123
     }, PropertyComparison.IgnoreCase)
     .Execute();
 }
예제 #10
0
 public void Assert_json_does_not_throw_an_exception_for_a_property_and_value_match()
 {
     Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient("{ \"Test\": 123 }"))
     .AssertJson(new
     {
         Test = 123
     })
     .Execute();
 }
예제 #11
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)));
        }
예제 #12
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."));
        }
예제 #13
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)));
        }
예제 #14
0
 public void Date_matcher_matches_dates_correctly()
 {
     Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(new
     {
         MyDate = DateTime.Parse("2015-07-25T12:30Z", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind)
     }))
     .AssertJson(new
     {
         MyDate = Matchers.MatchDate("2015-07-25T12:30Z", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind)
     })
     .Execute();
 }
예제 #15
0
        public void Assert_json_handles_multiple_properties_of_different_types_correctly()
        {
            var actual = new
            {
                MyInt    = 123,
                MyDouble = 123.123,
                MyString = "Hello!!!!????"
            };

            Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(actual))
            .AssertJson(actual)
            .Execute();
        }
예제 #16
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);
        }
예제 #17
0
        public void Assert_json_correctly_handles_arrays()
        {
            var actual = new
            {
                MyInts = new [] { 1, 2, 4 }
            };

            Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(actual))
            .AssertJson(new
            {
                MyInts = new[] { 1, 2, 4 }
            })
            .Execute();
        }
예제 #18
0
        public void Assert_json_correctly_handles_object_arrays()
        {
            var actual = new
            {
                MyObjects = new[]
                {
                    new { MyFirstArrayObjectProp = 1, MySecondArrayObjectProp = 2 }
                }
            };

            Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(actual))
            .AssertJson(actual)
            .Execute();
        }
예제 #19
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);
        }
예제 #20
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!!!!????'"));
        }
예제 #21
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."));
        }
예제 #22
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             Configuration.GetConnectionString("DefaultConnection")));
            services.AddDbContext <Bais3110IdentityContext>(options =>
                                                            options.UseSqlServer(
                                                                Configuration.GetConnectionString("DefaultConnection")));
            services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = false)
            .AddRoles <IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();
            services.AddRazorPages()
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeAreaFolder("Identity", "/Admin", "RequireAdmin");
            });
            services.AddAuthorization(options =>
            {
                options.AddPolicy("RequireAdmin", policy => policy.RequireRole("Admin"));
                options.AddPolicy("RequireAdminInfo", policy => policy.RequireClaim(Claims.Get(ClaimValues.AdminInfo)));
            }
                                      );
            services.Configure <IdentityOptions>(options =>
            {
                // Password settings.
                options.Password.RequireDigit           = true;
                options.Password.RequireLowercase       = true;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = true;
                options.Password.RequiredLength         = 8;
                options.Password.RequiredUniqueChars    = 1;

                // Lockout settings.
                options.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromMinutes(5);
                options.Lockout.MaxFailedAccessAttempts = 5;
                options.Lockout.AllowedForNewUsers      = true;

                // User settings.
                options.User.AllowedUserNameCharacters =
                    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
                options.User.RequireUniqueEmail = false;
            });
        }
예제 #23
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)));
        }
예제 #24
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'"));
        }
예제 #25
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'"));
        }
예제 #26
0
 public void Type_matchers_matches_the_property_if_match_returns_true()
 {
     Claims.Get("https://www.test.com", () => CreateMockedJsonHttpClient(new
     {
         TestStr    = "123",
         TestInt    = 123,
         TestFloat  = 1.23f,
         TestRegex  = "Hello!",
         TestArray  = new [] { 1, 2, 3 },
         TestObject = new { Prop = 123 }
     }))
     .AssertJson(new
     {
         TestStr    = Matchers.String,
         TestInt    = Matchers.Int,
         TestFloat  = Matchers.Float,
         TestRegex  = Matchers.Regex("^He"),
         TestArray  = Matchers.Array,
         TestObject = Matchers.Object
     })
     .Execute();
 }
예제 #27
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'"));
        }
예제 #28
0
 public void Assert_status_ok_does_not_throw_an_excepetion_if_the_status_is_ok()
 {
     Claims.Get("https://www.test.com", () => CreateMockedHttpClient(HttpStatusCode.OK))
     .AssertStatus(HttpStatusCode.OK)
     .Execute();
 }