public void GivenTodoItem_TitleChanged() { var context = new DBContext(); var gateway = new TodoItemGateway(context); Core.UseCases.AddTodoItem.Output actualOutput = null; var outputHandler = new Mock <Core.UseCases.IUseCaseOutputHandler <Core.UseCases.AddTodoItem.Output> > (); outputHandler.Setup(e => e.Handle(It.IsAny <Core.UseCases.AddTodoItem.Output> ())) .Callback <Core.UseCases.AddTodoItem.Output> (output => actualOutput = output); var addTodoItemBuilder = new Core.UseCases.AddTodoItem.InputBuilder(); addTodoItemBuilder.WithTitle("My Title"); var addTodoItem = new Core.UseCases.AddTodoItem.Interactor(outputHandler.Object, gateway); addTodoItem.Execute(addTodoItemBuilder.Build()); InputBuilder builder = new InputBuilder(); builder .WithTodoItemId(actualOutput.Id) .WithTitle("New Title"); IUseCase <Input> updatedTitle = new Interactor(gateway); Exception ex = Record.Exception(() => updatedTitle.Execute(builder.Build())); Assert.Null(ex); }
public void GivenNullContext_ThrowsException() { var context = new InMemoryContext(); var gateway = new TodoItemGateway(context); var responseHandler = new ResponseHandler(); var list = new ListTodoItems(responseHandler, gateway); list.Execute(); }
public void RemoveDoesNotRemoveTodoItem_WhenDoesNotExist() { InMemoryContext inMemory = new InMemoryContext(); ITodoItemGateway gateway = new TodoItemGateway(inMemory); IUseCase sut = new RemoveTodoItem(gateway); sut.Execute(Guid.NewGuid()); Assert.NotEmpty(inMemory.TodoItems.Where(e => e.Id == existingTodoItemId)); }
public void RemoveRemovesTodoItem() { InMemoryContext inMemory = new InMemoryContext(); ITodoItemGateway gateway = new TodoItemGateway(inMemory); IUseCase sut = new RemoveTodoItem(gateway); sut.Execute(existingTodoItemId); Assert.Empty(inMemory.TodoItems.Where(e => e.Id == existingTodoItemId)); }
public void MarkItemCompletedDoesNotChange() { InMemoryContext inMemory = new InMemoryContext(); ITodoItemGateway gateway = new TodoItemGateway(inMemory); IUseCase sut = new MarkItemCompleted(gateway); sut.Execute(Guid.NewGuid()); Assert.Empty(inMemory.TodoItems.Where(e => e.Id == existingTodoItemId && e.IsCompleted)); }
public void MarkItemCompletedSuccess() { InMemoryContext inMemory = new InMemoryContext(); ITodoItemGateway gateway = new TodoItemGateway(inMemory); IUseCase sut = new MarkItemCompleted(gateway); sut.Execute(existingTodoItemId); Assert.NotEmpty(inMemory.TodoItems.Where(e => e.Id == existingTodoItemId && e.IsCompleted)); }
public void GivenNullContext_ThrowsException() { var context = new DBContext(); var gateway = new TodoItemGateway(context); var outputHandler = new Mock <IUseCaseOutputHandler <Output> > (); IUseCase list = new Interactor(outputHandler.Object, gateway); list.Execute(); }
public void GivenNotNullTitle_ReturnsId() { var context = new InMemoryContext(); var gateway = new TodoItemGateway(context); var responseHandler = new ResponseHandler(); var entitiesFactory = new EntitiesFactory(); var request = new Request("My Title"); var addTodoItem = new AddTodoItem(responseHandler, gateway, entitiesFactory); addTodoItem.Execute(request); Assert.True(Guid.Empty != responseHandler.AddTodoItems[0].Id); }
public void GivenNotNullTitle_InvokeOutputHandler() { var context = new InMemoryContext(); var gateway = new TodoItemGateway(context); var responseHandler = new ResponseHandler(); var entitiesFactory = new EntitiesFactory(); var request = new Request("My Title"); var addTodoItem = new AddTodoItem(responseHandler, gateway, entitiesFactory); addTodoItem.Execute(request); Assert.Single(responseHandler.AddTodoItems); }
static void Main(string[] args) { InMemoryContext inMemoryContext = new InMemoryContext(); ITodoItemGateway gateway = new TodoItemGateway(inMemoryContext); EntitiesFactory entitiesFactory = new EntitiesFactory(); Presenter presenter = new Presenter(); var update = new Core.UseCases.UpdateTitle(gateway); var list = new Core.UseCases.ListTodoItems(presenter, gateway); var finish = new Core.UseCases.RemoveTodoItem(gateway); var add = new Core.UseCases.AddTodoItem(presenter, gateway, entitiesFactory); Startup startup = new Startup(add, finish, list, update); Console.WriteLine("Usage:\n\tadd [title]\n\tfinish [id]\n\tlist\n\tupdate [id] [title]\n\texit"); while (true) { string command = Console.ReadLine(); if (string.IsNullOrWhiteSpace(command) || string.Compare(command, "exit", StringComparison.CurrentCultureIgnoreCase) == 0) { break; } string[] input = command.Split(' '); if (string.Compare(input[0], "add", StringComparison.CurrentCultureIgnoreCase) == 0) { startup.AddTodoItem(input); } if (string.Compare(input[0], "finish", StringComparison.CurrentCultureIgnoreCase) == 0) { startup.RemoveTodoItem(input); } if (string.Compare(input[0], "list", StringComparison.CurrentCultureIgnoreCase) == 0) { startup.ListTodoItem(input); } if (string.Compare(input[0], "update", StringComparison.CurrentCultureIgnoreCase) == 0) { startup.UpdateTodoItem(input); } } }
public void GivenTodoItem_TitleChanged() { var context = new InMemoryContext(); var gateway = new TodoItemGateway(context); var responseHandler = new ResponseHandler(); var entitiesFactory = new EntitiesFactory(); var addTodoItem = new Core.UseCases.AddTodoItem(responseHandler, gateway, entitiesFactory); addTodoItem.Execute(new Core.Boundaries.AddTodoItem.Request("My Title")); var request = new Request(responseHandler.AddTodoItems[0].Id, "New Title"); var updatedTitle = new UpdateTitle(gateway); Exception ex = Record.Exception(() => updatedTitle.Execute(request)); Assert.Null(ex); }