コード例 #1
0
        public void PlayerScoreBoard_GivenValidUsername_ReturnsCorrectJson()
        {
            string expectedPlayerName = "player1";
            var    mockStorage        = new Mock <IDataStorage> ();

            mockStorage.Setup(x => x.GetAllScoresForUsername(expectedPlayerName)).Returns(new List <ScoreRecord>()
            {
                new ScoreRecord {
                    PlayerName = expectedPlayerName
                }
            });
            var bootstrapper = new TestableLightInjectNancyBootstrapper(mockStorage.Object);
            var browser      = new Browser(bootstrapper, defaults: to => to.Accept("application/json"));


            var response = browser.Get("/api/v1/playerScoreBoard", with =>
            {
                with.HttpRequest();
                with.Query("playerName", expectedPlayerName);
            });
            var responseModels = JsonConvert.DeserializeObject <IEnumerable <ScoreRecord> > (response.Body.AsString());

            Assert.IsTrue(responseModels.Count() >= 1);
            Assert.AreEqual(expectedPlayerName, responseModels.FirstOrDefault().PlayerName);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
		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);
		}
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        public void CountHigherScores_GivenValidGameNameAndScore_ReturnsCorrectNumberOfLargerScores()
        {
            string mockGameName  = "mockGame";
            int    expectedCount = 5;
            var    mockStorage   = new Mock <IDataStorage> ();

            mockStorage.Setup(x => x.CountHigherScores(mockGameName, 1000)).Returns(expectedCount);
            var bootstrapper = new TestableLightInjectNancyBootstrapper(mockStorage.Object);
            var browser      = new Browser(bootstrapper, defaults: to => to.Accept("application/json"));

            var response = browser.Get("/api/v1/countHigherScores", with =>
            {
                with.HttpRequest();
                with.Query("gameName", mockGameName);
                with.Query("score", "1000");
            });
            var responseCount = JsonConvert.DeserializeObject <int> (response.Body.AsString());

            Assert.IsTrue(responseCount == expectedCount);
        }
コード例 #7
0
		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);
		}
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
		public void PlayerScoreBoard_GivenValidUsername_ReturnsCorrectJson()
		{
			string expectedPlayerName = "player1";
			var mockStorage = new Mock<IDataStorage> ();
			mockStorage.Setup(x => x.GetAllScoresForUsername(expectedPlayerName)).Returns(new List<ScoreRecord>() { new ScoreRecord {PlayerName = expectedPlayerName}});
			var bootstrapper = new TestableLightInjectNancyBootstrapper(mockStorage.Object);
			var browser = new Browser(bootstrapper, defaults: to => to.Accept("application/json"));


			var response = browser.Get("/api/v1/playerScoreBoard", with =>
				{
					with.HttpRequest();
					with.Query("playerName", expectedPlayerName);
				});
			var responseModels = JsonConvert.DeserializeObject<IEnumerable<ScoreRecord>> (response.Body.AsString());

			Assert.IsTrue (responseModels.Count() >= 1);
			Assert.AreEqual (expectedPlayerName, responseModels.FirstOrDefault().PlayerName);
		}
コード例 #11
0
		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);


		}
コード例 #12
0
		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);

		}
コード例 #13
0
		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);

		}
コード例 #14
0
		public void CountHigherScores_GivenValidGameNameAndScore_ReturnsCorrectNumberOfLargerScores()
		{
			string mockGameName = "mockGame";
			int expectedCount = 5; 
			var mockStorage = new Mock<IDataStorage> ();
			mockStorage.Setup(x => x.CountHigherScores(mockGameName, 1000)).Returns(expectedCount);
			var bootstrapper = new TestableLightInjectNancyBootstrapper(mockStorage.Object);
			var browser = new Browser(bootstrapper, defaults: to => to.Accept("application/json"));

			var response = browser.Get("/api/v1/countHigherScores", with =>
				{
					with.HttpRequest();
					with.Query("gameName", mockGameName);
					with.Query("score", "1000");
				});
			var responseCount = JsonConvert.DeserializeObject<int> (response.Body.AsString());

			Assert.IsTrue (responseCount == expectedCount);

		}