public void SetUp() { dataJson = JObject.Parse(data); var repo = new Mock <IRepository>(); repo.Setup(r => r.GetSubject(It.IsAny <string>())).Returns((Subject)null); repo.Setup(r => r.GetLocation(It.IsAny <string>())).Returns((Location)null); repo.Setup(r => r.GetGenre(It.IsAny <string>())).Returns((Genre)null); importer = new FinnaImporter(repo.Object, " : "); item = importer.CreateItem(dataJson); }
public void NoPrimaryAuthorTest() { var data = @"{ ""primaryAuthors"": [], ""title"": ""Naamiot"", ""secondaryAuthors"": [ ""Kumara-Moisio, Taru, toimittaja"", ""Leinonen, Anne, toimittaja"", ""Roininen, Minna, toimittaja"" ], ""subjects"": [], }"; dataJson = JObject.Parse(data); item = importer.CreateItem(dataJson); Assert.AreEqual("Taru Kumara-Moisio", item.AuthorName, "The secondaryAuthors field should be used if there is no primary author"); }
public IHttpActionResult ImportFinnaItem([FromBody] JObject finnaItem, string password) { var settings = WebConfigurationManager.AppSettings; var adminPassword = settings["AdminPassword"]; if (string.IsNullOrEmpty(adminPassword) || adminPassword != password) { return(StatusCode(HttpStatusCode.Unauthorized)); } var separator = settings["SubjectPartSeparator"]; var importer = new FinnaImporter(repository, separator); Item item = importer.CreateItem(finnaItem); repository.AddItem(item); CreateAndSaveTitleCard(item); repository.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { controller = "Items", id = item.ID }, item)); }