public async Task GivenValidRequest_ShouldCreatePlanner()
        {
            var client = await _factory.GetAuthenticatedClientAsync();

            List <TagModel> listTags = new List <TagModel>();

            listTags.AddRange(new[] {
                new TagModel
                {
                    TagName = "Tag name 1"
                },
                new TagModel
                {
                    TagName = "Tag name 2"
                }
            });
            var command = new CreatePlannerCommand
            {
                Id      = Guid.NewGuid(),
                Purpose = "Test Purpose",
                Tags    = listTags,
                Title   = "Title Planner 1",
            };

            var content  = IntegrationTestHelper.GetRequestContent(command);
            var response = await client.PostAsync($"/api/Planner", content);

            response.EnsureSuccessStatusCode();
        }
        public async Task Handle_GivenValidRequest_ShouldCreatePlanner()
        {
            // Arrange
            var             sut    = new CreatePlannerCommandHandler(_context, _mapper);
            List <TagModel> lstTag = new List <TagModel> {
                new TagModel()
                {
                    TagName = "Test"
                }, new TagModel()
                {
                    TagName = "Test2"
                }
            };

            var command = new CreatePlannerCommand()
            {
                Id      = Guid.NewGuid(),
                Purpose = "Test purpose",
                Tags    = lstTag,
                Title   = "Test title",
            };

            // Act
            var result = await sut.Handle(command, CancellationToken.None);

            var entity = _context.Planners.Find(result.Id);

            entity.ShouldNotBeNull();
            entity.Title.ShouldBe("Test title");
            entity.Purpose.ShouldBe("Test purpose");
            entity.Tags.Count().ShouldBe(2);
            lstTag.ForEach(p => entity.Tags.Any(t => t.TagName == p.TagName).ShouldBeTrue());
        }
        public void IsValid_ShouldBeFalse_WhenIdIsNull()
        {
            var command = new CreatePlannerCommand
            {
                Title = "Not Null < 200 byte",
            };

            var validator = new CreatePlannerCommandValidator();

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
        }
        public void IsValid_ShouldBeFalse_WhenTitleIsNull()
        {
            var command = new CreatePlannerCommand
            {
                Title = null,
                Id    = Guid.NewGuid(),
            };

            var validator = new CreatePlannerCommandValidator();

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
        }
        public void IsValid_ShouldBeTrue_WhenTitleIsNotNull()
        {
            var command = new CreatePlannerCommand
            {
                Title = "Not Null < 200 byte",
                Id    = Guid.NewGuid(),
            };

            var validator = new CreatePlannerCommandValidator();

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(true);
        }
        public void IsValid_ShouldBeFalse_WhenTitleIsGreaterThan200Byte()
        {
            var command = new CreatePlannerCommand
            {
                Title = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
                        "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
                        "1",
                Id = Guid.NewGuid(),
            };

            var validator = new CreatePlannerCommandValidator();

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
        }
 public async Task <ActionResult <PlannerModel> > CreatePlanner(CreatePlannerCommand command)
 {
     return(await Mediator.Send(command));
 }