public void CreateNew_WithId_CreatesElement() { var person = new Mock <ProjectElement>(); person.Setup(p => p.Id).Returns("joe"); using (var tempFolder = new TemporaryFolder("ElementRepoTestFolder")) { var repo = new ElementRepository <ProjectElement>(tempFolder.Path, "elementGroupName", null, (folder, id, idChangedAction) => person.Object); repo.CreateNew("joe"); Assert.IsTrue(repo.AllItems.Contains(person.Object)); } }
public void GetById_Found_ReturnsItem() { var person = new Mock <ProjectElement>(); person.Setup(p => p.Id).Returns("joe"); using (var tempFolder = new TemporaryFolder("ElementRepoTestFolder")) { var repo = new ElementRepository <ProjectElement>(tempFolder.Path, "elementGroupName", null, (folder, id, idChangedAction) => person.Object); repo.CreateNew("joe"); Assert.AreEqual(person.Object, repo.GetById("joe")); } }
public void Setup() { SIL.Reporting.ErrorReport.IsOkToInteractWithUser = false; _tmpFolder = new TemporaryFolder("elementRepoTestFolder"); var peter = new Mock <Person>(); peter.Setup(p => p.Id).Returns("peter"); peter.Setup(p => p.GetComponentFiles()).Returns(new[] { ComponentFileTests.CreateComponentFile(_tmpFolder, peter.Object, "peterSong1.mp3"), ComponentFileTests.CreateComponentFile(_tmpFolder, peter.Object, "peterSong2.mp3"), }); var paul = new Mock <Person>(); paul.Setup(p => p.Id).Returns("paul"); paul.Setup(p => p.GetComponentFiles()).Returns(new[] { ComponentFileTests.CreateComponentFile(_tmpFolder, peter.Object, "paulSong1.mp3"), ComponentFileTests.CreateComponentFile(_tmpFolder, peter.Object, "paulSong2.mp3"), }); var mary = new Mock <Person>(); mary.Setup(p => p.Id).Returns("mary"); mary.Setup(p => p.GetComponentFiles()).Returns(new[] { ComponentFileTests.CreateComponentFile(_tmpFolder, peter.Object, "marySong1.mp3"), ComponentFileTests.CreateComponentFile(_tmpFolder, peter.Object, "marySong2.mp3"), }); _repo = new ElementRepository <Person>(_tmpFolder.Path, Person.kFolderName, new PersonFileType(null, null), (folder, id, idChangedAction) => { switch (id) { case "peter": return(peter.Object); case "paul": return(paul.Object); case "mary": return(mary.Object); } return(null); }); Directory.CreateDirectory(_tmpFolder.Combine(Person.kFolderName, "peter")); Directory.CreateDirectory(_tmpFolder.Combine(Person.kFolderName, "paul")); Directory.CreateDirectory(_tmpFolder.Combine(Person.kFolderName, "mary")); peter.Setup(p => p.FolderPath).Returns(_tmpFolder.Combine(Person.kFolderName, "peter")); paul.Setup(p => p.FolderPath).Returns(_tmpFolder.Combine(Person.kFolderName, "paul")); mary.Setup(p => p.FolderPath).Returns(_tmpFolder.Combine(Person.kFolderName, "mary")); _repo.CreateNew("peter"); _repo.CreateNew("paul"); _repo.CreateNew("mary"); _model = new ElementListViewModel <Person>(_repo); }
/// ------------------------------------------------------------------------------------ public T CreateNewElement() { return(_repository.CreateNew(null)); }