Exemplo n.º 1
0
 public void Post()
 {
     var mocks = new MockRepository();
     var reqFactory = mocks.StrictMock<IHttpWebRequestFactory>();
     var request = mocks.DynamicMock<IHttpWebRequest>();
     var response = mocks.DynamicMock<IHttpWebResponse>();
     With.Mocks(mocks).Expecting(delegate {
         Expect.Call(request.GetRequestStream())
             .Repeat.Once()
             .Return(new MemoryStream());
         Expect.Call(reqFactory.Create(new Uri("https://pepe")))
             .Repeat.Once()
             .Return(request);
         request.Method = HttpWebRequestMethod.POST;
         LastCall.On(request).Repeat.Once();
         Expect.Call(request.GetResponse())
             .Repeat.Once()
             .Return(response);
         Expect.Call(response.Headers)
             .Repeat.Any()
             .Return(new WebHeaderCollection());
         Expect.Call(response.GetResponseStream())
             .Repeat.Once()
             .Return(new MemoryStream());
     }).Verify(delegate {
         var conn = new SolrConnection("https://pepe", reqFactory);
         conn.Post("", "");
     });
 }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {

            var connection = new SolrConnection(solrURL);

            Startup.Init<Product>(connection);

            
            var p = new Product
            {
                Id = "SP2514N",
                Manufacturer = "Samsung Electronics Co. Ltd.",
                Categories = new[]
                {
                    "electronics",
                    "hard drive333333333111",
                },
                Price = 92,
                InStock = true,
            };

            var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
            solr.Add(p);
            solr.Commit();



            p = new Product
            {
                Id = "SP2514N2",
                Manufacturer = "AAA Electronics Co. Ltd.",
                Categories = new[]
                {
                    "electronics",
                    "hard 777777777",
                },
                Price = 92,
                InStock = true,
            };

            
            solr.Add(p);
            solr.Commit();
            

            var results = solr.Query(new SolrQueryByField("id", "SP2514N"));
            
            Console.WriteLine(results[0].Price);

            

            var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            
            string archiveFolder = Path.Combine(baseDirectory, "docs");


            try
            {
                solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
                solr.Delete(SolrQuery.All);
                connection = (SolrConnection) ServiceLocator.Current.GetInstance<ISolrConnection>();
                foreach (var file in Directory.GetFiles(archiveFolder, "*.xml"))
                {
                    connection.Post("/update", File.ReadAllText(file, Encoding.UTF8));
                }
                solr.Commit();
                solr.BuildSpellCheckDictionary();
            }
            catch (SolrConnectionException e)
            {
                throw new Exception(string.Format("Couldn't connect to Solr. Please make sure that Solr is running on '{0}' or change the address in your web.config, then restart the application.", solrURL), e);
            }

        }
Exemplo n.º 3
0
 public void InvalidHostPost_ShouldThrowException()
 {
     var mocks = new MockRepository();
     var reqFactory = mocks.StrictMock<IHttpWebRequestFactory>();
     var request = mocks.DynamicMock<IHttpWebRequest>();
     With.Mocks(mocks).Expecting(delegate {
         Expect.Call(request.GetRequestStream())
             .Repeat.Once()
             .Throw(new WebException());
         Expect.Call(reqFactory.Create(new Uri("http://lalala:12345/update")))
             .IgnoreArguments()
             .Repeat.Once()
             .Return(request);
     }).Verify(delegate {
         var conn = new SolrConnection("http://lalala:12345", reqFactory);
         conn.Post("/update", "");
     });
 }
Exemplo n.º 4
0
		public void InvalidHostPost_ShouldThrowException() {
		    var reqFactory = new Mocks.HttpWebRequestFactory {
		        create = _ => new Mocks.HttpWebRequest {
		            getRequestStream = () => { throw new WebException(); },
                    requestUri = () => new Uri("http://lalala:12345/update"),
		        }
		    };
            var conn = new SolrConnection("http://lalala:12345") { HttpWebRequestFactory = reqFactory };
            conn.Post("/update", "");
		}