public void GameScoreBoard_GivenValidGameNameAndCountOverAllowedNumber_ReturnsBadRequestStatusCode() { IDataStorage cache = new GameScoreBoardDataCache (); TestDataProvider.ProvideTestData (cache); var bootstrapper = new TestableLightInjectNancyBootstrapper (cache); var browser = new Browser(bootstrapper, defaults: to => to.Accept("application/json")); string expectedGameName = "game1"; int illegalNumberOfResults = 60; var response = browser.Get("/api/v1/gameScoreBoard", with => { with.HttpRequest(); with.Query("gameName", expectedGameName); with.Query("count", illegalNumberOfResults.ToString()); }); var responseCode = response.StatusCode; Assert.IsTrue (responseCode == HttpStatusCode.BadRequest); }
public void GameScoreBoard_GivenValidGameNameAndCount_ReturnsCorrectJson() { IDataStorage cache = new GameScoreBoardDataCache (); TestDataProvider.ProvideTestData (cache); var bootstrapper = new TestableLightInjectNancyBootstrapper (cache); var browser = new Browser(bootstrapper, defaults: to => to.Accept("application/json")); string expectedGameName = "game1"; int expectedNumberOfResults = 1; var response = browser.Get("/api/v1/gameScoreBoard", with => { with.HttpRequest(); with.Query("gameName", expectedGameName); with.Query("count", expectedNumberOfResults.ToString()); }); var responseModels = JsonConvert.DeserializeObject<IEnumerable<ScoreRecord>> (response.Body.AsString()); Assert.IsTrue (responseModels.Count() == expectedNumberOfResults); Assert.AreEqual (expectedGameName, responseModels.FirstOrDefault ().GameName); }
public void AddScoreBoardData_GivenValidGameRecordObjectAsJson_ReturnsCorrectObjectFromStorage() { IDataStorage cache = new GameScoreBoardDataCache (); TestDataProvider.ProvideTestData (cache); var bootstrapper = new TestableLightInjectNancyBootstrapper (cache); var browser = new Browser(bootstrapper, defaults: to => to.Accept("application/json")); string expectedGameName = "game5"; int expectedCount = 1; var scoreRecordObject = new ScoreRecord { GameName = expectedGameName, PlayerName = expectedCount.ToString(), Score = 5000 }; var post = browser.Post ("/api/v1/addScoreBoardData", with => { with.Header("Content-Type", "application/json"); with.JsonBody (scoreRecordObject); }); var response = browser.Get("/api/v1/gameScoreBoard", with => { with.HttpRequest(); with.Query("gameName", expectedGameName); with.Query("count", expectedCount.ToString()); }); var postRespons = JsonConvert.DeserializeObject<int> (post.Body.AsString ()); var responseModels = JsonConvert.DeserializeObject<IEnumerable<ScoreRecord>> (response.Body.AsString()); Assert.IsTrue (postRespons > -1); Assert.IsTrue (responseModels.Count() == expectedCount); Assert.AreEqual (expectedGameName, responseModels.FirstOrDefault ().GameName); }
public void GameNames_ReturnsCorrectGameNames() { IDataStorage cache = new GameScoreBoardDataCache(); TestDataProvider.ProvideTestData(cache); var bootstrapper = new TestableLightInjectNancyBootstrapper(cache); var browser = new Browser(bootstrapper, defaults: to => to.Accept("application/json")); var expectedGameNames = new List<string> { "game1", "game2", "game3" }; var response = browser.Get("api/v1/gameNames", with => { with.HttpRequest(); }); var responseObjects = JsonConvert.DeserializeObject<IEnumerable<string>>(response.Body.AsString()); var areEquivavelent = (expectedGameNames.Count() == responseObjects.Count() && !expectedGameNames.Except(responseObjects).Any()); Assert.IsTrue(areEquivavelent); }
public void AddScoreBoardData_GivenValidGameRecordObjectAsJson_ReturnsHttpCreated() { IDataStorage cache = new GameScoreBoardDataCache (); TestDataProvider.ProvideTestData (cache); var bootstrapper = new TestableLightInjectNancyBootstrapper (cache); var browser = new Browser(bootstrapper, defaults: to => to.Accept("application/json")); var scoreRecordObject = new ScoreRecord { GameName = "game5", PlayerName = "player5", Score = 5000 }; var response = browser.Post ("/api/v1/addScoreBoardData", with => { with.Header("Content-Type", "application/json"); with.JsonBody (scoreRecordObject); }); Assert.AreEqual (HttpStatusCode.Created, response.StatusCode); }
public TestGameScoreBoardDataCache() { m_gameScoreBoardCache = new GameScoreBoardDataCache (); }