public void CopyProgressesForUsersInGroup_Exception() { //Arrange int _groupId = 1; string _message = ""; Group _group = null; var _users = new List<User>() { new User() { Id = 3 } }; var _groupRepository = new Mock<IRepository<WorldOfWords.Domain.Models.Group>>(); _uow.Setup(u => u.GroupRepository).Returns(_groupRepository.Object); _groupRepository.Setup(g => g.GetById(_groupId)).Returns(_group); var _service = new WordProgressService(_factory.Object); //Act try { _service.CopyProgressesForUsersInGroup(_users, _groupId); } catch (ArgumentException ex) { _message = ex.Message; } //Assert Assert.AreEqual("Group with id you are requesting does not exist", _message); _factory.Verify(f => f.GetUnitOfWork(), Times.Once); _uow.Verify(u => u.GroupRepository, Times.Exactly(1)); _uow.Verify(u => u.WordProgressRepository, Times.Never); _groupRepository.Verify(g => g.GetById(_groupId), Times.Exactly(1)); _progressRepository.Verify(p => p.Add(It.IsAny<IEnumerable<WordProgress>>()), Times.Never); _uow.Verify(u => u.Save(), Times.Never); }
public void CopyProgressesForUsersInGroup_Copied() { //Arrange int _groupId = 1; List<WordSuite> _collection = new List<WordSuite>() { new WordSuite(){Id = 1, PrototypeId = null}, new WordSuite() {OwnerId = 3, PrototypeId = 1, PrototypeWordSuite=new WordSuite() { WordProgresses=new List<WordProgress>() }, WordProgresses = new List<WordProgress>() { new WordProgress() } } }; Group _group = new Group() { Course = new Course() { WordSuites = _collection } }; var _users = new List<User>() { new User() { Id = 3 } }; var _progressesToAdd = new List<WordProgress>(); var _groupRepository = new Mock<IRepository<WorldOfWords.Domain.Models.Group>>(); _uow.Setup(u => u.GroupRepository).Returns(_groupRepository.Object); _groupRepository.Setup(g => g.GetById(_groupId)).Returns(_group); _uow.Setup(u => u.WordProgressRepository).Returns(_progressRepository.Object); _uow.Setup(u => u.Save()); _progressRepository.Setup(p => p.Add(It.IsAny<IEnumerable<WordProgress>>())); var _service = new WordProgressService(_factory.Object); //Act _service.CopyProgressesForUsersInGroup(_users, _groupId); //Assert _factory.Verify(f => f.GetUnitOfWork(), Times.Once); _uow.Verify(u => u.GroupRepository, Times.Exactly(1)); _uow.Verify(u => u.WordProgressRepository, Times.Exactly(1)); _groupRepository.Verify(e => e.GetById(_groupId), Times.Exactly(1)); _progressRepository.Verify(p => p.Add(It.IsAny<IEnumerable<WordProgress>>()), Times.Once); _uow.Verify(u => u.Save(), Times.Once); }