public async void GetDiff_OnSuccess_ShouldReturnResponseFromResponseOK(string correlationId, DiffResponse response,
                                                                               IActionResult actionResult)
        {
            _diffService.Get(correlationId).Returns(response);
            _responseCreator.ResponseOK(response).Returns(actionResult);

            var result = await _sut.GetDiff(correlationId);

            result.Should().Be(actionResult);
        }
Esempio n. 2
0
        public void GetDiff_DataFieldsNotValid_StatusNotFound()
        {
            // Act
            var result = _ctrl.GetDiff(1).ExecuteAsync(CancellationToken.None);

            // Assert
            var statusCode = result.Result.StatusCode;

            Assert.IsTrue(statusCode == HttpStatusCode.NotFound);
        }
Esempio n. 3
0
        public void GetDiffExistingDataTest()
        {
            //Arrange
            string id   = "id";
            string data = "VGhlIGdyZWVuIGZ4IGZsaWVzIG92ZXIgdGhlIGJpZyBibHVlIGZhbmN5";

            _dataManagerMock.Setup(mock => mock.TryRetrieve($"{id}-left", string.Empty)).Returns(data);
            _dataManagerMock.Setup(mock => mock.TryRetrieve($"{id}-right", string.Empty)).Returns(data);
            _differMock.Setup(mock => mock.Diff(data, data)).Returns(new DiffResult("equal"));


            //Act
            var result = _sut.GetDiff(id);

            //Assert
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <DiffResult>));
        }
        public void PutDiff_DataFieldValid_StatusCreated()
        {
            // Arange
            var modelPutLeft = new DiffPutModel()
            {
                Data = "TGVwIHBvemRyYXYgaXogZGFsamF2IDIzNA=="
            };
            var modelPutRight = new DiffPutModel()
            {
                Data = "TGVwIHBvemRyYXYgMzU1"
            };
            var modelClean = new DiffPutModel()
            {
                Data = ""
            };

            // Act
            var cleanLeft  = _ctrl.PutDiff(999, "left", modelClean).Result.ExecuteAsync(CancellationToken.None);
            var cleanRight = _ctrl.PutDiff(999, "right", modelClean).Result.ExecuteAsync(CancellationToken.None);

            var resultLeft  = _ctrl.PutDiff(999, "left", modelPutLeft).Result.ExecuteAsync(CancellationToken.None);
            var resultRight = _ctrl.PutDiff(999, "right", modelPutRight).Result.ExecuteAsync(CancellationToken.None);

            var resultGet = _ctrl.GetDiff(999).ExecuteAsync(CancellationToken.None);

            cleanLeft  = _ctrl.PutDiff(999, "left", modelClean).Result.ExecuteAsync(CancellationToken.None);
            cleanRight = _ctrl.PutDiff(999, "right", modelClean).Result.ExecuteAsync(CancellationToken.None);

            // Assert
            var statusCodeGet = resultGet.Result.StatusCode;
            var json          = resultGet.Result.Content.ReadAsStringAsync().Result;
            var diffModel     = JsonConvert.DeserializeObject <DiffResultModel>(json);

            Assert.IsTrue(statusCodeGet == HttpStatusCode.OK);
            Assert.IsTrue(diffModel.DiffResultType == "SizeDoNotMatch");

            var statusCodeLeft  = resultLeft.Result.StatusCode;
            var statusCodeRight = resultRight.Result.StatusCode;

            Assert.IsTrue(statusCodeLeft == HttpStatusCode.Created);
            Assert.IsTrue(statusCodeRight == HttpStatusCode.Created);
        }
Esempio n. 5
0
        public void ShouldGetDiff()
        {
            var responsePost1 = _submitController.Post(Guid1, SubmitKey.Left, PostBody1).Result;

            responsePost1.StatusCode.Should().Be(HttpStatusCode.Accepted);

            var responsePost2 = _submitController.Post(Guid1, SubmitKey.Right, PostBody2).Result;

            responsePost2.StatusCode.Should().Be(HttpStatusCode.Accepted);

            Thread.Sleep(2000);

            var responseDiff = _diffController.GetDiff(Guid1);

            responseDiff.Body.Should().BeOfType <DiffRecord>();

            var diffRecord = (DiffRecord)responseDiff.Body;

            diffRecord.IsComplete.Should().BeTrue();
        }