public void ReadManningBooksJsonListAuthorsDuplicateOk() { //SETUP var callingAssemblyPath = TestData.GetCallingAssemblyTopLevelDir(); var fileDir = Path.GetFullPath(Path.Combine(callingAssemblyPath, "..\\BookApp.UI\\wwwroot\\seedData")); var filePath = Directory.GetFiles(fileDir, "ManningBooks*.json").FirstOrDefault(); //ATTEMPT var list = JsonConvert.DeserializeObject <List <ManningBooksJson> >(File.ReadAllText(filePath)); //VERIFY var authorsDict = new Dictionary <string, ManningBooksJson>(); foreach (var json in list) { var authors = ManningBookLoad.NormalizeAuthorNames(json).ToList(); if (!authors.Any()) { continue; } foreach (var author in authors) { if (authorsDict.ContainsKey(author)) { _output.WriteLine($"Duplicate author {author}. This books = {json.title}, last book = {authorsDict[author].title}"); } authorsDict[author] = json; } } }
public void TestLoadBooksOk() { //SETUP var callingAssemblyPath = TestData.GetCallingAssemblyTopLevelDir(); var fileDir = Path.Combine(TestData.GetTestDataDir(), "seedData\\"); var loader = new ManningBookLoad(fileDir, "ManningBooks*.json", "ManningDetails*.json"); //ATTEMPT var loadedBooks = loader.LoadBooks(false); //VERIFY loadedBooks.Count().ShouldEqual(6); }
public void TestLoadBooksFromTestDataOk() { //SETUP var fileDir = Path.Combine(TestData.GetTestDataDir(), "seedData\\"); var loader = new ManningBookLoad(fileDir, "ManningBooks*.json", "ManningDetails*.json"); //ATTEMPT var loadedBooks = loader.LoadBooks(true).ToList(); //VERIFY loadedBooks.Count().ShouldEqual(6); loadedBooks.Count(x => x.Details?.Description != null).ShouldEqual(0); loadedBooks.All(x => x.Tags.Select(x => x.TagId).Contains("Manning books")).ShouldBeTrue(); }
public void ReadManningBooksJsonListAuthorsDisplayConvertedOk() { //SETUP var callingAssemblyPath = TestData.GetCallingAssemblyTopLevelDir(); var fileDir = Path.GetFullPath(Path.Combine(callingAssemblyPath, "..\\BookApp.UI\\wwwroot\\seedData")); var filePath = Directory.GetFiles(fileDir, "ManningBooks*.json").FirstOrDefault(); //ATTEMPT var list = JsonConvert.DeserializeObject <List <ManningBooksJson> >(File.ReadAllText(filePath)); //VERIFY foreach (var json in list) { _output.WriteLine(string.Join('|', ManningBookLoad.NormalizeAuthorNames(json))); } }
public void TestLoadBooksCheckTagsOk(bool tagAsOriginal) { //SETUP var callingAssemblyPath = TestData.GetCallingAssemblyTopLevelDir(); var fileDir = Path.Combine(TestData.GetTestDataDir(), "seedData\\"); var loader = new ManningBookLoad(fileDir, "ManningBooks*.json", "ManningDetails*.json"); //ATTEMPT var loadedBooks = loader.LoadBooks(tagAsOriginal); //VERIFY foreach (var book in loadedBooks) { book.Tags.Any().ShouldBeTrue(); book.Tags.Select(x => x.TagId).Contains("Manning books").ShouldEqual(tagAsOriginal); } }
public void TestLoadBooksAddTenToDatabaseOk() { //SETUP var options = SqliteInMemory.CreateOptions <BookDbContext>(); using var context = new BookDbContext(options); context.Database.EnsureCreated(); var callingAssemblyPath = TestData.GetCallingAssemblyTopLevelDir(); var fileDir = Path.Combine(TestData.GetTestDataDir(), "seedData\\"); var loader = new ManningBookLoad(fileDir, "ManningBooks*.json", "ManningDetails*.json"); //ATTEMPT context.AddRange(loader.LoadBooks(false)); context.SaveChanges(); //VERIFY context.Books.Count().ShouldEqual(6); context.Authors.Count().ShouldEqual(8); context.Tags.Count().ShouldEqual(5); }