Removed SignalR related code from the sample and tests.
This commit is contained in:
parent
370475b807
commit
0972116697
|
|
@ -1,6 +1,6 @@
|
|||
<div class="jumbotron">
|
||||
<h1>MVC Music Store</h1>
|
||||
<img src="Images/home-showcase.png" />
|
||||
<img src="images/home-showcase.png" />
|
||||
</div>
|
||||
|
||||
<div ng-controller="MusicStore.Store.Home.HomeController as viewModel">
|
||||
|
|
|
|||
|
|
@ -5,11 +5,8 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNet.Cors.Core;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.SignalR;
|
||||
using Microsoft.AspNet.SignalR.Infrastructure;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Framework.Caching.Memory;
|
||||
using MusicStore.Hubs;
|
||||
using MusicStore.Models;
|
||||
using MusicStore.ViewModels;
|
||||
|
||||
|
|
@ -19,29 +16,12 @@ namespace MusicStore.Areas.Admin.Controllers
|
|||
[Microsoft.AspNet.Authorization.Authorize("ManageStore")]
|
||||
public class StoreManagerController : Controller
|
||||
{
|
||||
private IConnectionManager _connectionManager;
|
||||
private IHubContext _announcementHub;
|
||||
|
||||
[FromServices]
|
||||
public MusicStoreContext DbContext { get; set; }
|
||||
|
||||
[FromServices]
|
||||
public IMemoryCache Cache { get; set; }
|
||||
|
||||
[FromServices]
|
||||
public IConnectionManager ConnectionManager
|
||||
{
|
||||
get
|
||||
{
|
||||
return _connectionManager;
|
||||
}
|
||||
set
|
||||
{
|
||||
_connectionManager = value;
|
||||
_announcementHub = _connectionManager.GetHubContext<AnnouncementHub>();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// GET: /StoreManager/
|
||||
public async Task<IActionResult> Index()
|
||||
|
|
@ -113,7 +93,6 @@ namespace MusicStore.Areas.Admin.Controllers
|
|||
Url = Url.Action("Details", "Store", new { id = album.AlbumId })
|
||||
};
|
||||
|
||||
_announcementHub.Clients.All.announcement(albumData);
|
||||
Cache.Remove("latestAlbum");
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Framework.Caching.Memory;
|
||||
using MusicStore.Models;
|
||||
|
||||
namespace MusicStore.Components
|
||||
{
|
||||
[ViewComponent(Name = "Announcement")]
|
||||
public class AnnouncementComponent : ViewComponent
|
||||
{
|
||||
public AnnouncementComponent(MusicStoreContext dbContext, IMemoryCache cache, ISystemClock clock)
|
||||
{
|
||||
DbContext = dbContext;
|
||||
Cache = cache;
|
||||
Clock = clock;
|
||||
}
|
||||
|
||||
private MusicStoreContext DbContext { get; }
|
||||
|
||||
private IMemoryCache Cache { get; }
|
||||
|
||||
private ISystemClock Clock { get; }
|
||||
|
||||
public async Task<IViewComponentResult> InvokeAsync()
|
||||
{
|
||||
var cacheKey = "latestAlbum";
|
||||
Album latestAlbum;
|
||||
if(!Cache.TryGetValue(cacheKey, out latestAlbum))
|
||||
{
|
||||
latestAlbum = await GetLatestAlbum();
|
||||
|
||||
if (latestAlbum != null)
|
||||
{
|
||||
Cache.Set(
|
||||
cacheKey,
|
||||
latestAlbum,
|
||||
new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(10)));
|
||||
}
|
||||
}
|
||||
|
||||
return View(latestAlbum);
|
||||
}
|
||||
|
||||
private async Task<Album> GetLatestAlbum()
|
||||
{
|
||||
var latestAlbum = await DbContext.Albums
|
||||
.OrderByDescending(a => a.Created)
|
||||
.Where(a => (a.Created - Clock.UtcNow).TotalDays <= 2)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
return latestAlbum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
using Microsoft.AspNet.SignalR;
|
||||
using Microsoft.AspNet.SignalR.Hubs;
|
||||
|
||||
namespace MusicStore.Hubs
|
||||
{
|
||||
[HubName("Announcement")]
|
||||
public class AnnouncementHub : Hub
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -102,9 +102,6 @@ namespace MusicStore
|
|||
// Add MVC services to the services container
|
||||
services.AddMvc();
|
||||
|
||||
//Add all SignalR related services to IoC.
|
||||
services.AddSignalR();
|
||||
|
||||
//Add InMemoryCache
|
||||
services.AddSingleton<IMemoryCache, MemoryCache>();
|
||||
|
||||
|
|
@ -178,9 +175,6 @@ namespace MusicStore
|
|||
// Configure Session.
|
||||
app.UseSession();
|
||||
|
||||
//Configure SignalR
|
||||
app.UseSignalR();
|
||||
|
||||
// Add static files to the request pipeline
|
||||
app.UseStaticFiles();
|
||||
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ using MusicStore.Models;
|
|||
namespace MusicStore
|
||||
{
|
||||
/// <summary>
|
||||
/// To make runtime to load an environment based startup class, specify the environment by the following ways:
|
||||
/// To make runtime to load an environment based startup class, specify the environment by the following ways:
|
||||
/// 1. Drop a Microsoft.AspNet.Hosting.ini file in the wwwroot folder
|
||||
/// 2. Add a setting in the ini file named 'ASPNET_ENV' with value of the format 'Startup[EnvironmentName]'. For example: To load a Startup class named
|
||||
/// 'StartupNtlmAuthentication' the value of the env should be 'NtlmAuthentication' (eg. ASPNET_ENV=NtlmAuthentication). Runtime adds a 'Startup' prefix to this and loads 'StartupNtlmAuthentication'.
|
||||
/// If no environment name is specified the default startup class loaded is 'Startup'.
|
||||
/// 'StartupNtlmAuthentication' the value of the env should be 'NtlmAuthentication' (eg. ASPNET_ENV=NtlmAuthentication). Runtime adds a 'Startup' prefix to this and loads 'StartupNtlmAuthentication'.
|
||||
/// If no environment name is specified the default startup class loaded is 'Startup'.
|
||||
/// Alternative ways to specify environment are:
|
||||
/// 1. Set the environment variable named SET ASPNET_ENV=NtlmAuthentication
|
||||
/// 2. For selfhost based servers pass in a command line variable named --env with this value. Eg:
|
||||
|
|
@ -34,7 +34,7 @@ namespace MusicStore
|
|||
{
|
||||
public StartupNtlmAuthentication(IApplicationEnvironment env)
|
||||
{
|
||||
//Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources,
|
||||
//Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources,
|
||||
//then the later source will win. By this way a Local config can be overridden by a different setting while deployed remotely.
|
||||
var builder = new ConfigurationBuilder(env.ApplicationBasePath)
|
||||
.AddJsonFile("config.json")
|
||||
|
|
@ -65,9 +65,6 @@ namespace MusicStore
|
|||
// Add MVC services to the services container
|
||||
services.AddMvc();
|
||||
|
||||
//Add all SignalR related services to IoC.
|
||||
services.AddSignalR();
|
||||
|
||||
//Add InMemoryCache
|
||||
services.AddSingleton<IMemoryCache, MemoryCache>();
|
||||
|
||||
|
|
@ -95,8 +92,8 @@ namespace MusicStore
|
|||
// Note: Not recommended for production.
|
||||
app.UseErrorPage();
|
||||
|
||||
// Set up NTLM authentication for WebListener like below.
|
||||
// For IIS and IISExpress: Use inetmgr to setup NTLM authentication on the application vDir or modify the applicationHost.config to enable NTLM.
|
||||
// Set up NTLM authentication for WebListener like below.
|
||||
// For IIS and IISExpress: Use inetmgr to setup NTLM authentication on the application vDir or modify the applicationHost.config to enable NTLM.
|
||||
if ((app.Server as ServerInformation) != null)
|
||||
{
|
||||
var serverInformation = (ServerInformation)app.Server;
|
||||
|
|
@ -126,9 +123,6 @@ namespace MusicStore
|
|||
// Configure Session.
|
||||
app.UseSession();
|
||||
|
||||
//Configure SignalR
|
||||
app.UseSignalR();
|
||||
|
||||
// Add static files to the request pipeline
|
||||
app.UseStaticFiles();
|
||||
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@ using MusicStore.Models;
|
|||
namespace MusicStore
|
||||
{
|
||||
/// <summary>
|
||||
/// To make runtime to load an environment based startup class, specify the environment by the following ways:
|
||||
/// To make runtime to load an environment based startup class, specify the environment by the following ways:
|
||||
/// 1. Drop a Microsoft.AspNet.Hosting.ini file in the wwwroot folder
|
||||
/// 2. Add a setting in the ini file named 'ASPNET_ENV' with value of the format 'Startup[EnvironmentName]'. For example: To load a Startup class named
|
||||
/// 'StartupOpenIdConnect' the value of the env should be 'OpenIdConnect' (eg. ASPNET_ENV=OpenIdConnect). Runtime adds a 'Startup' prefix to this and loads 'StartupOpenIdConnect'.
|
||||
/// If no environment name is specified the default startup class loaded is 'Startup'.
|
||||
/// 'StartupOpenIdConnect' the value of the env should be 'OpenIdConnect' (eg. ASPNET_ENV=OpenIdConnect). Runtime adds a 'Startup' prefix to this and loads 'StartupOpenIdConnect'.
|
||||
/// If no environment name is specified the default startup class loaded is 'Startup'.
|
||||
/// Alternative ways to specify environment are:
|
||||
/// 1. Set the environment variable named SET ASPNET_ENV=OpenIdConnect
|
||||
/// 2. For selfhost based servers pass in a command line variable named --env with this value. Eg:
|
||||
|
|
@ -34,7 +34,7 @@ namespace MusicStore
|
|||
|
||||
public StartupOpenIdConnect(IApplicationEnvironment env, IRuntimeEnvironment runtimeEnvironment)
|
||||
{
|
||||
//Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources,
|
||||
//Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources,
|
||||
//then the later source will win. By this way a Local config can be overridden by a different setting while deployed remotely.
|
||||
var builder = new ConfigurationBuilder(env.ApplicationBasePath)
|
||||
.AddJsonFile("config.json")
|
||||
|
|
@ -90,9 +90,6 @@ namespace MusicStore
|
|||
// Add MVC services to the services container
|
||||
services.AddMvc();
|
||||
|
||||
//Add all SignalR related services to IoC.
|
||||
services.AddSignalR();
|
||||
|
||||
//Add InMemoryCache
|
||||
services.AddSingleton<IMemoryCache, MemoryCache>();
|
||||
|
||||
|
|
@ -130,9 +127,6 @@ namespace MusicStore
|
|||
// Configure Session.
|
||||
app.UseSession();
|
||||
|
||||
//Configure SignalR
|
||||
app.UseSignalR();
|
||||
|
||||
// Add static files to the request pipeline
|
||||
app.UseStaticFiles();
|
||||
|
||||
|
|
|
|||
|
|
@ -23,24 +23,6 @@
|
|||
<script type="text/javascript" src="~/Scripts/modernizr-2.6.2.js"></script>
|
||||
<script src="~/Scripts/jquery-2.0.3.js"></script>
|
||||
<script src="~/Scripts/jquery.signalR-2.0.1.min.js"></script>
|
||||
<script src="~/signalr/hubs" type="text/javascript"></script>
|
||||
<script>
|
||||
// To display what's new in the store
|
||||
$(function () {
|
||||
$.connection.hub.logging = true;
|
||||
var announcementsHub = $.connection.Announcement;
|
||||
|
||||
announcementsHub.client.announcement = function (item) {
|
||||
var newArrivals = $('a#NewArrivalsPanel');
|
||||
newArrivals.attr("href", item.Url); //Set the URL
|
||||
newArrivals.text(item.Title); //Set the title
|
||||
};
|
||||
|
||||
$.connection.hub.start().done(function () {
|
||||
console.log('hub connection open');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
|
|
@ -58,7 +40,6 @@
|
|||
<li><a asp-controller="Home" asp-action="Index">Home</a></li>
|
||||
@await Component.InvokeAsync("GenreMenu")
|
||||
@await Component.InvokeAsync("CartSummary")
|
||||
@await Component.InvokeAsync("Announcement")
|
||||
</ul>
|
||||
@await Html.PartialAsync("_LoginPartial")
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
"dependencies": {
|
||||
"EntityFramework.InMemory": "7.0.0-*",
|
||||
"EntityFramework.SqlServer": "7.0.0-*",
|
||||
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
|
||||
"Microsoft.AspNet.Antiforgery": "1.0.0-*",
|
||||
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
|
||||
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-*",
|
||||
|
|
@ -27,9 +26,9 @@
|
|||
"Microsoft.AspNet.Mvc": "6.0.0-*",
|
||||
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-*",
|
||||
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
|
||||
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
|
||||
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
|
||||
"Microsoft.AspNet.Session": "1.0.0-*",
|
||||
"Microsoft.AspNet.SignalR.Server": "3.0.0-*",
|
||||
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
|
||||
"Microsoft.AspNet.Tooling.Razor": "1.0.0-*",
|
||||
"Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-*",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ using System.Net.Http;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Server.Testing;
|
||||
using Microsoft.AspNet.SignalR.Client;
|
||||
using Microsoft.Framework.Logging;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -346,20 +345,6 @@ namespace E2ETests
|
|||
public async Task<string> CreateAlbum()
|
||||
{
|
||||
var albumName = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12);
|
||||
#if DNX451
|
||||
string dataFromHub = null;
|
||||
var OnReceivedEvent = new AutoResetEvent(false);
|
||||
var hubConnection = new HubConnection(_deploymentResult.ApplicationBaseUri + "SignalR");
|
||||
hubConnection.Received += (data) =>
|
||||
{
|
||||
_logger.LogVerbose("Data received by SignalR client: {receivedData}", data);
|
||||
dataFromHub = data;
|
||||
OnReceivedEvent.Set();
|
||||
};
|
||||
|
||||
IHubProxy proxy = hubConnection.CreateHubProxy("Announcement");
|
||||
await hubConnection.Start();
|
||||
#endif
|
||||
_logger.LogInformation("Trying to create an album with name '{album}'", albumName);
|
||||
var response = await _httpClient.GetAsync("Admin/StoreManager/create");
|
||||
await ThrowIfResponseStatusNotOk(response);
|
||||
|
|
@ -379,12 +364,6 @@ namespace E2ETests
|
|||
responseContent = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal<string>(_deploymentResult.ApplicationBaseUri + "Admin/StoreManager", response.RequestMessage.RequestUri.AbsoluteUri);
|
||||
Assert.Contains(albumName, responseContent);
|
||||
#if DNX451
|
||||
_logger.LogInformation("Waiting for the SignalR client to receive album created announcement");
|
||||
OnReceivedEvent.WaitOne(TimeSpan.FromSeconds(10));
|
||||
dataFromHub = dataFromHub ?? "No relevant data received from Hub";
|
||||
Assert.Contains(albumName, dataFromHub);
|
||||
#endif
|
||||
_logger.LogInformation("Successfully created an album with name '{album}' in the store", albumName);
|
||||
return albumName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace MusicStore
|
|||
|
||||
public StartupOpenIdConnectTesting(IApplicationEnvironment env, IRuntimeEnvironment runtimeEnvironment)
|
||||
{
|
||||
//Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources,
|
||||
//Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources,
|
||||
//then the later source will win. By this way a Local config can be overridden by a different setting while deployed remotely.
|
||||
var builder = new ConfigurationBuilder(env.ApplicationBasePath)
|
||||
.AddJsonFile("config.json")
|
||||
|
|
@ -98,9 +98,6 @@ namespace MusicStore
|
|||
// Add MVC services to the services container
|
||||
services.AddMvc();
|
||||
|
||||
//Add all SignalR related services to IoC.
|
||||
services.AddSignalR();
|
||||
|
||||
//Add InMemoryCache
|
||||
services.AddSingleton<IMemoryCache, MemoryCache>();
|
||||
|
||||
|
|
@ -138,9 +135,6 @@ namespace MusicStore
|
|||
// Configure Session.
|
||||
app.UseSession();
|
||||
|
||||
//Configure SignalR
|
||||
app.UseSignalR();
|
||||
|
||||
// Add static files to the request pipeline
|
||||
app.UseStaticFiles();
|
||||
|
||||
|
|
|
|||
|
|
@ -154,9 +154,6 @@ namespace MusicStore
|
|||
// Add MVC services to the services container
|
||||
services.AddMvc();
|
||||
|
||||
//Add all SignalR related services to IoC.
|
||||
services.AddSignalR();
|
||||
|
||||
//Add InMemoryCache
|
||||
services.AddSingleton<IMemoryCache, MemoryCache>();
|
||||
|
||||
|
|
@ -194,9 +191,6 @@ namespace MusicStore
|
|||
// Configure Session.
|
||||
app.UseSession();
|
||||
|
||||
//Configure SignalR
|
||||
app.UseSignalR();
|
||||
|
||||
// Add static files to the request pipeline
|
||||
app.UseStaticFiles();
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
"dependencies": {
|
||||
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
|
||||
"Microsoft.AspNet.Server.Testing": "1.0.0-*",
|
||||
"Microsoft.AspNet.SignalR.Client": "2.1.1",
|
||||
"Microsoft.AspNet.WebUtilities": "1.0.0-*",
|
||||
"Microsoft.Framework.Configuration.EnvironmentVariables": "1.0.0-*",
|
||||
"Microsoft.Framework.Logging.Console": "1.0.0-*",
|
||||
|
|
|
|||
|
|
@ -1,103 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Framework.Caching.Memory;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using MusicStore.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace MusicStore.Components
|
||||
{
|
||||
public class AnnouncementComponentTest
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public AnnouncementComponentTest()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
services.AddEntityFramework()
|
||||
.AddInMemoryDatabase()
|
||||
.AddDbContext<MusicStoreContext>(options =>
|
||||
options.UseInMemoryDatabase());
|
||||
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AnnouncementComponent_Returns_LatestAlbum()
|
||||
{
|
||||
// Arrange
|
||||
var today = new DateTime(year: 2002, month: 10, day: 30);
|
||||
|
||||
var dbContext = _serviceProvider.GetRequiredService<MusicStoreContext>();
|
||||
var cache = _serviceProvider.GetRequiredService<IMemoryCache>();
|
||||
var clock = new TestSystemClock() { UtcNow = today };
|
||||
|
||||
var announcementComponent = new AnnouncementComponent(dbContext, cache, clock);
|
||||
|
||||
PopulateData(dbContext, latestAlbumDate: today);
|
||||
|
||||
// Action
|
||||
var result = await announcementComponent.InvokeAsync();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
var viewResult = Assert.IsType<ViewViewComponentResult>(result);
|
||||
Assert.Null(viewResult.ViewName);
|
||||
var albumResult = Assert.IsType<Album>(viewResult.ViewData.Model);
|
||||
Assert.Equal(today, albumResult.Created.Date);
|
||||
}
|
||||
|
||||
private static void PopulateData(DbContext context, DateTime latestAlbumDate)
|
||||
{
|
||||
var albums = TestAlbumDataProvider.GetAlbums(latestAlbumDate);
|
||||
|
||||
foreach (var album in albums)
|
||||
{
|
||||
context.Add(album);
|
||||
}
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
private class TestAlbumDataProvider
|
||||
{
|
||||
public static Album[] GetAlbums(DateTime latestAlbumDate)
|
||||
{
|
||||
var generes = Enumerable.Range(1, 10).Select(n =>
|
||||
new Genre()
|
||||
{
|
||||
GenreId = n,
|
||||
Name = "Genre Name " + n,
|
||||
}).ToArray();
|
||||
|
||||
var artists = Enumerable.Range(1, 10).Select(n =>
|
||||
new Artist()
|
||||
{
|
||||
ArtistId = n + 1,
|
||||
Name = "Artist Name " + n,
|
||||
}).ToArray();
|
||||
|
||||
var albums = Enumerable.Range(1, 10).Select(n =>
|
||||
new Album()
|
||||
{
|
||||
Artist = artists[n - 1],
|
||||
ArtistId = n,
|
||||
Genre = generes[n - 1],
|
||||
GenreId = n,
|
||||
Created = latestAlbumDate.AddDays(1 - n),
|
||||
}).ToArray();
|
||||
|
||||
return albums;
|
||||
}
|
||||
}
|
||||
|
||||
private class TestSystemClock : ISystemClock
|
||||
{
|
||||
public DateTime UtcNow { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue