Exemple #1
0
        public HttpResponseMessage Add(ReportComponentDto reportDto)
        {
            var handler  = new AddHandler();
            var response = handler.Handle(reportDto);

            if (handler.Errors == null || handler.Errors.Count < 1)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, response.ReportComponentDtos[0]));
            }
            return(Request.CreateResponse(HttpStatusCode.BadRequest, handler.Errors));
        }
        public async Task Add_returns_with_success_for_valid_path()
        {
            var mockFileSystem = new MockFileSystem(
                new Dictionary <string, MockFileData> {
                { "output.txt", new MockFileData("my data") }
            }
                );

            var addHandler = new AddHandler(mockFileSystem);
            await addHandler.Handle(new AddOptions()
            {
                Path = "output.txt"
            }, CancellationToken.None);
        }
        public async Task Add_throws_exception_with_invalid_path()
        {
            var mockFileSystem = new MockFileSystem(
                new Dictionary <string, MockFileData> {
                { "output.txt", new MockFileData("my data") }
            }
                );

            var addHandler = new AddHandler(mockFileSystem);

            await Should.ThrowAsync <PathForAddNotFoundException>(async() =>
            {
                await addHandler.Handle(new AddOptions()
                {
                    Path = "notfound.txt"
                }, CancellationToken.None);
            });
        }
Exemple #4
0
        public async Task AddHandler_SumsAddends()
        {
            var addends = TestHelper.GeneratePositiveNumbers();
            var request = new AddRequest
            {
                Addends = addends
            };
            var expected = 0;

            foreach (var addend in request.Addends)
            {
                expected += addend;
            }
            var handler = new AddHandler();

            var response = await handler.Handle(request, default);

            response.Sum.Should().Be(expected);
        }