Inheritance: System.Web.Mvc.ActionFilterAttribute
Beispiel #1
0
            public void SetsResult_ToPartialRetiredDenial_WhenToken_MatchesExpiredEntity()
            {
                const string paramName    = "some value";
                var          confirmation = new EmailConfirmation(EmailConfirmationIntent.CreatePassword)
                {
                    ExpiresOnUtc = DateTime.UtcNow.AddHours(1),
                    RetiredOnUtc = DateTime.UtcNow.AddSeconds(-5),
                };
                var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(m => m.Query <EmailConfirmation>())
                .Returns(new[] { confirmation }.AsQueryable);
                var attribute = new ValidateConfirmEmailAttribute(paramName)
                {
                    Entities = entities.Object,
                };
                var filterContext = CreateFilterContext(paramName, confirmation.Token);

                attribute.OnActionExecuting(filterContext);

                filterContext.Result.ShouldNotBeNull();
                filterContext.Result.ShouldBeType <PartialViewResult>();
                var partialView = (PartialViewResult)filterContext.Result;

                partialView.ViewName.ShouldEqual(MVC.Identity.ConfirmEmail.Views._denied_all);
                partialView.Model.ShouldNotBeNull();
                partialView.Model.ShouldBeType <ConfirmDeniedModel>();
                var model = (ConfirmDeniedModel)partialView.Model;

                model.Reason.ShouldEqual(ConfirmDeniedBecause.IsRetired);
                model.Intent.ShouldEqual(confirmation.Intent);
            }
            public void SetsParamNameProperty_ToArgValue()
            {
                const string paramName = "test";

                var attribute = new ValidateConfirmEmailAttribute(paramName);

                attribute.ParamName.ShouldEqual(paramName);
            }
Beispiel #3
0
            public void SetsParamNameProperty_ToArgValue()
            {
                const string paramName = "test";

                var attribute = new ValidateConfirmEmailAttribute(paramName);

                attribute.ParamName.ShouldEqual(paramName);
            }
 public void CanBeSet_ByIocContainer()
 {
     const string paramName = "test";
     var attribute = new ValidateConfirmEmailAttribute(paramName)
     {
         Entities = null
     };
     attribute.Entities.ShouldBeNull();
 }
Beispiel #5
0
            public void CanBeSet_ByIocContainer()
            {
                const string paramName = "test";
                var          attribute = new ValidateConfirmEmailAttribute(paramName)
                {
                    Entities = null
                };

                attribute.Entities.ShouldBeNull();
            }
Beispiel #6
0
            public void ReturnsToken_FromScalarParameter()
            {
                const string paramName     = "some value";
                var          tokenValue    = Guid.NewGuid();
                var          attribute     = new ValidateConfirmEmailAttribute(paramName);
                var          filterContext = CreateFilterContext(paramName, tokenValue, false);

                var value = attribute.GetToken(filterContext);

                value.ShouldEqual(tokenValue);
            }
Beispiel #7
0
            public void ReturnsToken_FromModeledParameter()
            {
                var          tokenValue = Guid.NewGuid();
                const string paramName  = "some value";
                var          attribute  = new ValidateConfirmEmailAttribute(paramName);
                var          modeled    = new Mock <IModelConfirmAndRedeem>(MockBehavior.Strict);

                modeled.Setup(p => p.Token).Returns(tokenValue);
                var filterContext = CreateFilterContext(paramName, tokenValue, true);

                var value = attribute.GetToken(filterContext);

                value.ShouldEqual(tokenValue);
            }
Beispiel #8
0
            public void SetsResult_To404_WhenToken_IsEmptyGuid()
            {
                const string paramName = "some value";
                var          entities  = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(m => m.Query <EmailConfirmation>())
                .Returns(new[] { new EmailConfirmation(EmailConfirmationIntent.ResetPassword) }.AsQueryable);
                var attribute = new ValidateConfirmEmailAttribute(paramName)
                {
                    Entities = entities.Object,
                };
                var filterContext = CreateFilterContext(paramName, Guid.Empty);

                attribute.OnActionExecuting(filterContext);

                filterContext.Result.ShouldNotBeNull();
                filterContext.Result.ShouldBeType <HttpNotFoundResult>();
            }
