This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
* Allow null ViewData and TempData #3310
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,14 @@ | |
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNet.Http; | ||
using Microsoft.AspNet.Http.Internal; | ||
using Microsoft.AspNet.Mvc.Abstractions; | ||
using Microsoft.AspNet.Mvc.ModelBinding; | ||
using Microsoft.AspNet.Mvc.Rendering; | ||
using Microsoft.AspNet.Mvc.ViewEngines; | ||
using Microsoft.AspNet.Routing; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Net.Http.Headers; | ||
using Moq; | ||
using Xunit; | ||
|
@@ -112,6 +114,62 @@ await viewExecutor.ExecuteAsync( | |
Assert.Equal("abcd", Encoding.UTF8.GetString(memoryStream.ToArray())); | ||
} | ||
|
||
private static IServiceProvider GetServiceProvider() | ||
{ | ||
var httpContext = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() }; | ||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddInstance<IModelMetadataProvider>(new EmptyModelMetadataProvider()); | ||
var tempDataProvider = new SessionStateTempDataProvider(); | ||
serviceCollection.AddInstance<ITempDataDictionary>(new TempDataDictionary(httpContext, tempDataProvider)); | ||
|
||
return serviceCollection.BuildServiceProvider(); | ||
} | ||
|
||
[Fact] | ||
public async Task ExecuteAsync_ViewResultAllowNull() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need the same unit test for a |
||
{ | ||
// Arrange | ||
var tempDataNull = false; | ||
var viewDataNull = false; | ||
var deligateHit = false; | ||
|
||
var view = CreateView(async (v) => | ||
{ | ||
deligateHit = true; | ||
tempDataNull = v.TempData == null; | ||
viewDataNull = v.ViewData == null; | ||
|
||
await v.Writer.WriteAsync("abcd"); | ||
}); | ||
var context = new DefaultHttpContext(); | ||
|
||
var memoryStream = new MemoryStream(); | ||
context.Response.Body = memoryStream; | ||
|
||
var actionContext = new ActionContext( | ||
context, | ||
new RouteData(), | ||
new ActionDescriptor()); | ||
|
||
context.RequestServices = GetServiceProvider(); | ||
var viewExecutor = CreateViewExecutor(); | ||
|
||
// Act | ||
await viewExecutor.ExecuteAsync( | ||
actionContext, | ||
view, | ||
null, | ||
null, | ||
contentType: null, | ||
statusCode: 200); | ||
|
||
// Assert | ||
Assert.Equal(200, context.Response.StatusCode); | ||
Assert.True(deligateHit); | ||
Assert.False(viewDataNull); | ||
Assert.False(tempDataNull); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add an assertion showing the delegate calling |
||
} | ||
|
||
[Fact] | ||
public async Task ExecuteAsync_SetsStatusCode() | ||
{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange indentation now that you're not using a here string. Also try to get into the habit of putting spaces around binary operators even in test code. That way you won't mess up the product code.