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); } }
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}"); }