Exemplo n.º 1
0
        public void SetUp()
        {
            cachingServiceMoq = new Mock <IAnteeoCaching>();
            authServiceMoq    = new Mock <AuthenticationBase>();
            hotelServiceMoq   = new Mock <IHotelAndLocation>();
            configServiceMoq  = new Mock <IConfig>();

            hotelServiceMoq.Setup(p => p.TmsToken).Returns(It.IsAny <string>());
            hotelServiceMoq.Setup(p => p.Ping(It.IsAny <string>(), It.IsAny <RequestMessage>(), ModeType.Request));
            hotelServiceMoq.Setup(
                p =>
                p.GetAllHotelAndLocationData(It.IsAny <string>(), new Dictionary <string, string>(),
                                             It.IsAny <string>())).Returns(AnteeoXmlHelper.ParseFromXmlString(AnteeoFakeCach.xmlCacheValue).ToArray());

            cachingServiceMoq.Setup(p => p.GetCacheObject()).Returns(new Cache());
            cachingServiceMoq.Setup(p => p.SetCacheObject(new Cache()));
            cachingServiceMoq.Setup(p => p.GetFromCache(It.IsAny <string>())).Returns("Token");
            cachingServiceMoq.Setup(p => p.StoreIntoCache(It.IsAny <string>(), It.IsAny <object>(), It.IsAny <int>()));

            authServiceMoq.Setup(p => p.ComputeExpirationTime()).Returns(It.Is <DateTime>(p => p == DateTime.Now.AddMinutes(4)));
            authServiceMoq.Setup(p => p.GetToken(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(It.IsAny <string>());

            configServiceMoq.Setup(p => p.AuthUrl).Returns(It.IsAny <string>());
            configServiceMoq.Setup(p => p.CachingDuration).Returns(It.IsAny <int>().ToString());
            configServiceMoq.Setup(p => p.HotelServiceEndpointUrl).Returns(It.IsAny <string>());
            configServiceMoq.Setup(p => p.Password).Returns(It.IsAny <string>());
            configServiceMoq.Setup(p => p.UserName).Returns(It.IsAny <string>());
        }
Exemplo n.º 2
0
        public void Test_AnteeoXMLEngine_ParseFromXmlString_Passes_Parsing()
        {
            var regions = AnteeoXmlHelper.ParseFromXmlString(xml);

            var region1         = regions[0];
            var region2         = regions[1];
            var countriesInReg1 = region1.Countries;
            var countriesInReg2 = region2.Countries;
            var resortsInReg1   = countriesInReg1[0].Resorts;
            var resortsInReg2   = countriesInReg2[1].Resorts;
            var hotelsInReg1    = resortsInReg1[0].Hotels;
            var hotelsInReg2    = resortsInReg1[1].Hotels;
            var airportsInReg1  = resortsInReg2[0].Airports;
            var airportsInReg2  = resortsInReg2[1].Airports;


            //Regions
            Assert.AreEqual(regions.Count, 2);
            Assert.IsNotNull(region1.Name);
            Assert.IsNotNull(region2.Name);
            Assert.IsNotNull(region1.RegionCode);


            //Countries
            Assert.AreEqual(countriesInReg1.Count, 2);
            Assert.AreEqual(countriesInReg2.Count, 2);
            Assert.IsNotNull(countriesInReg1[0].Name);
            Assert.IsNotNull(countriesInReg2[1].Name);
            Assert.IsNotNull(countriesInReg1[0].CountryCode);
            Assert.IsNotNull(countriesInReg2[1].CountryCode);

            //Resorts

            Assert.AreEqual(resortsInReg1.Count, 2);
            Assert.AreEqual(resortsInReg2.Count, 2);
            Assert.IsNotNull(resortsInReg1[0].Name);
            Assert.IsNotNull(resortsInReg2[1].Name);
            Assert.IsNotNull(resortsInReg1[0].ResortCode);
            Assert.IsNotNull(resortsInReg2[1].ResortCode);


            //Hotels

            Assert.AreEqual(hotelsInReg1.Count, 2);
            Assert.AreEqual(hotelsInReg2.Count, 2);
            Assert.IsNotNull(hotelsInReg1[0].Name);
            Assert.IsNotNull(hotelsInReg2[1].Name);
            Assert.IsNotNull(hotelsInReg1[0].HotelCode);
            Assert.IsNotNull(hotelsInReg2[1].HotelCode);


            //Airports

            Assert.AreEqual(airportsInReg1.Count, 2);
            Assert.AreEqual(airportsInReg2.Count, 2);
            Assert.IsNotNull(airportsInReg1[0].Name);
            Assert.IsNotNull(airportsInReg2[1].Name);
            Assert.IsNotNull(airportsInReg1[0].AirportCode);
            Assert.IsNotNull(airportsInReg1[1].AirportCode);
        }
Exemplo n.º 3
0
        private ResponseMessage GetResponseMessage(HttpWebResponse response, ModeType modeType)
        {
            using (var stream = response.GetResponseStream())
            {
                var streamReader = new StreamReader(stream);
                try
                {
                    dynamic result = null;

                    switch (modeType)
                    {
                    case ModeType.Ping:
                        result = streamReader.ReadToEnd();
                        return(new ResponseMessage {
                            Content = new List <dynamic> {
                                true
                            }.ToArray()
                        });

                    case ModeType.Request:
                        var responseMessage = new ResponseMessage();
                        var xml             = streamReader.ReadToEnd();
                        result = AnteeoXmlHelper.ParseFromXmlString(xml);
                        responseMessage.Content = result.ToArray();
                        return(responseMessage);

                    case ModeType.Authentication:
                        result = streamReader.ReadToEnd();
                        return(new ResponseMessage {
                            Content = new List <dynamic> {
                                result
                            }.ToArray()
                        });
                    }
                }
                catch (Exception e)
                {
                    return(new ResponseMessage {
                        Content = new List <dynamic> {
                            string.Format("An error Occured!!: {0}", e.Message), e.StackTrace
                        }.ToArray()
                    });
                }
                return(new ResponseMessage {
                    Content = new[] { "No Service Mode Stated!!" }
                });
            }
        }