public static GameModel MapToModel(this GameModelResource game) { return(new GameModel( game.Player1.Name, game.Player2.Name, game.ThrowHistory.Select(x => (x.Value, x.Multiplier, x.Player)).ToList(), game.Id)); }
public void GameModelResourceMapper_CanMapThrowHistory() { var resource = new GameModelResource { HasWinner = false, Id = "123456", Player1 = new PlayerResource { IsWinner = false, Name = "Jack", Score = 0 }, Player2 = new PlayerResource { IsWinner = false, Name = "Kevin", Score = 0 }, ThrowHistory = new List <DartThrowResource> { new DartThrowResource { Multiplier = 2, Value = 20, Player = "Jack" }, new DartThrowResource { Multiplier = 3, Value = 17, Player = "Jack" } } }; var model = GameModelResourceMapper.MapToModel(resource); model.ThrowHistory.Count.Should().Be(resource.ThrowHistory.Count); }
public async Task Execute(GameModelResource game) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_blobStorageSettings.ConnecitonString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(_blobStorageSettings.GameContainer); CloudBlockBlob blob = container.GetBlockBlobReference($"{game.Id}.json"); blob.Properties.ContentType = "application/json"; using (Stream uploadStream = new MemoryStream()) { void LoadStreamWithJson(Stream streamToLoad) { StreamWriter writer = new StreamWriter(streamToLoad); writer.Write(JsonSerializer.Serialize(game)); writer.Flush(); streamToLoad.Position = 0; } LoadStreamWithJson(uploadStream); await blob.UploadFromStreamAsync(uploadStream).ConfigureAwait(false); } }