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