public void HasPropertyTest1() { Uri baseUri = new Uri("http://example.com/test"); string relativeUri = "#myResource"; Resource target = new Resource(new Uri(baseUri, relativeUri)); Property property = new Property(new Uri(baseUri, "#related")); int value1 = 1; int value2 = 2; Assert.AreEqual(false, target.HasProperty(property, value1)); target.AddProperty(property, value1); Assert.AreEqual(true, target.HasProperty(property, value1)); Assert.AreEqual(false, target.HasProperty(property, value2)); target.AddProperty(property, value2); Assert.AreEqual(true, target.HasProperty(property, value1)); Assert.AreEqual(true, target.HasProperty(property, value2)); target.RemoveProperty(property, value1); Assert.AreEqual(false, target.HasProperty(property, value1)); Assert.AreEqual(true, target.HasProperty(property, value2)); target.RemoveProperty(property, value2); Assert.AreEqual(false, target.HasProperty(property, value1)); Assert.AreEqual(false, target.HasProperty(property, value2)); }
public void AddResourceTest() { Uri uriResource = new Uri("http://example.org/AddResourceTest"); IResource resource = new Resource(uriResource); Property property = new Property(new Uri("http://example.org/MyProperty")); resource.AddProperty(property, "in the jungle"); resource.AddProperty(property, 123); resource.AddProperty(property, DateTime.Now); Model.AddResource(resource); IResource actual = Model.GetResource(uriResource); Assert.AreEqual(uriResource, uriResource); Assert.AreEqual(resource.ListValues(property).Count(), actual.ListValues(property).Count()); uriResource = new Uri("http://example.org/AddResourceTest2"); Contact contact = new Contact(uriResource); contact.Fullname = "Peter"; Model.AddResource <Contact>(contact); Contact actualContact = Model.GetResource <Contact>(uriResource); Assert.AreEqual(uriResource, uriResource); Assert.AreEqual(contact.Fullname, actualContact.Fullname); }
public Resource Map(User user, params string[] properties) { var resource = new Resource(new Link(_uriHelper.GetUserUri(user.Id))); if (properties.Contains(Firstname)) { resource.AddProperty(Firstname, user.Firstname); } if (properties.Contains(Lastname)) { resource.AddProperty(Lastname, user.Lastname); } if (properties.Contains(Username)) { resource.AddProperty(Username, user.Username); } if (properties.Contains(Email)) { resource.AddProperty(Email, user.Email); } return(resource); }
public IEnumerable <Resource> Create(IEnumerable <Match> matches, string gameId, string teamIdOnTop, out int numberOfMatches) { numberOfMatches = 0; var matchMapper = new MatchMapper(_uriHelper); var teamMapper = new TeamMapper(_uriHelper); var matchesGroupedByCompetitionId = matches.ToLookup(m => m.CompetitionId); var competitionResources = new List <Resource>(); foreach (var group in matchesGroupedByCompetitionId) { bool teamIdFound = false; var matchesForOneCompetitionResource = new Resource(new Link(_uriHelper.GetHomeUri())); var matchResources = new List <Resource>(); bool first = true; foreach (var match in group) { if (first) { matchesForOneCompetitionResource.AddProperty("competition-name", match.Round.CompetitionName); matchesForOneCompetitionResource.AddProperty("round-name", match.Round.Name); } if (match.HomeTeamId.Equals(teamIdOnTop, StringComparison.OrdinalIgnoreCase) || match.AwayTeamId.Equals(teamIdOnTop, StringComparison.OrdinalIgnoreCase)) { teamIdFound = true; } var matchResource = matchMapper.Map(match, MatchMapper.HomeScore, MatchMapper.AwayScore, MatchMapper.Played, MatchMapper.HomePenaltyScore, MatchMapper.AwayPenaltyScore, MatchMapper.PenaltiesTaken); matchResource.AddResource("home-team", teamMapper.Map(match.HomeTeam, TeamMapper.TeamName)); matchResource.AddResource("away-team", teamMapper.Map(match.AwayTeam, TeamMapper.TeamName)); matchResources.Add(matchResource); numberOfMatches++; first = false; } matchesForOneCompetitionResource.AddResource("rel:matches", matchResources); if (teamIdFound) { competitionResources.Insert(0, matchesForOneCompetitionResource); } else { competitionResources.Add(matchesForOneCompetitionResource); } } return(competitionResources); }
public Resource Map(Match match, params string[] properties) { var resource = new Resource(new Link(_uriHelper.GetMatchUri(match.GameId, match.Id))); if (properties.Contains(HomeScore)) { resource.AddProperty(HomeScore, match.HomeScore); } if (properties.Contains(AwayScore)) { resource.AddProperty(AwayScore, match.AwayScore); } if (properties.Contains(CompetitionName)) { resource.AddProperty(CompetitionName, match.Round.CompetitionName); } if (properties.Contains(CompetitionType)) { resource.AddProperty(CompetitionType, match.Round.CompetitionType.ToString()); } if (properties.Contains(Round)) { resource.AddProperty(Round, match.Round.Name); } if (properties.Contains(Date)) { resource.AddProperty(Date, match.Date.ToString("dd-MMM")); } if (properties.Contains(Played)) { resource.AddProperty(Played, match.Played); } if (properties.Contains(PenaltiesTaken)) { resource.AddProperty(PenaltiesTaken, match.PenaltiesTaken); } if (properties.Contains(HomePenaltyScore)) { resource.AddProperty(HomePenaltyScore, match.HomePenaltyScore); } if (properties.Contains(AwayPenaltyScore)) { resource.AddProperty(AwayPenaltyScore, match.AwayPenaltyScore); } return(resource); }
public void UpdateResourceTest() { Property property = new Property(new Uri("http://example.org/MyProperty")); Uri resourceUri = new Uri("http://example.org/MyResource"); IResource resource = Model.GetResource(resourceUri); resource.RemoveProperty(property, 123); resource.Commit(); IResource actual = Model.GetResource(resourceUri); Assert.AreEqual(resource, actual); actual = Model.GetResource <Resource>(resourceUri); Assert.AreEqual(resource, actual); // Try to update resource with different properties then persisted Resource r2 = new Resource(resourceUri); r2.AddProperty(property, "in the jengle"); r2.Model = Model; r2.Commit(); actual = Model.GetResource <Resource>(resourceUri); Assert.AreEqual(r2, actual); }
public Resource Map(Season season, params string[] properties) { var resource = new Resource(new Link(_uriHelper.GetSeasonUri(season.GameId, season.Id))); if (properties.Contains(SeasonShortName)) { resource.AddProperty(SeasonShortName, season.ShortName); } if (properties.Contains(SeasonLongName)) { resource.AddProperty(SeasonLongName, season.LongName); } return(resource); }
public void ListPropertiesTest() { Uri baseUri = new Uri("http://example.com/test"); string relativeUri = "#myResource"; Resource target = new Resource(new Uri(baseUri, relativeUri)); Property property1 = new Property(new Uri(baseUri, "#related")); bool v1 = true; Property property2 = new Property(new Uri(baseUri, "#related2")); bool v2 = false; Property property3 = new Property(new Uri(baseUri, "#related3")); bool v3 = true; List<Property> expected = new List<Property> { property1, property2, property3 }; target.AddProperty(property1, v1); target.AddProperty(property2, v2); target.AddProperty(property3, v3); IEnumerable<Property> actual = target.ListProperties(); foreach (Property prop in actual) { Assert.AreEqual(true, expected.Contains(prop)); } target.RemoveProperty(property1, v1); expected.Remove(property1); actual = target.ListProperties(); foreach (Property prop in actual) { Assert.AreEqual(true, expected.Contains(prop)); } target.RemoveProperty(property2, v2); expected.Remove(property2); actual = target.ListProperties(); foreach (Property prop in actual) { Assert.AreEqual(true, expected.Contains(prop)); } target.RemoveProperty(property3, v3); expected.Remove(property3); actual = target.ListProperties(); Assert.AreEqual(actual.Count(), 0); }
public Resource Map(Team team, params string[] properties) { var resource = new Resource(new Link(_uriHelper.GetTeamUri(team.GameId, team.Id))); if (properties.Contains(TeamName)) { resource.AddProperty(TeamName, team.Name); } if (properties.Contains(Rating)) { resource.AddProperty(Rating, team.Rating); } if (properties.Contains(RatingGoalkeeper)) { resource.AddProperty(RatingGoalkeeper, team.RatingGoalkeeper); } if (properties.Contains(RatingDefence)) { resource.AddProperty(RatingDefence, team.RatingDefence); } if (properties.Contains(RatingMidfield)) { resource.AddProperty(RatingMidfield, team.RatingMidfield); } if (properties.Contains(RatingAttack)) { resource.AddProperty(RatingAttack, team.RatingAttack); } if (properties.Contains(RatingPercentage)) { var ratingPercentage = (team.Rating / 20) * 100; resource.AddProperty(RatingPercentage, ratingPercentage); } if (properties.Contains(LeagueName)) { resource.AddProperty(LeagueName, team.CurrentLeagueCompetition.Name); } if (properties.Contains(CurrentLeaguePosition)) { resource.AddProperty(CurrentLeaguePosition, team.CurrentLeaguePosition); } return(resource); }
public Resource Map(SeasonStatistics seasonStatistics, params string[] properties) { bool applyAllProperties = !properties.Any(); var teamMapper = new TeamMapper(_uriHelper); var resource = new Resource(new Link(_uriHelper.GetSeasonUri(seasonStatistics.GameId, seasonStatistics.Id))); if (applyAllProperties || properties.Contains(SeasonShortName)) { resource.AddProperty(SeasonShortName, seasonStatistics.Season.ShortName); } if (applyAllProperties || properties.Contains(SeasonLongName)) { resource.AddProperty(SeasonLongName, seasonStatistics.Season.LongName); } if (applyAllProperties || properties.Contains(NationalChampion) && seasonStatistics.NationalChampion != null) { var team = teamMapper.Map(seasonStatistics.NationalChampion, TeamMapper.TeamName); resource.AddResource(NationalChampion, team); } if (applyAllProperties || properties.Contains(NationalChampionRunnerUp) && seasonStatistics.NationalChampionRunnerUp != null) { var team = teamMapper.Map(seasonStatistics.NationalChampionRunnerUp, TeamMapper.TeamName); resource.AddResource(NationalChampionRunnerUp, team); } if (applyAllProperties || properties.Contains(NationalCupWinner) && seasonStatistics.CupWinner != null) { var team = teamMapper.Map(seasonStatistics.CupWinner, TeamMapper.TeamName); resource.AddResource(NationalCupWinner, team); } if (applyAllProperties || properties.Contains(NationalCupRunnerUp) && seasonStatistics.CupRunnerUp != null) { var team = teamMapper.Map(seasonStatistics.CupRunnerUp, TeamMapper.TeamName); resource.AddResource(NationalCupRunnerUp, team); } return(resource); }
public Resource Map(GameInfo gameInfo, params string[] properties) { var resource = new Resource(new Link(_uriHelper.GetGameUri(gameInfo.Id))); if (properties.Contains(GameName)) { resource.AddProperty(GameName, gameInfo.Name); } if (gameInfo.CurrentTeam != null) { if (properties.Contains(TeamName)) { resource.AddProperty(TeamName, gameInfo.CurrentTeam.Name); } } return(resource); }
public void TestFloat() { Property myProperty = new Property(new Uri("ex:myProperty")); Resource r = new Resource(new Uri("ex:myResource")); float val = 1.234F; r.AddProperty(myProperty, val); object res = r.ListValues(myProperty).First(); Assert.AreEqual(val.GetType(), res.GetType()); Assert.AreEqual(val, res); r.RemoveProperty(myProperty, val); }
public void TestString() { Property myProperty = new Property(new Uri("ex:myProperty")); Resource r = new Resource(new Uri("ex:myResource")); string val = "Hello World!"; r.AddProperty(myProperty, val); object res = r.ListValues(myProperty).First(); Assert.AreEqual(val.GetType(), res.GetType()); Assert.AreEqual(val, res); r.RemoveProperty(myProperty, val); }
public void TestDateTime() { Property myProperty = new Property(new Uri("ex:myProperty")); Resource r = new Resource(new Uri("ex:myResource")); DateTime val = DateTime.Today; r.AddProperty(myProperty, val); object res = r.ListValues(myProperty).First(); Assert.AreEqual(val.GetType(), res.GetType()); Assert.AreEqual(val, res); r.RemoveProperty(myProperty, val); }
public void TestStringSerializeResource() { Resource r = new Resource("http://example.com/ex"); r.AddProperty(Ontologies.dc.title, "MyResource"); string res = SparqlSerializer.SerializeResource(r); string expected = "<http://example.com/ex> <http://purl.org/dc/elements/1.1/title> 'MyResource'. "; Assert.AreEqual(expected, res); }
public void HasPropertyTest2() { Uri baseUri = new Uri("http://example.com/test"); string relativeUri = "#myResource"; Resource target = new Resource(new Uri(baseUri, relativeUri)); // TODO: Passenden Wert initialisieren Property property = new Property(new Uri(baseUri, "#related")); string value1 = "Hallo Welt"; CultureInfo lang1 = CultureInfo.GetCultureInfo("DE"); string value2 = "Hello World"; CultureInfo lang2 = CultureInfo.GetCultureInfo("en-US"); string value3 = "Hello"; Assert.AreEqual(false, target.HasProperty(property, value1, lang1)); target.AddProperty(property, value1, lang1); // Current interpretation -> Value+Language != Value Assert.AreEqual(true, target.HasProperty(property, value1, lang1)); Assert.AreEqual(false, target.HasProperty(property, value1)); Assert.AreEqual(false, target.HasProperty(property, value2, lang2)); Assert.AreEqual(false, target.HasProperty(property, value3)); target.AddProperty(property, value2, lang2); Assert.AreEqual(true, target.HasProperty(property, value1, lang1)); Assert.AreEqual(true, target.HasProperty(property, value2, lang2)); Assert.AreEqual(false, target.HasProperty(property, value3)); target.AddProperty(property, value3); Assert.AreEqual(true, target.HasProperty(property, value1, lang1)); Assert.AreEqual(true, target.HasProperty(property, value2, lang2)); Assert.AreEqual(true, target.HasProperty(property, value3)); target.RemoveProperty(property, value3); Assert.AreEqual(true, target.HasProperty(property, value1, lang1)); Assert.AreEqual(true, target.HasProperty(property, value2, lang2)); Assert.AreEqual(false, target.HasProperty(property, value3)); target.RemoveProperty(property, value2, lang2); Assert.AreEqual(true, target.HasProperty(property, value1, lang1)); Assert.AreEqual(false, target.HasProperty(property, value2, lang2)); Assert.AreEqual(false, target.HasProperty(property, value2)); }
public Resource Map(GameDateTime gameDateTime, params string[] properties) { var resource = new Resource(new Link(_uriHelper.GetPresentGameDateTimeUri(gameDateTime.GameId, gameDateTime.Id))); if (!properties.Any() || properties.Contains(Date)) { resource.AddProperty(Date, gameDateTime.Date); } if (!properties.Any() || properties.Contains(DateTime)) { resource.AddProperty(DateTime, gameDateTime.DateTime); } if (!properties.Any() || properties.Contains(NavigationForm)) { AddForm(resource, gameDateTime.GameId, gameDateTime.CanNavigateToNext()); } return resource; }
public void AddPropertyTest() { Uri baseUri = new Uri("http://example.com/test"); string relativeUri = "#myResource"; Resource target = new Resource(new Uri(baseUri, relativeUri)); Property property = new Property(new Uri(baseUri, "#related")); bool value = false; target.AddProperty(property, value); Assert.IsTrue(target.HasProperty(property)); Assert.AreEqual(value, target.ListValues(property).First()); Assert.AreEqual(value.GetType(), target.ListValues(property).First().GetType()); }
public void RemovePropertyTest() { Uri baseUri = new Uri("http://example.com/test"); string relativeUri = "#myResource"; Resource target = new Resource(new Uri(baseUri, relativeUri)); Property property = new Property(new Uri(baseUri, "#related")); double value = 0.12345632F; // TODO: Passenden Wert initialisieren target.AddProperty(property, value); Assert.AreEqual(true, target.HasProperty(property, value)); target.RemoveProperty(property, value); Assert.AreEqual(false, target.HasProperty(property, value)); Assert.AreEqual(false, target.HasProperty(property)); }
public Resource Map(TeamStatistics teamStatistics, params string[] properties) { bool applyAllProperties = !properties.Any(); var resource = new Resource(new Link(_uriHelper.GetTeamStatsUri(teamStatistics.GameId, teamStatistics.TeamId))); if (applyAllProperties || properties.Contains(LeagueTablePositions)) { resource.AddProperty(LeagueTablePositions, teamStatistics.LeagueTablePositions); } return(resource); }
public Resource Map(LeagueTable leagueTable, params string[] properties) { var teamMapper = new TeamMapper(_uriHelper); var leagueTableLink = new Link(_uriHelper.GetCompetitionLeagueTableUri(leagueTable.GameId, leagueTable.SeasonCompetition.SeasonId, leagueTable.SeasonCompetition.CompetitionId)); var resource = new Resource(leagueTableLink); resource.AddProperty("competition-name", leagueTable.CompetitionName); var positions = new List <Resource>(); foreach (var leagueTablePosition in leagueTable.LeagueTablePositions) { var position = new Resource(leagueTableLink); position.AddResource("team", teamMapper.Map(leagueTablePosition.Team, TeamMapper.TeamName, TeamMapper.LeagueName, TeamMapper.CurrentLeaguePosition)); position.AddProperty("position", leagueTablePosition.Position); position.AddProperty("played", leagueTablePosition.Matches); position.AddProperty("points", leagueTablePosition.Points); if (properties.Contains(FullDetails)) { position.AddProperty("wins", leagueTablePosition.Wins); position.AddProperty("draws", leagueTablePosition.Draws); position.AddProperty("losses", leagueTablePosition.Losses); position.AddProperty("goals-scored", leagueTablePosition.GoalsScored); position.AddProperty("goals-conceded", leagueTablePosition.GoalsConceded); string goalDifference = leagueTablePosition.GoalDifference.ToString(); if (leagueTablePosition.GoalDifference > 0) { goalDifference = $"+{goalDifference}"; } position.AddProperty("goal-difference", goalDifference); } positions.Add(position); } resource.AddResource("positions", positions.ToArray()); return(resource); }
public void TestBool() { Property myProperty = new Property(new Uri("ex:myProperty")); Resource r1 = new Resource(new Uri("ex:myResource")); bool val = true; r1.AddProperty(myProperty, val); object res = r1.ListValues(myProperty).First(); Assert.AreEqual(res.GetType(), typeof(bool)); Assert.AreEqual((bool)res, val); }
public void TestInt() { Property myProperty = new Property(new Uri("ex:myProperty")); Resource r1 = new Resource(new Uri("ex:myResource")); int val1 = 123; r1.AddProperty(myProperty, val1); object res1 = r1.ListValues(myProperty).First(); Assert.AreEqual(val1.GetType(), res1.GetType()); Assert.AreEqual(res1, val1); r1.RemoveProperty(myProperty, val1); }
public void RemovePropertyTest4() { Uri baseUri = new Uri("http://example.com/test"); string relativeUri = "#myResource"; Resource target = new Resource(new Uri(baseUri, relativeUri)); Property property = new Property(new Uri(baseUri, "#related")); IResource value = new Resource(new Uri(baseUri, "#mySecondResource")); target.AddProperty(property, value); Assert.AreEqual(true, target.HasProperty(property, value)); target.RemoveProperty(property, value); Assert.AreEqual(false, target.HasProperty(property, value)); Assert.AreEqual(false, target.HasProperty(property)); }
public void RemovePropertyTest7() { Uri baseUri = new Uri("http://example.com/test"); string relativeUri = "#myResource"; Resource target = new Resource(new Uri(baseUri, relativeUri)); Property property = new Property(new Uri(baseUri, "#related")); string value = "Hello"; CultureInfo language = CultureInfo.GetCultureInfo("en-US"); target.AddProperty(property, value, language); Assert.AreEqual(true, target.HasProperty(property, value, language)); target.RemoveProperty(property, value, language); Assert.AreEqual(false, target.HasProperty(property, value, language)); Assert.AreEqual(false, target.HasProperty(property)); }
public void TestByteArray() { Property myProperty = new Property(new Uri("ex:myProperty")); Resource r = new Resource(new Uri("ex:myResource")); byte[] val = new byte[] { 1, 2, 3, 4, 5 }; r.AddProperty(myProperty, val); object res = r.ListValues(myProperty).First(); Assert.AreEqual(val.GetType(), res.GetType()); Assert.AreEqual(val, res); r.RemoveProperty(myProperty, val); }
public void TestLocalizedString() { Property myProperty = new Property(new Uri("ex:myProperty")); Resource r = new Resource(new Uri("ex:myResource")); string val = "Hello World!"; var ci = "en"; r.AddProperty(myProperty, val, ci); object res = r.ListValues(myProperty).First(); Assert.AreEqual(typeof(Tuple<string, string>), res.GetType()); Tuple<string, string> v = res as Tuple<string, string>; Assert.AreEqual(val, v.Item1); Assert.AreEqual(ci.ToLower(), v.Item2.ToLower()); r.RemoveProperty(myProperty, val, ci); }
public void TestSingle() { Uri resourceUri = new Uri("ex:myResource"); Property myProperty = new Property(new Uri("ex:myProperty")); Resource r1 = Model.CreateResource <Resource>(resourceUri); Single val = 1.223F; r1.AddProperty(myProperty, val); r1.Commit(); r1 = Model.GetResource <Resource>(resourceUri); object res = r1.ListValues(myProperty).First(); Assert.AreEqual(typeof(Single), res.GetType()); Assert.AreEqual(val, res); }
public void TestString() { Uri resourceUri = new Uri("ex:myResource"); Property myProperty = new Property(new Uri("ex:myProperty")); Resource r1 = Model.CreateResource <Resource>(resourceUri); string val = "Hello World!"; r1.AddProperty(myProperty, val); r1.Commit(); r1 = Model.GetResource <Resource>(resourceUri); object res = r1.ListValues(myProperty).First(); Assert.AreEqual(typeof(string), res.GetType()); Assert.AreEqual(val, res); }
public void TestDateTime() { Uri resourceUri = new Uri("ex:myResource"); Property myProperty = new Property(new Uri("ex:myProperty")); Resource r1 = Model.CreateResource <Resource>(resourceUri); DateTime val = DateTime.Today; r1.AddProperty(myProperty, val); r1.Commit(); r1 = Model.GetResource <Resource>(resourceUri); object res = r1.ListValues(myProperty).First(); Assert.AreEqual(typeof(DateTime), res.GetType()); Assert.AreEqual(val.ToLocalTime(), ((DateTime)res).ToLocalTime()); }