public static void Main(string[] args) { var listingService = new ListingService(); var listing1 = listingService.Create(new FreeListing { Name = "Restaurante Las Antillas" }); var listing2 = listingService.Create(null); }
public void GetAllTest() { Setup(); var id = GetRandomId(); var listing = new Listing { Id = id, ListingUrl = "https://url.com" }; var newListing = _listingService.Create(listing).Result; var listings = _listingService.GetAll(null).Result.ToList(); Assert.IsTrue(listings.Exists(x => x.Id == id)); }
public void Init() { path = Path.GetFullPath(path); parentPath = Path.GetFullPath(parentPath); testPath = Path.GetFullPath(testPath); if (!ListingService.Exists(path)) { ListingService.Create("Test", parentPath, Data.Listing.ListingTypeOption.Directory, Data.Listing.DuplicateListingActionOption.NoAction); } var deleteFiles = ListingService.GetListingByDirectory(path, true, true); foreach (var f in deleteFiles) { ListingService.Delete(f.FullFilePath); } var testFiles = ListingService.GetListingByDirectory(testPath, false, true); foreach (var f in testFiles) { ListingService.Copy(f.FullFilePath, path + @"\" + f.Name); } }
public void Delete() { // Delete non existance of file. try { ListingService.Delete(path + @"\delete.txt"); Assert.Fail(); } catch (ByteTurnNotFoundException byteturnex) { Assert.AreEqual(typeof(ByteTurnNotFoundException), byteturnex.GetType()); } // Illegal characters. try { ListingService.Delete(path + @"\dele|te.txt"); Assert.Fail(); } catch (ByteTurnNotSupportedException byteturnex) { Assert.AreEqual(typeof(ByteTurnNotSupportedException), byteturnex.GetType()); } var p = ListingService.Create("testfile-3.txt", path, ListingTypeOption.File, DuplicateListingActionOption.NoAction); ListingService.Delete(path + @"\testfile-3.txt"); }
public ActionResult <Listing> Create([FromBody] Listing newListing) { try { return(Ok(_bs.Create(newListing))); } catch (System.Exception err) { return(BadRequest(err)); } }
public void Move() { // Create 3 text files. var p = ListingService.Create("testfile-5.txt", path, ListingTypeOption.File, DuplicateListingActionOption.NoAction); ListingService.Create("testfile-51.txt", path, ListingTypeOption.File, DuplicateListingActionOption.NoAction); ListingService.Create("testfile-53.txt", path, ListingTypeOption.File, DuplicateListingActionOption.NoAction); // No action - file does not exist. var f = ListingService.Move(path + @"\testfile-5.txt", path + @"\testfile-52.txt", DuplicateListingActionOption.NoAction); Assert.AreEqual(f, path + @"\testfile-52.txt"); Assert.AreEqual(ListingService.Exists(path + @"\testfile-52.txt"), true); Assert.AreEqual(ListingService.Exists(path + @"\testfile-5.txt"), false); // No action - file exists. try { f = ListingService.Move(path + @"\testfile-51.txt", path + @"\testfile-52.txt", DuplicateListingActionOption.NoAction); Assert.Fail(); } catch (ByteTurnExistsException byteturnex) { Assert.AreEqual(typeof(ByteTurnExistsException), byteturnex.GetType()); } // Illegal characters. try { f = ListingService.Move(path + @"\testf|ile-51.txt", path + @"\testfil|e-52.txt", DuplicateListingActionOption.NoAction); Assert.Fail(); } catch (ByteTurnNotSupportedException byteturnex) { Assert.AreEqual(typeof(ByteTurnNotSupportedException), byteturnex.GetType()); } // Overwrite f = ListingService.Move(path + @"\testfile-51.txt", path + @"\testfile-52.txt", DuplicateListingActionOption.Overwrite); Assert.AreEqual(f, path + @"\testfile-52.txt"); Assert.AreEqual(ListingService.Exists(path + @"\testfile-52.txt"), true); Assert.AreEqual(ListingService.Exists(path + @"\testfile-51.txt"), false); // Append number f = ListingService.Move(path + @"\testfile-53.txt", path + @"\testfile-52.txt", DuplicateListingActionOption.AppendNumber); Assert.AreEqual(f, path + @"\(1) testfile-52.txt"); Assert.AreEqual(ListingService.Exists(path + @"\(1) testfile-52.txt"), true); Assert.AreEqual(ListingService.Exists(path + @"\testfile-53.txt"), false); }
public void Create() { try { ListingService.Create("testfile.txt", path, ListingTypeOption.File, DuplicateListingActionOption.NoAction); Assert.Fail(); } catch (ByteTurnExistsException byteturnex) { Assert.AreEqual(typeof(ByteTurnExistsException), byteturnex.GetType()); } // Illegal characters. try { ListingService.Create("testfile|.txt", path, ListingTypeOption.File, DuplicateListingActionOption.NoAction); Assert.Fail(); } catch (ByteTurnNotSupportedException byteturnex) { Assert.AreEqual(typeof(ByteTurnNotSupportedException), byteturnex.GetType()); } var p = ListingService.Create("testfile-2.txt", path, ListingTypeOption.File, DuplicateListingActionOption.NoAction); Assert.AreEqual(p, path + @"\testfile-2.txt"); Assert.AreEqual(ListingService.Exists(path + @"\testfile-2.txt"), true); p = ListingService.Create("testfile.txt", path, ListingTypeOption.File, DuplicateListingActionOption.AppendNumber); Assert.AreEqual(p, path + @"\(1) testfile.txt"); Assert.AreEqual(ListingService.Exists(path + @"\(1) testfile.txt"), true); p = ListingService.Create("testfile.txt", path, ListingTypeOption.File, DuplicateListingActionOption.Overwrite); Assert.AreEqual(p, path + @"\testfile.txt"); var f = new FileData(p); Assert.AreEqual(f.Size.IsEqual(new FileSize(0)), true); }
public ActionResult <Listing> Create(Listing listing) { _listingService.Create(listing); return(CreatedAtRoute("GetListing", new { id = listing.Id.ToString() }, listing)); }
public async Task <Listing> Post([FromBody] Listing request) { var listing = await _listingService.Create(request); return(listing); }