Exemplo n.º 1
0
        public void CommandLogStateFindsEntriesToEndDate()
        {
            LogEntry        searchableEntry = new LogEntry("search term");
            List <LogEntry> logEntries      = new List <LogEntry>()
            {
                searchableEntry
            };
            ILog mockLog = Substitute.For <ILog>();

            mockLog.GetEntries().Returns(logEntries);

            IConsole mockConsole = Substitute.For <IConsole>();

            DateTime startDate = DateTime.Now.AddDays(-1);
            DateTime endDate   = DateTime.Now.AddDays(-1);

            mockConsole.GetInput().Returns("search term", startDate.ToString(), endDate.ToString());

            ITodoList mockTodoList = Substitute.For <ITodoList>();

            CommandLogState state = new CommandLogState(mockConsole, mockLog, mockTodoList);

            state.Input = "s";

            state.Execute();

            mockConsole.DidNotReceive().Output(searchableEntry.CreatedTime.ToString("dd/MM/yy HH:mm> "));
            mockConsole.DidNotReceive().OutputLine(searchableEntry.Text);
        }
Exemplo n.º 2
0
        private void SetupMoqTests(Mock <ITodoList> mockTodoList)
        {
            //Return all Todo items.
            mockTodoList.Setup(mtl => mtl.Items).Returns(m_TodoItems);

            //Return a TodoItem by TodoId
            mockTodoList.Setup(mtl => mtl.GetItem(It.IsAny <int>())).Returns((int iTodoID) => m_TodoItems.Where(t => t.TodoID == iTodoID).Single());

            //Return a TodoItem by Index
            mockTodoList.Setup(mtl => mtl.GetByIndex(It.IsAny <int>())).Returns((int iIndex) => m_TodoItems[iIndex]);

            //Check if an Todo Item is contained in the TodoList
            mockTodoList.Setup(mtl => mtl.Contains(It.IsAny <int>())).Returns((int iTodoID) => (m_TodoItems.FirstOrDefault(t => t.TodoID == iTodoID) != null));

            /* NOT USED: Will Use Unit Test Instance of TodoList class instead.
             * //Sets up the ability to test adding items to the Todo List
             * mockTodoList.Setup(mtl => mtl.AddItem(It.IsAny<TodoItem>())).Callback((TodoItem item) => todoItems.Add(item));
             *
             * //Sets up the ability to test deleting items from the Todo List by TodoId
             * mockTodoList.Setup(mtl => mtl.DeleteItem(It.IsAny<int>()));
             *
             * //Sets up the ability to test deleting items from the Todo List by Index
             * mockTodoList.Setup(mtl => mtl.DeleteByIndex(It.IsAny<int>()));
             */

            //Complete the setup of the Mock TodoList Repository.
            MockRepoTodoList = mockTodoList.Object;
        }
Exemplo n.º 3
0
        public RemoveTodoItemState(IConsole console, ILog log, ITodoList todoList)
            : base(console, log, todoList)
        {
            SetNextState(typeof(ReadTodoState));

            RegisterState(typeof(RemoveTodoItemState), this);
        }
