Exemple #1
0
 public void CreateNew_WhenNameDescriptionLengthCanNotBeMoreThan500CharacterRule_IsBroken()
 {
     AssertBrokenRule <DescriptionLengthCanNotBeMoreThan500CharacterRule>(() =>
     {
         TodoListItem.CreateNew("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.");
     });
 }
Exemple #2
0
 public void CreateNew_WhenNameIsNull_IsBroken()
 {
     AssertBrokenRule <NameCanNotBeNullOrEmptyRule>(() =>
     {
         TodoListItem.CreateNew(null, string.Empty);
     });
 }
        public static TodoListItem CreateTodoListItemTestData(bool hasName = true, bool hasDescription = true, bool hasDueDate = true, string postfix = "1")
        {
            var name        = hasName ? $"Test TodoListItem {postfix}" : null;
            var description = hasDescription ? $"Test Description TodoListItem {postfix}" : null;
            var dueDate     = hasDueDate ? DateTime.Now : (DateTime?)null;

            return(TodoListItem.CreateNew(name, description, dueDate));
        }
        public async Task <ICommandResult <Guid> > Handle(AddTodoListItemCommand request, CancellationToken cancellationToken)
        {
            var validationResult = await _validator.ValidateAsync(request, cancellationToken);

            if (!validationResult.IsValid)
            {
                return(CommandResult <Guid> .Failure(validationResult.Errors));
            }

            var todoListItem = TodoListItem.CreateNew(request.Name,
                                                      request.Description,
                                                      request.DueDate);

            _todoListItemsRepository.Insert(todoListItem);

            await _todoListItemsRepository.SaveChangesAsync(cancellationToken);

            return(CommandResult <Guid> .Success(todoListItem.TodoListItemId, "The to-do item was added successfully"));
        }
Exemple #5
0
        protected override void Load(ContainerBuilder builder)
        {
            var optionsBuilder = new DbContextOptionsBuilder <DbContext>()
                                 .UseInMemoryDatabase(databaseName: "MockDB");

            builder
            .RegisterType <TodoListManagementDbContext>()
            .WithParameter(new TypedParameter(typeof(DbContextOptions), optionsBuilder.Options))
            .InstancePerLifetimeScope();


            var dbContext = new TodoListManagementDbContext(optionsBuilder.Options);

            dbContext.TodoListItems.Add(TodoListItem.CreateNew("Test 1", "Description 1", DateTime.Now));
            dbContext.TodoListItems.Add(TodoListItem.CreateNew("Test 2", "Description 2", DateTime.Now));
            dbContext.TodoListItems.Add(TodoListItem.CreateNew("Test 3", "Description 3", DateTime.Now));

            var todoListItem4 = TodoListItem.CreateNew("Test 4", "Description 4", DateTime.Now);

            todoListItem4.MarkAsDone();

            dbContext.TodoListItems.Add(todoListItem4);
            dbContext.TodoListItems.Add(TodoListItem.CreateNew("Test 5", "Description 5", DateTime.Now));

            var todoListItem6 = TodoListItem.CreateNew("Test 6", "Description 6", DateTime.Now);

            todoListItem6.MarkAsDone();
            dbContext.TodoListItems.Add(todoListItem6);

            dbContext.TodoListItems.Add(TodoListItem.CreateNew("Test 7", "Description 7", DateTime.Now));
            dbContext.TodoListItems.Add(TodoListItem.CreateNew("Test 8", "Description 8", DateTime.Now));
            dbContext.TodoListItems.Add(TodoListItem.CreateNew("Test 9", "Description 9", DateTime.Now));
            dbContext.TodoListItems.Add(TodoListItem.CreateNew("Test 10", "Description 10", DateTime.Now));
            dbContext.SaveChanges();

            builder.RegisterAssemblyTypes(ThisAssembly)
            .Where(type => type.Namespace.Contains("Persistence"))
            .AsImplementedInterfaces()
            .InstancePerLifetimeScope();
        }
Exemple #6
0
        public void CreateNew_WhenNameIsNull_ShouldThrowBusinessRuleValidationException()
        {
            var exception = Should.Throw <BusinessRuleValidationException>(() => TodoListItem.CreateNew(null, "test"));

            exception.Message.ShouldBe("Name must be provided");
        }