public async Task When_uploading_a_file_that_is_not_a_zip()
        {
            var client    = new MemoryBlobClient();
            var store     = new InMemoryStreamStore();
            var validator = new ZipArchiveValidator(Encoding.UTF8);
            var resolver  = Resolve.WhenEqualToMessage(
                new RoadNetworkChangesArchiveCommandModule(
                    client,
                    store,
                    new FakeRoadNetworkSnapshotReader(),
                    validator,
                    SystemClock.Instance
                    )
                );
            var controller = new UploadController(
                Dispatch.Using(resolver),
                client)
            {
                ControllerContext = new ControllerContext {
                    HttpContext = new DefaultHttpContext()
                }
            };
            var formFile = new FormFile(new MemoryStream(), 0L, 0L, "name", "name")
            {
                Headers = new HeaderDictionary(new Dictionary <string, StringValues>
                {
                    { "Content-Type", StringValues.Concat(StringValues.Empty, "application/octet-stream") }
                })
            };
            var result = await controller.Post(formFile);

            Assert.IsType <UnsupportedMediaTypeResult>(result);
        }
        public async Task When_uploading_a_file_that_is_a_zip()
        {
            var client    = new MemoryBlobClient();
            var store     = new InMemoryStreamStore();
            var validator = new ZipArchiveValidator(Encoding.UTF8);
            var resolver  = Resolve.WhenEqualToMessage(
                new RoadNetworkChangesArchiveCommandModule(
                    client,
                    store,
                    new FakeRoadNetworkSnapshotReader(),
                    validator,
                    SystemClock.Instance
                    )
                );
            var controller = new UploadController(Dispatch.Using(resolver),
                                                  client)
            {
                ControllerContext = new ControllerContext {
                    HttpContext = new DefaultHttpContext()
                }
            };

            using (var sourceStream = new MemoryStream())
            {
                using (var archive = new ZipArchive(sourceStream, ZipArchiveMode.Create, true, Encoding.UTF8))
                {
                    var entry = archive.CreateEntry("entry");
                    using (var entryStream = entry.Open())
                    {
                        entryStream.Write(new byte[] { 1, 2, 3, 4 });
                        entryStream.Flush();
                    }
                }

                sourceStream.Position = 0;

                var formFile = new FormFile(sourceStream, 0L, sourceStream.Length, "name", "name")
                {
                    Headers = new HeaderDictionary(new Dictionary <string, StringValues>
                    {
                        { "Content-Type", StringValues.Concat(StringValues.Empty, "application/zip") }
                    })
                };
                var result = await controller.Post(formFile);

                Assert.IsType <OkResult>(result);

                var page = await store.ReadAllForwards(Position.Start, 1, true);

                var message = Assert.Single(page.Messages);
                Assert.Equal(nameof(Messages.RoadNetworkChangesArchiveUploaded), message.Type);
                var uploaded =
                    JsonConvert.DeserializeObject <Messages.RoadNetworkChangesArchiveUploaded>(
                        await message.GetJsonData());

                Assert.True(await client.BlobExistsAsync(new BlobName(uploaded.ArchiveId)));
                var blob = await client.GetBlobAsync(new BlobName(uploaded.ArchiveId));

                using (var openStream = await blob.OpenAsync())
                {
                    var resultStream = new MemoryStream();
                    openStream.CopyTo(resultStream);
                    resultStream.Position = 0;
                    sourceStream.Position = 0;
                    Assert.Equal(sourceStream.ToArray(), resultStream.ToArray());
                }
            }
        }