public async Task <string> GetSpartanImageUrl(string gamertag, ImageSize size = ImageSize.ExtraSmall, Enumeration.CropType crop = Enumeration.CropType.Full) { gamertag = gamertag.ToUpper(); var data = await _db.FindAsync <SpartanImageData>(gamertag); if (data == null || (DateTime.UtcNow - data.Timestamp.ToUniversalTime()).TotalDays > 3) { var query = new GetSpartanImage().ForPlayer(gamertag).Size((int)size).Crop(crop); var image = await _session.Query(query); if (image == null) { return(null); } if (data == null) { data = new SpartanImageData(gamertag, image.Uri, DateTime.UtcNow); _db.InsertAsync(data); } else { data.Data = image.Uri; data.Timestamp = DateTime.UtcNow; //await _db.UpdateAsync(data); } } return(data.Data); }
public void GetConstructedUri_NoParamaters_MatchesExpected() { var query = new GetSpartanImage(); var uri = query.GetConstructedUri(); Assert.AreEqual($"profile/h5/profiles/{null}/spartan{null}", uri); }
public async Task GetSpartanImage_MissingGamertag() { var query = new GetSpartanImage(); await Global.Session.Query(query); Assert.Fail("An exception should have been thrown"); }
public void GetConstructedUri_NoParamaters_MatchesExpected() { var query = new GetSpartanImage(); var uri = query.GetConstructedUri(); Assert.AreEqual(string.Format(BaseUri, null, null), uri); }
public async Task GetSpartanImage_InvalidGamertag(string gamertag) { var query = new GetSpartanImage(gamertag); await Global.Session.Query(query); Assert.Fail("An exception should have been thrown"); }
public void GetConstructedUri_NoParameters_MatchesExpected() { var query = new GetSpartanImage(); var uri = query.GetConstructedUri(); Assert.AreEqual($"profile/h5/profiles/{null}/spartan{null}", uri); }
public async Task GetSpartanImage(string gamertag) { var query = new GetSpartanImage() .ForPlayer(gamertag); var result = await Global.Session.Query(query); Assert.IsInstanceOf(typeof (GetImage), result); }
public void GetConstructedUri_ForPlayer_MatchesExpected(string gamertag) { var query = new GetSpartanImage() .ForPlayer(gamertag); var uri = query.GetConstructedUri(); Assert.AreEqual($"profile/h5/profiles/{gamertag}/spartan{null}", uri); }
public void GetConstructedUri_Crop_MatchesExpected(Enumeration.CropType cropType) { var query = new GetSpartanImage() .Crop(cropType); var uri = query.GetConstructedUri(); Assert.AreEqual(string.Format(BaseUri, null, $"?crop={cropType}"), uri); }
public void GetConstructedUri_Size_MatchesExpected(int size) { var query = new GetSpartanImage() .Size(size); var uri = query.GetConstructedUri(); Assert.AreEqual($"profile/h5/profiles/{null}/spartan?size={size}", uri); }
public void GetConstructedUri_Crop_MatchesExpected(Enumeration.CropType cropType) { var query = new GetSpartanImage() .Crop(cropType); var uri = query.GetConstructedUri(); Assert.AreEqual($"profile/h5/profiles/{null}/spartan?crop={cropType}", uri); }
public async Task GetSpartanImage(string gamertag) { var query = new GetSpartanImage() .ForPlayer(gamertag); var result = await Global.Session.Query(query); Assert.IsInstanceOf(typeof(GetImage), result); }
public async Task GetSpartanImage_IsSerializable(string gamertag) { var query = new GetSpartanImage() .ForPlayer("Furiousn00b"); var result = await Global.Session.Query(query); SerializationUtility <GetImage> .AssertRoundTripSerializationIsPossible(result); }
public void GetConstructedUri_ForPlayer_MatchesExpected(string gamertag) { var query = new GetSpartanImage() .ForPlayer(gamertag); var uri = query.GetConstructedUri(); Assert.AreEqual(string.Format(BaseUri, gamertag, null), uri); }
public void GetConstructedUri_Size_MatchesExpected(int size) { var query = new GetSpartanImage() .Size(size); var uri = query.GetConstructedUri(); Assert.AreEqual(string.Format(BaseUri, null, $"?size={size}"), uri); }
public async Task GetSpartanImage_Crop() { var query = new GetSpartanImage() .ForPlayer("Furiousn00b") .Crop(Enumeration.CropType.Portrait); var result = await Session.Query(query); Assert.IsInstanceOf(typeof(Image), result); }
public async Task GetSpartanImage_Size(int size) { var query = new GetSpartanImage() .ForPlayer("Furiousn00b") .Size(size); var result = await Global.Session.Query(query); Assert.IsInstanceOf(typeof(GetImage), result); }
public async Task GetSpartanImage_Size(int size) { var query = new GetSpartanImage() .ForPlayer("Furiousn00b") .Size(size); var result = await Session.Query(query); Assert.IsInstanceOf(typeof(Image), result); }
public async Task GetSpartanImage_InvalidSize(int size) { var query = new GetSpartanImage() .ForPlayer("Furiousn00b") .Size(size); await Global.Session.Query(query); Assert.Fail("An exception should have been thrown"); }
public async Task GetSpartanImage_Crop() { var query = new GetSpartanImage() .ForPlayer("Furiousn00b") .Crop(Enumeration.CropType.Portrait); var result = await Global.Session.Query(query); Assert.IsInstanceOf(typeof(GetImage), result); }
public void GetConstructedUri_Complex_MatchesExpected(string gamertag, int size, Enumeration.CropType cropType) { var query = new GetSpartanImage() .ForPlayer(gamertag) .Size(size) .Crop(cropType); var uri = query.GetConstructedUri(); Assert.AreEqual($"profile/h5/profiles/{gamertag}/spartan?size={size}&crop={cropType}", uri); }
public async Task GetSpartanImage(string gamertag, int size, Enumeration.Halo5.CropType crop) { var query = new GetSpartanImage(gamertag) .Size(size) .Crop(crop) .SkipCache(); var result = await Global.Session.Query(query); Assert.IsInstanceOf(typeof(HaloImage), result); }
public async Task GetSpartanImage_IsSerializable(string gamertag, int size, Enumeration.Halo5.CropType crop) { var query = new GetSpartanImage(gamertag) .Size(size) .Crop(crop) .SkipCache(); var result = await Global.Session.Query(query); SerializationUtility <HaloImage> .AssertRoundTripSerializationIsPossible(result); }
public void GetConstructedUri_Complex_MatchesExpected(string gamertag, int size, Enumeration.CropType cropType) { var query = new GetSpartanImage() .ForPlayer(gamertag) .Size(size) .Crop(cropType); var uri = query.GetConstructedUri(); Assert.AreEqual(string.Format(BaseUri, gamertag, $"?size={size}&crop={cropType}"), uri); }
public void Uri_MatchesExpected(string gamertag, int size, Enumeration.Halo5.CropType crop) { var query = new GetSpartanImage(gamertag); Assert.AreEqual($"https://www.haloapi.com/profile/h5/profiles/{gamertag}/spartan", query.Uri); query.Size(size); Assert.AreEqual($"https://www.haloapi.com/profile/h5/profiles/{gamertag}/spartan?size={size}", query.Uri); query.Crop(crop); Assert.AreEqual($"https://www.haloapi.com/profile/h5/profiles/{gamertag}/spartan?size={size}&crop={crop}", query.Uri); }
public static void Validate(this GetSpartanImage getSpartanImage) { var validationResult = new ValidationResult(); if (!getSpartanImage.Player.IsValidGamertag()) { validationResult.Messages.Add("GetSpartanImage query requires a valid Gamertag (Player) to be set."); } if (getSpartanImage.Parameters.ContainsKey("size")) { var validSizes = new List <int> { 95, 128, 190, 256, 512 }; int size; var parsed = int.TryParse(getSpartanImage.Parameters["size"], out size); if (!parsed || !validSizes.Contains(size)) { validationResult.Messages.Add($"GetSpartanImage optional paramater 'Size' is invalid: {size}."); } } if (getSpartanImage.Parameters.ContainsKey("crop")) { var crop = getSpartanImage.Parameters["crop"]; var defined = Enum.IsDefined(typeof(Enumeration.CropType), crop); if (!defined) { validationResult.Messages.Add($"GetSpartanImage optional paramater 'Crop' is invalid: {crop}."); } } if (!validationResult.Success) { throw new ValidationException(validationResult.Messages); } }
public async Task GetSpartanImage_IsSerializable(string gamertag) { var query = new GetSpartanImage() .ForPlayer(gamertag); var result = await Global.Session.Query(query); var serializationUtility = new SerializationUtility<GetImage>(); serializationUtility.AssertRoundTripSerializationIsPossible(result); }
public async Task GetSpartanImage_InvalidGamertag(string gamertag) { var query = new GetSpartanImage() .ForPlayer(gamertag); try { await Global.Session.Query(query); Assert.Fail("An exception should have been thrown"); } catch (HaloApiException e) { Assert.AreEqual((int)Enumeration.StatusCode.BadRequest, e.HaloApiError.StatusCode); } catch (System.Exception e) { Assert.Fail("Unexpected exception of type {0} caught: {1}", e.GetType(), e.Message); } }
public async Task GetSpartanImage_IsSerializable(string gamertag) { var query = new GetSpartanImage() .ForPlayer("Furiousn00b") .SkipCache(); var result = await Global.Session.Query(query); SerializationUtility<GetImage>.AssertRoundTripSerializationIsPossible(result); }
public async Task GetSpartanImage_InvalidGamertag(string gamertag) { var query = new GetSpartanImage() .ForPlayer(gamertag); await Global.Session.Query(query); Assert.Fail("An exception should have been thrown"); }