Esempio n. 1
0
        public void GetAll_ValidScenario_ListOfAppiumProcesses()
        {
            var restClientMock       = new Mock <IRestClient>();
            var appiumRepositoryMock = new Mock <IRepository <AppiumProcess> >();
            var appiumController     = new AppiumController(restClientMock.Object, appiumRepositoryMock.Object, Logger);

            var appiumProcess1 = new AppiumProcess("123", "1111", "1112", 1, "1113", "1114");
            var appiumProcess2 = new AppiumProcess("123", "1111", "1112", 1, "1113", "1114");

            var appiumProcesses = new List <AppiumProcess>
            {
                appiumProcess1,
                appiumProcess2
            };

            appiumRepositoryMock.Setup(a => a.GetAll()).Returns(appiumProcesses);

            var result = appiumController.GetAll();

            var viewResult = Assert.IsType <List <AppiumProcess> >(result);

            Assert.Equal(2, result.Count());
            Assert.Contains(appiumProcess1, viewResult);
            Assert.Contains(appiumProcess2, viewResult);
        }
Esempio n. 2
0
        public void Create_NullRequest_BadRequest()
        {
            var restClientMock       = new Mock <IRestClient>();
            var appiumRepositoryMock = new Mock <IRepository <AppiumProcess> >();
            var appiumController     = new AppiumController(restClientMock.Object, appiumRepositoryMock.Object, Logger);

            var result = appiumController.Create(null);

            Assert.IsType <BadRequestObjectResult>(result);
        }
Esempio n. 3
0
        public void GetById_EmptyRequest_BadRequest()
        {
            var restClientMock       = new Mock <IRestClient>();
            var appiumRepositoryMock = new Mock <IRepository <AppiumProcess> >();
            var appiumController     = new AppiumController(restClientMock.Object, appiumRepositoryMock.Object, Logger);

            var result = appiumController.GetById(string.Empty);

            Assert.IsType <BadRequestObjectResult>(result);
        }
Esempio n. 4
0
        public void Create_InvalidDataInRequest_BadRequest(string deviceId, string appiumPort,
                                                           string appiumBootstrapPort, int appiumPid,
                                                           string webkitDebugProxyPort, string wdaLocalPort)
        {
            var restClientMock       = new Mock <IRestClient>();
            var appiumRepositoryMock = new Mock <IRepository <AppiumProcess> >();
            var appiumController     = new AppiumController(restClientMock.Object, appiumRepositoryMock.Object, Logger);

            var appiumProcess = new AppiumProcess(deviceId, appiumPort, appiumBootstrapPort, appiumPid,
                                                  webkitDebugProxyPort, wdaLocalPort);

            var result = appiumController.Create(appiumProcess);

            Assert.IsType <BadRequestObjectResult>(result);
        }
Esempio n. 5
0
        public void GetById_AppiumProcessNotInDatabase_NotFound()
        {
            var restClientMock       = new Mock <IRestClient>();
            var appiumRepositoryMock = new Mock <IRepository <AppiumProcess> >();

            var appiumProcess = new AppiumProcess("123", "1111", "1112", 1, "1113", "1114");

            appiumRepositoryMock.Setup(a => a.Find(It.IsAny <string>())).Returns((AppiumProcess)null);

            var appiumController = new AppiumController(restClientMock.Object, appiumRepositoryMock.Object, Logger);

            var result = appiumController.GetById("123");

            Assert.IsType <NotFoundObjectResult>(result);
        }
Esempio n. 6
0
        public void GetAll_NoAppiumProcesses_EmptyResult()
        {
            var restClientMock       = new Mock <IRestClient>();
            var appiumRepositoryMock = new Mock <IRepository <AppiumProcess> >();
            var appiumController     = new AppiumController(restClientMock.Object, appiumRepositoryMock.Object, Logger);


            appiumRepositoryMock.Setup(a => a.GetAll()).Returns(new List <AppiumProcess>());

            var result = appiumController.GetAll();

            var viewResult = Assert.IsType <List <AppiumProcess> >(result);

            Assert.Empty(viewResult);
        }
Esempio n. 7
0
        public void Delete_ValidScenario_Ok()
        {
            var restClientMock       = new Mock <IRestClient>();
            var appiumRepositoryMock = new Mock <IRepository <AppiumProcess> >();

            var appiumProcess = new AppiumProcess("123", "1111", "1112", 1, "1113", "1114");

            appiumRepositoryMock.Setup(a => a.Find(It.IsAny <string>())).Returns(appiumProcess);

            var appiumController = new AppiumController(restClientMock.Object, appiumRepositoryMock.Object, Logger);

            var result = appiumController.Delete("123");

            Assert.IsType <OkResult>(result);
        }
Esempio n. 8
0
        public void Create_AlreadyRunningAppiumForDeviceId_ErrorStatusCode()
        {
            var restClientMock       = new Mock <IRestClient>();
            var appiumRepositoryMock = new Mock <IRepository <AppiumProcess> >();

            appiumRepositoryMock.Setup(a => a.Find(It.IsAny <string>())).Returns(new AppiumProcess());

            var appiumController = new AppiumController(restClientMock.Object, appiumRepositoryMock.Object, Logger);

            var appiumProcess = new AppiumProcess("123", "1111", "1112", 1, "1113", "1114");
            var result        = appiumController.Create(appiumProcess);

            var viewResult = Assert.IsType <ObjectResult>(result);

            Assert.Equal(409, viewResult.StatusCode);
        }
Esempio n. 9
0
        public void Create_ValidScenario_CreatedAtRoute()
        {
            var restClientMock       = new Mock <IRestClient>();
            var appiumRepositoryMock = new Mock <IRepository <AppiumProcess> >();

            appiumRepositoryMock.Setup(a => a.Find(It.IsAny <string>())).Returns((AppiumProcess)null);

            var appiumController = new AppiumController(restClientMock.Object, appiumRepositoryMock.Object, Logger);

            var appiumProcess = new AppiumProcess("123", "1111", "1112", 1, "1113", "1114");
            var result        = appiumController.Create(appiumProcess);

            var viewResult = Assert.IsType <CreatedAtRouteResult>(result);

            Assert.Equal(appiumProcess, viewResult.Value);
        }
Esempio n. 10
0
        public void Create_AddThrowsAnException_ErrorStatusCode()
        {
            var restClientMock       = new Mock <IRestClient>();
            var appiumRepositoryMock = new Mock <IRepository <AppiumProcess> >();

            appiumRepositoryMock.Setup(a => a.Find(It.IsAny <string>())).Returns((AppiumProcess)null);
            appiumRepositoryMock.Setup(a => a.Add(It.IsAny <AppiumProcess>())).Throws(new Exception());

            var appiumController = new AppiumController(restClientMock.Object, appiumRepositoryMock.Object, Logger);

            var appiumProcess = new AppiumProcess("123", "1111", "1112", 1, "1113", "1114");
            var result        = appiumController.Create(appiumProcess);

            var viewResult = Assert.IsType <ObjectResult>(result);

            Assert.Equal(500, viewResult.StatusCode);
        }