Exemplo n.º 4
0
        public void CommandLogStateFindsEntriesMatchingSearchTermsCaseInsensitive()
        {
            LogEntry        searchableEntry   = new LogEntry("SeArCh TeRm");
            LogEntry        unsearchableEntry = new LogEntry("Nothing here");
            List <LogEntry> logEntries        = new List <LogEntry>()
            {
                searchableEntry, unsearchableEntry
            };
            ILog mockLog = Substitute.For <ILog>();

            mockLog.GetEntries().Returns(logEntries);

            IConsole mockConsole = Substitute.For <IConsole>();

            DateTime yesterday = DateTime.Now.AddDays(-1);
            DateTime tomorrow  = DateTime.Now.AddDays(+1);

            mockConsole.GetInput().Returns("search term", yesterday.ToString(), tomorrow.ToString());

            ITodoList mockTodoList = Substitute.For <ITodoList>();

            CommandLogState state = new CommandLogState(mockConsole, mockLog, mockTodoList);

            state.Input = "s";

            state.Execute();

            mockConsole.Received(1).Output(searchableEntry.CreatedTime.ToString("dd/MM/yy HH:mm> "));
            mockConsole.Received(1).OutputLine(searchableEntry.Text);
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("CreateTodoList Invoked.");

            string body = await req.Content.ReadAsStringAsync();

            ITodoList <IEnumerable <Item> > newList = JsonConvert.DeserializeObject <TodoList>(body);

            log.Info($"CreateTodoList Name: {newList.Name}.");

            // Define the row,
            string newItemGuid = Guid.NewGuid().ToString();

            // Create the Entity and set the partition to signup,
            TodoListEntity listEntity = new TodoListEntity("todovue", newItemGuid);

            listEntity.Id    = newItemGuid;
            listEntity.Name  = newList.Name;
            listEntity.Items = JsonConvert.SerializeObject(new List <Item>());

            TodoListTableStorage storage = new TodoListTableStorage();
            CloudTable           table   = storage.GetCloudTableReference();

            TableOperation insertOperation = TableOperation.Insert(listEntity);

            await table.ExecuteAsync(insertOperation);

            newList.Id = newItemGuid;

            return(req.CreateResponse(HttpStatusCode.OK, newList));
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "PUT", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("UpdateTodoList Invoked.");

            string body = await req.Content.ReadAsStringAsync();

            ITodoList <IEnumerable <Item> > inputList = JsonConvert.DeserializeObject <TodoList>(body);

            log.Info($"UpdateTodoList Id: {inputList.Name}.");


            TodoListEntity updateEntity = new TodoListEntity("todovue", inputList.Id);

            updateEntity.Items = JsonConvert.SerializeObject(inputList.Items);
            updateEntity.Name  = inputList.Name;
            updateEntity.Id    = inputList.Id;
            updateEntity.ETag  = "*"; //By default, the SDK enforces optimistic concurrency via ETags. Set this value to '*' in order to force an overwrite to an entity as part of an update operation.

            TableOperation operation = TableOperation.Replace(updateEntity);

            TodoListTableStorage storage = new TodoListTableStorage();
            CloudTable           table   = storage.GetCloudTableReference();
            await table.ExecuteAsync(operation);

            return(req.CreateResponse(HttpStatusCode.NoContent));
        }
Exemplo n.º 7
0
        public State(IConsole console, ILog log, ITodoList todoList)
        {
            if (null == console)
            {
                throw new ArgumentNullException("Console must not be null");
            }

            if (null == log)
            {
                throw new ArgumentNullException("Log must not be null");
            }

            if (null == todoList)
            {
                throw new ArgumentNullException("TODO list must not be null");
            }

            mConsole = console;
            mLog = log;
            mTodoList = todoList;

            if(null == mStates)
            {
                mStates = new Dictionary<Type, State>();
            }
        }
Exemplo n.º 8
0
        public State(IConsole console, ILog log, ITodoList todoList)
        {
            if (null == console)
            {
                throw new ArgumentNullException("Console must not be null");
            }

            if (null == log)
            {
                throw new ArgumentNullException("Log must not be null");
            }

            if (null == todoList)
            {
                throw new ArgumentNullException("TODO list must not be null");
            }

            mConsole  = console;
            mLog      = log;
            mTodoList = todoList;

            if (null == mStates)
            {
                mStates = new Dictionary <Type, State>();
            }
        }
        public DisplayTodoListHeaderState(IConsole console, ILog log, ITodoList todoList)
            : base(console, log, todoList)
        {
            SetNextState(typeof(ReadTodoState));

            RegisterState(typeof(DisplayTodoListHeaderState), this);
        }
Exemplo n.º 10
0
        public StoreState(IConsole console, ILog log, ITodoList todoList)
            : base(console, log, todoList)
        {
            SetNextState(typeof(ReadState));

            RegisterState(typeof(StoreState), this);
        }
Exemplo n.º 11
0
        public CommandState(IConsole console, ILog log, ITodoList todoList)
            : base(console, log, todoList)
        {
            mCommands = new Dictionary<string, Tuple<string, Action>>();

            AddSubCommand("?", "Display help", DisplayHelp);
        }
