public void ShouldUpdateToDoItem() { var updateToDoItemInput = new UpdateToDoItemInput { AssignedUserId = Guid.NewGuid().ToString(), State = (Perfectial.Application.Model.ToDoItemState)this.enumGenerator.Next(0, Enum.GetValues(typeof(Perfectial.Application.Model.ToDoItemState)).Length) }; var updatedToDoItem = this.CreateToDoItem(); var state = (ToDoItemState)this.enumGenerator.Next(0, Enum.GetValues(typeof(ToDoItemState)).Length); var assignedUser = this.CreateUser(); using (this.Repository.Record()) { Expect.Call(() => this.Logger.Info(Arg.Text.Contains("Updating ToDoItem for input:"))); Expect.Call(this.DbContextScopeFactory.Create()); Expect.Call(this.ToDoItemRepository.Get(0)).Constraints(Is.Equal(updateToDoItemInput.ToDoItemId)).Return(updatedToDoItem); Expect.Call(this.UserRepository.Get(string.Empty)).Constraints(Is.Equal(updateToDoItemInput.AssignedUserId)).Return(assignedUser); Expect.Call(this.Mapper.Map<ToDoItemState>(null)).Constraints(Is.Equal(updateToDoItemInput.State.Value)).Return(state); Expect.Call(this.ToDoItemRepository.Update(null)).Constraints(Is.Equal(updatedToDoItem)).Return(updatedToDoItem); Expect.Call(() => this.Logger.Info(Arg.Text.Contains("Updated ToDoItem for input:"))); } using (this.Repository.Playback()) { var toDoItemApplicationService = new ToDoItemApplicationService( this.ToDoItemRepository, this.UserRepository, this.DbContextScopeFactory, this.Mapper, this.Logger); toDoItemApplicationService.UpdateToDoItem(updateToDoItemInput); Assert.AreEqual(assignedUser, updatedToDoItem.AssignedUser); Assert.AreEqual(state, updatedToDoItem.State); } }
public void ShouldUpdateToDoItemWithoutState() { var updateToDoItemInput = new UpdateToDoItemInput { AssignedUserId = Guid.NewGuid().ToString(), State = null }; var updatedToDoItem = this.CreateToDoItem(); var assignedUser = this.CreateUser(); using (this.Repository.Record()) { Expect.Call(() => this.Logger.Info(Arg.Text.Contains("Updating ToDoItem for input:"))); Expect.Call(this.DbContextScopeFactory.Create()); Expect.Call(this.ToDoItemRepository.Get(0)).Constraints(Is.Equal(updateToDoItemInput.ToDoItemId)).Return(updatedToDoItem); Expect.Call(this.UserRepository.Get(string.Empty)).Constraints(Is.Equal(updateToDoItemInput.AssignedUserId)).Return(assignedUser); Expect.Call(this.Mapper.Map<ToDoItemState>(null)).Constraints(Is.Anything()).Repeat.Never(); Expect.Call(this.ToDoItemRepository.Update(null)).Constraints(Is.Equal(updatedToDoItem)).Return(updatedToDoItem); Expect.Call(() => this.Logger.Info(Arg.Text.Contains("Updated ToDoItem for input:"))); } using (this.Repository.Playback()) { var toDoItemApplicationService = new ToDoItemApplicationService( this.ToDoItemRepository, this.UserRepository, this.DbContextScopeFactory, this.Mapper, this.Logger); toDoItemApplicationService.UpdateToDoItem(updateToDoItemInput); Assert.AreEqual(assignedUser, updatedToDoItem.AssignedUser); } }