示例#1
0
        public async Task Handle_WhenRequestIsValid_ShouldReturnCommandResultSuccess()
        {
            //Arrange
            var successfulValidationResult = new ValidationResult();

            _validator.ValidateAsync(Arg.Any <MarkAsDoneTodoListItemCommand>()).Returns(successfulValidationResult);

            var todoListItem = TodoListItemTestData.CreateTodoListItemTestData();

            var todoListItemId = todoListItem.TodoListItemId;

            _todoListItemsRepository.AnyAsync(Arg.Any <Expression <Func <TodoListItem, bool> > >()).Returns(true);
            _todoListItemsRepository.GetTodoListItemsByIdAsync(Arg.Any <Guid>()).Returns(todoListItem);

            request = new MarkAsDoneTodoListItemCommand
            {
                TodoListItemId = todoListItemId
            };
            subject = new MarkAsDoneTodoListItemCommandHandler(_todoListItemsRepository, _validator);
            //Act
            var result = await subject.Handle(request, default);

            //Assert
            result.Errors.ShouldBeEmpty();
            result.IsSuccessful.ShouldBeTrue();
            result.Result.ShouldBeOfType <MediatR.Unit>();
            result.Message.ShouldBe("The to-do item was done successfully");
        }
示例#2
0
        public void CreateNew_Description_ShouldBeNull()
        {
            var todoListItem = TodoListItemTestData.CreateTodoListItemTestData(hasDescription: false);

            todoListItem.ShouldBeOfType <TodoListItem>();
            todoListItem.Description.ShouldBeNull();
        }
示例#3
0
        public void CreateNew_CompletedOn_ShouldBeNull()
        {
            var todoListItem = TodoListItemTestData.CreateTodoListItemTestData();


            todoListItem.ShouldBeOfType <TodoListItem>();
            todoListItem.CompletedOn.ShouldBeNull();
        }
示例#4
0
        public void CreateNew_DueDate_ShouldBeNull()
        {
            var todoListItem = TodoListItemTestData.CreateTodoListItemTestData(hasDueDate: false);


            todoListItem.ShouldBeOfType <TodoListItem>();
            todoListItem.DueDate.ShouldBeNull();
        }
示例#5
0
        public void AddNewTodoListItem_ShouldReturnNewGuid()
        {
            var todoListItem = TodoListItemTestData.CreateTodoListItemTestData();


            todoListItem.ShouldBeOfType <TodoListItem>();
            todoListItem.TodoListItemId.ShouldNotBe(Guid.Empty);
        }
示例#6
0
        public void NewTodoListItem_Status_ShouldBePending()
        {
            var todoListItem = TodoListItemTestData.CreateTodoListItemTestData();


            todoListItem.ShouldBeOfType <TodoListItem>();
            todoListItem.Status.ShouldBe(TodoListItemStatuses.Pending);
        }
示例#7
0
        public void Update_DueDate_ShouldBeNull()
        {
            var todoListItem = TodoListItemTestData.CreateTodoListItemTestData();

            todoListItem.Update("Update TodoListItem", "Update DescriptionTodoListItem");

            todoListItem.ShouldBeOfType <TodoListItem>();
            todoListItem.DueDate.ShouldBeNull();
        }
示例#8
0
        public void TodoListItem_MarkAsDone_Status_ShouldBe_Done()
        {
            var todoListItem = TodoListItemTestData.CreateTodoListItemTestData();

            todoListItem.MarkAsDone();


            todoListItem.Status.ShouldBe(TodoListItemStatuses.Done);
        }
示例#9
0
        public void TodoListItem_MarkAsDone_CompletedOn_ShouldNotBeNull()
        {
            var todoListItem = TodoListItemTestData.CreateTodoListItemTestData();

            todoListItem.MarkAsDone();


            todoListItem.CompletedOn.ShouldNotBeNull();
        }
