private async Task <string> PrepareGame() { SelectPlayerA(); await hub.OnConnectedAsync(); await hub.CreateGame(); SelectPlayerB(); await hub.OnConnectedAsync(); await hub.JoinWaitingGame(); var gameStartMsg = messages[^ 1];
public void CreateGame() { DbConnection connection = DbConnectionFactory.CreateTransient(); var user = new User { Id = 1 }; using (var gwintContext = new GwintContext(connection)) { gwintContext.Cards.AddRange(TestCardProvider.GetDefaultCards()); gwintContext.Users.Add(user); gwintContext.SaveChanges(); } var scopeMock = new Mock <ILifetimeScope>(); scopeMock.SetupResolve <ILifetimeScope, IGwintContext>(new GwintContext(connection)); var userConnectionMapMock = new Mock <IUserConnectionMap>(); userConnectionMapMock.SetupMapping(); scopeMock.SetupResolve <ILifetimeScope, IUserConnectionMap>(userConnectionMapMock.Object); var rootScopeMock = new Mock <ILifetimeScope>(); rootScopeMock.Setup(s => s.BeginLifetimeScope()).Returns(scopeMock.Object); var clientsMock = new Mock <IHubCallerConnectionContext <dynamic> >(); clientsMock.SetupClients(); var userName = "******"; var userId = "1"; var connectionID = "13245"; var hubCallerContextMock = CreateHubCallerContextMock(userName, userId, connectionID); GameHub hub = new GameHub(rootScopeMock.Object) { Context = hubCallerContextMock.Object, Clients = clientsMock.Object }; var result = hub.CreateGame(); Assert.Null(result.Error); Assert.NotNull(result.Data); }