public void NotesRepositoryDeleteCallsDeletesFromTheUnitOfWork() { // Arrange var user = new User { PartitionKey = User1PartitionKey, RowKey = User1RowKey }; var taskList = new TaskList("Test title", user) { PartitionKey = TaskList1PartitionKey, RowKey = _taskList1RowKey }; var note = new Note("Test title", "Test content", user, taskList) { PartitionKey = Note1PartitionKey, RowKey = _note1RowKey }; var taskListNote = new TaskListEntity(string.Format("{0}+{1}", TaskList1PartitionKey, _taskList1RowKey), string.Format("{0}+{1}", Note1PartitionKey, _note1RowKey)); var unitOfWorkMock = new Mock<IUnitOfWork>(); unitOfWorkMock.Setup(uow => uow.Get("TaskListNotes", It.IsAny<Expression<Func<TaskListEntity, bool>>>())).Returns(taskListNote); unitOfWorkMock.Setup(uow => uow.Load<NoteShareEntity>(It.Is<string>(s => s == "NoteShares"))).Returns(BuildNoteSharesTable()); var repository = new NotesRepository(unitOfWorkMock.Object); // Act repository.Delete(note); // Assert unitOfWorkMock.Verify(uow => uow.Delete<NoteEntity>("Notes", Note1PartitionKey, _note1RowKey), Times.Once()); unitOfWorkMock.Verify(uow => uow.Delete<TaskListEntity>("TaskListNotes", taskListNote.PartitionKey, taskListNote.RowKey), Times.Once()); unitOfWorkMock.Verify(uow => uow.Delete<NoteShareEntity>("NoteShares", string.Format("{0}+{1}", Note1PartitionKey, _note1RowKey), User1RowKey), Times.Once()); unitOfWorkMock.Verify(uow => uow.Delete<NoteShareEntity>("NoteShares", string.Format("{0}+{1}", Note1PartitionKey, _note1RowKey), User3RowKey), Times.Once()); }
public void TaskListRepositoryLoadContainerCallsGetsFromTheUnitOfWork() { // Arrange var taskList = new TaskListEntity(TaskList1PartitionKey, _taskList1RowKey); var taskListNote = new TaskListEntity { PartitionKey = string.Format("{0}+{1}", TaskList1PartitionKey, _taskList1RowKey), RowKey = string.Format("{0}+{1}", Note1PartitionKey, _note1RowKey) }; var note = new Note { PartitionKey = Note1PartitionKey, RowKey = _note1RowKey }; var unitOfWorkMock = new Mock<IUnitOfWork>(); unitOfWorkMock.Setup(u => u.Get("TaskListNotes", It.IsAny<Expression<Func<TaskListEntity, bool>>>())).Returns(taskListNote); unitOfWorkMock.Setup(u => u.Get("TaskLists", It.IsAny<Expression<Func<TaskListEntity, bool>>>())).Returns(taskList); var repository = new TaskListsRepository(unitOfWorkMock.Object); // Act repository.LoadContainer(note); // Assert Assert.IsNotNull(note.Container); unitOfWorkMock.Verify(uow => uow.Get("TaskListNotes", It.IsAny<Expression<Func<TaskListEntity, bool>>>()), Times.Once()); unitOfWorkMock.Verify(uow => uow.Get("TaskLists", It.IsAny<Expression<Func<TaskListEntity, bool>>>()), Times.Once()); }
public void TaskListsRepositoryGetSharedCallsLoadFromTheUnitOfWork() { // Arrange var user = new User { PartitionKey = User1PartitionKey, RowKey = User1RowKey }; var taskList = new TaskListEntity(TaskList1PartitionKey, _taskList1RowKey); var unitOfWorkMock = new Mock<IUnitOfWork>(); unitOfWorkMock.Setup(u => u.Load("TaskListShares", It.IsAny<Expression<Func<TaskListShareEntity, bool>>>())).Returns(BuildTaskListSharesTable()); unitOfWorkMock.Setup(u => u.Get("TaskLists", It.IsAny<Expression<Func<TaskListEntity, bool>>>())).Returns(taskList); var repository = new TaskListsRepository(unitOfWorkMock.Object); // Act var result = repository.GetShared(user); // Assert Assert.IsTrue(result.Count() == 2); unitOfWorkMock.Verify(uow => uow.Load("TaskListShares", It.IsAny<Expression<Func<TaskListShareEntity, bool>>>()), Times.Once()); unitOfWorkMock.Verify(uow => uow.Get("TaskLists", It.IsAny<Expression<Func<TaskListEntity, bool>>>()), Times.Exactly(2)); }
public void TaskListRepositoryGetCallsGetFromTheUnitOfWorkAndReturnsAnExistingTaskList() { // Arrange var taskList = new TaskListEntity(TaskList1PartitionKey, _taskList1RowKey); var unitOfWorkMock = new Mock<IUnitOfWork>(); unitOfWorkMock.Setup(u => u.Get("TaskLists", It.IsAny<Expression<Func<TaskListEntity, bool>>>())).Returns(taskList); var repository = new TaskListsRepository(unitOfWorkMock.Object); // Act var result = repository.Get(Note1PartitionKey, _note1RowKey); // Assert Assert.IsNotNull(result); unitOfWorkMock.Verify(uow => uow.Get("TaskLists", It.IsAny<Expression<Func<TaskListEntity, bool>>>()), Times.Once()); }