Beispiel #1
0
        public async Task <IActionResult> CalculateDiff([FromBody] DiffRequestViewModel guid)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                DiffViewModel diff = await _diffAppService.CalculateDiff(guid.Id);

                return(Ok(diff));
            }
            catch (Exception)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Beispiel #2
0
        public async Task CalculateDiff_success()
        {
            //Arrange
            Guid fakeGuid = new Guid();
            DiffRequestViewModel fakeData = new DiffRequestViewModel()
            {
                Id = fakeGuid
            };
            DiffViewModel fakeViewModel = GetDiffViewModelFake(fakeGuid);

            _diffAppServiceMock.Setup(x => x.CalculateDiff(It.IsAny <Guid>()))
            .Returns(Task.FromResult(fakeViewModel));

            //Act
            var diffController = new DiffController(_diffAppServiceMock.Object);

            diffController.ControllerContext.HttpContext = _contextMock.Object;
            var actionResult = await diffController.CalculateDiff(fakeData);

            //Assert
            Assert.Equal((actionResult as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
            Assert.Equal((((ObjectResult)actionResult).Value as DiffViewModel).Id, fakeGuid);
        }