Ejemplo n.º 1
0
        public void Model_ShouldReturnSameModelAsViewResult()
        {
            var model  = new object();
            var result = new TestController().ViewSimpleModel(model);

            result.Should().BeViewResult().Model.Should().BeSameAs(model);
        }
Ejemplo n.º 2
0
        public void ValueAs_GivenWrongType_ShouldFail()
        {
            var    result = new TestController().CreatedAtAction(string.Empty, string.Empty, null, TestValue);
            Action a      = () => result.Should().BeCreatedAtActionResult().ValueAs <int>().Should().Be(2);

            a.Should().Throw <Exception>();
        }
Ejemplo n.º 3
0
        public void ErrorAs_GivenUnexpectedError_ShouldFail()
        {
            var result = new TestController().Conflict(TestError);

            Action a = () => result.Should().BeConflictObjectResult().ErrorAs <string>().Should().Be("xyx");

            a.Should().Throw <Exception>();
        }
        public void ValueAs_GivenUnexpectedValue_ShouldFail()
        {
            var result = new TestController().NotFound(TestValue);

            Action a = () => result.Should().BeNotFoundObjectResult().ValueAs <string>().Should().Be("xyx");

            a.Should().Throw <Exception>();
        }
        public void WithViewData_GivenTwoExpectedValues_ShouldPass()
        {
            var result = new TestController().ViewWithTwoViewData();

            result.Should().BeViewResult()
            .WithViewData("key1", "value1")
            .WithViewData("key2", "value2");
        }
        public void WithTempData_GivenUnexpectedKey_ShouldFail()
        {
            var result = new TestController().ViewWithOneTempData();

            Action a = () => result.Should().BeViewResult().WithTempData("xyz", "value1");

            a.Should().Throw <Exception>();
        }
        public void ModelAs_GivenWrongType_ShouldFail()
        {
            var result = new TestController().ViewSimpleModel();

            Action a = () => result.Should().BeViewResult().ModelAs <int>().Should().Be(2);

            a.Should().Throw <Exception>();
        }
        public void ModelAs_GivenUnexpectedValue_ShouldFail()
        {
            var result = new TestController().ViewSimpleModel();

            Action a = () => result.Should().BeViewResult().ModelAs <string>().Should().Be("xyx");

            a.Should().Throw <Exception>();
        }
        public void ValueAs_GivenUnexpectedValue_ShouldFail()
        {
            var result = new TestController().Created(TestUri, TestValue);

            Action a = () => result.Should().BeCreatedResult().ValueAs <string>().Should().Be("xyx", Reason, ReasonArgs);

            a.Should().Throw <Exception>();
        }
        public void WithUri_GivenWrongUriAsString_ShouldFail()
        {
            var result         = new TestController().Created(TestWrongUriAsString, TestValue);
            var failureMessage = FailureMessageHelper.ExpectedContextToBeXButY("CreatedResult.Uri", TestUriAsString, TestWrongUriAsString);

            Action a = () => result.Should().BeCreatedResult().WithUri(TestUriAsString, Reason, ReasonArgs);

            a.Should().Throw <Exception>().WithMessage(failureMessage);
        }
        public void ValueAs_GivenWrongType_ShouldFail()
        {
            var result         = new TestController().Created(TestUri, TestValue);
            var failureMessage = FailureMessageHelper.ExpectedContextTypeXButFoundY("CreatedResult.Value", typeof(int), typeof(string));

            Action a = () => result.Should().BeCreatedResult().ValueAs <int>().Should().Be(2, Reason, ReasonArgs);

            a.Should().Throw <Exception>().WithMessage(failureMessage);
        }
        public void WithTempData_GivenUnexpectedKey_ShouldFail()
        {
            var result = new TestController().PartialViewWithOneTempData();

            Action a = () => result.Should().BePartialViewResult().WithTempData("xyz", "value1", Reason, ReasonArgs);

            a.Should().Throw <Exception>()
            .WithMessage("Expected PartialViewResult.TempData to contain value \"value1\" at key \"xyz\" because it is 10, but the key was not found.");;
        }
Ejemplo n.º 13
0
        public void WithTempData_GivenUnexpectedValue_ShouldFail()
        {
            var result = new TestController().ViewWithOneTempData();

            Action a = () => result.Should().BeViewResult().WithTempData("key1", "xyz", Reason, ReasonArgs);

            a.Should().Throw <Exception>()
            .WithMessage("Expected ViewResult.TempData to contain value \"xyz\" at key \"key1\" because it is 10 but found \"value1\".");
        }
Ejemplo n.º 14
0
        public void ModelAs_GivenWrongType_ShouldFail()
        {
            var result = new TestController().ViewSimpleModel();

            Action a = () => result.Should().BeViewResult().ModelAs <int>().Should().Be(2);

            a.Should().Throw <Exception>()
            .WithMessage("Expected ViewResult.Model to be of type System.Int32 but was System.String.");
        }
Ejemplo n.º 15
0
        public void ErrorAs_GivenWrongType_ShouldFail()
        {
            var result         = new TestController().Conflict(TestError);
            var failureMessage = FailureMessageHelper.ExpectedContextTypeXButFoundY(
                "ConflictObjectResult.Error", typeof(int), typeof(string));

            Action a = () => result.Should().BeConflictObjectResult().ErrorAs <int>().Should().Be(2);

            a.Should().Throw <Exception>().WithMessage(failureMessage);
        }
        public void ValueAs_GivenWrongType_ShouldFail()
        {
            var result         = new TestController().AcceptedAtAction(string.Empty, string.Empty, null, TestValue);
            var failureMessage = FailureMessageHelper.ExpectedContextTypeXButFoundY(
                "AcceptedAtActionResult.Value", typeof(int), typeof(string));

            Action a = () => result.Should().BeAcceptedAtActionResult().ValueAs <int>();

            a.Should().Throw <Exception>();
        }
