コード例 #1
0
ファイル: AtomsController.cs プロジェクト: alex-ks/Ecclesia
        public async Task <IActionResult> Get([FromQuery] string atoms)
        {
            try
            {
                var reqJson    = HttpUtility.UrlDecode(Encoding.UTF8.GetBytes(atoms), Encoding.UTF8);
                var givenAtoms = JsonConvert
                                 .DeserializeObject <IEnumerable <AtomIdArgument> >(reqJson)
                                 .Select(atom => new AtomId(atom.Kind, atom.Name, atom.Version));

                var allAtoms = await _resolver.ResolveAsync(givenAtoms);

                var contents = await Task.WhenAll(allAtoms.Select(atom => _storage.GetContentAsync(atom)));

                var result = from pair in Enumerable.Zip(allAtoms, contents, (atom, content) => (atom, content))
                             select new AtomContent
                {
                    Kind    = pair.atom.Kind,
                    Name    = pair.atom.Name,
                    Version = pair.atom.Version,
                    Content = Convert.ToBase64String(pair.content)
                };
                return(Ok(result));
            }
            catch (ArgumentException e)
            {
                return(NotFound(e.Message));
            }
            catch (FormatException e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #2
0
ファイル: StorageTest.cs プロジェクト: alex-ks/Ecclesia
        public async Task VersionWildcard_GetContent_LastContentGot()
        {
            // Given
            var context = InitContext();

            var contentString = "Hello, world!";
            var content       = Encoding.UTF8.GetBytes(contentString);

            var    atomId  = new AtomId("PlainText", "Hello");
            string version = "1.0.1";

            var dbAtom = new Atom
            {
                Kind    = atomId.Kind,
                Name    = atomId.Name,
                Version = version
            };

            dbAtom.Content = new AtomContent
            {
                Atom    = dbAtom,
                Content = content
            };

            context.Atoms.Add(dbAtom);
            context.SaveChanges();

            // When
            using (var storage = new AtomStorage(context))
            {
                var str = Encoding.UTF8.GetString(await storage.GetContentAsync(atomId));
                // Then
                Assert.Equal(contentString, str);
            }
        }