public void UserCanLockAfterWordHasBeenAdded() { // Setup var user1 = "users/1"; var user2 = "users/2"; var story = FakeEntityFactory.GetGenericStory("users/23"); IDocumentStore store = Global.GetInMemoryStore(); using (var session = store.OpenSession()) { session.Store(story); session.SaveChanges(); } var repository = new StoryRepository(store); using (var session = store.OpenSession()) { var firstLockResult = repository.LockStory(story.Id, user1); var saveStory = session.Load<Story>(story.Id); Assert.IsTrue(saveStory.HasEditor); Assert.AreEqual(saveStory.Lock.UserId, user1); var secondLockResult = repository.LockStory(story.Id, user2); saveStory = session.Load<Story>(story.Id); Assert.AreEqual(secondLockResult, StoryErrorCode.StoryLockedForEditing); Assert.AreEqual(saveStory.Lock.UserId, user1); } using (var session = store.OpenSession()) { var firstAddWordResult = repository.AddWord(story.Id, "word", user1); var saveStory = session.Load<Story>(story.Id); Assert.AreEqual(firstAddWordResult.ErrorCode, StoryErrorCode.Success); Assert.IsFalse(saveStory.HasEditor); } using (var session = store.OpenSession()) { var thirdLockResult = repository.LockStory(story.Id, user2); var saveStory = session.Load<Story>(story.Id); Assert.AreEqual(thirdLockResult, StoryErrorCode.Success); Assert.IsTrue(saveStory.HasEditor); Assert.AreEqual(saveStory.Lock.UserId, user2); } // Act // Assert }
public void LockStoryReturnsTrueIfStoryIsNotLocked() { Story story = new Story(); IDocumentStore store = Global.GetInMemoryStore(); using (var session = store.OpenSession()) { session.Store(story); session.SaveChanges(); } StoryRepository repository = new StoryRepository(store); // Act StoryErrorCode result = repository.LockStory(story.Id, "users/1"); using (var session = store.OpenSession()) { var savedStory = session.Load<Story>(story.Id); Assert.AreEqual(savedStory.Lock.UserId, "users/1"); Assert.GreaterOrEqual(savedStory.Lock.LockedDate, DateTime.Now.AddMinutes(-1)); } // Assert Assert.AreEqual(result, StoryErrorCode.Success); }
public void LockStoryReturnsFalseIfStoryIsAlreadyLocked() { // Setup Story story = new Story(); story.Lock.UserId = "users/1"; IDocumentStore store = Global.GetInMemoryStore(); using (var session = store.OpenSession()) { session.Store(story); session.SaveChanges(); } StoryRepository repository = new StoryRepository(store); // Act StoryErrorCode result = repository.LockStory(story.Id, "users/2"); // Assert Assert.AreEqual(result, StoryErrorCode.StoryLockedForEditing); }
public void AllowsALockIfYouveAlreadyLockedIt() { // Setup var store = Global.GetInMemoryStore(); var userId = "users/1"; var story = FakeEntityFactory.GetGenericStory(userId); story.Lock.UserId = userId; using (var session = store.OpenSession()) { session.Store(story); session.SaveChanges(); } // Act StoryRepository repo = new StoryRepository(store); var result = repo.LockStory("stories/1", userId); // Assert Assert.AreEqual(result, StoryErrorCode.Success); }