예제 #1
0
 public void TestEmptyThingRequest()
 {
     using (FakeServer fs = new FakeServer().Start())
     {
         JsonServiceClient client = new JsonServiceClient(FakeServer.BaseUri);
         ThingsRequest req = new ThingsRequest(new string[] { });
         IEnumerable<Thing> res = client.Get(req);
         Assert.AreEqual(0, res.Count());
     }
 }
예제 #2
0
 public void EmptyRequest()
 {
     using (FakeServer fs = new FakeServer().StartWithFakeRepos())
     {
         using(JsonServiceClient client = new JsonServiceClient(FakeServer.BaseUri)){
             ThingsRequest req = new ThingsRequest();
             var res = client.Get(req);
             Assert.AreEqual(0, res.Count());
         }
     }
 }
예제 #3
0
 public void TestThingRequest()
 {
     using (FakeServer fs = new FakeServer().Start())
     {
         Thing mike = new Thing("Mike");
         fs.fakeThingsRepos.Things.AddFirst(mike);
         JsonServiceClient client = new JsonServiceClient(FakeServer.BaseUri);
         ThingsRequest req = new ThingsRequest(new string[] { "Mike", "Mike", "Not Mike" });
         IEnumerable<Thing> res = client.Get(req);
         Assert.AreEqual(1, res.Count());
         Assert.That(res.First().Name, Is.EqualTo(mike.Name));
     }
 }
        public void AddNewThing()
        {
            using (FakeServer fs = new FakeServer().StartWithRealRepos())
            {
                using(JsonServiceClient client = new JsonServiceClient(FakeServer.BaseUri)){
                    var newThing = new Thing(){ Title="D", Description="Not C++", Quadrantid=Quadrant.Languages};
                    client.Post(newThing);
                    ThingsRequest req = new ThingsRequest(){Names = new string[] { "d" }};
                    IEnumerable<Thing> res = client.Get(req.UrlEncodeNames());

                    res.Count().ShouldBe(1);
                    res.First().Description.ShouldBe(newThing.Description);
                    res.First().Quadrantid.ShouldBe(newThing.Quadrantid);
                }
            }
        }
        public void UpdateThing()
        {
            using (FakeServer fs = new FakeServer().StartWithRealRepos())
            {
                using(JsonServiceClient client = new JsonServiceClient(FakeServer.BaseUri)){
                    var newThing = new Thing(){ Name="d", Title="D", Description="Not C++", Quadrantid=Quadrant.Languages};
                    newThing = fs.RealThingsRepos.StoreNew(newThing);

                    var updatedThing = new Thing() { Name = "d", Description = ", whatever" };
                    client.Put(updatedThing);

                    ThingsRequest req = new ThingsRequest(){Names = new string[] { "d" }};
                    IEnumerable<Thing> res = client.Get(req.UrlEncodeNames());

                    res.Count().ShouldBe(1);
                    Thing result = res.Single();
                    result.Quadrantid.ShouldBe(newThing.Quadrantid);
                    result.Description.ShouldBe(updatedThing.Description);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// handles any GET request for Things. 
        /// This will only retrieve data.
        /// </summary>
        /// <param name="request">Request.</param>
        public IEnumerable<Thing> Get(ThingsRequest request)
        {
            Console.WriteLine("Get received");

            logger.Debug("got request for things {}", this.RequestContext.AbsoluteUri);
            if (request.Names != null && request.Names.Length > 0)
            {
                return Repository.GetByName(request.Names);
            }

            IEnumerable<Thing> result = null;
            if (request.Quadrant.HasValue)
            {
                result = Repository.GetByQuadrant(request.Quadrant.Value);
            }
            if (request.Keywords != null && request.Keywords.Length > 0)
            {
                if (result == null)
                {
                    result = Repository.Search(request);
                }
                else
                {
                    result = result.Intersect(Repository.Search(request));
                }
            }
            else
            {
                if (result == null)
                {
                    // all request members empty -> search all.
                    result = Repository.GetAll();
                }
            }
            return result ?? new List<Thing>();
        }
 //TODO: make this perform properly
 public IEnumerable<Thing> Search(ThingsRequest request)
 {
     using (var connection = connectionFactory.Connect()) {
         return connection.Select<Thing>().Where( thing => thing.SoundsKindaLike(request.Keywords));
     }
 }
예제 #8
0
 public object Get(ThingsRequest request)
 {
     return Repository.GetByName (request.Names);
 }
 public IEnumerable<Thing> Search(ThingsRequest request)
 {
     return Things.Where( thing => thing.SoundsKindaLike(request.Keywords));
 }
예제 #10
0
        public void MultipleItemsInRequest()
        {
            using (FakeServer fs = new FakeServer().StartWithFakeRepos())
            {
                var things = fs.FakeThingsRepos.Things;
                things.AddFirst(new Thing(){Name="c#"});
                things.AddFirst(new Thing(){Name="mono"});
                things.AddFirst(new Thing(){Name="c++"});

                using(JsonServiceClient client = new JsonServiceClient(FakeServer.BaseUri)){
                    ThingsRequest req = new ThingsRequest(){Names = new string[] { "C#","mono" , "c++" }}; // notice that C# should be c#
                    IEnumerable<Thing> res = client.Get(req);

                    Assert.AreEqual(2, res.Count());
                }
            }
        }
예제 #11
0
        public void UpdateThingDescription()
        {
            using (FakeServer fs = new FakeServer().StartWithFakeRepos())
            {
                using(JsonServiceClient client = new JsonServiceClient(FakeServer.BaseUri)){
                    var newThing = new Thing(){ Name="d", Description="Not C++", Quadrantid=Quadrant.Languages};

                    fs.FakeThingsRepos.Things.AddLast(newThing);
                    var updatedThing = new Thing(){ Name="d", Description="Not C++, but kinda the same"};

                    client.Put(updatedThing);

                    ThingsRequest req = new ThingsRequest(){Names = new string[] { "d" }};
                    IEnumerable<Thing> res = client.Get(req.UrlEncodeNames());

                    Assert.AreEqual(1, res.Count());
                    Thing result = res.Single();
                    Assert.That(result.Quadrantid, Is.EqualTo(newThing.Quadrantid));
                    Assert.That(result.Description, Is.EqualTo(updatedThing.Description));
                }
            }
        }
예제 #12
0
        public void SingleRequesByNametWithSingleAnswer()
        {
            using (FakeServer fs = new FakeServer().StartWithFakeRepos())
            {
                Thing csharp = new Thing(){Name="c#"};
                fs.FakeThingsRepos.Things.AddFirst(csharp);

                using(JsonServiceClient client = new JsonServiceClient(FakeServer.BaseUri)){
                    ThingsRequest req = new ThingsRequest() { Names = new string[] { "VBS?", "Yes", csharp.Name } };
                    IEnumerable<Thing> res = client.Get(req);

                    Assert.AreEqual(1, res.Count());
                    Assert.That(res.First().Name, Is.EqualTo(csharp.Name));
                }
            }
        }
예제 #13
0
        public void SelectyByQuadrant()
        {
            using (FakeServer fs = new FakeServer().StartWithFakeRepos())
            {
                var things = fs.FakeThingsRepos.Things;
                things.AddFirst(new Thing(){Name="c#", Quadrantid=Quadrant.Languages});
                things.AddFirst(new Thing(){Name="mono", Quadrantid=Quadrant.Platforms});
                things.AddFirst(new Thing(){Name="c++", Quadrantid =Quadrant.Languages});

                using(JsonServiceClient client = new JsonServiceClient(FakeServer.BaseUri)){
                    ThingsRequest req = new ThingsRequest(){Quadrant = Quadrant.Languages};
                    IEnumerable<Thing> res = client.Get(req);

                    Assert.AreEqual(2, res.Count());
                }
            }
        }
예제 #14
0
        public void SelectByKeywordSearchAndQuadrant()
        {
            using (FakeServer fs = new FakeServer().StartWithFakeRepos())
            {
                var things = fs.FakeThingsRepos.Things;
                things.AddFirst(new Thing(){Name="c#", Quadrantid=Quadrant.Languages, Description="a Java like language from Microsoft" });
                things.AddFirst(new Thing(){Name="mono", Quadrantid=Quadrant.Platforms, Description="an application platform by Microsoft"});
                things.AddFirst(new Thing(){Name="c++", Quadrantid =Quadrant.Languages, Description="an ancient language"});

                using(JsonServiceClient client = new JsonServiceClient(FakeServer.BaseUri)){
                    ThingsRequest req = new ThingsRequest(){Keywords = new string[]{"microsoft"}, Quadrant = Quadrant.Languages};
                    IEnumerable<Thing> res = client.Get(req);

                    Assert.AreEqual(1, res.Count());
                }
            }
        }