diff --git a/src/FluentAssertions.Mvc.Shared/ActionResultAssertions.cs b/src/FluentAssertions.Mvc.Shared/ActionResultAssertions.cs
index 333935b..d2eba97 100644
--- a/src/FluentAssertions.Mvc.Shared/ActionResultAssertions.cs
+++ b/src/FluentAssertions.Mvc.Shared/ActionResultAssertions.cs
@@ -209,5 +209,34 @@ public ViewResultAssertions BeViewResult(string reason, params object[] reasonAr
return new ViewResultAssertions (Subject as ViewResult);
}
+
+ ///
+ /// Asserts that the subject is a .
+ ///
+ public JsonResultAssertions BeJsonResult()
+ {
+ return BeJsonResult(string.Empty, null);
+ }
+
+ ///
+ /// Asserts that the subject is a .
+ ///
+ ///
+ /// A formatted phrase as is supported by explaining why the assertion
+ /// is needed. If the phrase does not start with the word because, it is prepended automatically.
+ ///
+ ///
+ /// Zero or more objects to format using the placeholders in .
+ ///
+ public JsonResultAssertions BeJsonResult(string reason, params object[] reasonArgs)
+ {
+ Execute.Assertion
+ .BecauseOf(reason, reasonArgs)
+ .ForCondition(Subject is JsonResult)
+ .FailWith(Constants.CommonFailMessage, typeof(JsonResult).Name, Subject.GetType().Name);
+
+ return new JsonResultAssertions(Subject as JsonResult);
+ }
+
}
}
diff --git a/src/FluentAssertions.Mvc.Shared/FailureMessages.Designer.cs b/src/FluentAssertions.Mvc.Shared/FailureMessages.Designer.cs
index a262f5f..fad448f 100644
--- a/src/FluentAssertions.Mvc.Shared/FailureMessages.Designer.cs
+++ b/src/FluentAssertions.Mvc.Shared/FailureMessages.Designer.cs
@@ -9,37 +9,43 @@
//
//------------------------------------------------------------------------------
-namespace FluentAssertions.Mvc {
+namespace FluentAssertions.Mvc
+{
using System;
using System.Reflection;
-///
-/// A strongly-typed resource class, for looking up localized strings, etc.
-///
-// This class was auto-generated by the StronglyTypedResourceBuilder
-// class via a tool like ResGen or Visual Studio.
-// To add or remove a member, edit your .ResX file then rerun ResGen
-// with the /str option, or rebuild your VS project.
-[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ ///
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ ///
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class FailureMessages {
-
+ internal class FailureMessages
+ {
+
private static global::System.Resources.ResourceManager resourceMan;
-
+
private static global::System.Globalization.CultureInfo resourceCulture;
-
+
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal FailureMessages() {
+ internal FailureMessages()
+ {
}
-
+
///
/// Returns the cached ResourceManager instance used by this class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager {
- get {
- if (object.ReferenceEquals(resourceMan, null)) {
+ internal static global::System.Resources.ResourceManager ResourceManager
+ {
+ get
+ {
+ if (object.ReferenceEquals(resourceMan, null))
+ {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FluentAssertions.Mvc.FailureMessages", typeof(FailureMessages).Assembly);
resourceMan = temp;
@@ -47,119 +53,152 @@ internal FailureMessages() {
return resourceMan;
}
}
-
+
///
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture {
- get {
+ internal static global::System.Globalization.CultureInfo Culture
+ {
+ get
+ {
return resourceCulture;
}
- set {
+ set
+ {
resourceCulture = value;
}
}
-
+
///
/// Looks up a localized string similar to Expected {0} to be '{1}' but found '{2}'.
///
- internal static string CommonFailMessage {
- get {
+ internal static string CommonFailMessage
+ {
+ get
+ {
return ResourceManager.GetString("CommonFailMessage", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to RouteData.DataTokens does not contain key {0}..
///
- internal static string RouteData_DataTokens_ContainsKey {
- get {
+ internal static string RouteData_DataTokens_ContainsKey
+ {
+ get
+ {
return ResourceManager.GetString("RouteData_DataTokens_ContainsKey", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Expected RouteData.DataTokens[{0}] to have value {1}, but found {2}..
///
- internal static string RouteData_DataTokens_HaveValue {
- get {
+ internal static string RouteData_DataTokens_HaveValue
+ {
+ get
+ {
return ResourceManager.GetString("RouteData_DataTokens_HaveValue", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to RouteData.Values does not contain key {0}..
///
- internal static string RouteData_Values_ContainsKey {
- get {
+ internal static string RouteData_Values_ContainsKey
+ {
+ get
+ {
return ResourceManager.GetString("RouteData_Values_ContainsKey", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Expected RouteData.Values[{0}] to have value {1}, but found {2}..
///
- internal static string RouteData_Values_HaveValue {
- get {
+ internal static string RouteData_Values_HaveValue
+ {
+ get
+ {
return ResourceManager.GetString("RouteData_Values_HaveValue", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Expected MasterName to be {0} but found {1}..
///
- internal static string ViewResult_MasterName {
- get {
+ internal static string ViewResult_MasterName
+ {
+ get
+ {
return ResourceManager.GetString("ViewResult_MasterName", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Expected Model to be of type {0}, but no Model was supplied..
///
- internal static string ViewResultBase_NullModel {
- get {
+ internal static string ViewResultBase_NullModel
+ {
+ get
+ {
return ResourceManager.GetString("ViewResultBase_NullModel", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to ViewData does not contain key of {0}..
///
- internal static string ViewResultBase_ViewData_ContainsKey {
- get {
+ internal static string ViewResultBase_ViewData_ContainsKey
+ {
+ get
+ {
return ResourceManager.GetString("ViewResultBase_ViewData_ContainsKey", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Expected ViewData[{0}] to have value {1}, but found {2}..
///
- internal static string ViewResultBase_ViewData_HaveValue {
- get {
+ internal static string ViewResultBase_ViewData_HaveValue
+ {
+ get
+ {
return ResourceManager.GetString("ViewResultBase_ViewData_HaveValue", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Expected ViewName to be {0} but found {1}..
///
- internal static string ViewResultBase_ViewName {
- get {
+ internal static string ViewResultBase_ViewName
+ {
+ get
+ {
return ResourceManager.GetString("ViewResultBase_ViewName", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Expected default view, but view {0} was rendered..
///
- internal static string ViewResultBase_WithDefaultViewName {
- get {
+ internal static string ViewResultBase_WithDefaultViewName
+ {
+ get
+ {
return ResourceManager.GetString("ViewResultBase_WithDefaultViewName", resourceCulture);
}
}
+
+ internal static string JsonResult_WithDataPredicate
+ {
+ get
+ {
+ return ResourceManager.GetString("JsonResult_WithDataPredicate", resourceCulture);
+ }
+ }
}
}
#endif
\ No newline at end of file
diff --git a/src/FluentAssertions.Mvc.Shared/FailureMessages.resx b/src/FluentAssertions.Mvc.Shared/FailureMessages.resx
index ac089de..7c8a2de 100644
--- a/src/FluentAssertions.Mvc.Shared/FailureMessages.resx
+++ b/src/FluentAssertions.Mvc.Shared/FailureMessages.resx
@@ -120,6 +120,9 @@
Expected {0} to be '{1}' but found '{2}'
+
+ Expected {0} to match the predicate test, but '{1}' did not
+
RouteData.DataTokens does not contain key {0}.
diff --git a/src/FluentAssertions.Mvc.Shared/FluentAssertions.Mvc.Shared.projitems b/src/FluentAssertions.Mvc.Shared/FluentAssertions.Mvc.Shared.projitems
index 6fcd139..34a059e 100644
--- a/src/FluentAssertions.Mvc.Shared/FluentAssertions.Mvc.Shared.projitems
+++ b/src/FluentAssertions.Mvc.Shared/FluentAssertions.Mvc.Shared.projitems
@@ -22,6 +22,7 @@
+
diff --git a/src/FluentAssertions.Mvc.Shared/JsonResultAssertions.cs b/src/FluentAssertions.Mvc.Shared/JsonResultAssertions.cs
new file mode 100644
index 0000000..77387cd
--- /dev/null
+++ b/src/FluentAssertions.Mvc.Shared/JsonResultAssertions.cs
@@ -0,0 +1,93 @@
+using System;
+using System.Text;
+using FluentAssertions.Execution;
+using FluentAssertions.Primitives;
+using System.Web.Mvc;
+
+namespace FluentAssertions.Mvc
+{
+ ///
+ /// Contains a number of methods to assert that a is in the expected state.
+ ///
+ public class JsonResultAssertions : ObjectAssertions
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public JsonResultAssertions(JsonResult subject) : base(subject)
+ {
+
+ }
+
+ ///
+ /// Asserts that the Data is exactly the same as the expected Data.
+ /// This uses a standard object.Equals comparisson so the validity of this test will depend on the nature of the equality overrides (if any)
+ ///
+ /// The expected content of the result.
+ ///
+ /// A formatted phrase as is supported by explaining why the assertion
+ /// is needed. If the phrase does not start with the word because, it is prepended automatically.
+ ///
+ ///
+ /// Zero or more objects to format using the placeholders in .
+ ///
+ public JsonResultAssertions WithData(object expectedData, string reason = "", params object[] reasonArgs)
+ {
+ var actual = (Subject as JsonResult).Data;
+
+ Execute.Assertion
+ .ForCondition(object.Equals(actual, expectedData))
+ .BecauseOf(reason, reasonArgs)
+ .FailWith(string.Format(FailureMessages.CommonFailMessage, "JsonResult.Data", expectedData, actual));
+
+ return this;
+ }
+
+ ///
+ /// Asserts that the Data is exactly the same as the expected Data.
+ /// This uses a standard object.Equals comparisson so the validity of this test will depend on the nature of the equality overrides (if any)
+ ///
+ /// A predicate that validates the data.
+ ///
+ /// A formatted phrase as is supported by explaining why the assertion
+ /// is needed. If the phrase does not start with the word because, it is prepended automatically.
+ ///
+ ///
+ /// Zero or more objects to format using the placeholders in .
+ ///
+ public JsonResultAssertions WithData(Func