Exemplo n.º 12
0
 public void ReadStateThrowsExceptionWhenPassedNullTodoList()
 {
     ILog      mockLog      = Substitute.For <ILog>();
     IConsole  mockConsole  = Substitute.For <IConsole>();
     ITodoList mockTodoList = Substitute.For <ITodoList>();
     State     state        = new ReadState(mockConsole, mockLog, null);
 }
Exemplo n.º 13
0
        public void CommandLogStateSearchesAllResultsIfRecursiveSearchIsCalledBeforeStandardSearch()
        {
            List <LogEntry> logEntries = new List <LogEntry>()
            {
                new LogEntry("search term a"),
                new LogEntry("search term b"),
                new LogEntry("other text b")
            };
            ILog mockLog = Substitute.For <ILog>();

            mockLog.GetEntries().Returns(logEntries);

            IConsole mockConsole = Substitute.For <IConsole>();

            mockConsole.GetInput().Returns("search term", "", "");

            ITodoList mockTodoList = Substitute.For <ITodoList>();

            CommandLogState state = new CommandLogState(mockConsole, mockLog, mockTodoList);

            mockConsole.GetInput().Returns("b", "", "");
            state.Input = "rs";

            state.Execute();

            mockConsole.DidNotReceive().OutputLine("search term a");
            mockConsole.Received(1).OutputLine("search term b");
            mockConsole.Received(1).OutputLine("other text b");
        }
Exemplo n.º 14
0
        public void CommandLogStateSearchesAllEntriesIfNoDatesSpecified()
        {
            LogEntry        entry      = new LogEntry("search term");
            List <LogEntry> logEntries = new List <LogEntry>()
            {
                entry
            };
            ILog mockLog = Substitute.For <ILog>();

            mockLog.GetEntries().Returns(logEntries);

            IConsole mockConsole = Substitute.For <IConsole>();
            DateTime yesterday   = DateTime.Now.AddDays(-1);
            DateTime tomorrow    = DateTime.Now.AddDays(+1);

            mockConsole.GetInput().Returns("search term", "", "");

            ITodoList mockTodoList = Substitute.For <ITodoList>();

            CommandLogState state = new CommandLogState(mockConsole, mockLog, mockTodoList);

            state.Input = "s";

            state.Execute();

            mockConsole.Received(1).Output("Please enter the term you wish to search for: ");
            mockConsole.Received(1).Output("Please enter the date to start searching from: ");
            mockConsole.Received(1).Output("Please enter the date to search up to: ");

            mockConsole.Received(3).GetInput();

            mockConsole.Received(1).Output(entry.CreatedTime.ToString("dd/MM/yy HH:mm> "));
            mockConsole.Received(1).OutputLine(entry.Text);
        }
Exemplo n.º 15
0
        public CommandTodoState(IConsole console, ILog log, ITodoList todoList) : base(console, log, todoList)
        {
            AddSubCommand("r", "Remove todo list entry", DeleteEntry);

            SetNextState(typeof(ReadTodoState));

            RegisterState(typeof(CommandTodoState), this);
        }
Exemplo n.º 16
0
 /// <param name='operations'>
 /// Reference to the MyDashDataAPI.ITodoList.
 /// </param>
 /// <param name='owner'>
 /// Required.
 /// </param>
 /// <param name='id'>
 /// Required.
 /// </param>
 public static Todo GetById(this ITodoList operations, string owner, int id)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((ITodoList)s).GetByIdAsync(owner, id);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Exemplo n.º 17
0
 /// <param name='operations'>
 /// Reference to the MyDashDataAPI.ITodoList.
 /// </param>
 /// <param name='todo'>
 /// Required.
 /// </param>
 public static object Put(this ITodoList operations, Todo todo)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((ITodoList)s).PutAsync(todo);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Exemplo n.º 18
