Exemple #1
0
            public async Task ShouldNotSetETagHeader_WhenRevisionContextResponseRevisionIsNull()
            {
                // Arrange
                var revisionContext = new RevisionContext();
                var appOptions      = new ApplicationOptions();

                var revisionActionFilter = new RevisionActionFilter(revisionContext, appOptions);

                var context = GetActionExcutingContext();

                // Act
                await revisionActionFilter.OnActionExecutionAsync(context, Next);

                // Assert
                context.HttpContext.Response.Headers.ContainsKey("ETag").Should().BeFalse();
            }
Exemple #2
0
            public async Task ShouldSetRevisionContextRequestRevision_WhenIfMatchHeaderIsSet()
            {
                // Arrange
                var ifMatchValue = Guid.NewGuid();

                var revisionContext = new RevisionContext();
                var appOptions      = new ApplicationOptions();

                var revisionActionFilter = new RevisionActionFilter(revisionContext, appOptions);

                var context = GetActionExcutingContext();

                context.HttpContext.Request.Headers.Add("If-Match", ifMatchValue.ToString());

                // Act
                await revisionActionFilter.OnActionExecutionAsync(context, Next);

                // Assert
                revisionContext.RequestRevision.Should().Be(ifMatchValue);
            }
Exemple #3
0
            public async Task ShouldSetETagHeader_WhenRevisionContextResponseRevisionIsSet()
            {
                // Arrange
                var revisionContext = new RevisionContext
                {
                    ResponseRevision = Guid.NewGuid()
                };
                var appOptions = new ApplicationOptions();

                var revisionActionFilter = new RevisionActionFilter(revisionContext, appOptions);

                var context = GetActionExcutingContext();

                // Act
                await revisionActionFilter.OnActionExecutionAsync(context, Next);

                // Assert
                context.HttpContext.Response.Headers.ContainsKey("ETag").Should().BeTrue();
                context.HttpContext.Response.Headers["ETag"].ToString().Should().Be(revisionContext.ResponseRevision.ToString());
            }
Exemple #4
0
            public void ShouldNotThrowRequiredPreconditionInvalidException_WhenIfMatchIsNullRequireRevisionMatchingIsSetAndHttpMethodIsExcluded(string httpMethod)
            {
                // Arrange
                var revisionContext = new RevisionContext();
                var appOptions      = new ApplicationOptions
                {
                    RequireRevisionMatching = true
                };

                var revisionActionFilter = new RevisionActionFilter(revisionContext, appOptions);

                var context = GetActionExcutingContext();

                context.HttpContext.Request.Method = httpMethod;

                // Act
                Func <Task> result = () => revisionActionFilter.OnActionExecutionAsync(context, Next);

                // Assert
                result.Should().NotThrow <RequiredPreconditionInvalidException>();
            }
Exemple #5
0
            public async Task ShouldNotSetRevisionContextRequestRevision_WhenIfMatchIsInvalid(string ifMatchValue)
            {
                // Arrange
                var revisionContext = new RevisionContext();
                var appOptions      = new ApplicationOptions();

                var revisionActionFilter = new RevisionActionFilter(revisionContext, appOptions);

                var context = GetActionExcutingContext();

                if (ifMatchValue != null)
                {
                    context.HttpContext.Request.Headers.Add("If-Match", ifMatchValue.ToString());
                }

                // Act
                await revisionActionFilter.OnActionExecutionAsync(context, Next);

                // Assert
                revisionContext.RequestRevision.Should().BeNull();
            }