public void ShouldCreateToDoItemWithEmptyUser()
        {
            var createToDoItemInput = new CreateToDoItemInput {
                AssignedUserId = null, Description = Faker.Lorem.Sentence()
            };

            using (this.Repository.Record())
            {
                Expect.Call(this.DbContextScopeFactory.Create());
                Expect.Call(this.UserRepository.Get(string.Empty)).Constraints(Is.Equal(null)).Repeat.Never();
                Expect.Call(this.ToDoItemRepository.Add(null)).Constraints(Is.Anything()).Repeat.Once();
                Expect.Call(() => this.Logger.Info(Arg.Text.Contains("Creating ToDoItem for input:"))).Repeat.Once();
                Expect.Call(() => this.Logger.Info(Arg.Text.Contains("Created ToDoItem for input:"))).Repeat.Once();
            }

            using (this.Repository.Playback())
            {
                var toDoItemApplicationService = new ToDoItemApplicationService(
                    this.ToDoItemRepository,
                    this.UserRepository,
                    this.DbContextScopeFactory,
                    this.Mapper,
                    this.Logger);
                toDoItemApplicationService.CreateToDoItem(createToDoItemInput);
            }
        }
Esempio n. 2
0
        public async Task <CreateToDoItemPayload> CreateToDoItemAsync(
            CreateToDoItemInput input,
            [ScopedService] ApplicationDbContext context,
            CancellationToken cancellationToken)
        {
            var item = new ToDoItem
            {
                Content     = input.Content,
                CreatedDate = DateTimeOffset.UtcNow,
                Status      = input.Status.HasValue ? input.Status.Value : ToDoItemStatus.PENDING
            };

            context.ToDoItems.Add(item);

            await context.SaveChangesAsync(cancellationToken);

            return(new CreateToDoItemPayload(item));
        }
Esempio n. 3
0
        public void CreateToDoItem(CreateToDoItemInput input)
        {
            this.Logger.Info($"Creating ToDoItem for input: {input}");

            using (var dbContextScope = this.DbContextScopeFactory.Create())
            {
                var toDoItem = new ToDoItem {
                    Description = input.Description
                };
                if (!string.IsNullOrEmpty(input.AssignedUserId))
                {
                    toDoItem.AssignedUser = this.userRepository.Get(input.AssignedUserId);
                }

                this.toDoItemRepository.Add(toDoItem);

                dbContextScope.SaveChanges();
            }

            this.Logger.Info($"Created ToDoItem for input: {input}");
        }