Ejemplo n.º 17
0
        public void SerializableError_GivenExpectedModelState_ShouldPass()
        {
            const string testErrorKey     = "TestErrorKey";
            const string testErrorMessage = "TestErrorMessage";
            var          testModelState   = new ModelStateDictionary();

            testModelState.AddModelError(testErrorKey, testErrorMessage);
            var result = new TestController().Conflict(testModelState);

            result.Should().BeConflictObjectResult().SerializableError.Should().ContainKey(testErrorKey);
        }
Ejemplo n.º 18
0
        public void WithTempData_GivenUnexpectedKey_ShouldFail()
        {
            var result         = new TestController().ViewWithOneTempData();
            var failureMessage = FailureMessageHelper.ExpectedContextContainValueAtKeyButKeyNotFound(
                "ViewResult.TempData", "value1", "xyz");

            Action a = () => result.Should().BeViewResult().WithTempData("xyz", "value1", Reason, ReasonArgs);

            a.Should().Throw <Exception>()
            .WithMessage(failureMessage);
        }
Ejemplo n.º 19
0
        public void WithViewData_GivenUnexpectedKey_ShouldFail()
        {
            var expectedKey = "xyz";

            var result = new TestController().ViewWithTwoViewData();

            Action a = () => result.Should().BeViewResult().WithViewData(expectedKey, "value1", Reason, ReasonArgs);

            a.Should().Throw <Exception>()
            .WithMessage("Expected ViewResult.ViewData to contain value \"value1\" at key \"xyz\" because it is 10, but the key was not found.");
        }
        public void ValueAs_GivenWrongType_ShouldFail()
        {
            var    result         = new TestController().NotFound(TestValue);
            string failureMessage = FailureMessageHelper.ExpectedContextTypeXButFoundY(
                "NotFoundObjectResult.Value", typeof(int), typeof(string));

            Action a = () => result.Should().BeNotFoundObjectResult().ValueAs <int>().Should().Be(2);

            a.Should().Throw <Exception>()
            .WithMessage(failureMessage);
        }
        public void WithViewData_GivenUnexpectedValue_ShouldFail()
        {
            var key           = "key1";
            var expectedValue = "abc";

            var result = new TestController().PartialViewWithOneViewData();

            Action a = () => result.Should().BePartialViewResult().WithViewData(key, expectedValue, Reason, ReasonArgs);

            a.Should().Throw <Exception>()
            .WithMessage("Expected PartialViewResult.ViewData to contain value \"abc\" at key \"key1\" because it is 10 but found \"value1\".");
        }
        public void WithViewData_GivenUnexpectedValue_ShouldFail()
        {
            var key            = "key1";
            var actualValue    = "value1";
            var expectedValue  = "abc";
            var failureMessage = FailureMessageHelper.Format(FailureMessages.ViewResultBase_ViewData_HaveValue, key, expectedValue, actualValue);

            var result = new TestController().ViewWithOneViewData();

            Action a = () => result.Should().BeViewResult().WithViewData(key, expectedValue);

            a.Should().Throw <Exception>()
            .WithMessage(failureMessage);
        }
        public void WithViewData_GivenUnexpectedKey_ShouldFail()
        {
            var actualKey   = "key1";
            var expectedKey = "xyz";

            var result = new TestController().ViewWithTwoViewData();

            var failureMessage = FailureMessageHelper.Format(FailureMessages.ViewResultBase_ViewData_ContainsKey, expectedKey, actualKey);

            Action a = () => result.Should().BeViewResult().WithViewData(expectedKey, "value1");

            a.Should().Throw <Exception>()
            .WithMessage(failureMessage);
        }
        public void ValueAs_GivenNotFoundObjectResult_ShouldHaveTheSameValue()
        {
            var result = new TestController().NotFound(TestValue);

            result.Should().BeNotFoundObjectResult().ValueAs <string>().Should().BeSameAs(TestValue);
        }
        public void Value_GivenOkObjectResult_ShouldHaveTheSameValue()
        {
            var result = new TestController().Ok(TestValue);

            result.Should().BeOkObjectResult().Value.Should().BeSameAs(TestValue);
        }
        public void ValueAs_GivenAcceptedAtActionResult_ShouldHaveTheSameValue()
        {
            var result = new TestController().AcceptedAtAction(string.Empty, string.Empty, null, TestValue);

            result.Should().BeAcceptedAtActionResult().ValueAs <string>().Should().BeSameAs(TestValue);
        }
Ejemplo n.º 27
0
        public void ValueAs_GivenCreatedAtRouteResult_ShouldHaveTheSameValue()
        {
            var result = new TestController().CreatedAtRoute(string.Empty, null, TestValue);

            result.Should().BeCreatedAtRouteResult().ValueAs <string>().Should().BeSameAs(TestValue);
        }
        public void WithPreserveMethod_GivenExpectedPermanentPreserveMethod_ShouldPass()
        {
            var result = new TestController().LocalRedirectPermanentPreserveMethod(TestLocalUrl);

            result.Should().BeLocalRedirectResult().WithPermanent(true).WithPreserveMethod(true);
        }
        public void WithLocalUrl_GivenExpectedLocalUrl_ShouldPass()
        {
            var result = new TestController().LocalRedirect(TestLocalUrl);

            result.Should().BeLocalRedirectResult().WithLocalUrl(TestLocalUrl);
        }
Ejemplo n.º 30
0
        public void ErrorAs_GivenExpectedError_ShouldPass()
        {
            var result = new TestController().Conflict(TestError);

            result.Should().BeConflictObjectResult().ErrorAs <string>().Should().Be(TestError);
        }