Esempio n. 1
0
        public void IsValid_ShouldBeFalse_WhenListTitleIsNotUnique()
        {
            Context.TodoLists.Add(new TodoList {
                Title = "Shopping"
            });
            Context.SaveChanges();

            var command = new CreateTodoListCommand
            {
                Title = "Shopping"
            };

            var validator = new CreateTodoListCommandValidator(Context);

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
        }
Esempio n. 2
0
        public async Task ShouldCreateTodoList()
        {
            var userId = await RunAsDefaultUserAsync();

            var command = new CreateTodoListCommand
            {
                Title = "Tasks"
            };

            var id = await SendAsync(command);

            var list = await FindAsync <TodoList>(id);

            list.Should().NotBeNull();
            list.Title.Should().Be(command.Title);
            list.CreatedBy.Should().Be(userId);
            list.Created.Should().BeCloseTo(DateTime.Now, 10000);
        }
Esempio n. 3
0
        public async Task <HttpResponseData> CreateTodosList([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "todolists")]
                                                             HttpRequestData req,
                                                             FunctionContext functionContext)
        {
            logger.LogInformation("Called CreateTodosList");

            var todoList = await req.ReadFromJsonAsync <TodoList>();

            var command = new CreateTodoListCommand
            {
                Title = todoList.Title
            };

            return(await this.processor.ExecuteAsync <CreateTodoListCommand, int>(functionContext,
                                                                                  req,
                                                                                  command,
                                                                                  (r) => req.CreateObjectCreatedResponseAsync("todolists", r)));
        }
Esempio n. 4
0
        public async Task Handle_ShouldPersistTodoList()
        {
            // Arrange
            var command = new CreateTodoListCommand
            {
                Title = "Bucket List"
            };

            var handler = new CreateTodoListCommandHandler(Context);

            // Act
            var id = await handler.Handle(command,
                                          CancellationToken.None);

            var entity = Context.TodoLists.Find(id);

            entity.ShouldNotBeNull();
            entity.Title.ShouldBe(command.Title);
        }
Esempio n. 5
0
        public async void ShouldCreateTodoList_WhenValidListIsReceived()
        {
            // Arrange
            var userId = await _fixture.RunAsDefaultUserAsync();

            var command = new CreateTodoListCommand()
            {
                Title = "New List"
            };

            // Act
            var createdTodoListId = await _fixture.SendAsync(command);

            // Assert
            var createdList = await _fixture.FindAsync <TodoList>(createdTodoListId);

            createdList.ShouldNotBeNull();
            createdList.Title.ShouldBe(command.Title);
        }
Esempio n. 6
0
        public async void ShouldThrowException_WhenMinimumFiledsAreNotFilledIn()
        {
            // Arrange
            var command = new CreateTodoListCommand();

            // Act
            var exception = (ValidationException)await Record.ExceptionAsync(async() =>
            {
                await _fixture.SendAsync(command);
            });

            // Assert
            exception.ShouldBeOfType <ValidationException>();
            exception.Message.ShouldContain("One or more validation failures have occurred.");

            var errors = exception.Errors;

            errors.ShouldNotBeNull();

            errors.TryGetValue("Title", out string[] errorText);
            errorText.ShouldNotBeNull();
            errorText.Count().ShouldBe(1);
            errorText[0].ShouldBe("Title is required.");
        }
 public async Task <ActionResult <int> > PostTodoList(CreateTodoListCommand command)
 {
     return(await Sender.Send(command));
 }
        public async Task <ActionResult <int> > Create(CreateTodoListCommand command)
        {
            await Mediator.Send(command);

            return(this.Redirect("/Todo"));
        }
Esempio n. 9
0
 public async Task <ActionResult <int> > Create(CreateTodoListCommand command)
 {
     return(await Mediator.Send(command));
 }
 public Task <ApiResponse <int> > CreateTodoList(CreateTodoListCommand command) =>
 this.PostJson <CreateTodoListCommand, int>("api/TodoLists", command);
 public async Task <ApiResponse <int> > Create(CreateTodoListCommand command)
 {
     return(await Mediator.Send(command));
 }
Esempio n. 12
0
        public void Handle(CreateTodoListCommand message)
        {
            var list = TodoListAggregate.Factory.Create(message.ListId, message.ListName);

            _todoListAggregateRepository.Save(list);
        }
Esempio n. 13
0
        public IViewComponentResult Invoke()
        {
            var command = new CreateTodoListCommand();

            return(View(command));
        }
Esempio n. 14
0
        public async Task <IActionResult> CreateTodo([FromBody] CreateTodoListCommand createTodoListCommand)
        {
            await _mediator.Send(createTodoListCommand);

            return(Ok());
        }