Esempio n. 1
0
        public async Task PostDiffDataShouldUpdateRightDataWhenLeftDataAlreadyExists()
        {
            // Arrange
            var someValidId = int.MaxValue;

            // Act
            IHttpActionResult insertLeftResponse = await _diffController.PostLeftDiffData(someValidId, _leftBase64StringValidData);

            IHttpActionResult updatedRightResponse = await _diffController.PostRightDiffData(someValidId, _rightBase64StringValidData);

            // Assert
            Assert.IsInstanceOfType(insertLeftResponse, typeof(OkResult));
            Assert.IsInstanceOfType(updatedRightResponse, typeof(OkResult));

            // Only the updated record should be present.
            Assert.AreEqual(1, _repository.DiffDataCount());

            InMemoryDiffData savedData = _repository.GetById(someValidId);

            // The record in db should be retrieved with the provided id via API call.
            Assert.IsNotNull(savedData);

            // The left and the right data should be populated.
            // The first API call will create the record and the second API call will update the same record.
            Assert.IsTrue(_leftValidData.SequenceEqual(savedData.Left));
            Assert.IsTrue(_rightValidData.SequenceEqual(savedData.Right));
        }
Esempio n. 2
0
        public async Task PostRightDiffDataShouldReturnStatusCodeOkWhenNoErrorsOccurs()
        {
            // Arrange
            var someValidId    = int.MaxValue;
            var diffController = new DiffController(_defaultRepositoryMock.Object, _defaultDiffAnalyserMock.Object, _defaultMapperMock.Object);

            // Act
            IHttpActionResult result = await diffController.PostRightDiffData(someValidId, _validBase64string);

            // Assert
            Assert.IsInstanceOfType(result, typeof(OkResult));
        }
Esempio n. 3
0
        public async Task PostRightDiffDataShouldReturnInternalServerErrorWhenSomeUnexpectedErrorsOccurs()
        {
            // Arrange
            var someValidId    = int.MaxValue;
            var repositoryMock = new Mock <IDiffRepositoryManager>();

            repositoryMock
            .Setup(r => r.Save(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <DiffItemType>()))
            .ThrowsAsync(new Exception());

            var diffController = new DiffController(repositoryMock.Object, _defaultDiffAnalyserMock.Object, _defaultMapperMock.Object);

            // Act
            IHttpActionResult result = await diffController.PostRightDiffData(someValidId, _validBase64string);

            // Assert
            Assert.IsInstanceOfType(result, typeof(InternalServerErrorResult));
        }