/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IKernel kernel) { kernel.Bind <IDbContext>().To <DataBaseContext>().InRequestScope(); //kernel.Bind<IDbContextFactory>().To<DbContextFactory>().InRequestScope(); kernel.Bind <EFRepositoryFactories>().To <EFRepositoryFactories>().InSingletonScope(); kernel.Bind <IEFRepositoryProvider>().To <EFRepositoryProvider>().InRequestScope(); kernel.Bind <IUOW>().To <UOW>().InRequestScope(); kernel.Bind <BaseIUOW>().To <UOW>().InRequestScope(); kernel.Bind <IUserStore <User> >().To <UserStore>().InRequestScope(); kernel.Bind <IRoleStore <Role> >().To <RoleStore>().InRequestScope(); kernel.Bind <IUserStore <UserInt, int> >().To <UserStoreInt>().InRequestScope(); kernel.Bind <IRoleStore <RoleInt, int> >().To <RoleStoreInt>().InRequestScope(); kernel.Bind <ApplicationSignInManager>().To <ApplicationSignInManager>().InRequestScope(); kernel.Bind <ApplicationUserManager>().To <ApplicationUserManager>().InRequestScope(); kernel.Bind <ApplicationRoleManager>().To <ApplicationRoleManager>().InRequestScope(); kernel.Bind <IAuthenticationManager>().ToMethod(a => HttpContext.Current.GetOwinContext().Authentication).InRequestScope(); // http://stackoverflow.com/questions/5646820/logger-wrapper-best-practice kernel.Bind <NLog.ILogger>().ToMethod(a => NLog.LogManager.GetCurrentClassLogger()); kernel.Bind <IUserNameResolver>().ToMethod(a => new UserNameResolver(UserNameFactory.GetCurrentUserNameFactory())).InRequestScope(); }
public async Task CombinedChannelsConnectThenSubscribeThenDisconnectAsync() { // Arrange var pusher = PusherFactory.GetPusher(new FakeAuthoriser(UserNameFactory.CreateUniqueUserName()), saveTo: _clients); var disconnectedEvent = new AutoResetEvent(false); pusher.Disconnected += sender => { disconnectedEvent.Set(); }; List <string> channelNames = CreateChannelNames(); // Act await ConnectThenSubscribeMultipleChannelsTestAsync(pusher, channelNames).ConfigureAwait(false); await pusher.DisconnectAsync().ConfigureAwait(false); disconnectedEvent.WaitOne(TimeSpan.FromSeconds(5)); // Need to delay as there is no channel disconnected event to wait upon. await Task.Delay(1000).ConfigureAwait(false); // Assert AssertIsDisconnected(pusher, channelNames); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IKernel kernel) { kernel.Bind <IDbContext>().To <WarehouseDbContext>().InRequestScope(); kernel.Bind <EFRepositoryFactories>().To <EFRepositoryFactories>().InSingletonScope(); kernel.Bind <IEFRepositoryProvider>().To <EFRepositoryProvider>().InRequestScope(); kernel.Bind <IPurchaseUOW>().To <PurchaseUOW>().InRequestScope(); kernel.Bind <IWarehouseUOW>().To <WarehouseUOW>().InRequestScope(); kernel.Bind <IUserStore <User> >().To <UserStore>().InRequestScope(); kernel.Bind <IRoleStore <Role> >().To <RoleStore>(); kernel.Bind <IUserStore <UserInt, int> >().To <UserStoreInt>().InRequestScope(); kernel.Bind <IRoleStore <RoleInt, int> >().To <RoleStoreInt>().InRequestScope(); kernel.Bind <ApplicationSignInManager>().To <ApplicationSignInManager>().InRequestScope(); kernel.Bind <ApplicationUserManager>().To <ApplicationUserManager>().InRequestScope(); kernel.Bind <ApplicationRoleManager>().To <ApplicationRoleManager>().InRequestScope(); kernel.Bind <IAuthenticationManager>().ToMethod(a => HttpContext.Current.GetOwinContext().Authentication).InRequestScope(); kernel.Bind <NLog.ILogger>().ToMethod(a => NLog.LogManager.GetCurrentClassLogger()); kernel.Bind <IUserNameResolver>().ToMethod(a => new UserNameResolver(UserNameFactory.GetCurrentUserNameFactory())).InSingletonScope(); }
public async Task UnsubscribeAllWithBacklogTest() { /* * Test provides code coverage for Pusher.Backlog scenarios. */ // Arrange var pusher = PusherFactory.GetPusher(new FakeAuthoriser(UserNameFactory.CreateUniqueUserName()), saveTo: _clients); List <string> channelNames = CreateChannelNames(numberOfChannels: 6); // Act await SubscribeMultipleChannelsTestAsync(connectBeforeSubscribing : true, pusher, channelNames).ConfigureAwait(false); IList <Channel> channels = pusher.GetAllChannels(); await pusher.DisconnectAsync().ConfigureAwait(false); await pusher.UnsubscribeAllAsync().ConfigureAwait(false); await pusher.ConnectAsync().ConfigureAwait(false); // Assert foreach (Channel channel in channels) { ValidateUnsubscribedChannel(pusher, channel); } }
public async Task CombinedChannelsSubscribeThenConnectThenUnsubscribeTest() { // Arrange var pusher = PusherFactory.GetPusher(new FakeAuthoriser(UserNameFactory.CreateUniqueUserName()), saveTo: _clients); List <string> channelNames = CreateChannelNames(numberOfChannels: 6); // Act foreach (string channelName in channelNames) { await pusher.SubscribeAsync(channelName).ConfigureAwait(false); } await pusher.ConnectAsync().ConfigureAwait(false); IList <Channel> channels = pusher.GetAllChannels(); foreach (string channelName in channelNames) { await pusher.UnsubscribeAsync(channelName).ConfigureAwait(false); } // Assert foreach (Channel channel in channels) { ValidateUnsubscribedChannel(pusher, channel); } }
public async Task CombinedChannelsConnectThenSubscribeAsync() { // Arrange var pusher = PusherFactory.GetPusher(new FakeAuthoriser(UserNameFactory.CreateUniqueUserName()), saveTo: _clients); List <string> channelNames = CreateChannelNames(); // Act and Assert await ConnectThenSubscribeMultipleChannelsTestAsync(pusher, channelNames).ConfigureAwait(false); }
public async Task CombinedChannelsConnectThenSubscribeThenUnsubscribeAllTest() { // Arrange var pusher = PusherFactory.GetPusher(new FakeAuthoriser(UserNameFactory.CreateUniqueUserName()), saveTo: _clients); List <string> channelNames = CreateChannelNames(numberOfChannels: 6); // Act await SubscribeMultipleChannelsTestAsync(connectBeforeSubscribing : true, pusher, channelNames).ConfigureAwait(false); IList <Channel> channels = pusher.GetAllChannels(); await pusher.UnsubscribeAllAsync().ConfigureAwait(false); // Assert foreach (Channel channel in channels) { ValidateUnsubscribedChannel(pusher, channel); } }
public void PresenceChannelShouldAddATypedMemberWhenGivenAMemberAsync() { // Arrange var stubOptions = new PusherOptions { Authorizer = new FakeAuthoriser(UserNameFactory.CreateUniqueUserName()) }; var pusher = PusherFactory.GetPusher(stubOptions); AutoResetEvent reset = new AutoResetEvent(false); pusher.Connected += sender => { reset.Set(); }; AsyncContext.Run(() => pusher.ConnectAsync()); reset.WaitOne(TimeSpan.FromSeconds(5)); reset.Reset(); var mockChannelName = ChannelNameFactory.CreateUniqueChannelName(presenceChannel: true); var channelSubscribed = false; // Act var channel = AsyncContext.Run(() => pusher.SubscribePresenceAsync <FakeUserInfo>(mockChannelName)); channel.Subscribed += sender => { channelSubscribed = true; reset.Set(); }; reset.WaitOne(TimeSpan.FromSeconds(10)); // Assert Assert.IsNotNull(channel); StringAssert.Contains(mockChannelName, channel.Name); Assert.IsTrue(channel.IsSubscribed); Assert.IsTrue(channelSubscribed); CollectionAssert.IsNotEmpty(channel.Members); }
public void PusherShouldSubscribeToAChannelWhenGivenAPopulatedPrivateChannelName() { // Arrange var stubOptions = new PusherOptions { Authorizer = new FakeAuthoriser(UserNameFactory.CreateUniqueUserName()) }; var pusher = PusherFactory.GetPusher(stubOptions); AutoResetEvent reset = new AutoResetEvent(false); pusher.Connected += sender => { reset.Set(); }; pusher.Connect(); reset.WaitOne(TimeSpan.FromSeconds(5)); reset.Reset(); var mockChannelName = ChannelNameFactory.CreateUniqueChannelName(privateChannel: true); var channelSubscribed = false; // Act var channel = AsyncContext.Run(() => pusher.Subscribe(mockChannelName)); channel.Subscribed += sender => { channelSubscribed = true; reset.Set(); }; reset.WaitOne(TimeSpan.FromSeconds(5)); // Assert Assert.IsNotNull(channel); StringAssert.Contains(mockChannelName, channel.Name); Assert.IsTrue(channel.IsSubscribed); Assert.IsTrue(channelSubscribed); }
public async Task CombinedChannelsSubscribeThenConnectThenReconnectWhenTheUnderlyingSocketIsClosedAsync() { // Arrange var pusher = PusherFactory.GetPusher(new FakeAuthoriser(UserNameFactory.CreateUniqueUserName()), saveTo: _clients); var subscribedEvent = new AutoResetEvent(false); List <string> channelNames = CreateChannelNames(); // Act await SubscribeThenConnectMultipleChannelsTestAsync(pusher, channelNames).ConfigureAwait(false); int subscribedCount = 0; pusher.Subscribed += (sender, channelName) => { subscribedCount++; if (subscribedCount == channelNames.Count) { subscribedEvent.Set(); } }; await Task.Run(() => { WebSocket socket = ConnectionTest.GetWebSocket(pusher); socket.Close(); }).ConfigureAwait(false); // Assert Assert.IsTrue(subscribedEvent.WaitOne(TimeSpan.FromSeconds(5))); AssertIsSubscribed(pusher, channelNames); }