Beispiel #9
0
            public void ThrowsArgumentNullException_WhenArgIsNull()
            {
                ArgumentNullException exception = null;

                try
                {
                    var obj = new ValidateConfirmEmailAttribute(null);
                    obj.ShouldBeNull();
                }
                catch (ArgumentNullException ex)
                {
                    exception = ex;
                }

                exception.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                exception.ParamName.ShouldEqual("paramName");
                // ReSharper restore PossibleNullReferenceException
            }
            public void ThrowsArgumentNullException_WhenArgIsNull()
            {
                ArgumentNullException exception = null;

                try
                {
                    var obj = new ValidateConfirmEmailAttribute(null);
                    obj.ShouldBeNull();
                }
                catch (ArgumentNullException ex)
                {
                    exception = ex;
                }

                exception.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                exception.ParamName.ShouldEqual("paramName");
                // ReSharper restore PossibleNullReferenceException
            }
Beispiel #11
0
            public void SetsResult_To404_WhenToken_MatchesNoEntity()
            {
                const string paramName  = "some value";
                var          tokenValue = Guid.NewGuid();
                var          entities   = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(m => m.Query <EmailConfirmation>())
                .Returns(new EmailConfirmation[] { }.AsQueryable);
                var attribute = new ValidateConfirmEmailAttribute(paramName)
                {
                    Entities = entities.Object,
                };
                var filterContext = CreateFilterContext(paramName, tokenValue);

                attribute.OnActionExecuting(filterContext);

                filterContext.Result.ShouldNotBeNull();
                filterContext.Result.ShouldBeType <HttpNotFoundResult>();
                entities.Verify(m => m.Query <EmailConfirmation>(), Times.Once());
            }
Beispiel #12
0
            public void ThrowsInvalidOperationException_WhenTokenParamValue_IsNotFound()
            {
                const string paramName              = "some value";
                var          attribute              = new ValidateConfirmEmailAttribute(paramName);
                var          filterContext          = CreateFilterContext(paramName, "not a guid or interface");
                InvalidOperationException exception = null;

                try
                {
                    attribute.GetToken(filterContext);
                }
                catch (InvalidOperationException ex)
                {
                    exception = ex;
                }

                exception.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                exception.Message.ShouldContain(paramName);
                // ReSharper restore PossibleNullReferenceException
            }
