public void TestCreateExistingStoryForDatabaseNonIncrement() { var username = "******"; var condition = Builders <ConnStoryTable> .Filter.Empty; MongoClient mongoClient = new MongoClient(); var dataBase = mongoClient.GetDatabase(dataBaseName); var collection = dataBase.GetCollection <ConnStoryTable>("StoryTable"); int count = collection.Find(condition).ToList().Count; // Gives the initial count ResultCode result; ConnStoryTable obj = new ConnStoryTable(); obj.Title = "Test"; // Already existing story obj.Scenario = "Test"; obj.Genre = "Test"; obj.Type = "Test"; obj.To = "01/01/2017"; obj.From = "01/02/2017"; result = new DatabaseAccess().CreateStory(obj, username); Assert.IsFalse(result.Result); // value not saved int countNew = collection.Find(condition).ToList().Count; // new count Assert.AreEqual(count, countNew); // Value not added to database }
public void TestCreateStoryForDatabaseIncrement() { var username = "******"; var condition = Builders <ConnStoryTable> .Filter.Empty; MongoClient mongoClient = new MongoClient(); var dataBase = mongoClient.GetDatabase(dataBaseName); var collection = dataBase.GetCollection <ConnStoryTable>("StoryTable"); int count = collection.Find(condition).ToList().Count; // Gives the initial count ResultCode result; ConnStoryTable obj = new ConnStoryTable(); obj.Title = DateTime.Now.ToString(CultureInfo.InvariantCulture).Replace(" ", "") + "Test"; obj.Scenario = "Test"; obj.Genre = "Test"; obj.Type = "Test"; obj.To = "01/01/2017"; obj.From = "01/02/2017"; result = new DatabaseAccess().CreateStory(obj, username); Assert.IsTrue(result.Result); // value saved int countNew = collection.Find(condition).ToList().Count; // new count Assert.AreEqual(count + 1, countNew); // Value added to database }
public ResultCode CreateStory(ConnStoryTable story, string username) { ResultCode resultCode = new ResultCode(); try { var tableCollection = CreateDataConnection(new MongoClient()) .GetCollection <ConnStoryTable>("StoryTable"); var condition = Builders <ConnStoryTable> .Filter.Eq(p => p.Title, story.Title); var fields = Builders <ConnStoryTable> .Projection.Include(p => p.Title).Include(p => p.StoryID); var results = tableCollection.Find(condition).Project <ConnStoryTable>(fields).ToList().AsQueryable(); if (results.Count() == 1) { // story exists resultCode.Result = false; resultCode.Message = "Story with same title exists !!"; return(resultCode); } var collection = CreateDataConnection(new MongoClient()).GetCollection <BsonDocument>("StoryTable"); BsonDocument task = null; task = collection.Find(new BsonDocument()) .Sort(Builders <BsonDocument> .Sort.Descending("StoryID")) .Limit(1) .FirstOrDefault(); ConnStoryTable result = null; if (task != null) { result = BsonSerializer.Deserialize <ConnStoryTable>(task.ToBsonDocument()); } var StoryID = (task != null) ? (result.StoryID + 1) : 1; // If table is empty, push value as 1. story.StoryID = StoryID; var documnt = story.ToBsonDocument(); collection.InsertOne(documnt); var Collect = CreateDataConnection(new MongoClient()) .GetCollection <BsonDocument>("CreatorStoryTable"); CreatorStoryModel crtrObj = new CreatorStoryModel(); crtrObj.StoryID = StoryID; crtrObj.EditorID = username; var documnt2 = crtrObj.ToBsonDocument(); Collect.InsertOne(documnt2); resultCode.Result = true; resultCode.Message = "Story Created !!"; return(resultCode); } catch (Exception ex) { resultCode.Result = false; resultCode.Message = "Error occured, Please try again !!"; return(resultCode); } }
public void TestEditorForExistingStory() { ResultCode result; var username = "******"; ConnStoryTable obj = new ConnStoryTable(); obj.Title = "Test"; // Already existing story obj.Scenario = "Test"; obj.Genre = "Test"; obj.Type = "Test"; obj.To = "01/01/2017"; obj.From = "01/02/2017"; result = new DatabaseAccess().CreateStory(obj, username); Assert.IsFalse(result.Result); // value not saved }
public ResultCode CreateEditorStory(StoryModel story, string username) { DatabaseAccess objDatabaseAccess = new DatabaseAccess(); ConnStoryTable obj = new ConnStoryTable(); obj.Content = story.Content; obj.From = Convert.ToString(story.From, CultureInfo.InvariantCulture); obj.Scenario = story.Scenario; obj.StoryID = story.StoryID; obj.Title = story.Title; obj.To = Convert.ToString(story.To, CultureInfo.InvariantCulture); obj.Type = story.Type; obj.Genre = story.Genre; return(objDatabaseAccess.CreateStory(obj, username));; }
public void TestEditorCreateStory() { ResultCode result; ConnStoryTable obj = new ConnStoryTable(); Thread.Sleep(1000); var username = "******"; obj.Title = DateTime.Now.ToString(CultureInfo.InvariantCulture).Replace(" ", "") + "Test"; obj.Scenario = "Test"; obj.Genre = "Test"; obj.Type = "Test"; obj.To = "01/01/2017"; obj.From = "01/02/2017"; result = new DatabaseAccess().CreateStory(obj, username); Assert.IsTrue(result.Result); // value saved }
public List <ConnStoryTable> BrowseCreatedStories(string username) { List <ConnStoryTable> crtrStoryListObj = new List <ConnStoryTable>(); ConnStoryTable crtrStoryObj = new ConnStoryTable(); try { var tableCollection = CreateDataConnection(new MongoClient()) .GetCollection <CreatorStoryModel>("CreatorStoryTable"); var condition = Builders <CreatorStoryModel> .Filter.Eq(p => p.EditorID, username); var results = tableCollection.Find(condition).ToList().AsQueryable(); if (results == null) { crtrStoryListObj[0].MessageString = "Data is null"; } else { foreach (var story in results) { var tableCollection2 = CreateDataConnection(new MongoClient()) .GetCollection <ConnStoryTable>("StoryTable"); var fields = Builders <ConnStoryTable> .Projection.Include(p => p.Title).Include(p => p.Content).Include(p => p.StoryID).Include(p => p.Genre).Include(p => p.Scenario); var condition2 = Builders <ConnStoryTable> .Filter.Eq(p => p.StoryID, story.StoryID); var StoryResults = tableCollection2.Find(condition2).Project <ConnStoryTable>(fields).ToList(); for (int i = 0; i < StoryResults.Count(); i++) { crtrStoryListObj.Add(StoryResults[i]); } } } return(crtrStoryListObj); } catch (Exception ex) { return(null); } }