public void GetAirportInformationByAirportCodeWhenParamIsValid()
        {
            Init();

            const string airportCode = "AMS";

            AirportDto airportDto = new AirportDto
            {
                AirportCode = "AMS",
                CityOrAirportName = "AMSTERDAM SCHIPHOL",
                Country = "Netherlands",
                CountryCode = "461",
                LatitudeDegree = "52",
                LongitudeDegree = "4"
            };

            m_ServiceDaoMock.GetAirportInformationByAirportCode(airportCode).Returns(response);

            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(response);

            XmlNodeList nodeList = xmlDocument.SelectNodes("NewDataSet/Table");

            if (nodeList != null)
            {
                string serializeObject = nodeList[0].SerializeObject();
                Airport deserializeObject = (Airport)serializeObject.DeserializeObject<Airport>();

                MapToAirport.MapFromObjectToAirport(deserializeObject);
                
                AirportManager airportManager = new AirportManager(m_ServiceDaoMock, m_CouchbaseDaoMock);
                airportManager.GetAirportInformationByAirportCode(airportCode).ShouldBeEquivalentTo(airportDto);
            }
        }
        public void SearchWhenGetFromService()
        {
            Init();
            string code = "AMS";

            AirportDto airportDto = new AirportDto
            {
                AirportCode = "AMS",
                CityOrAirportName = "Amsterdam",
                Country = "Netherlands",
                CountryCode = "461",
                LatitudeDegree = "52",
                LongitudeDegree = "4"
            };

            m_AirportControllerHandlerMock.GetAirportInformationByAirportCode(code).Returns(airportDto);
            m_AirportControllerHandlerMock.AddAirportInformationToCouchbase(airportDto);

            AirportViewModel airportViewModel = new AirportViewModel
            {
                AirportCode = airportDto.AirportCode,
                CityOrAirportName = airportDto.CityOrAirportName,
                Country = airportDto.Country,
                CountryCode = airportDto.CountryCode,
                LatitudeDegree = airportDto.LatitudeDegree,
                LongitudeDegree = airportDto.LongitudeDegree
            };

            AirportController airportController = new AirportController(m_AirportControllerHandlerMock);

            var result = airportController.Search(code) as ActionResult;

            Assert.IsNotNull(airportViewModel);
            Assert.IsNotNull(result);
        }
        /// <summary>
        /// Adds the airport information to couchbase.
        /// </summary>
        /// <param name="airportDto">The airport dto.</param>
        /// <returns></returns>
        public bool AddAirportInformationToCouchbase(AirportDto airportDto)
        {
            bool result = default (bool);
            
            if (!airportDto.IsNullOrDefault())
            {
                using (var defaultBucket = m_Cluster.OpenBucket())
                {
                    Document<AirportDto> document = new Document<AirportDto>
                    {
                        Id = airportDto.AirportCode,
                        Content = new AirportDto
                        {
                            AirportCode = airportDto.AirportCode,
                            CityOrAirportName = airportDto.CityOrAirportName,
                            Country = airportDto.Country,
                            CountryCode = airportDto.CountryCode,
                            LatitudeDegree = airportDto.LatitudeDegree,
                            LongitudeDegree = airportDto.LongitudeDegree
                        }
                    };

                    IDocumentResult<AirportDto> upsert = defaultBucket.Upsert(document);
                    if (upsert.Success)
                    {
                        result = true;
                    }
                }     
            }
            return result;
        }
        /// <summary>
        /// Gets the airport information from couchbase by airport code.
        /// </summary>
        /// <param name="airportCode">The airport code.</param>
        /// <returns></returns>
        public AirportDto GetAirportInformationFromCouchbaseByAirportCode(string airportCode)
        {
            if (!string.IsNullOrWhiteSpace(airportCode))
            {
                using (var defaultBucket = m_Cluster.OpenBucket())
                {
                    IDocumentResult<AirportDto> document = defaultBucket.GetDocument<AirportDto>(airportCode);

                    if (!document.IsNullOrDefault() && !document.Document.IsNullOrDefault())
                    {
                        AirportDto content = document.Document.Content;

                        AirportDto airportDto = new AirportDto
                        {
                            AirportCode = content.AirportCode,
                            CityOrAirportName = content.CityOrAirportName,
                            Country = content.Country,
                            CountryCode = content.CountryCode,
                            LatitudeDegree = content.LatitudeDegree,
                            LongitudeDegree = content.LongitudeDegree
                        };

                        return airportDto;      
                    }
                }    
            }
            
            return default(AirportDto);
        }
        /// <summary>
        /// Adds the airport information to couchbase.
        /// </summary>
        /// <param name="airportDto">The airport dto.</param>
        /// <returns></returns>
        public bool AddAirportInformationToCouchbase(AirportDto airportDto)
        {
            if (!airportDto.IsNullOrDefault())
            {
                bool result = m_CouchbaseDao.AddAirportInformationToCouchbase(airportDto);
                return result;                
            }

            return default(bool);
        }
        public static AirportDto MapFromObjectToAirport(Airport airport)
        {
            if (!airport.IsNullOrDefault())
            {
                AirportDto airportDto = new AirportDto
                {
                    AirportCode = airport.AirportCode,
                    Country = airport.Country,
                    CountryCode = airport.CountryCode,
                    CityOrAirportName = airport.CityOrAirportName,
                    LatitudeDegree = airport.LatitudeDegree,
                    LongitudeDegree = airport.LongitudeDegree
                };

                return airportDto;
            }

            return null;
        }
        public void GetAirportInformationFromCouchbaseByAirportCodeWhenParamIsValid()
        {
            Init();

            string airportCode = "AMS";

            AirportDto airportDto = new AirportDto
            {
                AirportCode = "AMS",
                CityOrAirportName = "Amsterdam",
                Country = "Netherlands",
                CountryCode = "461",
                LatitudeDegree = "52",
                LongitudeDegree = "4"
            };

            m_AirportManagerMock.GetAirportInformationFromCouchbaseByAirportCode(airportCode).Returns(airportDto);

            AirportControllerHandler airportControllerHandler = new AirportControllerHandler(m_AirportManagerMock);
            airportControllerHandler.GetAirportInformationFromCouchbaseByAirportCode(airportCode).ShouldBeEquivalentTo(airportDto);
        }
        public void AddAirportInformationToCouchbaseWhenParamIsValid()
        {
            Init();

            AirportDto airportDto = new AirportDto
            {
                AirportCode = "AMS",
                CityOrAirportName = "Amsterdam",
                Country = "Netherlands",
                CountryCode = "461",
                LatitudeDegree = "52",
                LongitudeDegree = "4"
            };

            var expected = m_CouchbaseDaoMock.AddAirportInformationToCouchbase(airportDto);

            AirportManager airportManager = new AirportManager(m_ServiceDaoMock, m_CouchbaseDaoMock);
            var actual = airportManager.AddAirportInformationToCouchbase(airportDto);

            Assert.AreEqual(expected, actual);
        }
        public void AddAirportInformationToCouchbaseWhenParamIsValid()
        {
            Init();

            AirportDto airportDto = new AirportDto
            {
                AirportCode = "AMS",
                CityOrAirportName = "Amsterdam",
                Country = "Netherlands",
                CountryCode = "461",
                LatitudeDegree = "52",
                LongitudeDegree = "4"
            };

            bool actual = m_AirportManagerMock.AddAirportInformationToCouchbase(airportDto);

            AirportControllerHandler airportControllerHandler = new AirportControllerHandler(m_AirportManagerMock);
            bool excepted = airportControllerHandler.AddAirportInformationToCouchbase(airportDto);

            Assert.AreEqual(excepted,actual);
        }