0
        public void ReadTodoStateNextStateIsNull()
        {
            IConsole      mockConsole  = Substitute.For <IConsole>();
            ILog          mockLog      = Substitute.For <ILog>();
            ITodoList     mockTodoList = Substitute.For <ITodoList>();
            ReadTodoState state        = new ReadTodoState(mockConsole, mockLog, mockTodoList);

            Assert.IsNull(state.GetNextState());
        }
Exemplo n.º 19
0
        public void StoreTodoStateNextStateIsReadTodoState()
        {
            ILog           mockLog      = Substitute.For <ILog>();
            IConsole       mockConsole  = Substitute.For <IConsole>();
            ITodoList      mockTodoList = Substitute.For <ITodoList>();
            StoreTodoState state        = new StoreTodoState(mockConsole, mockLog, mockTodoList);

            Assert.IsInstanceOfType(state.GetNextState(), typeof(ReadTodoState));
        }
Exemplo n.º 20
0
        public void DisplayTodoListHeaderStateReturnsReadState()
        {
            IConsole  mockConsole            = Substitute.For <IConsole>();
            ILog      mockLog                = Substitute.For <ILog>();
            ITodoList mockTodoList           = Substitute.For <ITodoList>();
            DisplayTodoListHeaderState state = new DisplayTodoListHeaderState(mockConsole, mockLog, mockTodoList);

            Assert.IsInstanceOfType(state.GetNextState(), typeof(ReadTodoState));
        }
Exemplo n.º 21
0
        public CommandTodoState(IConsole console, ILog log, ITodoList todoList)
            : base(console, log, todoList)
        {
            AddSubCommand("r", "Remove todo list entry", DeleteEntry);

            SetNextState(typeof(ReadTodoState));

            RegisterState(typeof(CommandTodoState), this);
        }
Exemplo n.º 22
0
        public void CommandLogStateReturnsReadState()
        {
            ILog      mockLog      = Substitute.For <ILog>();
            IConsole  mockConsole  = Substitute.For <IConsole>();
            ITodoList mockTodoList = Substitute.For <ITodoList>();

            CommandLogState state = new CommandLogState(mockConsole, mockLog, mockTodoList);

            Assert.IsInstanceOfType(state.GetNextState(), typeof(ReadState));
        }
Exemplo n.º 23
0
        public void ReadTodoStateOutputsPromptCharacter()
        {
            IConsole      mockConsole  = Substitute.For <IConsole>();
            ILog          mockLog      = Substitute.For <ILog>();
            ITodoList     mockTodoList = Substitute.For <ITodoList>();
            ReadTodoState state        = new ReadTodoState(mockConsole, mockLog, mockTodoList);

            state.Execute();

            mockConsole.Received(1).Output(">");
        }
Exemplo n.º 24
0
        public void ReadTodoStateReadsConsoleWhenExecuted()
        {
            IConsole      mockConsole  = Substitute.For <IConsole>();
            ILog          mockLog      = Substitute.For <ILog>();
            ITodoList     mockTodoList = Substitute.For <ITodoList>();
            ReadTodoState state        = new ReadTodoState(mockConsole, mockLog, mockTodoList);

            state.Execute();

            mockConsole.Received(1).GetInput();
        }
Exemplo n.º 25
0
        public void ReadStateReturnsNullStateWhenReadingBlankString()
        {
            IConsole  mockConsole  = Substitute.For <IConsole>();
            ILog      mockLog      = Substitute.For <ILog>();
            ITodoList mockTodoList = Substitute.For <ITodoList>();
            ReadState state        = new ReadState(mockConsole, mockLog, mockTodoList);

            state.Execute();

            Assert.IsNull(state.GetNextState());
        }
Exemplo n.º 26
0
        public void ReadTodoStateReturnsDisplayLogHeaderStateStateWhenReadingBlankString()
        {
            IConsole      mockConsole  = Substitute.For <IConsole>();
            ILog          mockLog      = Substitute.For <ILog>();
            ITodoList     mockTodoList = Substitute.For <ITodoList>();
            ReadTodoState state        = new ReadTodoState(mockConsole, mockLog, mockTodoList);

            state.Execute();

            Assert.IsInstanceOfType(state.GetNextState(), typeof(DisplayLogHeaderState));
        }
