Пример #1
0
        private async Task <IActionResult> PostLeft()
        {
            var controller = new DiffController(_mediator.Object);
            var result     = await controller.PostLeft(_id, _json);

            _mediator.Verify(_mediatorSendRequest, Times.Once);
            return(result);
        }
Пример #2
0
        public void ShouldNotSaveLeft()
        {
            var e = new Entity()
            {
                Id = 700
            };
            var ctrl = new DiffController();
            var res  = ctrl.PostLeft(e.Id, e) as BadRequestObjectResult;

            Assert.AreEqual(400, res.StatusCode);
        }
Пример #3
0
        public async Task PostLeftReturnsBadRequestResultWhenModelIsInvalid()
        {
            var service = Substitute.For <IDifferenceService>();

            var controller = new DiffController(service);

            controller.ModelState.AddModelError("error", "some error");

            var result = await controller.PostLeft(10, new SourceContentRequest());

            result.Should().BeOfType <BadRequestResult>();
        }
Пример #4
0
        public async Task PostLeftReturnsBadRequestResultWhenModelDataIsNotBase64()
        {
            var service = Substitute.For <IDifferenceService>();
            var request = new SourceContentRequest
            {
                Data = "__."
            };

            var controller = new DiffController(service);
            var result     = await controller.PostLeft(10, request);

            result.Should().BeOfType <BadRequestResult>();
        }
Пример #5
0
        public void ShouldGetEntityLeft()
        {
            var e = new Entity()
            {
                Id = 800, Left = left
            };
            var controller = new DiffController();

            controller.PostLeft(e.Id, e);
            var res = controller.GetLeft(e.Id).Value;

            Assert.AreEqual(e.Left, res);
        }
Пример #6
0
        public void ShouldSaveLeft()
        {
            var e = new Entity()
            {
                Id = 500, Left = left
            };

            e.Id = new Random().Next(20, 30);
            var ctrl = new DiffController();
            var res  = ctrl.PostLeft(e.Id, e) as OkObjectResult;

            Assert.AreEqual(200, res.StatusCode);
        }
Пример #7
0
        public async Task PostLeftAddsSourceForGivenDiff(int diffId)
        {
            var data    = new byte[] { 1, 2, 3 };
            var service = Substitute.For <IDifferenceService>();
            var request = new SourceContentRequest
            {
                Data = Convert.ToBase64String(data)
            };

            var controller = new DiffController(service);
            var result     = await controller.PostLeft(diffId, request);

            result.Should().BeOfType <OkResult>();
            await service.Received().AddSourceAsync(diffId, Arg.Is <SourceContent>(
                                                        c => c.SourceSide == SourceSide.Left && c.Data.SequenceEqual(data)));
        }
Пример #8
0
        public void PostCorrectDataTest()
        {
            //Arrange
            string id = "1";

            _dataManagerMock.Setup(mock => mock.Add(id + "-left", _img1));

            //Act
            var response = _sut.PostLeft(id, new DiffRequest()
            {
                Data = _img1
            });

            //Assert
            Assert.IsInstanceOfType(response, typeof(CreatedNegotiatedContentResult <string>));
        }