Esempio n. 1
0
        public void GetListStarShipsAsync_WrongMethod()
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            if (config.AppSettings.Settings["baseURL"] != null)
            {
                config.AppSettings.Settings.Remove("baseURL");
            }
            config.AppSettings.Settings.Add("baseURL", "https://swapi.co/api/");

            if (config.AppSettings.Settings["getMethodName"] != null)
            {
                config.AppSettings.Settings.Remove("getMethodName");
            }
            config.AppSettings.Settings.Add("getMethodName", "noexist1/");

            config.Save(ConfigurationSaveMode.Modified, true);
            ConfigurationManager.RefreshSection("appSettings");

            IStarShipsOperations swAPI = GetNewFactoryStarWarsAPI();

            Assert.That(() => {
                IList <StarShip> listStarShip = swAPI.GetListStarShipsAsync().Result;
            }, Throws.Exception);
        }
Esempio n. 2
0
        public void GetOutputData_EmptyListStarShips()
        {
            IStarShipsOperations swAPI = GetNewFactoryStarWarsAPI();

            Assert.That(() => {
                swAPI.GetOutputData(new List <StarShip>(), 10).ToList();
            },
                        Throws.InstanceOf <StarShipException>());
        }
Esempio n. 3
0
        public void GetAmountStopValue_ValidCalc()
        {
            IStarShipsOperations swAPI = GetNewFactoryStarWarsAPI();

            Assert.AreEqual(swAPI.GetAmountStopValue(10, 10), 1);
            Assert.AreEqual(swAPI.GetAmountStopValue(20, 10), 2);
            Assert.AreEqual(swAPI.GetAmountStopValue(22, 10), 3);
            Assert.AreEqual(swAPI.GetAmountStopValue(25, 10), 3);
            Assert.AreEqual(swAPI.GetAmountStopValue(2, 10), 1);
            Assert.AreEqual(swAPI.GetAmountStopValue(69, 5), 14);
            Assert.AreEqual(swAPI.GetAmountStopValue(0, 10), 0);
        }
Esempio n. 4
0
        public void GetOutputData_ZeroMGLT()
        {
            IList <StarShip> listStarShip = new List <StarShip>()
            {
                new StarShip()
                {
                    name = "1", model = "M1", MGLT = "15"
                }
            };

            IStarShipsOperations swAPI = GetNewFactoryStarWarsAPI();

            Assert.Throws <StarShipException>(() => swAPI.GetOutputData(listStarShip, 0).ToList());
        }
Esempio n. 5
0
        public void GetOutputData_ExpectedOutput()
        {
            IList <StarShip> listStarShips = new List <StarShip>()
            {
                new StarShip()
                {
                    name = "1", model = "M1", MGLT = "15"
                },
                new StarShip()
                {
                    name = "2", model = "M2", MGLT = "10"
                }
            };

            IStarShipsOperations swAPI        = GetNewFactoryStarWarsAPI();
            IEnumerable <string> outputValues = swAPI.GetOutputData(listStarShips, 15);

            Assert.AreEqual(outputValues.First(), "1: 1");
            Assert.AreEqual(outputValues.Last(), "2: 2");
        }
Esempio n. 6
0
        public void GetListStarShipsAsync_ValidAccess()
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            if (config.AppSettings.Settings["baseURL"] != null)
            {
                config.AppSettings.Settings.Remove("baseURL");
            }
            config.AppSettings.Settings.Add("baseURL", "https://swapi.co/api/");

            if (config.AppSettings.Settings["getMethodName"] != null)
            {
                config.AppSettings.Settings.Remove("getMethodName");
            }
            config.AppSettings.Settings.Add("getMethodName", "starships/");

            config.Save(ConfigurationSaveMode.Modified, true);
            ConfigurationManager.RefreshSection("appSettings");

            IStarShipsOperations swAPI        = GetNewFactoryStarWarsAPI();
            IList <StarShip>     listStarShip = swAPI.GetListStarShipsAsync().Result;

            Assert.Pass();
        }
Esempio n. 7
0
        public void GetOutputData_NullListStarShips()
        {
            IStarShipsOperations swAPI = GetNewFactoryStarWarsAPI();

            Assert.Throws <StarShipException>(() => swAPI.GetOutputData(null, 10).ToList());
        }