public async Task Post_WithInvalidName_ReturnsBadRequestWithMessage(string name) { var model = new GamePost() { Name = name, }; var controller = new GameController(null, null, _logger); var response = await controller.Post(model); var badRequest = response as BadRequestObjectResult; Assert.That(badRequest, Is.Not.Null); Assert.That(badRequest.StatusCode, Is.EqualTo((int)HttpStatusCode.BadRequest)); Assert.That(badRequest.Value.ToString(), Is.EqualTo($"Invalid {nameof(model.Name)} provided.")); }
public async Task Post_WithValidModel_CallsPublishAndReturnsCreatedWithIdInLocationHeader() { var model = new GamePost() { Name = "Test Game", }; var publisher = Mock.Of <IPublisher <GameView> >(); var publisherMock = Mock.Get(publisher); publisherMock.Setup(p => p.Publish(It.IsAny <GameView>())).ReturnsAsync(true); var controller = new GameController(null, publisher, _logger); var response = await controller.Post(model); var created = response as CreatedResult; Assert.That(created, Is.Not.Null); Assert.That(created.StatusCode, Is.EqualTo((int)HttpStatusCode.Created)); Assert.That(created.Location, Is.Not.Null); }
public async Task Post_WithPublisherThrowingException_ReturnsInternalServerErrorWithMessage() { var model = new GamePost() { Name = "Test Game", }; var publisher = Mock.Of <IPublisher <GameView> >(); var publisherMock = Mock.Get(publisher); publisherMock.Setup(p => p.Publish(It.IsAny <GameView>())).Throws <Exception>(); var controller = new GameController(null, publisher, _logger); var response = await controller.Post(model); var error = response as ObjectResult; Assert.That(error, Is.Not.Null); Assert.That(error.StatusCode, Is.EqualTo((int)HttpStatusCode.InternalServerError)); Assert.That(error.Value.ToString(), Is.EqualTo("Something went wrong saving the new game.")); }
public async Task Post_WithPublisherThrowingArgumentException_ReturnsBadRequestWithExceptionMessage() { var model = new GamePost() { Name = "Test Game", }; var exception = "I threw this exception."; var publisher = Mock.Of <IPublisher <GameView> >(); var publisherMock = Mock.Get(publisher); publisherMock.Setup(p => p.Publish(It.IsAny <GameView>())).Throws(new ArgumentException(exception)); var controller = new GameController(null, publisher, _logger); var response = await controller.Post(model); var error = response as BadRequestObjectResult; Assert.That(error, Is.Not.Null); Assert.That(error.StatusCode, Is.EqualTo((int)HttpStatusCode.BadRequest)); Assert.That(error.Value.ToString(), Is.EqualTo(exception)); }
public void Init() { if (_isInitialized) { return; } _isInitialized = true; _hubConnection = new HubConnection(Secrets.GoHubUrl); _goHub = _hubConnection.CreateHubProxy("GoHub"); _goHub.On(nameof(UserConnected), (UserPrefs user) => UserConnected?.Invoke(user)); _goHub.On(nameof(UserDisconnected), (string user) => UserDisconnected?.Invoke(user)); _goHub.On(nameof(LobbyPost), (Post post) => LobbyPost?.Invoke(post)); _goHub.On(nameof(GamePost), (Post post) => GamePost?.Invoke(post)); _goHub.On(nameof(GameRequested), (string name) => GameRequested?.Invoke(name)); _goHub.On(nameof(GameRequestDeclined), (string name) => GameRequestDeclined?.Invoke(name)); _goHub.On(nameof(GameRequestCancelled), (string name) => GameRequestCancelled?.Invoke(name)); _goHub.On(nameof(GameRequestAccepted), (string name) => GameRequestAccepted?.Invoke(name)); _goHub.On(nameof(GameAborted), (string name) => GameAborted?.Invoke(name)); }