React to removal of [Activate] for ViewComponents
This commit is contained in:
parent
9e62751649
commit
c428ddffa3
|
|
@ -1,5 +1,6 @@
|
|||
[Oo]bj/
|
||||
[Bb]in/
|
||||
.vs/
|
||||
*.xap
|
||||
*.user
|
||||
/TestResults
|
||||
|
|
|
|||
|
|
@ -11,26 +11,18 @@ namespace MusicStore.Components
|
|||
[ViewComponent(Name = "Announcement")]
|
||||
public class AnnouncementComponent : ViewComponent
|
||||
{
|
||||
[Activate]
|
||||
public MusicStoreContext DbContext
|
||||
public AnnouncementComponent(MusicStoreContext dbContext, IMemoryCache cache, ISystemClock clock)
|
||||
{
|
||||
get;
|
||||
set;
|
||||
DbContext = dbContext;
|
||||
Cache = cache;
|
||||
Clock = clock;
|
||||
}
|
||||
|
||||
[Activate]
|
||||
public IMemoryCache Cache
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
private MusicStoreContext DbContext { get; }
|
||||
|
||||
[Activate]
|
||||
public ISystemClock Clock
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
private IMemoryCache Cache { get; }
|
||||
|
||||
private ISystemClock Clock { get; }
|
||||
|
||||
public async Task<IViewComponentResult> InvokeAsync()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@ namespace MusicStore.Components
|
|||
[ViewComponent(Name = "CartSummary")]
|
||||
public class CartSummaryComponent : ViewComponent
|
||||
{
|
||||
[Activate]
|
||||
public MusicStoreContext DbContext
|
||||
public CartSummaryComponent(MusicStoreContext dbContext)
|
||||
{
|
||||
get;
|
||||
set;
|
||||
DbContext = dbContext;
|
||||
}
|
||||
|
||||
private MusicStoreContext DbContext { get; }
|
||||
|
||||
public async Task<IViewComponentResult> InvokeAsync()
|
||||
{
|
||||
var cartItems = await GetCartItems();
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@ namespace MusicStore.Components
|
|||
[ViewComponent(Name = "GenreMenu")]
|
||||
public class GenreMenuComponent : ViewComponent
|
||||
{
|
||||
[Activate]
|
||||
public MusicStoreContext DbContext
|
||||
public GenreMenuComponent(MusicStoreContext dbContext)
|
||||
{
|
||||
get;
|
||||
set;
|
||||
DbContext = dbContext;
|
||||
}
|
||||
|
||||
private MusicStoreContext DbContext { get; }
|
||||
|
||||
public async Task<IViewComponentResult> InvokeAsync()
|
||||
{
|
||||
var genres = await GetGenres();
|
||||
|
|
|
|||
|
|
@ -31,14 +31,13 @@ namespace MusicStore.Components
|
|||
// Arrange
|
||||
var today = new DateTime(year: 2002, month: 10, day: 30);
|
||||
|
||||
var announcementComponent = new AnnouncementComponent()
|
||||
{
|
||||
DbContext = _serviceProvider.GetRequiredService<MusicStoreContext>(),
|
||||
Cache = _serviceProvider.GetRequiredService<IMemoryCache>(),
|
||||
Clock = new TestSystemClock() { UtcNow = today },
|
||||
};
|
||||
var dbContext = _serviceProvider.GetRequiredService<MusicStoreContext>();
|
||||
var cache = _serviceProvider.GetRequiredService<IMemoryCache>();
|
||||
var clock = new TestSystemClock() { UtcNow = today };
|
||||
|
||||
PopulateData(announcementComponent.DbContext, latestAlbumDate: today);
|
||||
var announcementComponent = new AnnouncementComponent(dbContext, cache, clock);
|
||||
|
||||
PopulateData(dbContext, latestAlbumDate: today);
|
||||
|
||||
// Action
|
||||
var result = await announcementComponent.InvokeAsync();
|
||||
|
|
|
|||
|
|
@ -53,9 +53,8 @@ namespace MusicStore.Components
|
|||
PopulateData(dbContext, cartId, albumTitle: "AlbumA", itemCount: 10);
|
||||
|
||||
// CartSummaryComponent initialization
|
||||
var cartSummaryComponent = new CartSummaryComponent()
|
||||
var cartSummaryComponent = new CartSummaryComponent(dbContext)
|
||||
{
|
||||
DbContext = dbContext,
|
||||
ViewContext = viewContext,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -27,12 +27,10 @@ namespace MusicStore.Components
|
|||
public async Task GenreMenuComponent_Returns_NineGenres()
|
||||
{
|
||||
// Arrange
|
||||
var genreMenuComponent = new GenreMenuComponent()
|
||||
{
|
||||
DbContext = _serviceProvider.GetRequiredService<MusicStoreContext>(),
|
||||
};
|
||||
var dbContext = _serviceProvider.GetRequiredService<MusicStoreContext>();
|
||||
var genreMenuComponent = new GenreMenuComponent(dbContext);
|
||||
|
||||
PopulateData(genreMenuComponent.DbContext);
|
||||
PopulateData(dbContext);
|
||||
|
||||
// Act
|
||||
var result = await genreMenuComponent.InvokeAsync();
|
||||
|
|
|
|||
Loading…
Reference in New Issue