public InventoryItem(NancyContext context, InventoryItemDto item) : base(context.Request.Url.ToString(), new [] { "item", "detail" }) { Properties = new Dictionary <string, object> { { "Name", item.Name }, { "Quantity", item.Quantity } }; Links = new LinksFactory(context) .With(new GetInventoryLink(), WithLink <GetInventoryLink> .Property(x => x.Title = "Back to inventory")) .Build(); Actions = new ActionsFactory(context) .With(new AddInventoryItemQuantityAction(item.Id, item.Version), WithAction <AddInventoryItemQuantityAction> .Field(x => x.Version) .Having(x => x.Type = "hidden")) .With(new RemoveInventoryItemQuantityAction(item.Id, item.Version), WithAction <RemoveInventoryItemQuantityAction> .Field(x => x.Version) .Having(x => x.Type = "hidden")) .With(new RenameInventoryItemAction(item.Id, item.Version, item.Name), WithAction <RenameInventoryItemAction> .Field(x => x.Version) .Having(x => x.Type = "hidden")) .Build(); }
public void TestLoadAndRunDynamicSecondImpl() { var cities = new Cities(); cities.ReadCities(CitiesTestFile); ILinks links = LinksFactory.Create(cities, "Fhnw.Ecnf.RoutePlanner.RoutePlannerTest.TestLinksValidConstructor"); Assert.AreEqual(42, links.ReadLinks("nonsense")); ILinks links2 = LinksFactory.Create(cities, "Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.Links"); Assert.AreNotEqual(links.GetType(), links2.GetType()); try { LinksFactory.Create(cities, "Fhnw.Ecnf.RoutePlanner.RoutePlannerTest.Lab5Test.TestLinksInvalidConstructor"); Assert.Fail("Should throw a NotSupportedException, because it doesn't have the right constructor"); } catch (NotSupportedException) { } try { LinksFactory.Create(cities, "Fhnw.Ecnf.RoutePlanner.RoutePlannerTest.Lab10Test.TestLinksNoInterface"); Assert.Fail("Should throw a NotSupportedException, because ILinks is not implemented"); } catch (NotSupportedException) { } }
public Root(NancyContext context) : base(context.Request.Url.ToString(), "root") { Links = new LinksFactory(context).With(new GetUsers()).Build(); Actions = new ActionsFactory(context) .With(new DeleteLogout()) .Build(); }
public void TestLoadDynamicValid() { var cities = new Cities(); // now test for correct dynamic creation of valid routed class passed as string var links = LinksFactory.Create(cities, "Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.Links"); Assert.IsInstanceOfType(links, typeof(ILinks)); }
public UsersCollection(NancyContext context, IEnumerable <Domain.User> users) : base(context.Request.Url.ToString(), new[] { "users", "collection" }) { int pageNumber = context.Request.Query.PageNumber; int pageSize = context.Request.Query.PageSize; int totalEntries = users.Count(); var usersPage = users.Skip(pageNumber * pageSize).Take(pageSize); Properties = new Dictionary <string, object> { { "Page Details", PagedProperties.GetPageDetails(pageNumber, pageSize, totalEntries) } }; Entities = new List <Entity>(usersPage.Select(x => new UsersCollectionItem(context, x))); Links = new LinksFactory(context).WithPage <GetUsers>(pageNumber, pageSize, totalEntries).Build(); }
public UsersCollectionItem(NancyContext context, Domain.User user) : base(string.Format("{0}{1}{2}/{3}", context.Request.Url.SiteBase, context.Request.Url.BasePath, context.Request.Url.Path, user.Id), "user") { Properties = new Dictionary <string, object> { { "Username", user.Username }, { "Created On", user.CreatedOn.ToShortDateString() } }; Links = new LinksFactory(context).With(new GetUser(user.Id)).Build(); Actions = new ActionsFactory(context).With(new DeleteUser { Id = user.Id }).Build(); }
public InventoryCollectionItem(NancyContext context, InventoryListItemDto item) : base($"{context.Request.Url.SiteBase}{context.Request.Url.BasePath}{context.Request.Url.Path}/{item.Id}", "inventory-item") { Properties = new Dictionary <string, object> { { "Name", item.Name } }; Links = new LinksFactory(context).With(new GetInventoryItemLink(item.Id)).Build(); Actions = new ActionsFactory(context) .With(new RemoveInventoryItemAction(item.Id, item.Version), WithAction <RemoveInventoryItemAction> .Field(x => x.Version) .Having(x => x.Type = "hidden")) .Build(); }
public User(NancyContext context, Domain.User user) : base(context.Request.Url.ToString(), "user") { Properties = new Dictionary <string, object> { { "Username", user.Username }, { "Claims", string.Join(", ", user.Claims.Select(x => x.ToString()).ToList()) } }; Links = new LinksFactory(context).With(new GetUsers(), WithLink <GetUsers> .Property(x => x.Title = "Back to all users")).Build(); Actions = new ActionsFactory(context).With(new PutClaims(user), WithAction <PutClaims> .Field(x => x.Claims) .Having(x => x.Type = "select") .Having(x => x.Options = GetClaimsOptions())).Build(); }
public InventoryCollection(NancyContext context, ICollection <InventoryListItemDto> items) : base(context.Request.Url.ToString(), new[] { "inventory", "collection" }) { int pageNumber = context.Request.Query.PageNumber; int pageSize = context.Request.Query.PageSize; int totalEntries = items.Count; var booksPage = items.Skip(pageNumber * pageSize).Take(pageSize); Properties = new Dictionary <string, object> { { "Page Details", PagedProperties.GetPageDetails(pageNumber, pageSize, totalEntries) } }; Entities = new List <Entity>(booksPage.Select(x => new InventoryCollectionItem(context, x))); Links = new LinksFactory(context).WithPage <GetInventoryLink>(pageNumber, pageSize, totalEntries).Build(); Actions = new ActionsFactory(context).With(new AddInventoryItemAction()).Build(); }
public void TestLoadAndRunDynamicClassicImpl() { var cities = new Cities(); cities.ReadCities(CitiesTestFile); ILinks links = LinksFactory.Create(cities, "Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.Links"); links.ReadLinks(LinksTestFile); Assert.AreEqual(28, cities.Count); // test available cities List <Link> resultLinks = links.FindShortestRouteBetween("Zürich", "Basel", TransportMode.Rail); var expectedLinks = new List <Link>(); expectedLinks.Add(new Link(new City("Zürich", "Switzerland", 7000, 1, 2), new City("Aarau", "Switzerland", 7000, 1, 2), 0)); expectedLinks.Add(new Link(new City("Aarau", "Switzerland", 7000, 1, 2), new City("Liestal", "Switzerland", 7000, 1, 2), 0)); expectedLinks.Add(new Link(new City("Liestal", "Switzerland", 7000, 1, 2), new City("Basel", "Switzerland", 7000, 1, 2), 0)); Assert.IsNotNull(resultLinks); Assert.AreEqual(expectedLinks.Count, resultLinks.Count); for (int i = 0; i < resultLinks.Count; i++) { Assert.IsTrue( (expectedLinks[i].FromCity.Name == resultLinks[i].FromCity.Name && expectedLinks[i].ToCity.Name == resultLinks[i].ToCity.Name) || (expectedLinks[i].FromCity.Name == resultLinks[i].ToCity.Name && expectedLinks[i].ToCity.Name == resultLinks[i].FromCity.Name)); } try { resultLinks = links.FindShortestRouteBetween("doesNotExist", "either", TransportMode.Rail); Assert.Fail("Should throw a KeyNotFoundException"); } catch (KeyNotFoundException) { } }
public static void TestGexf(string filename) { using (var memoryManager = new UInt64LinksMemoryManager(filename, 512 * 1024 * 1024)) { var options = new LinksOptions<ulong>(); options.MemoryManager = memoryManager; var linksFactory = new LinksFactory<ulong>(options); var links = linksFactory.Create(); const int linksToCreate = 1024; links.RunRandomCreations(linksToCreate); memoryManager.ExportSourcesTree(filename + ".gexf"); Console.ReadKey(); } }
public void TestLoadDynamicInvalid() { var cities = new Cities(); // pass a name of a class that does not exist try { ILinks links = LinksFactory.Create(cities, "Class.Does.Not.Exist"); Assert.Fail("Should throw a NotSupportedException"); } catch (NotSupportedException) { } // pass a name of a class that exists, but does not implement the interface try { ILinks links = LinksFactory.Create(cities, "Cities"); Assert.Fail("Should throw a NotSupportedException"); } catch (NotSupportedException) { } }
public Root(NancyContext context) : base(context.Request.Url.ToString(), "root") { Links = new LinksFactory(context) .With(new GetInventoryLink()) .Build(); }