示例#10
0
        public void Update_WhenDescriptionLengthCanNotBeMoreThan500CharacterRule_IsBroken()
        {
            var todoListItem = TodoListItemTestData.CreateTodoListItemTestData();

            AssertBrokenRule <DescriptionLengthCanNotBeMoreThan500CharacterRule>(() =>
            {
                todoListItem.Update("Test", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ornare nec elit et pretium. Cras aliquet sed metus et facilisis. Suspendisse augue nisi, efficitur at rutrum eget, dapibus et quam. Nullam magna sem, rhoncus eget lorem eget, varius pulvinar quam. Nulla hendrerit a orci nec mattis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Nam non erat in magna lacinia dapibus. Sed at dignissim magna, eget interdum mauris. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin condimentum velit ac elit vehicula accumsan. Vestibulum at urna finibus, blandit sem a, lobortis quam. Morbi sodales fringilla est elementum dignissim. Duis accumsan fringilla risus non rhoncus. Integer et congue odio. Sed tempus fermentum mi.");
            });
        }
示例#11
0
        public void Update_WhenNameCanNotBeNullOrEmptyRule_IsBroken()
        {
            var todoListItem = TodoListItemTestData.CreateTodoListItemTestData();

            AssertBrokenRule <NameCanNotBeNullOrEmptyRule>(() =>
            {
                todoListItem.Update(null, string.Empty);
            });
        }
示例#12
0
        public void Update_Description_ShouldBeNull()
        {
            //Act
            var todoListItem = TodoListItemTestData.CreateTodoListItemTestData();

            todoListItem.Update("Update TodoListItem", null);

            //Assert
            todoListItem.ShouldBeOfType <TodoListItem>();
            todoListItem.Description.ShouldBeNull();
        }
        public async Task Handle_WhenRequestIsValid_ShouldReturnPendingTodoListItemDto()
        {
            //Arrange
            var data = TodoListItemTestData.CreateListTodoListItemTestData();

            request = new GetTodoListItemsQuery
            {
                PageNumber = 1,
                PageSize   = 5,
                Status     = 1
            };

            _todoListItemsRepository.CountAsync(Arg.Any <Expression <Func <TodoListItem, bool> > >()).Returns(data.Count);

            _todoListItemsRepository
            .GetAllTodoListItemsByStatusAsync(Arg.Any <TodoListItemStatuses>(), Arg.Any <int>(), Arg.Any <int>()).Returns(data);



            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new TodoListsProfile());
            });

            _mapper = mappingConfig.CreateMapper();

            subject = new GetTodoListItemsQueryHandler(_todoListItemsRepository, _mapper);
            //Act
            var result = await subject.Handle(request, default);

            //Assert

            var todoListItems = new List <TodoListItemDto>();

            foreach (var item in data)
            {
                todoListItems.Add(new TodoListItemDto
                {
                    TodoListItemId = item.TodoListItemId,
                    Name           = item.Name,
                    Description    = item.Description,
                    DueDate        = item.DueDate,
                    CompletedOn    = item.CompletedOn,
                });
            }

            var results = todoListItems.ToPagedList(request.PageNumber, request.PageSize, data.Count);


            result.ShouldBeOfType <PagedList <TodoListItemDto> >();
            result.ShouldBeEquivalentTo(results);
        }
示例#14
0
        public async Task Handle_WhenRequestIsValid_ShouldReturnTodoItemDto()
        {
            //Arrange

            var todoListItem = TodoListItemTestData.CreateTodoListItemTestData();

            var todoListItemId = todoListItem.TodoListItemId;

            _todoListItemsRepository.GetTodoListItemsByIdAsync(Arg.Any <Guid>()).Returns(todoListItem);

            request = new GetTodoListItemQuery
            {
                TodoListItemId = todoListItemId,
            };

            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new TodoListsProfile());
            });

            _mapper = mappingConfig.CreateMapper();

            subject = new GetTodoListItemQueryHandler(_todoListItemsRepository, _mapper);
            //Act
            var result = await subject.Handle(request, default);

            //Assert

            var querResult = new TodoItemDto
            {
                TodoListItemId = todoListItem.TodoListItemId,
                Name           = todoListItem.Name,
                Description    = todoListItem.Description,
                DueDate        = todoListItem.DueDate,
                CompletedOn    = todoListItem.CompletedOn,
                StatusName     = todoListItem.Status == TodoListItemStatuses.Pending ? "Pending" : "Done"
            };

            result.ShouldBeOfType <TodoItemDto>();
            result.ShouldBeEquivalentTo(querResult);
        }