Beispiel #13
0
            public void SetsNoResult_WhenTokenMatchesEntity_Unexpired_Unredeemed_Unretired()
            {
                const string paramName    = "some value";
                var          confirmation = new EmailConfirmation(EmailConfirmationIntent.ResetPassword)
                {
                    ExpiresOnUtc = DateTime.UtcNow.AddHours(1),
                };
                var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize();

                entities.Setup(m => m.Query <EmailConfirmation>())
                .Returns(new[] { confirmation }.AsQueryable);
                var attribute = new ValidateConfirmEmailAttribute(paramName)
                {
                    Entities = entities.Object,
                };
                var filterContext = CreateFilterContext(paramName, confirmation.Token);

                attribute.OnActionExecuting(filterContext);

                filterContext.Result.ShouldBeNull();
            }
            public void ThrowsInvalidOperationException_WhenParamName_IsNotFound()
            {
                const string paramName = "some value";
                var attribute = new ValidateConfirmEmailAttribute(paramName);
                var filterContext = CreateFilterContext(null, null);
                InvalidOperationException exception = null;

                try
                {
                    attribute.GetToken(filterContext);
                }
                catch (InvalidOperationException ex)
                {
                    exception = ex;
                }

                exception.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                exception.Message.ShouldContain(paramName);
                // ReSharper restore PossibleNullReferenceException
            }
            public void ReturnsToken_FromScalarParameter()
            {
                const string paramName = "some value";
                var tokenValue = Guid.NewGuid();
                var attribute = new ValidateConfirmEmailAttribute(paramName);
                var filterContext = CreateFilterContext(paramName, tokenValue, false);

                var value = attribute.GetToken(filterContext);

                value.ShouldEqual(tokenValue);
            }
            public void ReturnsToken_FromModeledParameter()
            {
                var tokenValue = Guid.NewGuid();
                const string paramName = "some value";
                var attribute = new ValidateConfirmEmailAttribute(paramName);
                var modeled = new Mock<IModelConfirmAndRedeem>(MockBehavior.Strict);
                modeled.Setup(p => p.Token).Returns(tokenValue);
                var filterContext = CreateFilterContext(paramName, tokenValue, true);

                var value = attribute.GetToken(filterContext);

                value.ShouldEqual(tokenValue);
            }
            public void SetsResult_To404_WhenToken_IsEmptyGuid()
            {
                const string paramName = "some value";
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Query<EmailConfirmation>())
                    .Returns(new[] { new EmailConfirmation(EmailConfirmationIntent.ResetPassword) }.AsQueryable);
                var attribute = new ValidateConfirmEmailAttribute(paramName)
                {
                    Entities = entities.Object,
                };
                var filterContext = CreateFilterContext(paramName, Guid.Empty);

                attribute.OnActionExecuting(filterContext);

                filterContext.Result.ShouldNotBeNull();
                filterContext.Result.ShouldBeType<HttpNotFoundResult>();
            }
            public void SetsNoResult_WhenTokenMatchesEntity_Unexpired_Unredeemed_Unretired()
            {
                const string paramName = "some value";
                var confirmation = new EmailConfirmation(EmailConfirmationIntent.ResetPassword)
                {
                    ExpiresOnUtc = DateTime.UtcNow.AddHours(1),
                };
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Query<EmailConfirmation>())
                    .Returns(new[] { confirmation }.AsQueryable);
                var attribute = new ValidateConfirmEmailAttribute(paramName)
                {
                    Entities = entities.Object,
                };
                var filterContext = CreateFilterContext(paramName, confirmation.Token);

                attribute.OnActionExecuting(filterContext);

                filterContext.Result.ShouldBeNull();
            }
            public void SetsResult_ToPartialRetiredDenial_WhenToken_MatchesExpiredEntity()
            {
                const string paramName = "some value";
                var confirmation = new EmailConfirmation(EmailConfirmationIntent.CreatePassword)
                {
                    ExpiresOnUtc = DateTime.UtcNow.AddHours(1),
                    RetiredOnUtc = DateTime.UtcNow.AddSeconds(-5),
                };
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Query<EmailConfirmation>())
                    .Returns(new[] { confirmation }.AsQueryable);
                var attribute = new ValidateConfirmEmailAttribute(paramName)
                {
                    Entities = entities.Object,
                };
                var filterContext = CreateFilterContext(paramName, confirmation.Token);

                attribute.OnActionExecuting(filterContext);

                filterContext.Result.ShouldNotBeNull();
                filterContext.Result.ShouldBeType<PartialViewResult>();
                var partialView = (PartialViewResult)filterContext.Result;
                partialView.ViewName.ShouldEqual(MVC.Identity.ConfirmEmail.Views._denied_all);
                partialView.Model.ShouldNotBeNull();
                partialView.Model.ShouldBeType<ConfirmDeniedModel>();
                var model = (ConfirmDeniedModel)partialView.Model;
                model.Reason.ShouldEqual(ConfirmDeniedBecause.IsRetired);
                model.Intent.ShouldEqual(confirmation.Intent);
            }
            public void SetsResult_To404_WhenToken_MatchesNoEntity()
            {
                const string paramName = "some value";
                var tokenValue = Guid.NewGuid();
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Query<EmailConfirmation>())
                    .Returns(new EmailConfirmation[] { }.AsQueryable);
                var attribute = new ValidateConfirmEmailAttribute(paramName)
                {
                    Entities = entities.Object,
                };
                var filterContext = CreateFilterContext(paramName, tokenValue);

                attribute.OnActionExecuting(filterContext);

                filterContext.Result.ShouldNotBeNull();
                filterContext.Result.ShouldBeType<HttpNotFoundResult>();
                entities.Verify(m => m.Query<EmailConfirmation>(), Times.Once());
            }