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(); }
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); }
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()); }
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>(); }
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(); }