Exemple #1
0
        public OutContent ProcessRequest <T>(ArraySegment <byte> content, SearchDelegate <T> searchHandler, T param)
        {
            try
            {
                List <DirectorySearchItem> foundItems = null;
                bool moreAvailable = false;

                var request = DirectorySearchRequest.Parse(CreateXmlReader(content));

                int maxResults = Math.Min(MaxResults, request.MaxResults);

                foreach (var searchTerm in request.SearchTerms)
                {
                    const string testPrefix = @"TESTJDOE";
                    if (searchTerm.Key == @"givenName" && string.Compare(searchTerm.Value, 0, testPrefix, 0, testPrefix.Length) == 0)
                    {
                        int requestedResults;
                        if (int.TryParse(searchTerm.Value.Substring(testPrefix.Length), out requestedResults))
                        {
                            foundItems = new List <DirectorySearchItem>();

                            for (int i = 0; i < maxResults && i < requestedResults; i++)
                            {
                                foundItems.Add(new DirectorySearchItem()
                                {
                                    Uri         = string.Format(@"jdoe{0}@officesip.local", i),
                                    DisplayName = string.Format(@"Joe Doe {0}", i),
                                    Title       = string.Format(@"Title {0}", i),
                                    Office      = string.Format(@"#{0}", i),
                                    Phone       = string.Format(@"+1 111 111 1111 ext.{0}", i),
                                    Company     = string.Format(@"Company #{0}", i),
                                    City        = string.Format(@"City{0}", i),
                                    State       = string.Format(@"State{0}", i),
                                    Country     = string.Format(@"Country{0}", i),
                                    Email       = string.Format(@"jdoe{0}@officesip.com", i),
                                });
                            }

                            moreAvailable = (maxResults < requestedResults);
                        }
                        break;
                    }
                }

                DirectorySearchResponse response = null;

                if (foundItems == null && searchHandler != null)
                {
                    response = searchHandler(this, request, param);
                }
                else
                {
                    response = new DirectorySearchResponse()
                    {
                        Items         = foundItems,
                        MoreAvailable = moreAvailable,
                    };
                }

                return(new OutContent(response, new object()));
            }
            catch (Exception)
            {
                return(new OutContent(
                           new DirectorySearchResponse()
                {
                    Items = new List <DirectorySearchItem>(),
                },
                           new object()));
            }
        }
        public void GenerateTest()
        {
            string xml1 = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\"><SOAP-ENV:Body><m:directorySearch><m:moreAvailable>false</m:moreAvailable><m:returned>0</m:returned><m:value m:href=\"#rows\" /></m:directorySearch><m:Array m:id=\"rows\" /></SOAP-ENV:Body></SOAP-ENV:Envelope>";
            string xml2 = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\"><SOAP-ENV:Body><m:directorySearch><m:moreAvailable>false</m:moreAvailable><m:returned>2</m:returned><m:value m:href=\"#rows\" /></m:directorySearch><m:Array m:id=\"rows\"><m:row m:uri=\"uri1\" m:displayName=\"name2\" m:title=\"title3\" m:office=\"office4\" m:phone=\"phone5\" m:company=\"company6\" m:city=\"city7\" m:state=\"state8\" m:country=\"country9\" m:email=\"email10\" /><m:row m:uri=\"uri21\" m:displayName=\"name22\" m:title=\"title23\" m:office=\"office24\" m:phone=\"phone25\" m:company=\"company26\" m:city=\"city27\" m:state=\"state28\" m:country=\"country29\" m:email=\"email210\" /></m:Array></SOAP-ENV:Body></SOAP-ENV:Envelope>";
            string xml3 = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:m=\"http://schemas.microsoft.com/winrtc/2002/11/sip\"><SOAP-ENV:Body><m:directorySearch><m:moreAvailable>false</m:moreAvailable><m:returned>1</m:returned><m:value m:href=\"#rows\" /></m:directorySearch><m:Array m:id=\"rows\"><m:row m:uri=\"\" m:displayName=\"\" m:title=\"\" m:office=\"\" m:phone=\"\" m:company=\"\" m:city=\"\" m:state=\"\" m:country=\"\" m:email=\"\" /></m:Array></SOAP-ENV:Body></SOAP-ENV:Envelope>";

            DirectorySearchResponse response0 = new DirectorySearchResponse();

            DirectorySearchResponse response1 = new DirectorySearchResponse()
            {
                Items = new List <DirectorySearchItem>(),
            };

            Assert.AreEqual(xml1.Length, GenerateXml(response0).GetEqualLength(xml1));
            Assert.AreEqual(xml1.Length, GenerateXml(response1).GetEqualLength(xml1));

            DirectorySearchResponse response2 = new DirectorySearchResponse()
            {
                Items = new List <DirectorySearchItem>()
                {
                    new DirectorySearchItem()
                    {
                        Uri         = @"uri1",
                        DisplayName = @"name2",
                        Title       = @"title3",
                        Office      = @"office4",
                        Phone       = @"phone5",
                        Company     = @"company6",
                        City        = @"city7",
                        State       = @"state8",
                        Country     = @"country9",
                        Email       = @"email10",
                    },
                    new DirectorySearchItem()
                    {
                        Uri         = @"uri21",
                        DisplayName = @"name22",
                        Title       = @"title23",
                        Office      = @"office24",
                        Phone       = @"phone25",
                        Company     = @"company26",
                        City        = @"city27",
                        State       = @"state28",
                        Country     = @"country29",
                        Email       = @"email210",
                    },
                },
            };

            Assert.AreEqual(xml2.Length, GenerateXml(response2).GetEqualLength(xml2));

            DirectorySearchResponse response3 = new DirectorySearchResponse()
            {
                Items = new List <DirectorySearchItem>()
                {
                    new DirectorySearchItem(),
                },
            };

            Assert.AreEqual(xml3.Length, GenerateXml(response3).GetEqualLength(xml3));
        }