Exemple #1
0
        public void Test_GetAll()
        {
            var mockService = new Mock <IHighScoresService>();
            var mockResults = new List <HighScore>()
            {
                new HighScore()
                {
                    Name = "Clark Kent", Score = 1
                },
                new HighScore()
                {
                    Name = "Bruce Wayne", Score = 2
                },
            };

            mockService.Setup(service => service.ReadAll())
            .Returns(mockResults);

            var controller = new HighScoresController(mockService.Object);
            var results    = controller.GetAll();

            mockService.Verify(service => service.ReadAll(), Times.Once());

            Assert.AreEqual(mockResults, results);
            Assert.IsTrue(results.Count == 2);

            mockResults.Clear();

            results = controller.GetAll();
            Assert.AreEqual(mockResults, results);
            Assert.IsTrue(results.Count == 0);
        }
Exemple #2
0
 private void Awake()
 {
     _highScoresController = FindObjectOfType <HighScoresController>();
     _pixelPerfectCamera   = FindObjectOfType <PixelPerfectCamera>();
     _spawner        = FindObjectOfType <Spawner>();
     _timeController = GetComponent <TimeController>();
 }
Exemple #3
0
        public void Test_Delete()
        {
            var mockService = new Mock <IHighScoresService>();
            var mockResults = new List <HighScore>()
            {
                new HighScore()
                {
                    Name = "Clark Kent", Score = 1
                },
                new HighScore()
                {
                    Name = "Bruce Wayne", Score = 1
                }
            };

            mockService.Setup(service => service.Delete(It.IsAny <int>()))
            .Callback((int id) => mockResults.RemoveAll(hs => hs.Score == id));

            var controller = new HighScoresController(mockService.Object);

            Assert.IsTrue(mockResults.Count == 2);

            controller.Delete("1");
            mockService.Verify(service => service.Delete(It.IsAny <int>()), Times.Once());
        }
Exemple #4
0
        public void Test_Delete_Exception()
        {
            var mockService = new Mock <IHighScoresService>();
            var controller  = new HighScoresController(mockService.Object);

            controller.Delete("Tony Stark");

            mockService.Verify(service => service.Delete(It.IsAny <int>()), Times.Never);
        }
        public UnitTest1()
        {
            var options = new DbContextOptionsBuilder <DataContext>()
                          .UseCosmos("https://csm.documents.azure.com:443",
                                     "o9t7nHTTr1ch22TvmKIXtv6MNS1bxG2Ukmk48J4EdXg68WR3nSg2EAItJSPIeAnkRKaDPem9KFdFsTFbSLV3mw==", "ShootingHighscore")
                          .Options;

            dataContext = new DataContext(options);
            controller  = new HighScoresController(dataContext);
        }
Exemple #6
0
        public void Test_Get_Exception()
        {
            var mockService = new Mock <IHighScoresService>();
            var mockResult  = new HighScore()
            {
                Name = "Diana Prince", Score = 1
            };
            var controller = new HighScoresController(mockService.Object);

            controller.Get("Natasha Romanova");

            mockService.Verify(service => service.ReadAll(), Times.Never);
        }
Exemple #7
0
        public void Test_Post()
        {
            var mockService = new Mock <IHighScoresService>();

            mockService.Setup(service => service.Create(It.IsAny <HighScore>()));

            var controller = new HighScoresController(mockService.Object);
            var highScore  = new HighScore()
            {
                Name = "Peter Parker", Score = 1
            };

            controller.Post(highScore);

            mockService.Verify(service => service.Create(It.IsAny <HighScore>()), Times.Once());
        }
Exemple #8
0
        public void Test_Get()
        {
            var mockService = new Mock <IHighScoresService>();
            var mockResult  = new HighScore()
            {
                Name = "Diana Prince", Score = 1
            };

            mockService.Setup(service => service.Read(1))
            .Returns(mockResult);

            var controller = new HighScoresController(mockService.Object);
            var result     = controller.Get("1");

            mockService.Verify(service => service.Read(1), Times.Once());

            Assert.IsNotNull(result);
            Assert.AreEqual(mockResult, result);

            result = controller.Get("2");

            Assert.IsNull(result);
        }
Exemple #9
0
 // Created by:
 // Hugo Kamps
 // S1084074
 public HighScoresController GetHighScoresController()
 {
     return(HighScoresController ?? (HighScoresController = new HighScoresController()));
 }