예제 #1
0
        private Response _CreateMessage(string boxName, string id, Message msg)
        {
            Response ret;

            using (var db = RavenDbManager.OpenSession())
            {
                var box = db.Query <Box>().Where(x => x.Name == boxName).FirstOrDefault();

                if (box == null)
                {
                    ret = new ActionFailedResponse("Box doesn't exist", HttpStatusCode.NotFound);
                }
                else
                {
                    if (box.Messages.ContainsKey(id))
                    {
                        ret = new ActionFailedResponse("Message ID Already Exists", HttpStatusCode.Conflict);
                    }
                    else
                    {
                        box.Messages.Add(id, msg);
                        db.SaveChanges();
                        ret = new SimplifiedJsonResponse(new { Result = "Message Added" });
                    }
                }
            }

            return(ret);
        }
예제 #2
0
        private Response _GetMessage(string boxName, string id)
        {
            Response ret;

            using (var db = RavenDbManager.OpenSession())
            {
                var box = db.Query <Box>().Where(x => x.Name == boxName).FirstOrDefault();

                if (box == null)
                {
                    ret = new ActionFailedResponse("Box doesn't exist", HttpStatusCode.NotFound);
                }
                else
                {
                    if (!box.Messages.ContainsKey(id))
                    {
                        ret = new ActionFailedResponse("Message doesn't exist", HttpStatusCode.NotFound);
                    }
                    else
                    {
                        ret = new SimplifiedJsonResponse(new { box.Messages[id].Body });
                    }
                }
            }

            return(ret);
        }
    public void CreateCreatesDatabase()
    {
      var manager = new RavenDbManager {Description = new DbDescription {ConnectionInfo = GlobalTest.DbManager1.Description.ConnectionInfo}};

      manager.Create();

      var server = manager.CreateServer();
      Assert.IsTrue(server.DatabaseExists(manager.Description.ConnectionInfo.DatabaseName));
    }
예제 #4
0
    private void InvalidParameterTests(Action<RavenDbManager> action)
    {
      var manager = new RavenDbManager();
      Assert.That(() => action(manager), Throws.ArgumentException.With.Property("ParamName").EqualTo("Description"));

      manager = new RavenDbManager {Description = new DbDescription()};
      Assert.That(() => action(manager), Throws.ArgumentException.With.Property("ParamName").EqualTo("Description.ConnectionInfo"));

      manager = new RavenDbManager {Description = new DbDescription {ConnectionInfo = new DbConnectionInfo()}};
      Assert.That(() => action(manager), Throws.ArgumentException.With.Property("ParamName").EqualTo("Description.ConnectionInfo.ConnectionString"));
    }
예제 #5
0
        private Response _GetBoxList()
        {
            Dictionary <string, string> ret;

            using (var db = RavenDbManager.OpenSession())
            {
                var urlBase = Request.Url.ToUri() + "/";
                var data    = db.Query <Box>().ToList();
                ret = data.ToDictionary(x => x.Name, x => urlBase + x.Name);
            }

            return(new SimplifiedJsonResponse(ret));
        }
    public void CreateWithLiteralSchemaCreatesSchema()
    {
      var manager = new RavenDbManager
                      {
                        Description = new DbDescription
                                        {
                                          ConnectionInfo = GlobalTest.DbManager1.Description.ConnectionInfo,
                                          Schemas = new List<DbScript> {new DbScript {ScriptType = ScriptType.Literal, ScriptValue = LiteralSchema}}
                                        }
                      };

      manager.Create();

      var db = manager.CreateDatabase();

      var result = db.GetCollectionNames().FirstOrDefault(c => c == "c1");
      Assert.IsNotNull(result);
    }
    public void SeedFromLiteralSeedsDatabase()
    {
      var manager = new RavenDbManager
                    {
                      Description = new DbDescription
                                    {
                                      ConnectionInfo = GlobalTest.DbManager1.Description.ConnectionInfo,
                                      Schemas = new List<DbScript> {new DbScript {ScriptType = ScriptType.Literal, ScriptValue = LiteralSchema}},
                                      Seeds = new List<DbScript> {new DbScript {ScriptType = ScriptType.Literal, ScriptValue = LiteralSeed}}
                                    }
                    };

      manager.Create();
      manager.Seed();

      var db = manager.CreateDatabase();

      Assert.That(db["c1"].Count(), Is.EqualTo(2));
      Assert.That(db["c2"].Count(), Is.EqualTo(1));
    }
예제 #8
0
        private Response _CreateBox(string boxName)
        {
            //todo: validate the box name to make sure it's valid
            Response ret;

            using (var db = RavenDbManager.OpenSession())
            {
                if (db.Query <Box>().Where(x => x.Name == boxName).Any())
                {
                    ret = new ActionFailedResponse("Box already exists", HttpStatusCode.Conflict);
                }
                else
                {
                    var box = new Box(boxName);
                    db.Store(box);
                    db.SaveChanges();
                    ret = new BoxCreatedResponse(Request.Url.ToUri().ToString());
                }
            }

            return(ret);
        }
예제 #9
0
        private Response _DeleteBox(string boxName)
        {
            Response ret;

            using (var db = RavenDbManager.OpenSession())
            {
                var box = db.Query <Box>().Where(x => x.Name == boxName).FirstOrDefault();

                if (box == null)
                {
                    ret = new ActionFailedResponse("Box doesn't exist", HttpStatusCode.NotFound);
                }
                else
                {
                    db.Delete(box);
                    db.SaveChanges();
                    ret = new SimplifiedJsonResponse(new { Result = "Box Deleted" });
                }
            }

            return(ret);
        }
예제 #10
0
    public void SetUp()
    {
      try
      {
        Logger = new NLogLoggerFactory().GetCurrentInstanceLogger();
   
        DbManager1 = new RavenDbManager
                     {
                       Description = new DbDescription {ConnectionInfo = new DbConnectionInfo {ConnectionStringName = "Test1"}}
                     };

        DbManager2 = new RavenDbManager
                     {
                       Description = new DbDescription {ConnectionInfo = new DbConnectionInfo {ConnectionStringName = "Test1"}}
                     };
      }
      catch (Exception e)
      {
        if (Logger != null) Logger.Fatal(e, "SetUp : {0} : {1}", e.GetType(), e.Message);
        throw;
      }
    }
예제 #11
0
        private Response _GetMessagesInBox(string boxName)
        {
            Response ret;

            using (var db = RavenDbManager.OpenSession())
            {
                var box = db.Query <Box>().Where(x => x.Name == boxName).FirstOrDefault();

                if (box == null)
                {
                    ret = new ActionFailedResponse("Box doesn't exist", HttpStatusCode.NotFound);
                }
                else
                {
                    var urlBase = Request.Url.ToUri() + "/";

                    var messages = box.Messages.Keys.ToDictionary(x => x, x => urlBase + x);
                    ret = new SimplifiedJsonResponse(messages);
                }
            }

            return(ret);
        }