Exemplo n.º 27
0
        public void DisplayTodoListHeaderStateOutputsHeaderText()
        {
            IConsole  mockConsole            = Substitute.For <IConsole>();
            ILog      mockLog                = Substitute.For <ILog>();
            ITodoList mockTodoList           = Substitute.For <ITodoList>();
            DisplayTodoListHeaderState state = new DisplayTodoListHeaderState(mockConsole, mockLog, mockTodoList);

            state.Execute();

            mockConsole.Received(1).Clear();
            mockConsole.Received().OutputLine(Arg.Any <String>());
        }
Exemplo n.º 28
0
        public void StoreTodoStateStoresTextInTodoList()
        {
            ILog           mockLog      = Substitute.For <ILog>();
            IConsole       mockConsole  = Substitute.For <IConsole>();
            ITodoList      mockTodoList = Substitute.For <ITodoList>();
            StoreTodoState state        = new StoreTodoState(mockConsole, mockLog, mockTodoList);

            state.Input = "This is the entry text";
            state.Execute();

            mockTodoList.Received(1).AddEntry(Arg.Is <TodoEntry>(entry => entry.Text == state.Input));
        }
Exemplo n.º 29
0
        public CommandLogState(IConsole console, ILog log, ITodoList todoList) : base(console, log, todoList)
        {
            AddSubCommand("s", "Search log entries", SearchEntries);
            AddSubCommand("", "Search log entries", SearchEntries);
            AddSubCommand("rs", "Search previous results", SearchPreviousSearchResults);
            AddSubCommand("t", "Enter TODO list", EnterTodoList);

            RegisterState(typeof(CommandLogState), this);
            SetNextState(typeof(ReadState));

            mPreviousSearchResults = mLog.GetEntries();
        }
Exemplo n.º 30
0
        public CommandLogState(IConsole console, ILog log, ITodoList todoList)
            : base(console, log, todoList)
        {
            AddSubCommand("s", "Search log entries", SearchEntries);
            AddSubCommand("", "Search log entries", SearchEntries);
            AddSubCommand("rs", "Search previous results", SearchPreviousSearchResults);
            AddSubCommand("t", "Enter TODO list", EnterTodoList);

            RegisterState(typeof(CommandLogState), this);
            SetNextState(typeof(ReadState));

            mPreviousSearchResults = mLog.GetEntries();
        }
Exemplo n.º 31
0
        public void CommandLogStateReturnsTodoListState()
        {
            ILog      mockLog      = Substitute.For <ILog>();
            IConsole  mockConsole  = Substitute.For <IConsole>();
            ITodoList mockTodoList = Substitute.For <ITodoList>();

            CommandLogState state = new CommandLogState(mockConsole, mockLog, mockTodoList);

            state.Input = "t";

            state.Execute();

            Assert.IsInstanceOfType(state.GetNextState(), typeof(DisplayTodoListHeaderState));
        }
Exemplo n.º 32
0
        public void CommandTodoStateReturnsRemoveTodoItemState()
        {
            ILog      mockLog      = Substitute.For <ILog>();
            IConsole  mockConsole  = Substitute.For <IConsole>();
            ITodoList mockTodoList = Substitute.For <ITodoList>();

            CommandTodoState state = new CommandTodoState(mockConsole, mockLog, mockTodoList);

            state.Input = "r";

            state.Execute();

            Assert.IsInstanceOfType(state.GetNextState(), typeof(RemoveTodoItemState));
        }
Exemplo n.º 33
0
        public void RemoveTodoItemStateHandlesUnknownTodoListIDs()
        {
            ILog      mockLog      = Substitute.For <ILog>();
            IConsole  mockConsole  = Substitute.For <IConsole>();
            ITodoList mockTodoList = Substitute.For <ITodoList>();

            mockConsole.GetInput().Returns("0");
            mockTodoList.When(todoList => todoList.RemoveEntry(Arg.Any <UInt32>())).Do(x => { throw new ArgumentOutOfRangeException(); });

            RemoveTodoItemState state = new RemoveTodoItemState(mockConsole, mockLog, mockTodoList);

            state.Execute();

            mockConsole.Received(1).OutputLine("Item with given ID not found");
        }
