public async Task WhenPostThenStoreFile() { var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api1/otfs"); var content = GetAsStrem("[BOF]" + Environment.NewLine); request.Content = new StreamContent(content); request.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain"); request.Content.Headers.ContentLength = content.Length; var storeCalled = false; Action <string, Stream> assertAction = (stationName, stream) => { stationName.Should().Be("Centenario"); stream.Should().Not.Be.Null(); storeCalled = true; }; IStationFileStore fileStore = new StationFileStoreActionMock(assertAction); OtfsController controller = new OtfsController(fileStore, new EnqueuerMock <StationFileToProcess>()); controller.Request = request; controller.Configuration = new HttpConfiguration(); await controller.Post("Centenario"); storeCalled.Should().Be.True(); }
public async Task WhenPostNoPlainTextThenUnsupportedMediaType() { var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api1/otfs"); request.Content = new StreamContent(new MemoryStream()); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); OtfsController controller = GetController(); controller.Request = request; controller.Configuration = new HttpConfiguration(); var response = await controller.Post("Centenario"); response.StatusCode.Should().Be(HttpStatusCode.UnsupportedMediaType); }
public async Task WhenPostNoSizeThenBadResquest() { var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api1/otfs"); request.Content = new StreamContent(GetAsStrem("")); request.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain"); request.Content.Headers.ContentLength = 0; OtfsController controller = GetController(); controller.Request = request; controller.Configuration = new HttpConfiguration(); var response = await controller.Post("Centenario"); response.StatusCode.Should().Be(HttpStatusCode.BadRequest); }
public async Task WhenFileConContentThenAcceptd() { var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api1/otfs"); var content = GetAsStrem("[BOF]" + Environment.NewLine); request.Content = new StreamContent(content); request.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain"); request.Content.Headers.ContentLength = content.Length; OtfsController controller = GetController(); controller.Request = request; controller.Configuration = new HttpConfiguration(); var response = await controller.Post("Centenario"); response.StatusCode.Should().Be(HttpStatusCode.Accepted); }
public async Task WhenPostThenEnqueueFileToProcess() { var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api1/otfs"); var content = GetAsStrem("[BOF]" + Environment.NewLine); request.Content = new StreamContent(content); request.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain"); request.Content.Headers.ContentLength = content.Length; var enqueuer = new EnqueuerMock <StationFileToProcess>(); OtfsController controller = new OtfsController(new NoOpStationFileStore("centenario/piiza.txt"), enqueuer); controller.Request = request; controller.Configuration = new HttpConfiguration(); await controller.Post("Centenario"); var actual = enqueuer.Messages.First(); actual.FilePath.Should().Be("centenario/piiza.txt"); actual.StationId.Should().Be("Centenario"); actual.RecivedAt.Should().Not.Be(DateTimeOffset.MinValue); }