Exemplo n.º 34
0
        public void ReadTodoStateReturnsCommandStateWhenReadingCommand()
        {
            IConsole mockConsole = Substitute.For <IConsole>();

            mockConsole.GetInput().Returns(">COMMANDSTRING");

            ILog          mockLog      = Substitute.For <ILog>();
            ITodoList     mockTodoList = Substitute.For <ITodoList>();
            ReadTodoState state        = new ReadTodoState(mockConsole, mockLog, mockTodoList);

            state.Execute();

            State nextState = state.GetNextState();

            Assert.IsInstanceOfType(nextState, typeof(CommandTodoState));
            Assert.AreEqual("COMMANDSTRING", nextState.Input);
        }
Exemplo n.º 35
0
        public void CommandTodoStateDisplaysHelpOnQuestionMark()
        {
            ILog      mockLog      = Substitute.For <ILog>();
            IConsole  mockConsole  = Substitute.For <IConsole>();
            ITodoList mockTodoList = Substitute.For <ITodoList>();

            CommandTodoState state = new CommandTodoState(mockConsole, mockLog, mockTodoList);

            state.Input = "?";

            state.Execute();

            mockConsole.Received(0).OutputLine("Unrecognised command. Please enter one of the following commands");
            mockConsole.Received(1).OutputLine("Remove todo list entry");
            mockConsole.Received(1).OutputLine("Display help");

            Assert.IsInstanceOfType(state.GetNextState(), typeof(ReadTodoState));
        }
Exemplo n.º 36
0
        public void ReadTodoStateReturnsStoreStateWhenReadingPlainText()
        {
            const string cConsoleInput = "This is plain text";
            IConsole     mockConsole   = Substitute.For <IConsole>();

            mockConsole.GetInput().Returns(cConsoleInput);

            ILog          mockLog      = Substitute.For <ILog>();
            ITodoList     mockTodoList = Substitute.For <ITodoList>();
            ReadTodoState state        = new ReadTodoState(mockConsole, mockLog, mockTodoList);

            state.Execute();

            State nextState = state.GetNextState();

            Assert.IsInstanceOfType(nextState, typeof(StoreTodoState));
            Assert.AreEqual(cConsoleInput, nextState.Input);
        }
Exemplo n.º 37
0
        public void RemoveTodoItemStateRequestsItemIdToRemoveUntilValidIdIsProvided()
        {
            ILog      mockLog      = Substitute.For <ILog>();
            IConsole  mockConsole  = Substitute.For <IConsole>();
            ITodoList mockTodoList = Substitute.For <ITodoList>();

            const UInt32 cTodoItemId = 0;

            mockConsole.GetInput().Returns("", "-1", "NOT A NUMBER", cTodoItemId.ToString());

            RemoveTodoItemState state = new RemoveTodoItemState(mockConsole, mockLog, mockTodoList);

            state.Execute();

            mockConsole.Received(4).Output("Enter the item ID to remove");
            mockConsole.Received(4).GetInput();
            mockTodoList.Received(1).RemoveEntry(cTodoItemId);
        }
 public SetDateServiceCommand(ITodoList todoList)
 {
     this.todoList = todoList;
 }
Exemplo n.º 39
0
 public RenameServiceCommand(ITodoList todoList)
 {
     this.todoList = todoList;
 }
 public CompleteServiceCommand(ITodoList todoList)
 {
     this.todoList = todoList;
 }
Exemplo n.º 41
0
 public TaskManagerService(ITodoList todoList, IArgToCommandConverter commandConverter, ISpecificationsConverter specConverter)
 {
     this.todoList = todoList;
     this.commandConverter = commandConverter;
     this.specConverter = specConverter;
 }
Exemplo n.º 42
0
 public ReadTodoState(IConsole console, ILog log, ITodoList todoList)
     : base(console, log, todoList)
 {
     RegisterState(typeof(ReadTodoState), this);
 }
 public ClearDateServiceCommand(ITodoList todoList)
 {
     this.todoList = todoList;
 }